From 9f5a9eae9a7863412cc5eb433bf15e5ee71da616 Mon Sep 17 00:00:00 2001 From: Danielshe Date: Sun, 3 Nov 2019 14:44:52 +0800 Subject: 3.2.1 --- build.gradle | 14 +- gradle.properties | 2 +- .../hammercore/client/utils/Scissors.java | 52 ---- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 7 +- .../java/me/shedaniel/rei/api/ClientHelper.java | 24 +- src/main/java/me/shedaniel/rei/api/Entry.java | 17 +- .../java/me/shedaniel/rei/api/EntryRegistry.java | 76 ++++- src/main/java/me/shedaniel/rei/api/EntryStack.java | 153 ++++++++++ .../me/shedaniel/rei/api/LiveRecipeGenerator.java | 18 +- .../java/me/shedaniel/rei/api/ObjectHolder.java | 22 ++ .../java/me/shedaniel/rei/api/RecipeCategory.java | 16 +- .../java/me/shedaniel/rei/api/RecipeDisplay.java | 68 ++++- .../java/me/shedaniel/rei/api/RecipeHelper.java | 35 ++- src/main/java/me/shedaniel/rei/api/Renderer.java | 18 ++ .../shedaniel/rei/api/TransferRecipeDisplay.java | 26 +- .../rei/api/annotations/Experimental.java | 17 ++ .../me/shedaniel/rei/api/annotations/Internal.java | 17 ++ .../shedaniel/rei/api/annotations/ToBeRemoved.java | 17 ++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 19 +- .../me/shedaniel/rei/gui/OverlaySearchField.java | 96 ++++++ .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 16 +- .../rei/gui/VillagerRecipeViewingScreen.java | 19 +- .../shedaniel/rei/gui/credits/CreditsScreen.java | 2 +- .../rei/gui/renderers/SimpleRecipeRenderer.java | 94 ++++-- .../rei/gui/widget/CategoryBaseWidget.java | 2 +- .../rei/gui/widget/ClickableLabelWidget.java | 14 +- .../rei/gui/widget/DetailedButtonWidget.java | 3 + .../shedaniel/rei/gui/widget/EntryListWidget.java | 323 ++++++++++----------- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 195 +++++++++++++ .../me/shedaniel/rei/gui/widget/LabelWidget.java | 25 +- .../me/shedaniel/rei/gui/widget/PanelWidget.java | 111 +++++++ .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 71 +---- .../rei/gui/widget/SearchFieldWidget.java | 97 ------- .../shedaniel/rei/gui/widget/SlotBaseWidget.java | 2 +- .../me/shedaniel/rei/gui/widget/SlotWidget.java | 78 +++-- .../me/shedaniel/rei/gui/widget/TabWidget.java | 20 +- .../java/me/shedaniel/rei/gui/widget/Widget.java | 8 + .../me/shedaniel/rei/impl/AbstractEntryStack.java | 78 +++++ .../shedaniel/rei/impl/BaseBoundsHandlerImpl.java | 30 +- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 20 +- .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 22 +- .../me/shedaniel/rei/impl/EmptyEntryStack.java | 96 ++++++ .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 30 +- .../java/me/shedaniel/rei/impl/FluidEntry.java | 15 + .../me/shedaniel/rei/impl/FluidEntryStack.java | 186 ++++++++++++ .../java/me/shedaniel/rei/impl/ItemEntryStack.java | 158 ++++++++++ .../java/me/shedaniel/rei/impl/ItemStackEntry.java | 15 + .../me/shedaniel/rei/impl/ObjectHolderImpl.java | 51 ++++ .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 49 ++-- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 17 +- .../rei/mixin/MixinBrewingRecipeRegistry.java | 14 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 80 ++--- .../autocrafting/DefaultCategoryHandler.java | 22 +- .../plugin/blasting/DefaultBlastingCategory.java | 92 ------ .../plugin/blasting/DefaultBlastingDisplay.java | 68 +---- .../rei/plugin/brewing/DefaultBrewingCategory.java | 23 +- .../rei/plugin/brewing/DefaultBrewingDisplay.java | 45 ++- .../plugin/campfire/DefaultCampfireCategory.java | 13 +- .../plugin/campfire/DefaultCampfireDisplay.java | 31 +- .../composting/DefaultCompostingCategory.java | 34 +-- .../composting/DefaultCompostingDisplay.java | 32 +- .../rei/plugin/cooking/DefaultCookingCategory.java | 96 ++++++ .../rei/plugin/cooking/DefaultCookingDisplay.java | 84 ++++++ .../plugin/crafting/DefaultCraftingCategory.java | 14 +- .../plugin/crafting/DefaultCraftingDisplay.java | 10 +- .../rei/plugin/crafting/DefaultCustomDisplay.java | 20 +- .../rei/plugin/crafting/DefaultShapedDisplay.java | 28 +- .../plugin/crafting/DefaultShapelessDisplay.java | 28 +- .../plugin/smelting/DefaultSmeltingCategory.java | 91 ------ .../plugin/smelting/DefaultSmeltingDisplay.java | 68 +---- .../rei/plugin/smoking/DefaultSmokingCategory.java | 91 ------ .../rei/plugin/smoking/DefaultSmokingDisplay.java | 69 +---- .../stonecutting/DefaultStoneCuttingCategory.java | 11 +- .../stonecutting/DefaultStoneCuttingDisplay.java | 28 +- .../plugin/stripping/DefaultStrippingCategory.java | 13 +- .../plugin/stripping/DefaultStrippingDisplay.java | 20 +- .../me/shedaniel/rei/utils/CollectionUtils.java | 161 ++++++++++ 77 files changed, 2578 insertions(+), 1269 deletions(-) delete mode 100644 src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java create mode 100644 src/main/java/me/shedaniel/rei/api/EntryStack.java create mode 100644 src/main/java/me/shedaniel/rei/api/ObjectHolder.java create mode 100644 src/main/java/me/shedaniel/rei/api/annotations/Experimental.java create mode 100644 src/main/java/me/shedaniel/rei/api/annotations/Internal.java create mode 100644 src/main/java/me/shedaniel/rei/api/annotations/ToBeRemoved.java create mode 100644 src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/PanelWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/SearchFieldWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java create mode 100644 src/main/java/me/shedaniel/rei/impl/EmptyEntryStack.java create mode 100644 src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ObjectHolderImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingCategory.java create mode 100644 src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java create mode 100644 src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java delete mode 100644 src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingCategory.java delete mode 100644 src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingCategory.java create mode 100644 src/main/java/me/shedaniel/rei/utils/CollectionUtils.java diff --git a/build.gradle b/build.gradle index e0d273c5b..d998b6d22 100755 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,6 @@ static def buildTime() { license { header rootProject.file('HEADER') include '**/*.java' - exclude '**/Scissors.java' } repositories { @@ -56,7 +55,7 @@ dependencies { modImplementation("me.shedaniel.cloth:config-2:${cloth_config_version}") { transitive = false } - modApi("me.shedaniel.cloth:fiber2cloth:1.2.0") { + modApi("me.shedaniel.cloth:fiber2cloth:1.2.1") { transitive = false } modApi "me.zeroeightsix:fiber:0.6.0-7" @@ -68,7 +67,7 @@ dependencies { include("me.shedaniel.cloth:config-2:${cloth_config_version}") { transitive = false } - include("me.shedaniel.cloth:fiber2cloth:1.2.0") { + include("me.shedaniel.cloth:fiber2cloth:1.2.1") { transitive = false } include "me.zeroeightsix:fiber:0.6.0-7" @@ -84,6 +83,15 @@ task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource } +task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) { + classifier = "maven" + afterEvaluate { + input = file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar") +// archiveName = "${archivesBaseName}-${version}-maven.jar" + addNestedDependencies = false + } +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/gradle.properties b/gradle.properties index 691d1fcce..dc5057377 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -mod_version=3.1.8-unstable +mod_version=3.2.1-unstable minecraft_version=19w44a yarn_version=19w44a+build.3 fabricloader_version=0.6.3+build.168 diff --git a/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java b/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java deleted file mode 100644 index c32053447..000000000 --- a/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.zeitheron.hammercore.client.utils; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.util.Window; -import org.lwjgl.opengl.GL11; - -/** - * This is originally the part of Hammer Lib, repacked in REI with permission. - * Adapted GL scissor for minecraft pixel resolution and adjusts (0;0) as left-top corner. - * - * @author Zeitheron - */ -public class Scissors { - /** - * Starts the scissor test - */ - public static void begin() { - GL11.glEnable(GL11.GL_SCISSOR_TEST); - } - - /** - * Setup the scissor bounds - * - * @param x the top left x coordinates - * @param y the top left y coordinates - * @param width the width of the bounds - * @param height the height of the bounds - */ - public static void scissor(int x, int y, int width, int height) { - Window window = MinecraftClient.getInstance().getWindow(); - - int sw = window.getWidth(); - int sh = window.getHeight(); - float dw = window.getScaledWidth(); - float dh = window.getScaledHeight(); - - x = Math.round(sw * (x / dw)); - y = Math.round(sh * (y / dh)); - - width = Math.round(sw * (width / dw)); - height = Math.round(sh * (height / dh)); - - GL11.glScissor(x, sh - height - y, width, height); - } - - /** - * Stops the scissor test - */ - public static void end() { - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } -} \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 1b6d91e5b..dc65ed688 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -136,9 +136,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { registerClothEvents(); discoverPluginEntries(); - FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).filter(metadata -> metadata.containsCustomValue("roughlyenoughitems:plugins")).forEach(modMetadata -> { - RoughlyEnoughItemsCore.LOGGER.error("[REI] REI plugin from " + modMetadata.getId() + " is not loaded because it is too old!"); - }); + for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { + if (modContainer.getMetadata().containsCustomValue("roughlyenoughitems:plugins")) + RoughlyEnoughItemsCore.LOGGER.error("[REI] REI plugin from " + modContainer.getMetadata().getId() + " is not loaded because it is too old!"); + } ClientSidePacketRegistry.INSTANCE.register(RoughlyEnoughItemsNetwork.CREATE_ITEMS_MESSAGE_PACKET, (packetContext, packetByteBuf) -> { ItemStack stack = packetByteBuf.readItemStack(); diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 458379457..b72e86ea0 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -55,28 +55,40 @@ public interface ClientHelper { void registerFabricKeyBinds(); /** - * Tries to cheat items using either packets or commands. + * Tries to cheat stack using either packets or commands. * * @param stack the stack to cheat in * @return whether it failed */ - boolean tryCheatingStack(ItemStack stack); + boolean tryCheatingEntry(EntryStack stack); + + default boolean tryCheatingStack(ItemStack stack) { + return tryCheatingEntry(EntryStack.create(stack)); + } /** - * Finds recipe for the item and opens the recipe screen. + * Finds recipe for the stack and opens the recipe screen. * * @param stack the stack to find recipe for * @return whether the stack has any recipes to show */ - boolean executeRecipeKeyBind(ItemStack stack); + boolean executeRecipeKeyBind(EntryStack stack); + + default boolean executeRecipeKeyBind(ItemStack stack) { + return executeRecipeKeyBind(EntryStack.create(stack)); + } /** - * Finds usage for the item and opens the recipe screen. + * Finds usage for the stack and opens the recipe screen. * * @param stack the stack to find usage for * @return whether the stack has any usages to show */ - boolean executeUsageKeyBind(ItemStack stack); + boolean executeUsageKeyBind(EntryStack stack); + + default boolean executeUsageKeyBind(ItemStack stack) { + return executeUsageKeyBind(EntryStack.create(stack)); + } FabricKeyBinding getFocusSearchFieldKeyBinding(); diff --git a/src/main/java/me/shedaniel/rei/api/Entry.java b/src/main/java/me/shedaniel/rei/api/Entry.java index fca8f9fd2..c0eb609bb 100644 --- a/src/main/java/me/shedaniel/rei/api/Entry.java +++ b/src/main/java/me/shedaniel/rei/api/Entry.java @@ -5,6 +5,7 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import me.shedaniel.rei.impl.FluidEntry; import me.shedaniel.rei.impl.ItemStackEntry; import net.minecraft.fluid.Fluid; @@ -12,7 +13,9 @@ import net.minecraft.item.ItemStack; import javax.annotation.Nullable; -public interface Entry { +@Deprecated +@ToBeRemoved +public interface Entry extends Cloneable { @SuppressWarnings("deprecation") static Entry create(ItemStack itemStack) { return new ItemStackEntry(itemStack); @@ -31,6 +34,18 @@ public interface Entry { @Nullable Fluid getFluid(); + Entry clone(); + + default EntryStack toEntryStack() { + if (getEntryType() == Type.ITEM) + return EntryStack.create(getItemStack()); + if (getEntryType() == Type.FLUID) + return EntryStack.create(getFluid()); + return EntryStack.empty(); + } + + boolean equalsEntry(Entry other, boolean checkTags); + public static enum Type { ITEM, FLUID } diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index effd1c8a4..9a811a127 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -5,10 +5,13 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.annotations.ToBeRemoved; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import java.util.Collections; import java.util.List; public interface EntryRegistry { @@ -18,7 +21,17 @@ public interface EntryRegistry { * * @return an unmodifiable item list */ - List getEntryList(); + @Deprecated + default List getEntryList() { + return Collections.unmodifiableList(getModifiableEntryList()); + } + + /** + * Gets the current modifiable stacks list + * + * @return a stacks list + */ + List getStacksList(); /** * Gets the current modifiable item list @@ -26,7 +39,9 @@ public interface EntryRegistry { * @return an modifiable item list */ @Deprecated - List getModifiableEntryList(); + default List getModifiableEntryList() { + return CollectionUtils.map(getStacksList(), EntryStack::toEntry); + } /** * Gets all possible stacks from an item @@ -42,31 +57,66 @@ public interface EntryRegistry { * @param afterItem the stack to put after * @param stack the stack to register */ - void registerItemStack(Item afterItem, ItemStack stack); + @Deprecated + default void registerItemStack(Item afterItem, ItemStack stack) { + registerEntryAfter(EntryStack.create(afterItem), EntryStack.create(stack)); + } - void registerFluid(Fluid fluid); + @Deprecated + default void registerFluid(Fluid fluid) { + registerEntry(EntryStack.create(fluid)); + } + + default void registerEntry(EntryStack stack) { + registerEntryAfter(null, stack); + } + + void registerEntryAfter(EntryStack afterEntry, EntryStack stack); + + @ToBeRemoved + @Deprecated + default void registerItemStack(Item afterItem, ItemStack... stacks) { + EntryStack afterStack = EntryStack.create(afterItem); + for (int i = stacks.length - 1; i >= 0; i--) { + ItemStack stack = stacks[i]; + if (stack != null && !stack.isEmpty()) + registerEntryAfter(afterStack, EntryStack.create(stack)); + } + } /** * Registers multiple stacks to the item list * - * @param afterItem the stack to put after - * @param stacks the stacks to register + * @param afterStack the stack to put after + * @param stacks the stacks to register */ - default void registerItemStack(Item afterItem, ItemStack... stacks) { + default void registerEntriesAfter(EntryStack afterStack, EntryStack... stacks) { for (int i = stacks.length - 1; i >= 0; i--) { - ItemStack stack = stacks[i]; + EntryStack stack = stacks[i]; if (stack != null && !stack.isEmpty()) - registerItemStack(afterItem, stack); + registerEntryAfter(afterStack, stack); } } + @ToBeRemoved + @Deprecated + default void registerItemStack(ItemStack... stacks) { + registerItemStack(null, stacks); + } + /** * Registers multiple stacks to the item list * * @param stacks the stacks to register */ - default void registerItemStack(ItemStack... stacks) { - registerItemStack(null, stacks); + default void registerEntries(EntryStack... stacks) { + registerEntriesAfter(null, stacks); + } + + @ToBeRemoved + @Deprecated + default boolean alreadyContain(ItemStack stack) { + return alreadyContain(EntryStack.create(stack)); } /** @@ -75,8 +125,8 @@ public interface EntryRegistry { * @param stack the stack to check * @return whether the stack has been registered */ - default boolean alreadyContain(ItemStack stack) { - return getEntryList().stream().filter(entry -> entry.getEntryType() == Entry.Type.ITEM).anyMatch(entry -> ItemStack.areEqualIgnoreDamage(stack, entry.getItemStack())); + default boolean alreadyContain(EntryStack stack) { + return CollectionUtils.anyMatchEqualsAll(getStacksList(), stack); } } diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java new file mode 100644 index 000000000..3baa4e5e0 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -0,0 +1,153 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api; + +import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.annotations.ToBeRemoved; +import me.shedaniel.rei.gui.widget.QueuedTooltip; +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.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; + +public interface EntryStack { + + static EntryStack empty() { + return EmptyEntryStack.EMPTY; + } + + static EntryStack create(Fluid fluid) { + return create(fluid, 1000); + } + + static EntryStack create(Fluid fluid, int amount) { + return new FluidEntryStack(fluid, amount); + } + + static EntryStack create(ItemStack stack) { + return new ItemEntryStack(stack); + } + + static EntryStack create(ItemConvertible item) { + return new ItemEntryStack(new ItemStack(item)); + } + + static EntryStack create(Block block) { + return new ItemEntryStack(new ItemStack(block)); + } + + Optional getIdentifier(); + + EntryStack.Type getType(); + + int getAmount(); + + void setAmount(int amount); + + boolean isEmpty(); + + @ToBeRemoved + @Deprecated + Entry toEntry(); + + EntryStack copy(); + + Object getObject(); + + boolean equals(EntryStack stack, boolean ignoreTags, boolean ignoreAmount); + + boolean equalsIgnoreTagsAndAmount(EntryStack stack); + + boolean equalsIgnoreTags(EntryStack stack); + + boolean equalsIgnoreAmount(EntryStack stack); + + boolean equalsAll(EntryStack stack); + + int getZ(); + + void setZ(int z); + + default ItemStack getItemStack() { + if (getType() == Type.ITEM) + return (ItemStack) getObject(); + return null; + } + + default Item getItem() { + if (getType() == Type.ITEM) + return ((ItemStack) getObject()).getItem(); + return null; + } + + default Fluid getFluid() { + if (getType() == Type.FLUID) + return (Fluid) getObject(); + return null; + } + + EntryStack setting(Settings settings, T value); + + EntryStack removeSetting(Settings settings); + + EntryStack clearSettings(); + + default EntryStack addSetting(Settings settings, T value) { + return setting(settings, value); + } + + ObjectHolder getSetting(Settings settings); + + @Nullable + QueuedTooltip getTooltip(int mouseX, int mouseY); + + void render(Rectangle bounds, int mouseX, int mouseY, float delta); + + public static enum Type { + ITEM, FLUID, EMPTY + } + + public static class Settings { + public static final Supplier TRUE = () -> true; + public static final Supplier FALSE = () -> false; + public static final Settings> RENDER = new Settings(TRUE); + public static final Settings> CHECK_TAGS = new Settings(FALSE); + public static final Settings> TOOLTIP_ENABLED = new Settings(TRUE); + public static final Settings> TOOLTIP_APPEND_MOD = new Settings(TRUE); + public static final Settings> RENDER_COUNTS = new Settings(TRUE); + public static final Settings>> TOOLTIP_APPEND_EXTRA = new Settings>>(stack -> Collections.emptyList()); + public static final Settings> COUNTS = new Settings>(stack -> null); + + private T defaultValue; + + public Settings(T defaultValue) { + this.defaultValue = defaultValue; + } + + public T getDefaultValue() { + return defaultValue; + } + + public static class Item { + public static final Settings> RENDER_OVERLAY = new Settings(TRUE); + + private Item() { + } + } + } +} diff --git a/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java b/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java index 2e331b1df..8200fcdc0 100644 --- a/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java +++ b/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java @@ -15,8 +15,22 @@ public interface LiveRecipeGenerator { Identifier getCategoryIdentifier(); - Optional> getRecipeFor(ItemStack stack); + @Deprecated + default Optional> getRecipeFor(ItemStack stack) { + return Optional.empty(); + } - Optional> getUsageFor(ItemStack stack); + default Optional> getRecipeFor(EntryStack entry) { + return Optional.empty(); + } + + @Deprecated + default Optional> getUsageFor(ItemStack stack) { + return Optional.empty(); + } + + default Optional> getUsageFor(EntryStack entry) { + return Optional.empty(); + } } diff --git a/src/main/java/me/shedaniel/rei/api/ObjectHolder.java b/src/main/java/me/shedaniel/rei/api/ObjectHolder.java new file mode 100644 index 000000000..d3b6189b1 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/ObjectHolder.java @@ -0,0 +1,22 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api; + +public interface ObjectHolder { + int intValue(); + + long longValue(); + + boolean booleanValue(); + + float floatValue(); + + double doubleValue(); + + String stringValue(); + + T value(); +} \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 233cf4553..4cecb6fce 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -6,6 +6,7 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.renderers.RecipeRenderer; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; @@ -32,9 +33,18 @@ public interface RecipeCategory { /** * Gets the renderer of the icon, allowing developers to render things other than items * + * @see RecipeCategory#getLogo() * @return the renderer of the icon */ - Renderer getIcon(); + @ToBeRemoved + @Deprecated + default Renderer getIcon() { + return Renderer.empty(); + } + + default EntryStack getLogo() { + return getIcon().getEntry(); + } /** * Gets the category name @@ -51,7 +61,7 @@ public interface RecipeCategory { */ @SuppressWarnings("unchecked") default RecipeRenderer getSimpleRenderer(T recipe) { - return Renderer.fromRecipe(recipe::getInput, recipe::getOutput); + return Renderer.fromRecipeEntries(recipe::getInputEntries, recipe::getOutputEntries); } /** @@ -126,7 +136,9 @@ public interface RecipeCategory { * Gets whether the category will check tags, useful for potions * * @return whether the category will check tags + * @deprecated no longer used */ + @Deprecated default boolean checkTags() { return false; } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java index 693712fc6..dd563f01a 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java @@ -5,10 +5,12 @@ package me.shedaniel.rei.api; -import com.google.common.collect.Lists; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -16,21 +18,79 @@ public interface RecipeDisplay { /** * @return a list of items + * @see RecipeDisplay#getInputStacks() */ - List> getInput(); + @ToBeRemoved + @Deprecated + default List> getInput() { + return Collections.emptyList(); + } + + /** + * @return a list of inputs + */ + default List> getInputEntries() { + List> input = getInput(); + if (input.isEmpty()) + return Collections.emptyList(); + List> list = new ArrayList<>(); + for (List stacks : input) { + List entries = new ArrayList<>(); + for (ItemStack stack : stacks) { + entries.add(EntryStack.create(stack)); + } + list.add(entries); + } + return list; + } /** * @return a list of outputs */ - List getOutput(); + @ToBeRemoved + @Deprecated + default List getOutput() { + return Collections.emptyList(); + } + + /** + * @return a list of outputs + */ + default List getOutputEntries() { + List input = getOutput(); + if (input.isEmpty()) + return Collections.emptyList(); + List entries = new ArrayList<>(); + for (ItemStack stack : input) { + entries.add(EntryStack.create(stack)); + } + return entries; + } /** * Gets the required items used in craftable filters * * @return the list of required items */ + default List> getRequiredEntries() { + List> input = getRequiredItems(); + if (input.isEmpty()) + return Collections.emptyList(); + List> list = new ArrayList<>(); + for (List stacks : input) { + List entries = new ArrayList<>(); + for (ItemStack stack : stacks) { + entries.add(EntryStack.create(stack)); + } + list.add(entries); + } + return list; + } + + @ToBeRemoved + @Deprecated default List> getRequiredItems() { - return Lists.newArrayList(); + return Collections.emptyList(); } /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 3ef78f603..9c66a6eb4 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -7,12 +7,14 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -50,7 +52,22 @@ public interface RecipeHelper { * @param inventoryItems the materials * @return the list of craftable items */ - List findCraftableByItems(List inventoryItems); + default List findCraftableByItems(List inventoryItems) { + List itemStacks = new ArrayList<>(); + for (EntryStack item : findCraftableEntriesByItems(inventoryItems)) { + if (item.getItemStack() != null) + itemStacks.add(item.getItemStack()); + } + return itemStacks; + } + + /** + * Gets all craftable items from materials. + * + * @param inventoryItems the materials + * @return the list of craftable entries + */ + List findCraftableEntriesByItems(List inventoryItems); /** * Registers a category @@ -91,7 +108,13 @@ public interface RecipeHelper { * @param stack the stack to be crafted * @return the map of recipes */ - Map, List> getRecipesFor(ItemStack stack); + Map, List> getRecipesFor(EntryStack stack); + + @ToBeRemoved + @Deprecated + default Map, List> getRecipesFor(ItemStack stack) { + return getRecipesFor(EntryStack.create(stack)); + } RecipeCategory getCategory(Identifier identifier); @@ -115,7 +138,13 @@ public interface RecipeHelper { * @param stack the stack to be used * @return the map of recipes */ - Map, List> getUsagesFor(ItemStack stack); + Map, List> getUsagesFor(EntryStack stack); + + @ToBeRemoved + @Deprecated + default Map, List> getUsagesFor(ItemStack stack) { + return getUsagesFor(EntryStack.create(stack)); + } /** * Gets the optional of the speed crafting button area from a category diff --git a/src/main/java/me/shedaniel/rei/api/Renderer.java b/src/main/java/me/shedaniel/rei/api/Renderer.java index c2b6b133c..823a9ceb5 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderer.java +++ b/src/main/java/me/shedaniel/rei/api/Renderer.java @@ -5,6 +5,7 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.annotations.ToBeRemoved; import me.shedaniel.rei.gui.renderers.EmptyRenderer; import me.shedaniel.rei.gui.renderers.FluidRenderer; import me.shedaniel.rei.gui.renderers.ItemStackRenderer; @@ -14,14 +15,17 @@ import net.minecraft.client.gui.DrawableHelper; import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +@Deprecated public abstract class Renderer extends DrawableHelper { /** * Gets an item stack renderer by an item stack supplier @@ -102,10 +106,16 @@ public abstract class Renderer extends DrawableHelper { * @param output the list of output items * @return the recipe renderer */ + @ToBeRemoved + @Deprecated public static SimpleRecipeRenderer fromRecipe(Supplier>> input, Supplier> output) { return new SimpleRecipeRenderer(input, output); } + public static SimpleRecipeRenderer fromRecipeEntries(Supplier>> input, Supplier> output) { + return new SimpleRecipeRenderer(input, output, 0); + } + public static ItemStackRenderer fromItemStacks(List stacks) { return fromItemStacks(() -> stacks, true, null); } @@ -185,6 +195,14 @@ public abstract class Renderer extends DrawableHelper { */ public abstract void render(int x, int y, double mouseX, double mouseY, float delta); + public EntryStack getEntry() { + if (this instanceof ItemStackRenderer) + return EntryStack.create(((ItemStackRenderer) this).getItemStack()); + if (this instanceof FluidRenderer) + return EntryStack.create(((FluidRenderer) this).getFluid()); + return EntryStack.empty(); + } + @Nullable public QueuedTooltip getQueuedTooltip(float delta) { return null; diff --git a/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java index 3e7ed1bc8..f7d509f17 100644 --- a/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java @@ -5,10 +5,13 @@ package me.shedaniel.rei.api; +import com.google.common.collect.Lists; import me.shedaniel.rei.server.ContainerInfo; import net.minecraft.container.Container; import net.minecraft.item.ItemStack; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; public interface TransferRecipeDisplay extends RecipeDisplay { @@ -17,6 +20,27 @@ public interface TransferRecipeDisplay extends RecipeDisplay { int getHeight(); - List> getOrganisedInput(ContainerInfo containerInfo, Container container); + default List> getOrganisedInput(ContainerInfo containerInfo, Container container) { + List> list = Lists.newArrayListWithCapacity(containerInfo.getCraftingWidth(container) * containerInfo.getCraftingHeight(container)); + for (int i = 0; i < containerInfo.getCraftingWidth(container) * containerInfo.getCraftingHeight(container); i++) { + list.add(Lists.newArrayList()); + } + return list; + } + + default List> getOrganisedInputEntries(ContainerInfo containerInfo, Container container) { + List> input = getOrganisedInput(containerInfo, container); + if (input.isEmpty()) + return Collections.emptyList(); + List> list = new ArrayList<>(); + for (List stacks : input) { + List entries = new ArrayList<>(); + for (ItemStack stack : stacks) { + entries.add(EntryStack.create(stack)); + } + list.add(entries); + } + return list; + } } diff --git a/src/main/java/me/shedaniel/rei/api/annotations/Experimental.java b/src/main/java/me/shedaniel/rei/api/annotations/Experimental.java new file mode 100644 index 000000000..043b0daae --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/annotations/Experimental.java @@ -0,0 +1,17 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(value = {CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) +public @interface Experimental { +} diff --git a/src/main/java/me/shedaniel/rei/api/annotations/Internal.java b/src/main/java/me/shedaniel/rei/api/annotations/Internal.java new file mode 100644 index 000000000..4b120c1de --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/annotations/Internal.java @@ -0,0 +1,17 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(value = {CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) +public @interface Internal { +} diff --git a/src/main/java/me/shedaniel/rei/api/annotations/ToBeRemoved.java b/src/main/java/me/shedaniel/rei/api/annotations/ToBeRemoved.java new file mode 100644 index 000000000..cb026533b --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/annotations/ToBeRemoved.java @@ -0,0 +1,17 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.api.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(value = {CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) +public @interface ToBeRemoved { +} diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 26d3045a2..9e285e756 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -13,7 +13,7 @@ import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.api.Entry; +import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.gui.config.SearchFieldLocation; import me.shedaniel.rei.gui.widget.*; @@ -21,6 +21,7 @@ import me.shedaniel.rei.impl.RecipeHelperImpl; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.Weather; import me.shedaniel.rei.listeners.ContainerScreenHooks; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; @@ -46,7 +47,6 @@ import org.apache.logging.log4j.util.TriConsumer; import javax.annotation.Nullable; import java.util.*; -import java.util.stream.Collectors; public class ContainerScreenOverlay extends Widget { @@ -310,7 +310,7 @@ public class ContainerScreenOverlay extends Widget { buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0; } if (ScreenHelper.searchField == null) - ScreenHelper.searchField = new SearchFieldWidget(0, 0, 0, 0); + ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0)); ScreenHelper.searchField.getBounds().setBounds(getTextFieldArea()); this.widgets.add(ScreenHelper.searchField); ScreenHelper.searchField.setText(searchTerm); @@ -436,14 +436,14 @@ public class ContainerScreenOverlay extends Widget { DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); } - if (SearchFieldWidget.isSearching) { + if (OverlaySearchField.isSearching) { GuiLighting.disable(); setBlitOffset(200); if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; int left = hooks.rei_getContainerLeft(), top = hooks.rei_getContainerTop(); for (Slot slot : ((AbstractContainerScreen) MinecraftClient.getInstance().currentScreen).getContainer().slotList) - if (!slot.hasStack() || !entryListWidget.filterEntry(Entry.create(slot.getStack()), entryListWidget.getLastSearchArgument())) + if (!slot.hasStack() || !entryListWidget.filterEntry(EntryStack.create(slot.getStack()), entryListWidget.getLastSearchArgument())) fillGradient(left + slot.xPosition, top + slot.yPosition, left + slot.xPosition + 16, top + slot.yPosition + 16, -601874400, -601874400); } setBlitOffset(0); @@ -456,7 +456,7 @@ public class ContainerScreenOverlay extends Widget { for (RecipeHelperImpl.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) if (area.getRectangle().contains(mouseX - hooks.rei_getContainerLeft(), mouseY - hooks.rei_getContainerTop())) { - String collect = Arrays.asList(area.getCategories()).stream().map(identifier -> RecipeHelper.getInstance().getCategory(identifier).getCategoryName()).collect(Collectors.joining(", ")); + String collect = CollectionUtils.mapAndJoinToString(area.getCategories(), identifier -> RecipeHelper.getInstance().getCategory(identifier).getCategoryName(), ", "); QUEUED_TOOLTIPS.add(QueuedTooltip.create(I18n.translate("text.rei.view_recipes_for", collect))); break; } @@ -470,7 +470,10 @@ public class ContainerScreenOverlay extends Widget { toggleButtonWidget.lateRender(mouseX, mouseY, delta); Screen currentScreen = MinecraftClient.getInstance().currentScreen; if (!(currentScreen instanceof RecipeViewingScreen) || !((RecipeViewingScreen) currentScreen).choosePageActivated) - QUEUED_TOOLTIPS.stream().filter(Objects::nonNull).forEach(this::renderTooltip); + for (QueuedTooltip queuedTooltip : QUEUED_TOOLTIPS) { + if (queuedTooltip != null) + renderTooltip(queuedTooltip); + } } QUEUED_TOOLTIPS.clear(); } @@ -495,7 +498,7 @@ public class ContainerScreenOverlay extends Widget { private boolean hasSameListContent(List list1, List list2) { list1.sort(Comparator.comparing(Object::toString)); list2.sort(Comparator.comparing(Object::toString)); - return list1.stream().map(Objects::toString).collect(Collectors.joining("")).equals(list2.stream().map(Objects::toString).collect(Collectors.joining(""))); + return CollectionUtils.mapAndJoinToString(list1, Object::toString, "").equals(CollectionUtils.mapAndJoinToString(list2, Object::toString, "")); } public void addTooltip(@Nullable QueuedTooltip queuedTooltip) { diff --git a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java new file mode 100644 index 000000000..eeb782220 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java @@ -0,0 +1,96 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui; + +import me.shedaniel.math.compat.RenderHelper; +import me.shedaniel.rei.gui.widget.TextFieldWidget; +import me.shedaniel.rei.impl.ScreenHelper; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.util.InputUtil; +import net.minecraft.sound.SoundEvents; + +public class OverlaySearchField extends TextFieldWidget { + + public static boolean isSearching = false; + public long keybindFocusTime = -1; + public int keybindFocusKey = -1; + protected long lastClickedTime = -1; + + OverlaySearchField(int x, int y, int width, int height) { + super(x, y, width, height); + setMaxLength(10000); + } + + public void laterRender(int int_1, int int_2, float float_1) { + GuiLighting.disable(); + RenderHelper.disableDepthTest(); + setEditableColor(ContainerScreenOverlay.getEntryListWidget().children().isEmpty() && !getText().isEmpty() ? 16733525 : isSearching ? -1313241 : 14737632); + setSuggestion(!isFocused() && getText().isEmpty() ? I18n.translate("text.rei.search.field.suggestion") : null); + super.render(int_1, int_2, float_1); + RenderHelper.enableDepthTest(); + } + + @Override + public void renderBorder() { + if (!isSearching) + super.renderBorder(); + else if (this.hasBorder()) { + fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -1313241); + fill(this.getBounds().x, this.getBounds().y, this.getBounds().x + this.getBounds().width, this.getBounds().y + this.getBounds().height, -16777216); + } + } + + @Override + public boolean mouseClicked(double double_1, double double_2, int int_1) { + boolean contains = containsMouse(double_1, double_2); + if (isVisible() && contains && int_1 == 1) + setText(""); + if (contains && int_1 == 0) + if (lastClickedTime == -1) + lastClickedTime = System.currentTimeMillis(); + else if (System.currentTimeMillis() - lastClickedTime > 1200) + lastClickedTime = -1; + else { + lastClickedTime = -1; + isSearching = !isSearching; + minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + } + return super.mouseClicked(double_1, double_2, int_1); + } + + @Override + public boolean keyPressed(int int_1, int int_2, int int_3) { + if (this.isVisible() && this.isFocused()) + if (int_1 == 257 || int_1 == 335) { + setFocused(false); + return true; + } + return super.keyPressed(int_1, int_2, int_3); + } + + @Override + public boolean charTyped(char char_1, int int_1) { + if (System.currentTimeMillis() - keybindFocusTime < 1000 && InputUtil.isKeyPressed(MinecraftClient.getInstance().window.getHandle(), keybindFocusKey)) { + keybindFocusTime = -1; + keybindFocusKey = -1; + return true; + } + return super.charTyped(char_1, int_1); + } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return ScreenHelper.getLastOverlay().isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); + } + + @Override + public void render(int int_1, int int_2, float float_1) { + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 335780890..3a8f1a6cc 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -13,6 +13,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ScreenHelper; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; @@ -123,7 +124,8 @@ public class RecipeViewingScreen extends Screen { this.widgets.clear(); this.largestWidth = width - 100; this.largestHeight = height - 40; - this.guiWidth = MathHelper.clamp(getCurrentDisplayed().stream().map(display -> selectedCategory.getDisplayWidth(display)).max(Integer::compareTo).orElse(150) + 30, 0, largestWidth); + int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), display -> selectedCategory.getDisplayWidth((RecipeDisplay) display), (Comparator) Comparator.naturalOrder()).orElse(150); + this.guiWidth = MathHelper.clamp(maxWidthDisplay, 0, largestWidth); this.guiHeight = MathHelper.floor(MathHelper.clamp((selectedCategory.getDisplayHeight() + 7d) * (getRecipesPerPage() + 1d) + 40d, 186d, (double) largestHeight)); this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1); @@ -272,7 +274,7 @@ public class RecipeViewingScreen extends Screen { return false; } }); - tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * TABS_PER_PAGE == categories.indexOf(selectedCategory)); + tab.setRenderer(categories.get(j), categories.get(j).getLogo(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * TABS_PER_PAGE == categories.indexOf(selectedCategory)); } } Optional supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(selectedCategory); @@ -379,7 +381,10 @@ public class RecipeViewingScreen extends Screen { fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, 0xFF9E9E9E); } } - tabs.stream().filter(tabWidget -> !tabWidget.isSelected()).forEach(tabWidget -> tabWidget.render(mouseX, mouseY, delta)); + for (TabWidget tab : tabs) { + if (!tab.isSelected()) + tab.render(mouseX, mouseY, delta); + } GuiLighting.disable(); super.render(mouseX, mouseY, delta); widgets.forEach(widget -> { @@ -388,7 +393,10 @@ public class RecipeViewingScreen extends Screen { }); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); GuiLighting.disable(); - tabs.stream().filter(TabWidget::isSelected).forEach(tabWidget -> tabWidget.render(mouseX, mouseY, delta)); + for (TabWidget tab : tabs) { + if (tab.isSelected()) + tab.render(mouseX, mouseY, delta); + } GuiLighting.disable(); ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 4d02a3a5f..e212e22bd 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -7,8 +7,8 @@ package me.shedaniel.rei.gui; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import me.shedaniel.clothconfig2.api.ScissorsHandler; import com.mojang.blaze3d.systems.RenderSystem; -import com.zeitheron.hammercore.client.utils.Scissors; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -17,6 +17,7 @@ import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.renderers.RecipeRenderer; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ScreenHelper; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; @@ -37,7 +38,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; public class VillagerRecipeViewingScreen extends Screen { @@ -185,7 +185,7 @@ public class VillagerRecipeViewingScreen extends Screen { return false; } }); - tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getCategoryName(), tab.getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex); + tab.setRenderer(categories.get(j), categories.get(j).getLogo(), categories.get(j).getCategoryName(), tab.getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex); } } ButtonWidget w, w2; @@ -247,7 +247,7 @@ public class VillagerRecipeViewingScreen extends Screen { @Override public boolean mouseClicked(double mouseX, double mouseY, int int_1) { - double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight)); + double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight()); int actualHeight = scrollListBounds.height - 2; if (height > actualHeight && scrollBarAlpha > 0 && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) { double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6; @@ -271,7 +271,7 @@ public class VillagerRecipeViewingScreen extends Screen { @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { - double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight)); + double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight()); if (scrollListBounds.contains(double_1, double_2) && height > scrollListBounds.height - 2) { if (double_3 > 0) scroll -= 16; @@ -337,8 +337,7 @@ public class VillagerRecipeViewingScreen extends Screen { GuiLighting.disable(); ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); RenderSystem.pushMatrix(); - Scissors.begin(); - Scissors.scissor(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2); + ScissorsHandler.INSTANCE.scissor(new Rectangle(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2)); for (int i = 0; i < buttonWidgets.size(); i++) { ButtonWidget buttonWidget = buttonWidgets.get(i); buttonWidget.getBounds().y = scrollListBounds.y + 1 + yOffset - (int) scroll; @@ -356,7 +355,7 @@ public class VillagerRecipeViewingScreen extends Screen { ScreenHelper.getLastOverlay().addTooltip(recipeRenderers.get(i).getQueuedTooltip(delta)); } } - double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight)); + double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight()); if (height > scrollListBounds.height - 2) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBufferBuilder(); @@ -385,7 +384,7 @@ public class VillagerRecipeViewingScreen extends Screen { RenderSystem.enableAlphaTest(); RenderSystem.enableTexture(); } - Scissors.end(); + ScissorsHandler.INSTANCE.removeLastScissor(); RenderSystem.popMatrix(); ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); } @@ -393,7 +392,7 @@ public class VillagerRecipeViewingScreen extends Screen { @Override public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) { if (int_1 == 0 && scrollBarAlpha > 0 && draggingScrollBar) { - double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight)); + double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight()); int actualHeight = scrollListBounds.height - 2; if (height > actualHeight && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) { int int_3 = MathHelper.clamp((int) ((actualHeight * actualHeight) / height), 32, actualHeight - 8); diff --git a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java index b6f33d2e2..df4c59561 100644 --- a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java @@ -83,7 +83,7 @@ public class CreditsScreen extends Screen { @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { - if (entryListWidget.mouseScrolled(double_1, double_2, double_3 * 3)) + if (entryListWidget.mouseScrolled(double_1, double_2, double_3)) return true; return super.mouseScrolled(double_1, double_2, double_3); } diff --git a/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeRenderer.java b/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeRenderer.java index 1aa45aa3f..db124a3b2 100644 --- a/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeRenderer.java +++ b/src/main/java/me/shedaniel/rei/gui/renderers/SimpleRecipeRenderer.java @@ -6,11 +6,13 @@ package me.shedaniel.rei.gui.renderers; import com.google.common.collect.Lists; +import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import me.shedaniel.rei.gui.widget.QueuedTooltip; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; +import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; @@ -26,54 +28,94 @@ import java.util.stream.Collectors; public class SimpleRecipeRenderer extends RecipeRenderer { - public static final Comparator ITEM_STACK_COMPARATOR = (o1, o2) -> { - if (o1.getItem() == o2.getItem()) { - if (o1.getCount() != o2.getCount()) - return o1.getCount() - o2.getCount(); - int compare = Boolean.compare(o1.hasTag(), o2.hasTag()); + 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 (o1.getTag().getSize() != o2.getTag().getSize()) - return o1.getTag().getSize() - o2.getTag().getSize(); - return o1.getTag().hashCode() - o2.getTag().hashCode(); + if (i1.getTag().getSize() != i2.getTag().getSize()) + return i1.getTag().getSize() - i2.getTag().getSize(); + return i1.getTag().hashCode() - i2.getTag().hashCode(); } - return o1.getItem().hashCode() - o2.getItem().hashCode(); + return i1.getItem().hashCode() - i2.getItem().hashCode(); }; private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); - private List inputRenderer; - private ItemStackRenderer outputRenderer; + private List inputRenderer; + private Renderer outputRenderer; private QueuedTooltip lastTooltip; + @Deprecated public SimpleRecipeRenderer(Supplier>> input, Supplier> output) { - List, AtomicInteger>> newList = Lists.newArrayList(); - List, Integer>> a = input.get().stream().map(stacks -> new Pair<>(stacks, stacks.stream().map(ItemStack::getCount).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(); + this(() -> (List>) input.get().stream().map(s -> s.stream().map(EntryStack::create).collect(Collectors.toList())).collect(Collectors.toList()), + () -> output.get().stream().map(EntryStack::create).collect(Collectors.toList()), 0); + } + + public SimpleRecipeRenderer(Supplier>> input, Supplier> output, int forDifferentConstructor) { + List, AtomicInteger>> newList = Lists.newArrayList(); + List, Integer>> a = input.get().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