Skip to content

Commit

Permalink
Fix all (non-deprecation) compiler warnings (VazkiiMods#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alwinfy authored Jun 6, 2020
1 parent 2c9ceb0 commit da9aec4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package vazkii.patchouli.client.book;

import com.google.common.collect.Streams;

import java.util.stream.Stream;

public abstract class AbstractReadStateHolder {
Expand All @@ -24,8 +22,7 @@ public void markReadStateDirty() {

protected abstract EntryDisplayState computeReadState();

public static EntryDisplayState mostImportantState(Stream<EntryDisplayState>... streams) {
Stream<EntryDisplayState> stream = Streams.concat(streams);
public static EntryDisplayState mostImportantState(Stream<EntryDisplayState> stream) {
return EntryDisplayState.fromOrdinal(stream.mapToInt(EntryDisplayState::ordinal).min().orElse(EntryDisplayState.DEFAULT_TYPE.ordinal()));
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/patchouli/client/book/BookCategory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vazkii.patchouli.client.book;

import com.google.common.collect.Streams;
import com.google.gson.annotations.SerializedName;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -182,7 +183,7 @@ public boolean isExtension() {
protected EntryDisplayState computeReadState() {
Stream<EntryDisplayState> entryStream = entries.stream().filter(e -> !e.isLocked()).map(BookEntry::getReadState);
Stream<EntryDisplayState> childrenStream = children.stream().map(BookCategory::getReadState);
return mostImportantState(entryStream, childrenStream);
return mostImportantState(Streams.concat(entryStream, childrenStream));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class GuiBookCategory extends GuiBookEntryList {

Expand Down Expand Up @@ -66,6 +67,11 @@ public boolean equals(Object obj) {
return obj == this || (obj instanceof GuiBookCategory && ((GuiBookCategory) obj).category == category && ((GuiBookCategory) obj).spread == spread);
}

@Override
public int hashCode() {
return Objects.hashCode(category) * 31 + Objects.hashCode(spread);
}

@Override
public boolean canBeOpened() {
return !category.isLocked() && !equals(Minecraft.getInstance().currentScreen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class GuiBookEntry extends GuiBook implements IComponentRenderContext {
Expand Down Expand Up @@ -163,6 +164,11 @@ public boolean equals(Object obj) {
return obj == this || (obj instanceof GuiBookEntry && ((GuiBookEntry) obj).entry == entry && ((GuiBookEntry) obj).spread == spread);
}

@Override
public int hashCode() {
return Objects.hashCode(entry) * 31 + Objects.hashCode(spread);
}

@Override
public boolean canBeOpened() {
return !entry.isLocked() && !equals(Minecraft.getInstance().currentScreen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public PageDoubleRecipeRegistry(IRecipeType<T> recipeType) {
@Nullable
private T getRecipe(ResourceLocation id) {
RecipeManager manager = Minecraft.getInstance().world.getRecipeManager();
Map<ResourceLocation, T> recipes = Collections.emptyMap();
try {
recipes = (Map<ResourceLocation, T>) GET_RECIPE_MAP.invoke(manager, recipeType);
@SuppressWarnings("unchecked")
Map<ResourceLocation, T> recipes = (Map<ResourceLocation, T>) GET_RECIPE_MAP.invoke(manager, recipeType);
return recipes.get(id);
} catch (IllegalAccessException | InvocationTargetException e) {
Patchouli.LOGGER.error("Failed to get recipe map", e);
return null;
}
return recipes.get(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static BookTemplate createTemplate(Book book, String type, @Nullable Temp
return template;
}

public void compile(IVariableProvider variables) {
public void compile(IVariableProvider<String> variables) {
if (compiled) {
return;
}
Expand All @@ -90,7 +90,7 @@ public void compile(IVariableProvider variables) {
components.removeIf(Objects::isNull);

if (processor != null) {
IVariableProvider processorVars = variables;
IVariableProvider<String> processorVars = variables;
if (encapsulation != null) {
processorVars = encapsulation.wrapProvider(variables);
}
Expand Down

0 comments on commit da9aec4

Please sign in to comment.