From 0cc101e5cb57e62674abe421983444f79ea630fc Mon Sep 17 00:00:00 2001 From: Danielshe Date: Wed, 6 Nov 2019 21:40:11 +0800 Subject: 3.2.6 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 6 +- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 1 - .../java/me/shedaniel/rei/api/ConfigManager.java | 5 + .../java/me/shedaniel/rei/api/DisplayHelper.java | 4 + .../java/me/shedaniel/rei/api/EntryRegistry.java | 6 + src/main/java/me/shedaniel/rei/api/EntryStack.java | 15 +- .../java/me/shedaniel/rei/api/REIPluginEntry.java | 6 + .../java/me/shedaniel/rei/api/RecipeCategory.java | 2 +- .../me/shedaniel/rei/api/plugins/REIPluginV0.java | 11 +- .../rei/gui/entries/SimpleRecipeEntry.java | 156 ++++++++++++++++++++ .../rei/gui/renderers/SimpleRecipeEntry.java | 157 --------------------- .../me/shedaniel/rei/impl/FluidEntryStack.java | 13 +- .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 34 ++++- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 46 ++++-- .../rei/plugin/brewing/DefaultBrewingDisplay.java | 7 - .../rei/plugin/cooking/DefaultCookingCategory.java | 2 +- .../rei/plugin/crafting/DefaultShapedDisplay.java | 9 +- .../plugin/crafting/DefaultShapelessDisplay.java | 9 +- 18 files changed, 278 insertions(+), 211 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeEntry.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index dc65ed688..05588262e 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -61,24 +61,28 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl(); private static final Map plugins = Maps.newHashMap(); private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes")); - private static ConfigManagerImpl configManager; + private static ConfigManager configManager; static { LOGGER = LogManager.getFormatterLogger("REI"); } + @Deprecated public static RecipeHelper getRecipeHelper() { return RECIPE_HELPER; } + @Deprecated public static ConfigManager getConfigManager() { return configManager; } + @Deprecated public static EntryRegistry getEntryRegistry() { return ENTRY_REGISTRY; } + @Deprecated public static DisplayHelper getDisplayHelper() { return DISPLAY_HELPER; } diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 26b96e243..9369dc1be 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -100,7 +100,6 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { } catch (Exception e) { e.printStackTrace(); } - // } }); FabricLoader.getInstance().getEntrypoints("rei_containers", Runnable.class).forEach(Runnable::run); } diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index e64d5df55..bd9ea38cb 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -5,6 +5,7 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.zeroeightsix.fiber.exception.FiberException; import net.minecraft.client.gui.screen.Screen; @@ -12,6 +13,10 @@ import java.io.IOException; public interface ConfigManager { + static ConfigManager getInstance() { + return RoughlyEnoughItemsCore.getConfigManager(); + } + /** * Saves the config. * diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 2fe8be295..be6ed6a2f 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -16,6 +16,10 @@ import static net.minecraft.util.ActionResult.PASS; public interface DisplayHelper { + static DisplayHelper getInstance() { + return RoughlyEnoughItemsCore.getDisplayHelper(); + } + /** * Gets the sorted version of all responsible bounds handlers * diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index 338986578..03cf0c21e 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -5,6 +5,8 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -13,6 +15,10 @@ import java.util.List; public interface EntryRegistry { + static EntryRegistry getInstance() { + return RoughlyEnoughItemsCore.getEntryRegistry(); + } + /** * Gets the current modifiable stacks list * diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 01fc901b4..905540d56 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -11,6 +11,7 @@ import me.shedaniel.rei.impl.EmptyEntryStack; import me.shedaniel.rei.impl.FluidEntryStack; import me.shedaniel.rei.impl.ItemEntryStack; import net.minecraft.block.Block; +import net.minecraft.client.resource.language.I18n; import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; @@ -31,7 +32,7 @@ public interface EntryStack { } static EntryStack create(Fluid fluid) { - return create(fluid, 1000); + return new FluidEntryStack(fluid); } static EntryStack create(Fluid fluid, int amount) { @@ -46,10 +47,6 @@ public interface EntryStack { return new ItemEntryStack(new ItemStack(item)); } - static EntryStack create(Block block) { - return new ItemEntryStack(new ItemStack(block)); - } - Optional getIdentifier(); EntryStack.Type getType(); @@ -144,5 +141,13 @@ public interface EntryStack { private Item() { } } + + public static class Fluid { + // Return null to disable + public static final Settings> AMOUNT_TOOLTIP = new Settings>(stack -> I18n.translate("tooltip.rei.fluid_amount", stack.getAmount())); + + private Fluid() { + } + } } } diff --git a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java index 8651c6751..cdc5574cf 100644 --- a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java +++ b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java @@ -5,6 +5,8 @@ package me.shedaniel.rei.api; +import net.fabricmc.loader.api.SemanticVersion; +import net.fabricmc.loader.util.version.VersionParsingException; import net.minecraft.util.Identifier; /** @@ -12,6 +14,10 @@ import net.minecraft.util.Identifier; */ public interface REIPluginEntry { + default SemanticVersion getMinimumVersion() throws VersionParsingException { + return null; + } + /** * Gets the priority of the plugin. * diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 82ed70eca..f212a3db2 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -8,7 +8,7 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.renderers.SimpleRecipeEntry; +import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; diff --git a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java index 22ad3af01..1c4a5c2a4 100644 --- a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java +++ b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java @@ -9,16 +9,17 @@ import me.shedaniel.rei.api.DisplayHelper; import me.shedaniel.rei.api.EntryRegistry; import me.shedaniel.rei.api.REIPluginEntry; import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import net.fabricmc.loader.api.SemanticVersion; import net.fabricmc.loader.util.version.VersionParsingException; public interface REIPluginV0 extends REIPluginEntry { - SemanticVersion getMinimumVersion() throws VersionParsingException; - /** * On register of the plugin */ + @ToBeRemoved + @Deprecated default void onFirstLoad() { } @@ -62,4 +63,10 @@ public interface REIPluginV0 extends REIPluginEntry { default void registerOthers(RecipeHelper recipeHelper) { } + default void preRegister() { + } + + default void postRegister() { + } + } diff --git a/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java b/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java new file mode 100644 index 000000000..97d5aab97 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java @@ -0,0 +1,156 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.entries; + +import com.google.common.collect.Lists; +import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.gui.widget.EntryWidget; +import me.shedaniel.rei.gui.widget.QueuedTooltip; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.Pair; +import net.minecraft.util.math.MathHelper; + +import javax.annotation.Nullable; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class SimpleRecipeEntry extends RecipeEntry { + + private static final Comparator ENTRY_COMPARATOR = (o1, o2) -> { + if (o1.getType() == EntryStack.Type.FLUID) { + if (o2.getType() == EntryStack.Type.ITEM) + return -1; + return o1.getFluid().hashCode() - o2.getFluid().hashCode(); + } else if (o2.getType() == EntryStack.Type.FLUID) { + if (o1.getType() == EntryStack.Type.ITEM) + return 1; + return o1.getFluid().hashCode() - o2.getFluid().hashCode(); + } + ItemStack i1 = o1.getItemStack(); + ItemStack i2 = o2.getItemStack(); + if (i1.getItem() == i2.getItem()) { + if (i1.getCount() != i2.getCount()) + return i1.getCount() - i2.getCount(); + int compare = Boolean.compare(i1.hasTag(), i2.hasTag()); + if (compare != 0) + return compare; + if (i1.getTag().getSize() != i2.getTag().getSize()) + return i1.getTag().getSize() - i2.getTag().getSize(); + return i1.getTag().hashCode() - i2.getTag().hashCode(); + } + return i1.getItem().hashCode() - i2.getItem().hashCode(); + }; + private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + private List inputWidgets; + private EntryWidget outputWidget; + + protected SimpleRecipeEntry(List> input, List output) { + List, AtomicInteger>> newList = Lists.newArrayList(); + List, Integer>> a = input.stream().map(stacks -> new Pair<>(stacks, stacks.stream().map(EntryStack::getAmount).max(Integer::compareTo).orElse(1))).collect(Collectors.toList()); + for (Pair, Integer> pair : a) { + Optional, AtomicInteger>> any = newList.stream().filter(pairr -> equalsList(pair.getLeft(), pairr.getLeft())).findAny(); + if (any.isPresent()) { + any.get().getRight().addAndGet(pair.getRight()); + } else + newList.add(new Pair<>(pair.getLeft(), new AtomicInteger(pair.getRight()))); + } + List> b = Lists.newArrayList(); + for (Pair, AtomicInteger> pair : newList) + b.add(pair.getLeft().stream().map(stack -> { + EntryStack s = stack.copy(); + s.setAmount(pair.getRight().get()); + return s; + }).collect(Collectors.toList())); + this.inputWidgets = b.stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> { + return EntryWidget.create(0, 0).entries(stacks).noBackground().noHighlight().noTooltips(); + }).collect(Collectors.toList()); + this.outputWidget = EntryWidget.create(0, 0).entries(CollectionUtils.filter(output, stack -> !stack.isEmpty())).noBackground().noHighlight().noTooltips(); + } + + public static RecipeEntry create(Supplier>> input, Supplier> output) { + return create(input.get(), output.get()); + } + + public static RecipeEntry create(List> input, List output) { + return new SimpleRecipeEntry(input, output); + } + + public static boolean equalsList(List list_1, List list_2) { + List stacks_1 = list_1.stream().distinct().sorted(ENTRY_COMPARATOR).collect(Collectors.toList()); + List stacks_2 = list_2.stream().distinct().sorted(ENTRY_COMPARATOR).collect(Collectors.toList()); + if (stacks_1.equals(stacks_2)) + return true; + if (stacks_1.size() != stacks_2.size()) + return false; + for (int i = 0; i < stacks_1.size(); i++) + if (!stacks_1.get(i).equalsIgnoreTagsAndAmount(stacks_2.get(i))) + return false; + return true; + } + + @Override + public void render(Rectangle bounds, int mouseX, int mouseY, float delta) { + int xx = bounds.x + 4, yy = bounds.y + 2; + int j = 0; + int itemsPerLine = getItemsPerLine(); + for (EntryWidget entryWidget : inputWidgets) { + entryWidget.setZ(getZ() + 50); + entryWidget.getBounds().setLocation(xx, yy); + entryWidget.render(mouseX, mouseY, delta); + xx += 18; + j++; + if (j >= getItemsPerLine() - 2) { + yy += 18; + xx = bounds.x + 4; + j = 0; + } + } + xx = bounds.x + 4 + 18 * (getItemsPerLine() - 2); + yy = bounds.y + getHeight() / 2 - 8; + GuiLighting.disable(); + MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + blit(xx, yy, 0, 28, 18, 18); + xx += 18; + outputWidget.setZ(getZ() + 50); + outputWidget.getBounds().setLocation(xx, yy); + outputWidget.render(mouseX, mouseY, delta); + } + + @Nullable + @Override + public QueuedTooltip getTooltip(int mouseX, int mouseY) { + for (EntryWidget widget : inputWidgets) { + if (widget.containsMouse(mouseX, mouseY)) + return widget.getCurrentTooltip(mouseX, mouseY); + } + if (outputWidget.containsMouse(mouseX, mouseY)) + return outputWidget.getCurrentTooltip(mouseX, mouseY); + return null; + } + + @Override + public int getHeight() { + return 4 + getItemsHeight() * 18; + } + + public int getItemsHeight() { + return MathHelper.ceil(((float) inputWidgets.size()) / (getItemsPerLine() - 2)); + } + + public int getItemsPerLine() { + return MathHelper.floor((getWidth() - 4f) / 18f); + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeEntry.java b/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeEntry.java deleted file mode 100644 index c0682b226..000000000 --- a/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeEntry.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.gui.renderers; - -import com.google.common.collect.Lists; -import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.widget.EntryWidget; -import me.shedaniel.rei.gui.widget.QueuedTooltip; -import me.shedaniel.rei.utils.CollectionUtils; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.GuiLighting; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; -import net.minecraft.util.math.MathHelper; - -import javax.annotation.Nullable; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -public class SimpleRecipeEntry extends RecipeEntry { - - private static final Comparator ENTRY_COMPARATOR = (o1, o2) -> { - if (o1.getType() == EntryStack.Type.FLUID) { - if (o2.getType() == EntryStack.Type.ITEM) - return -1; - return o1.getFluid().hashCode() - o2.getFluid().hashCode(); - } else if (o2.getType() == EntryStack.Type.FLUID) { - if (o1.getType() == EntryStack.Type.ITEM) - return 1; - return o1.getFluid().hashCode() - o2.getFluid().hashCode(); - } - ItemStack i1 = o1.getItemStack(); - ItemStack i2 = o2.getItemStack(); - if (i1.getItem() == i2.getItem()) { - if (i1.getCount() != i2.getCount()) - return i1.getCount() - i2.getCount(); - int compare = Boolean.compare(i1.hasTag(), i2.hasTag()); - if (compare != 0) - return compare; - if (i1.getTag().getSize() != i2.getTag().getSize()) - return i1.getTag().getSize() - i2.getTag().getSize(); - return i1.getTag().hashCode() - i2.getTag().hashCode(); - } - return i1.getItem().hashCode() - i2.getItem().hashCode(); - }; - private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); - private List inputWidgets; - private EntryWidget outputWidget; - - protected SimpleRecipeEntry(List> input, List output) { - List, AtomicInteger>> newList = Lists.newArrayList(); - List, Integer>> a = input.stream().map(stacks -> new Pair<>(stacks, stacks.stream().map(EntryStack::getAmount).max(Integer::compareTo).orElse(1))).collect(Collectors.toList()); - for (Pair, Integer> pair : a) { - Optional, AtomicInteger>> any = newList.stream().filter(pairr -> equalsList(pair.getLeft(), pairr.getLeft())).findAny(); - if (any.isPresent()) { - any.get().getRight().addAndGet(pair.getRight()); - } else - newList.add(new Pair<>(pair.getLeft(), new AtomicInteger(pair.getRight()))); - } - List> b = Lists.newArrayList(); - for (Pair, AtomicInteger> pair : newList) - b.add(pair.getLeft().stream().map(stack -> { - EntryStack s = stack.copy(); - s.setAmount(pair.getRight().get()); - return s; - }).collect(Collectors.toList())); - this.inputWidgets = b.stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> { - return EntryWidget.create(0, 0).entries(stacks).noBackground().noHighlight().noTooltips(); - }).collect(Collectors.toList()); - this.outputWidget = EntryWidget.create(0, 0).entries(CollectionUtils.filter(output, stack -> !stack.isEmpty())).noBackground().noHighlight().noTooltips(); - } - - public static RecipeEntry create(Supplier>> input, Supplier> output) { - return create(input.get(), output.get()); - } - - public static RecipeEntry create(List> input, List output) { - return new SimpleRecipeEntry(input, output); - } - - public static boolean equalsList(List list_1, List list_2) { - List stacks_1 = list_1.stream().distinct().sorted(ENTRY_COMPARATOR).collect(Collectors.toList()); - List stacks_2 = list_2.stream().distinct().sorted(ENTRY_COMPARATOR).collect(Collectors.toList()); - if (stacks_1.equals(stacks_2)) - return true; - if (stacks_1.size() != stacks_2.size()) - return false; - for (int i = 0; i < stacks_1.size(); i++) - if (!stacks_1.get(i).equalsIgnoreTagsAndAmount(stacks_2.get(i))) - return false; - return true; - } - - @Override - public void render(Rectangle bounds, int mouseX, int mouseY, float delta) { - int xx = bounds.x + 4, yy = bounds.y + 2; - int j = 0; - int itemsPerLine = getItemsPerLine(); - for (EntryWidget entryWidget : inputWidgets) { - entryWidget.setZ(getZ() + 50); - entryWidget.getBounds().setLocation(xx, yy); - entryWidget.render(mouseX, mouseY, delta); - xx += 18; - j++; - if (j >= getItemsPerLine() - 2) { - yy += 18; - xx = bounds.x + 4; - j = 0; - } - } - xx = bounds.x + 4 + 18 * (getItemsPerLine() - 2); - yy = bounds.y + getHeight() / 2 - 8; - GuiLighting.disable(); - MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); - blit(xx, yy, 0, 28, 18, 18); - xx += 18; - outputWidget.setZ(getZ() + 50); - outputWidget.getBounds().setLocation(xx, yy); - outputWidget.render(mouseX, mouseY, delta); - } - - @Nullable - @Override - public QueuedTooltip getTooltip(int mouseX, int mouseY) { - for (EntryWidget widget : inputWidgets) { - if (widget.containsMouse(mouseX, mouseY)) - return widget.getCurrentTooltip(mouseX, mouseY); - } - if (outputWidget.containsMouse(mouseX, mouseY)) - return outputWidget.getCurrentTooltip(mouseX, mouseY); - return null; - } - - @Override - public int getHeight() { - return 4 + getItemsHeight() * 18; - } - - public int getItemsHeight() { - return MathHelper.ceil(((float) inputWidgets.size()) / (getItemsPerLine() - 2)); - } - - public int getItemsPerLine() { - return MathHelper.floor((getWidth() - 4f) / 18f); - } - -} diff --git a/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java b/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java index 816ec4d47..c9583dae7 100644 --- a/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java +++ b/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java @@ -37,9 +37,14 @@ import java.util.Optional; @Deprecated public class FluidEntryStack extends AbstractEntryStack { private static final Map> FLUID_SPRITE_CACHE = new HashMap<>(); + private static final int EMPTY_AMOUNT = -1319182373; private Fluid fluid; private int amount; + public FluidEntryStack(Fluid fluid) { + this(fluid, EMPTY_AMOUNT); + } + public FluidEntryStack(Fluid fluid, int amount) { this.fluid = fluid; this.amount = amount; @@ -79,7 +84,7 @@ public class FluidEntryStack extends AbstractEntryStack { @Override public void setAmount(int amount) { - this.amount = Math.max(amount, 0); + this.amount = amount == EMPTY_AMOUNT ? EMPTY_AMOUNT : Math.max(amount, 0); if (isEmpty()) { fluid = Fluids.EMPTY; } @@ -87,7 +92,7 @@ public class FluidEntryStack extends AbstractEntryStack { @Override public boolean isEmpty() { - return amount <= 0 || fluid == Fluids.EMPTY; + return (amount != EMPTY_AMOUNT && amount <= 0) || fluid == Fluids.EMPTY; } @Override @@ -138,6 +143,10 @@ public class FluidEntryStack extends AbstractEntryStack { if (!getSetting(Settings.TOOLTIP_ENABLED).value().get() || isEmpty()) return null; List toolTip = Lists.newArrayList(EntryListWidget.tryGetEntryStackName(this)); + if (amount >= 0) { + String amountTooltip = getSetting(Settings.Fluid.AMOUNT_TOOLTIP).value().apply(this); + if (amountTooltip != null) for (String s : amountTooltip.split("\n")) toolTip.add(s); + } toolTip.addAll(getSetting(Settings.TOOLTIP_APPEND_EXTRA).value().apply(this)); if (getSetting(Settings.TOOLTIP_APPEND_MOD).value().get() && RoughlyEnoughItemsCore.getConfigManager().getConfig().shouldAppendModNames()) { final String modString = ClientHelper.getInstance().getFormattedModFromIdentifier(Registry.FLUID.getId(fluid)); diff --git a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java index 37480fdd3..fd013ae51 100644 --- a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java @@ -251,14 +251,25 @@ public class RecipeHelperImpl implements RecipeHelper { Version reiVersion = FabricLoader.getInstance().getModContainer("roughlyenoughitems").get().getMetadata().getVersion(); if (!(reiVersion instanceof SemanticVersion)) RoughlyEnoughItemsCore.LOGGER.warn("[REI] Roughly Enough Items is not using semantic versioning, will be ignoring plugins' minimum versions!"); - plugins.forEach(plugin -> { + for (REIPluginEntry plugin : plugins) { + try { + if (reiVersion instanceof SemanticVersion) + if (plugin.getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) { + throw new IllegalStateException("Requires " + plugin.getMinimumVersion().getFriendlyString() + " version of REI!"); + } + if (plugin instanceof REIPluginV0) + ((REIPluginV0) plugin).preRegister(); + } catch (Exception e) { + RoughlyEnoughItemsCore.LOGGER.error("[REI] " + plugin.getPluginIdentifier().toString() + " plugin failed to pre register!", e); + } + } + for (REIPluginEntry plugin : plugins) { Identifier identifier = plugin.getPluginIdentifier(); try { + if (reiVersion instanceof SemanticVersion) + if (plugin.getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) + return; if (plugin instanceof REIPluginV0) { - if (reiVersion instanceof SemanticVersion) - if (((REIPluginV0) plugin).getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) { - throw new IllegalStateException("Requires " + ((REIPluginV0) plugin).getMinimumVersion().getFriendlyString() + " version of REI!"); - } ((REIPluginV0) plugin).registerBounds(RoughlyEnoughItemsCore.getDisplayHelper()); ((REIPluginV0) plugin).registerEntries(RoughlyEnoughItemsCore.getEntryRegistry()); ((REIPluginV0) plugin).registerPluginCategories(this); @@ -270,7 +281,18 @@ public class RecipeHelperImpl implements RecipeHelper { } catch (Exception e) { RoughlyEnoughItemsCore.LOGGER.error("[REI] " + identifier.toString() + " plugin failed to load!", e); } - }); + } + for (REIPluginEntry plugin : plugins) { + try { + if (reiVersion instanceof SemanticVersion) + if (plugin.getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) + return; + if (plugin instanceof REIPluginV0) + ((REIPluginV0) plugin).postRegister(); + } catch (Exception e) { + RoughlyEnoughItemsCore.LOGGER.error("[REI] " + plugin.getPluginIdentifier().toString() + " plugin failed to post register!", e); + } + } if (!recipeFunctions.isEmpty()) { List allSortedRecipes = getAllSortedRecipes(); Collections.reverse(allSortedRecipes); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index ca3d49953..77a139f98 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -10,10 +10,7 @@ import com.google.common.collect.Maps; import it.unimi.dsi.fastutil.objects.Object2FloatMap; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.api.EntryRegistry; -import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.*; import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; @@ -47,10 +44,7 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.fluid.EmptyFluid; import net.minecraft.fluid.Fluid; -import net.minecraft.item.Item; -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import net.minecraft.item.*; import net.minecraft.potion.PotionUtil; import net.minecraft.recipe.*; import net.minecraft.util.Identifier; @@ -95,7 +89,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerEntries(EntryRegistry entryRegistry) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { + if (!ConfigManager.getInstance().getConfig().isLoadingDefaultPlugin()) { return; } for (Item item : Registry.ITEM) { @@ -124,7 +118,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerPluginCategories(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { + if (!ConfigManager.getInstance().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerCategory(new DefaultCraftingCategory()); @@ -140,7 +134,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerRecipeDisplays(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { + if (!ConfigManager.getInstance().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerRecipes(CRAFTING, ShapelessRecipe.class, DefaultShapelessDisplay::new); @@ -154,7 +148,7 @@ public class DefaultPlugin implements REIPluginV0 { recipeHelper.registerDisplay(BREWING, display); } List arrowStack = Collections.singletonList(EntryStack.create(Items.ARROW)); - for (EntryStack entry : RoughlyEnoughItemsCore.getEntryRegistry().getStacksList()) { + for (EntryStack entry : EntryRegistry.getInstance().getStacksList()) { if (entry.getItem() == Items.LINGERING_POTION) { List> input = new ArrayList<>(); for (int i = 0; i < 4; i++) @@ -192,9 +186,33 @@ public class DefaultPlugin implements REIPluginV0 { }); } + @Override + public void postRegister() { + // Sit tight! This will be a fast journey! + long time = System.currentTimeMillis(); + for (EntryStack stack : EntryRegistry.getInstance().getStacksList()) + applyPotionTransformer(stack); + for (List displays : RecipeHelper.getInstance().getAllRecipes().values()) { + for (RecipeDisplay display : displays) { + for (List entries : display.getInputEntries()) + for (EntryStack stack : entries) + applyPotionTransformer(stack); + for (EntryStack stack : display.getOutputEntries()) + applyPotionTransformer(stack); + } + } + time = System.currentTimeMillis() - time; + RoughlyEnoughItemsCore.LOGGER.info("[REI] Applied Check Tags for potion in %dms.", time); + } + + private void applyPotionTransformer(EntryStack stack) { + if (stack.getItem() instanceof PotionItem) + stack.addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); + } + @Override public void registerBounds(DisplayHelper displayHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { + if (!ConfigManager.getInstance().getConfig().isLoadingDefaultPlugin()) { return; } displayHelper.getBaseBoundsHandler().registerExclusionZones(AbstractInventoryScreen.class, new DefaultPotionEffectExclusionZones()); @@ -269,7 +287,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerOthers(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { + if (!ConfigManager.getInstance().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerWorkingStations(CRAFTING, EntryStack.create(Items.CRAFTING_TABLE)); diff --git a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java index 5516c0560..21ca07b14 100644 --- a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java @@ -11,7 +11,6 @@ import me.shedaniel.rei.api.RecipeDisplay; import me.shedaniel.rei.plugin.DefaultPlugin; import net.minecraft.client.resource.language.I18n; import net.minecraft.item.ItemStack; -import net.minecraft.item.PotionItem; import net.minecraft.recipe.Ingredient; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -27,19 +26,13 @@ public class DefaultBrewingDisplay implements RecipeDisplay { public DefaultBrewingDisplay(ItemStack input, Ingredient reactant, ItemStack output) { this.input = EntryStack.create(input).setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("category.rei.brewing.input"))); - if (this.input.getItem() instanceof PotionItem) - this.input = this.input.setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); this.reactant = new ArrayList<>(); for (ItemStack stack : reactant.getMatchingStacksClient()) { EntryStack entryStack = EntryStack.create(stack); - if (stack.getItem() instanceof PotionItem) - entryStack.setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); entryStack.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("category.rei.brewing.reactant"))); this.reactant.add(entryStack); } this.output = EntryStack.create(output).setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("category.rei.brewing.result"))); - if (this.output.getItem() instanceof PotionItem) - this.output = this.output.setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java index bb11a8447..8165f0a7a 100644 --- a/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java @@ -12,7 +12,7 @@ import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.TransferRecipeCategory; import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.renderers.SimpleRecipeEntry; +import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; import me.shedaniel.rei.gui.widget.EntryWidget; import me.shedaniel.rei.gui.widget.RecipeArrowWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; diff --git a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapedDisplay.java b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapedDisplay.java index 7858e3f31..b470d5574 100644 --- a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapedDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapedDisplay.java @@ -7,7 +7,6 @@ package me.shedaniel.rei.plugin.crafting; import me.shedaniel.rei.api.EntryStack; import net.minecraft.item.ItemStack; -import net.minecraft.item.PotionItem; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.ShapedRecipe; import net.minecraft.util.Identifier; @@ -29,15 +28,11 @@ public class DefaultShapedDisplay implements DefaultCraftingDisplay { this.input = recipe.getPreviewInputs().stream().map(i -> { List entries = new ArrayList<>(); for (ItemStack stack : i.getMatchingStacksClient()) { - if (stack.getItem() instanceof PotionItem) - entries.add(EntryStack.create(stack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); - else entries.add(EntryStack.create(stack)); + entries.add(EntryStack.create(stack)); } return entries; }).collect(Collectors.toList()); - if (recipe.getOutput().getItem() instanceof PotionItem) - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); - else this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapelessDisplay.java b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapelessDisplay.java index 65fbd5fd7..c62708323 100644 --- a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapelessDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultShapelessDisplay.java @@ -7,7 +7,6 @@ package me.shedaniel.rei.plugin.crafting; import me.shedaniel.rei.api.EntryStack; import net.minecraft.item.ItemStack; -import net.minecraft.item.PotionItem; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.ShapelessRecipe; import net.minecraft.util.Identifier; @@ -29,15 +28,11 @@ public class DefaultShapelessDisplay implements DefaultCraftingDisplay { this.input = recipe.getPreviewInputs().stream().map(i -> { List entries = new ArrayList<>(); for (ItemStack stack : i.getMatchingStacksClient()) { - if (stack.getItem() instanceof PotionItem) - entries.add(EntryStack.create(stack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); - else entries.add(EntryStack.create(stack)); + entries.add(EntryStack.create(stack)); } return entries; }).collect(Collectors.toList()); - if (recipe.getOutput().getItem() instanceof PotionItem) - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); - else this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); } @Override -- cgit