From 02d1d95dd54285cc1237d1b5016401274a5ae5f0 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 25 Mar 2021 18:15:16 +0800 Subject: Refactor Default Plugin packages, fix favorites Signed-off-by: shedaniel --- .../rei/api/client/gui/SimpleDisplayRenderer.java | 14 +- .../rei/api/client/gui/widgets/WidgetHolder.java | 9 + .../rei/api/client/gui/widgets/Widgets.java | 42 ++- .../rei/api/common/entry/EntryIngredient.java | 23 ++ .../rei/api/common/transfer/info/MenuInfo.java | 2 +- .../info/simple/RecipeBookGridMenuInfo.java | 72 +++++ .../me/shedaniel/rei/api/common/util/Animator.java | 102 +++++++ .../rei/api/common/util/EntryIngredients.java | 28 +- .../shedaniel/rei/api/common/util/EntryStacks.java | 91 ++---- .../main/java/me/shedaniel/rei/impl/Internals.java | 4 + build.gradle | 10 + .../autocrafting/DefaultRecipeBookHandler.java | 4 +- .../beacon/base/DefaultBeaconBaseCategory.java | 182 ----------- .../beacon/base/DefaultBeaconBaseDisplay.java | 64 ---- .../payment/DefaultBeaconPaymentCategory.java | 182 ----------- .../payment/DefaultBeaconPaymentDisplay.java | 64 ---- .../plugin/blasting/DefaultBlastingDisplay.java | 51 ---- .../rei/plugin/brewing/BrewingRecipe.java | 39 --- .../rei/plugin/brewing/DefaultBrewingCategory.java | 84 ------ .../rei/plugin/brewing/DefaultBrewingDisplay.java | 90 ------ .../plugin/brewing/RegisteredBrewingRecipe.java | 39 --- .../rei/plugin/client/DefaultClientPlugin.java | 101 ++++--- .../client/categories/DefaultBrewingCategory.java | 85 ++++++ .../client/categories/DefaultCampfireCategory.java | 81 +++++ .../categories/DefaultCompostingCategory.java | 124 ++++++++ .../client/categories/DefaultFuelCategory.java | 118 ++++++++ .../categories/DefaultInformationCategory.java | 216 +++++++++++++ .../client/categories/DefaultPathingCategory.java | 76 +++++ .../client/categories/DefaultSmithingCategory.java | 76 +++++ .../categories/DefaultStoneCuttingCategory.java | 80 +++++ .../categories/DefaultStrippingCategory.java | 76 +++++ .../client/categories/DefaultTillingCategory.java | 76 +++++ .../beacon/DefaultBeaconBaseCategory.java | 183 +++++++++++ .../beacon/DefaultBeaconPaymentCategory.java | 183 +++++++++++ .../categories/cooking/DefaultCookingCategory.java | 121 ++++++++ .../crafting/DefaultCraftingCategory.java | 112 +++++++ .../client/favorites/GameModeFavoriteEntry.java | 289 ++++++++++++++++++ .../client/favorites/WeatherFavoriteEntry.java | 335 +++++++++++++++++++++ .../shedaniel/rei/plugin/common/BuiltinPlugin.java | 24 +- .../shedaniel/rei/plugin/common/DefaultPlugin.java | 41 +-- .../common/campfire/DefaultCampfireCategory.java | 80 ----- .../common/campfire/DefaultCampfireDisplay.java | 73 ----- .../composting/DefaultCompostingCategory.java | 123 -------- .../composting/DefaultCompostingDisplay.java | 77 ----- .../common/cooking/DefaultCookingCategory.java | 120 -------- .../common/cooking/DefaultCookingDisplay.java | 94 ------ .../common/crafting/DefaultCraftingCategory.java | 110 ------- .../common/crafting/DefaultCraftingDisplay.java | 100 ------ .../common/crafting/DefaultCustomDisplay.java | 96 ------ .../common/crafting/DefaultShapedDisplay.java | 79 ----- .../common/crafting/DefaultShapelessDisplay.java | 79 ----- .../common/displays/DefaultCampfireDisplay.java | 73 +++++ .../common/displays/DefaultCompostingDisplay.java | 77 +++++ .../plugin/common/displays/DefaultFuelDisplay.java | 63 ++++ .../common/displays/DefaultInformationDisplay.java | 132 ++++++++ .../common/displays/DefaultPathingDisplay.java | 63 ++++ .../common/displays/DefaultSmithingDisplay.java | 66 ++++ .../displays/DefaultStoneCuttingDisplay.java | 59 ++++ .../common/displays/DefaultStrippingDisplay.java | 63 ++++ .../common/displays/DefaultTillingDisplay.java | 63 ++++ .../displays/beacon/DefaultBeaconBaseDisplay.java | 49 +++ .../displays/beacon/DefaultBeaconDisplay.java | 50 +++ .../beacon/DefaultBeaconPaymentDisplay.java | 49 +++ .../common/displays/brewing/BrewingRecipe.java | 39 +++ .../displays/brewing/DefaultBrewingDisplay.java | 94 ++++++ .../displays/cooking/DefaultBlastingDisplay.java | 50 +++ .../displays/cooking/DefaultCookingDisplay.java | 94 ++++++ .../displays/cooking/DefaultSmeltingDisplay.java | 50 +++ .../displays/cooking/DefaultSmokingDisplay.java | 47 +++ .../displays/crafting/DefaultCraftingDisplay.java | 100 ++++++ .../displays/crafting/DefaultCustomDisplay.java | 96 ++++++ .../displays/crafting/DefaultShapedDisplay.java | 79 +++++ .../displays/crafting/DefaultShapelessDisplay.java | 79 +++++ .../stonecutting/DefaultStoneCuttingCategory.java | 79 ----- .../stonecutting/DefaultStoneCuttingDisplay.java | 59 ---- .../containers/CraftingGridMenuInfoWrapper.java | 73 ----- .../shedaniel/rei/plugin/favorites/Animator.java | 97 ------ .../plugin/favorites/GameModeFavoriteEntry.java | 288 ------------------ .../rei/plugin/favorites/WeatherFavoriteEntry.java | 334 -------------------- .../rei/plugin/fuel/DefaultFuelCategory.java | 118 -------- .../rei/plugin/fuel/DefaultFuelDisplay.java | 63 ---- .../information/DefaultInformationCategory.java | 215 ------------- .../information/DefaultInformationDisplay.java | 102 ------- .../rei/plugin/pathing/DefaultPathingCategory.java | 75 ----- .../rei/plugin/pathing/DefaultPathingDisplay.java | 75 ----- .../rei/plugin/pathing/DummyShovelItem.java | 41 --- .../plugin/smelting/DefaultSmeltingDisplay.java | 51 ---- .../plugin/smithing/DefaultSmithingCategory.java | 75 ----- .../plugin/smithing/DefaultSmithingDisplay.java | 66 ---- .../rei/plugin/smoking/DefaultSmokingDisplay.java | 48 --- .../plugin/stripping/DefaultStrippingCategory.java | 75 ----- .../plugin/stripping/DefaultStrippingDisplay.java | 63 ---- .../rei/plugin/stripping/DummyAxeItem.java | 40 --- .../rei/plugin/tilling/DefaultTillingCategory.java | 75 ----- .../rei/plugin/tilling/DefaultTillingDisplay.java | 63 ---- .../shedaniel/rei/plugin/tilling/DummyHoeItem.java | 41 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 35 +-- .../rei/impl/client/ClientHelperImpl.java | 1 - .../shedaniel/rei/impl/client/REIHelperImpl.java | 2 +- .../rei/impl/client/config/ConfigManagerImpl.java | 8 +- .../client/config/entries/FilteringScreen.java | 2 +- .../entry/filtering/rules/ManualFilteringRule.java | 2 +- .../entry/filtering/rules/SearchFilteringRule.java | 4 +- .../entry/type/types/RenderingEntryDefinition.java | 4 +- .../impl/client/gui/ContainerScreenOverlay.java | 108 +++---- .../rei/impl/client/gui/credits/CreditsScreen.java | 2 +- .../client/gui/dragging/CurrentDraggingStack.java | 42 ++- .../rei/impl/client/gui/modules/Menu.java | 2 +- .../entries/EntryStackSubsetsMenuEntry.java | 4 +- .../gui/modules/entries/SubSubsetsMenuEntry.java | 2 +- .../gui/screen/AbstractDisplayViewingScreen.java | 21 +- .../gui/screen/CompositeDisplayViewingScreen.java | 6 +- .../gui/screen/DefaultDisplayViewingScreen.java | 6 +- .../impl/client/gui/screen/TransformingScreen.java | 1 - .../gui/screen/UncertainDisplayViewingScreen.java | 4 +- .../impl/client/gui/widget/EntryListWidget.java | 8 +- .../rei/impl/client/gui/widget/EntryWidget.java | 2 +- .../client/gui/widget/FavoritesListWidget.java | 186 +++++++----- .../impl/client/gui/widget/InternalWidgets.java | 3 +- .../gui/widget/search/OverlaySearchField.java | 2 +- .../client/registry/screen/ScreenRegistryImpl.java | 2 +- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 2 +- .../rei/impl/common/compat/LBASupportPlugin.java | 2 +- .../rei/impl/common/entry/EntryIngredientImpl.java | 71 +++++ .../impl/common/entry/type/EntryRegistryImpl.java | 2 +- .../entry/type/types/BuiltinEntryDefinition.java | 2 +- .../entry/type/types/EmptyEntryDefinition.java | 2 +- .../common/fluid/FluidSupportProviderImpl.java | 2 +- .../rei/impl/common/plugins/PluginManagerImpl.java | 22 +- .../impl/common/transfer/MenuInfoRegistryImpl.java | 4 +- .../shedaniel/rei/impl/common/util/Animator.java | 102 ------- .../plugin/client/DefaultClientRuntimePlugin.java | 8 +- .../plugin/client/entry/FluidEntryDefinition.java | 7 +- .../plugin/client/entry/ItemEntryDefinition.java | 4 +- 134 files changed, 4510 insertions(+), 4554 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetHolder.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/BrewingRecipe.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultBrewingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCampfireCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultFuelCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultInformationCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultPathingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultSmithingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultStoneCuttingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultStrippingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultTillingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconBaseCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconPaymentCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/cooking/DefaultCookingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/campfire/DefaultCampfireCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/campfire/DefaultCampfireDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/composting/DefaultCompostingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/composting/DefaultCompostingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/cooking/DefaultCookingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/cooking/DefaultCookingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/crafting/DefaultCraftingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/crafting/DefaultCraftingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/crafting/DefaultCustomDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/crafting/DefaultShapedDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/crafting/DefaultShapelessDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCampfireDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultFuelDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultPathingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultStoneCuttingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultStrippingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultTillingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/beacon/DefaultBeaconBaseDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/beacon/DefaultBeaconDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/beacon/DefaultBeaconPaymentDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/BrewingRecipe.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/cooking/DefaultBlastingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/cooking/DefaultCookingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/cooking/DefaultSmeltingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/cooking/DefaultSmokingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultShapedDisplay.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultShapelessDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/stonecutting/DefaultStoneCuttingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/common/stonecutting/DefaultStoneCuttingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/containers/CraftingGridMenuInfoWrapper.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/Animator.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/GameModeFavoriteEntry.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/favorites/WeatherFavoriteEntry.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/fuel/DefaultFuelCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/fuel/DefaultFuelDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/pathing/DefaultPathingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/pathing/DefaultPathingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/pathing/DummyShovelItem.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DefaultStrippingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/stripping/DummyAxeItem.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/tilling/DefaultTillingCategory.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/tilling/DefaultTillingDisplay.java delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/tilling/DummyHoeItem.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/util/Animator.java diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java index 12dec407f..9765edb99 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java @@ -30,12 +30,14 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Slot; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.WidgetHolder; import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.api.common.util.EntryStacks; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; @@ -46,18 +48,21 @@ import java.util.Comparator; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; -public class SimpleDisplayRenderer extends DisplayRenderer { +public class SimpleDisplayRenderer extends DisplayRenderer implements WidgetHolder { private static final Comparator> ENTRY_COMPARATOR = Comparator.comparingLong(EntryStacks::hashExact); private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private List inputWidgets; private List outputWidgets; + private List widgets; @ApiStatus.Internal private SimpleDisplayRenderer(List input, List output) { this.inputWidgets = simplify(input).stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> Widgets.createSlot(new Point(0, 0)).entries(stacks).disableBackground().disableHighlight().disableTooltips()).collect(Collectors.toList()); this.outputWidgets = CollectionUtils.map(simplify(output), outputStacks -> Widgets.createSlot(new Point(0, 0)).entries(CollectionUtils.filterToList(outputStacks, stack -> !stack.isEmpty())).disableBackground().disableHighlight().disableTooltips()); + this.widgets = Stream.concat(inputWidgets.stream(), outputWidgets.stream()).collect(Collectors.toList()); } private static List simplify(List original) { @@ -149,4 +154,9 @@ public class SimpleDisplayRenderer extends DisplayRenderer { public int getItemsPerLine() { return Mth.floor((getWidth() - 4f) / 18f); } + + @Override + public List children() { + return widgets; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetHolder.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetHolder.java new file mode 100644 index 000000000..74d66a18a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetHolder.java @@ -0,0 +1,9 @@ +package me.shedaniel.rei.api.client.gui.widgets; + +import net.minecraft.client.gui.components.events.GuiEventListener; + +import java.util.List; + +public interface WidgetHolder { + List children(); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index 643aa7580..fea6292e3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api.client.gui.widgets; +import com.google.common.collect.AbstractIterator; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import me.shedaniel.math.Dimension; @@ -44,11 +45,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Predicate; import java.util.function.Supplier; @Environment(EnvType.CLIENT) @@ -301,4 +301,40 @@ public final class Widgets { public static void produceClickSound() { Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } + + public static Iterable walk(Iterable listeners, Predicate predicate) { + return () -> new AbstractIterator() { + Stack> stack; + + { + stack = new Stack<>(); + stack.push(listeners.iterator()); + } + + @Override + protected T computeNext() { + while (!stack.empty()) { + Iterator peek = stack.peek(); + GuiEventListener listener = peek.next(); + if (!peek.hasNext()) + stack.pop(); + if (predicate.test(listener)) { + return (T) listener; + } + if (listener instanceof ContainerEventHandler) { + List children = ((ContainerEventHandler) listener).children(); + if (!children.isEmpty()) { + stack.push(children.iterator()); + } + } else if (listener instanceof WidgetHolder) { + List children = ((WidgetHolder) listener).children(); + if (!children.isEmpty()) { + stack.push(children.iterator()); + } + } + } + return endOfData(); + } + }; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java index fde4d8d8b..103586d35 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java @@ -51,6 +51,14 @@ public interface EntryIngredient extends List> { return Internals.getEntryIngredientProvider().of((Iterable>) (Iterable) stacks); } + static Builder builder() { + return Internals.getEntryIngredientProvider().builder(); + } + + static Builder builder(int initialCapacity) { + return Internals.getEntryIngredientProvider().builder(initialCapacity); + } + static EntryIngredient from(ListTag tag) { if (tag.isEmpty()) return empty(); EntryStack[] stacks = new EntryStack[tag.size()]; @@ -61,4 +69,19 @@ public interface EntryIngredient extends List> { } ListTag save(); + + @SuppressWarnings("rawtypes") + default List> cast() { + return (List>) (List) this; + } + + interface Builder { + Builder add(EntryStack stack); + + Builder add(EntryStack... stacks); + + Builder addAll(Iterable> stacks); + + EntryIngredient build(); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java index d8b453f43..0a7560a8f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java @@ -49,7 +49,7 @@ import java.util.List; * @see me.shedaniel.rei.api.common.transfer.info.simple.SimpleGridMenuInfo */ public interface MenuInfo { - Class getContainerClass(); + Class getMenuClass(); default RecipeFinderPopulator getRecipeFinderPopulator() { return (context, recipeFinder) -> { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java new file mode 100644 index 000000000..a513c649a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java @@ -0,0 +1,72 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.transfer.info.simple; + +import me.shedaniel.rei.api.common.display.SimpleMenuDisplay; +import me.shedaniel.rei.api.common.transfer.RecipeFinder; +import net.minecraft.world.inventory.RecipeBookMenu; +import net.minecraft.world.item.ItemStack; + +public class RecipeBookGridMenuInfo, D extends SimpleMenuDisplay> implements SimpleGridMenuInfo { + private final Class> menuClass; + + public RecipeBookGridMenuInfo(Class menuClass) { + this.menuClass = menuClass; + } + + @Override + public Class getMenuClass() { + return (Class) menuClass; + } + + @Override + public int getCraftingResultSlotIndex(T menu) { + return menu.getResultSlotIndex(); + } + + @Override + public int getCraftingWidth(T menu) { + return menu.getGridWidth(); + } + + @Override + public int getCraftingHeight(T menu) { + return menu.getGridHeight(); + } + + @Override + public void clearInputSlots(T menu) { + menu.clearCraftingContent(); + } + + @Override + public void populateRecipeFinder(T container, RecipeFinder finder) { + container.fillCraftSlotsStackedContents(new net.minecraft.world.entity.player.StackedContents() { + @Override + public void accountSimpleStack(ItemStack stack) { + finder.addNormalItem(stack); + } + }); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java b/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java new file mode 100644 index 000000000..e0e313c16 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java @@ -0,0 +1,102 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.util; + +import me.shedaniel.clothconfig2.impl.EasingMethod; +import net.minecraft.Util; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public final class Animator extends Number { + private double amount; + private double target; + private long start; + private long duration; + + public Animator() { + } + + public Animator(double amount) { + setAs(amount); + } + + public void setAs(double value) { + this.set(value, false, 0); + } + + public void setTo(double value, long duration) { + if (target != value) + this.set(value, true, duration); + } + + private void set(double value, boolean animated, long duration) { + this.target = value; + this.start = Util.getMillis(); + + if (animated) { + this.duration = duration; + } else { + this.duration = 0; + this.amount = this.target; + } + } + + public void update(double delta) { + if (duration != 0) { + if (amount < target) { + this.amount = Math.min(ease(amount, target + (target - amount), Math.min(((double) Util.getMillis() - start) / duration * delta * 3.0D, 1.0D), EasingMethod.EasingMethodImpl.LINEAR), target); + } else if (amount > target) { + this.amount = Math.max(ease(amount, target - (amount - target), Math.min(((double) Util.getMillis() - start) / duration * delta * 3.0D, 1.0D), EasingMethod.EasingMethodImpl.LINEAR), target); + } + } + } + + private static double ease(double start, double end, double amount, EasingMethod easingMethod) { + return start + (end - start) * easingMethod.apply(amount); + } + + @Override + public int intValue() { + return (int) amount; + } + + @Override + public long longValue() { + return (long) amount; + } + + @Override + public float floatValue() { + return (float) amount; + } + + @Override + public double doubleValue() { + return amount; + } + + public double target() { + return target; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java index d61f975ad..9b022ff28 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java @@ -30,6 +30,7 @@ import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; @@ -80,35 +81,25 @@ public final class EntryIngredients { public static EntryIngredient of(EntryDefinition definition, Collection values) { if (values.size() == 0) return EntryIngredient.empty(); if (values.size() == 1) return EntryIngredient.of(EntryStack.of(definition, values.iterator().next())); - List> result = new ArrayList<>(values.size()); + EntryIngredient.Builder result = EntryIngredient.builder(values.size()); for (T value : values) { result.add(EntryStack.of(definition, value)); } - return EntryIngredient.of(result); + return result.build(); } public static EntryIngredient ofItems(Collection stacks) { if (stacks.size() == 0) return EntryIngredient.empty(); if (stacks.size() == 1) return EntryIngredient.of(EntryStacks.of(stacks.iterator().next())); - List> result = new ArrayList<>(stacks.size()); + EntryIngredient.Builder result = EntryIngredient.builder(stacks.size()); for (ItemLike stack : stacks) { result.add(EntryStacks.of(stack)); } - return EntryIngredient.of(result); + return result.build(); } public static EntryIngredient ofItemStacks(Collection stacks) { - if (stacks.size() == 0) return EntryIngredient.empty(); - if (stacks.size() == 1) { - ItemStack stack = stacks.iterator().next(); - if (stack.isEmpty()) return EntryIngredient.empty(); - return EntryIngredient.of(EntryStacks.of(stack)); - } - List> result = new ArrayList<>(stacks.size()); - for (ItemStack stack : stacks) { - result.add(EntryStacks.of(stack)); - } - return EntryIngredient.of(result); + return of(VanillaEntryTypes.ITEM, stacks); } public static EntryIngredient ofIngredient(Ingredient ingredient) { @@ -116,12 +107,13 @@ public final class EntryIngredients { ItemStack[] matchingStacks = ingredient.getItems(); if (matchingStacks.length == 0) return EntryIngredient.empty(); if (matchingStacks.length == 1) return EntryIngredient.of(EntryStacks.of(matchingStacks[0])); - List> result = new ArrayList<>(matchingStacks.length); + EntryIngredient.Builder result = EntryIngredient.builder(matchingStacks.length); for (ItemStack matchingStack : matchingStacks) { - if (!matchingStack.isEmpty()) + if (!matchingStack.isEmpty()) { result.add(EntryStacks.of(matchingStack)); + } } - return EntryIngredient.of(result); + return result.build(); } public static List ofIngredients(List ingredients) { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java index b28d91add..b7882298b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.common.util; -import com.google.common.collect.ImmutableList; import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -35,11 +34,10 @@ import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.material.Fluid; -import java.util.*; +import java.util.Iterator; import java.util.stream.Stream; public final class EntryStacks { @@ -73,61 +71,18 @@ public final class EntryStacks { return of(new ItemStack(item)); } - public static List> ofItems(Collection stacks) { - if (stacks.size() == 0) return Collections.emptyList(); - if (stacks.size() == 1) return Collections.singletonList(of(stacks.iterator().next())); - List> result = new ArrayList<>(stacks.size()); - for (ItemLike stack : stacks) { - result.add(of(stack)); - } - return ImmutableList.copyOf(result); - } - - public static List> ofItemStacks(Collection stacks) { - if (stacks.size() == 0) return Collections.emptyList(); - if (stacks.size() == 1) { - ItemStack stack = stacks.iterator().next(); - if (stack.isEmpty()) return Collections.emptyList(); - return Collections.singletonList(of(stack)); - } - List> result = new ArrayList<>(stacks.size()); - for (ItemStack stack : stacks) { - result.add(of(stack)); - } - return ImmutableList.copyOf(result); - } - - public static List> ofIngredient(Ingredient ingredient) { - if (ingredient.isEmpty()) return Collections.emptyList(); - ItemStack[] matchingStacks = ingredient.getItems(); - if (matchingStacks.length == 0) return Collections.emptyList(); - if (matchingStacks.length == 1) return Collections.singletonList(of(matchingStacks[0])); - List> result = new ArrayList<>(matchingStacks.length); - for (ItemStack matchingStack : matchingStacks) { - if (!matchingStack.isEmpty()) - result.add(of(matchingStack)); - } - return ImmutableList.copyOf(result); - } - - public static List>> ofIngredients(List ingredients) { - if (ingredients.size() == 0) return Collections.emptyList(); - if (ingredients.size() == 1) { - Ingredient ingredient = ingredients.get(0); - if (ingredient.isEmpty()) return Collections.emptyList(); - return Collections.singletonList(ofIngredient(ingredient)); - } - boolean emptyFlag = true; - List>> result = new ArrayList<>(ingredients.size()); - for (int i = ingredients.size() - 1; i >= 0; i--) { - Ingredient ingredient = ingredients.get(i); - if (emptyFlag && ingredient.isEmpty()) continue; - result.add(0, ofIngredient(ingredient)); - emptyFlag = false; - } - return ImmutableList.copyOf(result); - } - + /** + * Compares equality under the provided {@code context}. + * Prioritizes {@link me.shedaniel.rei.api.common.entry.type.EntryDefinition#equals(Object, Object, ComparisonContext)} then compares + * with {@link EntryTypeBridge} for differing {@link EntryType}. + *

+ * For example, a lava bucket should still be equals to a lava fluid. + * + * @param left the first stack to compare + * @param right the second stack to compare + * @param context the context of the equality check + * @return the equality under the provided {@code context} + */ public static boolean equals(EntryStack left, EntryStack right, ComparisonContext context) { if (left == null) return right == null; if (right == null) return left == null; @@ -164,10 +119,30 @@ public final class EntryStacks { return false; } + /** + * Compares equality for the {@link ComparisonContext#EXACT} context, stacks that equal should share the same normalized stack. + *

+ * For example, enchantment books of different enchantments will not be equal under this context. + * However, difference between the amount of objects in a stack will not affect the result. + * + * @param left the first stack to compare + * @param right the second stack to compare + * @return the equality for the {@link ComparisonContext#EXACT} context + */ public static boolean equalsExact(EntryStack left, EntryStack right) { return equals(left, right, ComparisonContext.EXACT); } + /** + * Compares equality for the {@link ComparisonContext#FUZZY} context, stacks that equal may not share the same normalized stack. + * This result is less specific, mainly used for fuzzy matching between different stacks. + *

+ * For example, enchantment books of different enchantments should still be equal under this context. + * + * @param left the first stack to compare + * @param right the second stack to compare + * @return the equality for the {@link ComparisonContext#EXACT} context + */ public static boolean equalsFuzzy(EntryStack left, EntryStack right) { return equals(left, right, ComparisonContext.FUZZY); } diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java index afa599934..6c2bc189b 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -123,6 +123,10 @@ public final class Internals { EntryIngredient of(EntryStack... stacks); EntryIngredient of(Iterable> stacks); + + EntryIngredient.Builder builder(); + + EntryIngredient.Builder builder(int initialCapacity); } public interface NbtHasherProvider { diff --git a/build.gradle b/build.gradle index 927684add..bb7ce9244 100755 --- a/build.gradle +++ b/build.gradle @@ -217,3 +217,13 @@ publishing { } } }*/ + +allprojects { + repositories { + mavenLocal() + } + + architectury { + transformerVersion = "2.1.9999" + } +} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java index 797073814..07884806d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java @@ -27,8 +27,8 @@ import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.display.SimpleMenuDisplay; -import me.shedaniel.rei.plugin.common.cooking.DefaultCookingDisplay; -import me.shedaniel.rei.plugin.common.crafting.DefaultCraftingDisplay; +import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay; +import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.Screen; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java deleted file mode 100644 index 7e27410c4..000000000 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.plugin.beacon.base; - -import com.google.common.collect.Lists; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.api.ScrollingContainer; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.REIHelper; -import me.shedaniel.rei.api.client.gui.DisplayRenderer; -import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.widgets.Slot; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.api.client.registry.display.DisplayCategory; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.plugin.common.BuiltinPlugin; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.util.Mth; -import net.minecraft.world.level.block.Blocks; - -import java.util.List; -import java.util.Objects; - -public class DefaultBeaconBaseCategory implements DisplayCategory { - @Override - public CategoryIdentifier getCategoryIdentifier() { - return BuiltinPlugin.BEACON_BASE; - } - - @Override - public Component getTitle() { - return new TranslatableComponent("category.rei.beacon_base"); - } - - @Override - public Renderer getIcon() { - return EntryStacks.of(Blocks.BEACON); - } - - @Override - public DisplayRenderer getDisplayRenderer(DefaultBeaconBaseDisplay display) { - Component name = getTitle(); - return new DisplayRenderer() { - @Override - public int getHeight() { - return 10 + Minecraft.getInstance().font.lineHeight; - } - - @Override - public void render(PoseStack matrices, Rectangle rectangle, int mouseX, int mouseY, float delta) { - Minecraft.getInstance().font.draw(matrices, name, rectangle.x + 5, rectangle.y + 6, -1); - } - }; - } - - @Override - public List setupDisplay(DefaultBeaconBaseDisplay display, Rectangle bounds) { - List widgets = Lists.newArrayList(); - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 8, bounds.y + 3)).entry(EntryStacks.of(Blocks.BEACON))); - Rectangle rectangle = new Rectangle(bounds.getCenterX() - (bounds.width / 2) - 1, bounds.y + 23, bounds.width + 2, bounds.height - 28); - widgets.add(Widgets.createSlotBase(rectangle)); - widgets.add(new ScrollableSlotsWidget(rectangle, CollectionUtils.map(display.getEntries(), t -> Widgets.createSlot(new Point(0, 0)).disableBackground().entry(t)))); - return widgets; - } - - @Override - public int getDisplayHeight() { - return 140; - } - - @Override - public int getFixedDisplaysPerPage() { - return 1; - } - - private static class ScrollableSlotsWidget extends WidgetWithBounds { - private Rectangle bounds; - private List widgets; - private final ScrollingContainer scrolling = new ScrollingContainer() { - @Override - public Rectangle getBounds() { - Rectangle bounds = ScrollableSlotsWidget.this.getBounds(); - return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); - } - - @Override - public int getMaxScrollHeight() { - return Mth.ceil(widgets.size() / 8f) * 18; - } - }; - - public ScrollableSlotsWidget(Rectangle bounds, List widgets) { - this.bounds = Objects.requireNonNull(bounds); - this.widgets = Lists.newArrayList(widgets); - } - - @Override - public boolean mouseScrolled(double double_1, double double_2, double double_3) { - if (containsMouse(double_1, double_2)) { - scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); - return true; - } - return false; - } - - @Override - public Rectangle getBounds() { - return bounds; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (scrolling.updateDraggingState(mouseX, mouseY, button)) - return true; - return super.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) - return true; - return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - scrolling.updatePosition(delta); - Rectangle innerBounds = scrolling.getScissorBounds(); - ScissorsHandler.INSTANCE.scissor(innerBounds); - for (int y = 0; y < Mth.ceil(widgets.size() / 8f); y++) { - for (int x = 0; x < 8; x++) { - int index = y * 8 + x; - if (widgets.size() <= index) - break; - Slot widget = widgets.get(index); - widget.getBounds().setLocation(bounds.x + 1 + x * 18, (int) (bounds.y + 1 + y * 18 - scrolling.scrollAmount)); - widget.render(matrices, mouseX, mouseY, delta); - } - } - ScissorsHandler.INSTANCE.removeLastScissor(); - ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); - scrolling.renderScrollBar(0xff000000, 1, REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); - ScissorsHandler.INSTANCE.removeLastScissor(); - } - - @Override - public List children() { - return widgets; - } - } -} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java deleted file mode 100644 index e7c5a53a0..000000000 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.plugin.beacon.base; - -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.util.EntryIngredients; -import me.shedaniel.rei.plugin.common.BuiltinPlugin; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.world.item.ItemStack; - -import java.util.Collections; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class DefaultBeaconBaseDisplay implements Display { - private EntryIngredient entries; - - public DefaultBeaconBaseDisplay(List entries) { - this.entries = EntryIngredients.ofItemStacks(entries); - } - - @Override - public List getInputEntries() { - return Collections.singletonList(entries); - } - - public EntryIngredient getEntries() { - return entries; - } - - @Override - public List getOutputEntries() { - return Collections.emptyList(); - } - - @Override - public CategoryIdentifier getCategoryIdentifier() { - return BuiltinPlugin.BEACON_BASE; - } -} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java deleted file mode 100644 index d1f146bda..000000000 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.plugin.beacon.payment; - -import com.google.common.collect.Lists; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.api.ScrollingContainer; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.REIHelper; -import me.shedaniel.rei.api.client.gui.DisplayRenderer; -import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.widgets.Slot; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.api.client.registry.display.DisplayCategory; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.plugin.common.BuiltinPlugin; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.util.Mth; -import net.minecraft.world.level.block.Blocks; - -import java.util.List; -import java.util.Objects; - -public class DefaultBeaconPaymentCategory implements DisplayCategory { - @Override - public CategoryIdentifier getCategoryIdentifier() { - return BuiltinPlugin.BEACON_PAYMENT; - } - - @Override - public Component getTitle() { - return new TranslatableComponent("category.rei.beacon_payment"); - } - - @Override - public Renderer getIcon() { - return EntryStacks.of(Blocks.BEACON); - } - - @Override - public DisplayRenderer getDisplayRenderer(DefaultBeaconPaymentDisplay display) { - Component name = getTitle(); - return new DisplayRenderer() { - @Override - public int getHeight() { - return 10 + Minecraft.getInstance().font.lineHeight; - } - - @Override - public void render(PoseStack matrices, Rectangle rectangle, int mouseX, int mouseY, float delta) { - Minecraft.getInstance().font.draw(matrices, name, rectangle.x + 5, rectangle.y + 6, -1); - } - }; - } - - @Override - public List setupDisplay(DefaultBeaconPaymentDisplay display, Rectangle bounds) { - List widgets = Lists.newArrayList(); - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 8, bounds.y + 3)).entry(EntryStacks.of(Blocks.BEACON))); - Rectangle rectangle = new Rectangle(bounds.getCenterX() - (bounds.width / 2) - 1, bounds.y + 23, bounds.width + 2, bounds.height - 28); - widgets.add(Widgets.createSlotBase(rectangle)); - widgets.add(new ScrollableSlotsWidget(rectangle, CollectionUtils.map(display.getEntries(), t -> Widgets.createSlot(new Point(0, 0)).disableBackground().entry(t)))); - return widgets; - } - - @Override - public int getDisplayHeight() { - return 140; - } - - @Override - public int getFixedDisplaysPerPage() { - return 1; - } - - private static class ScrollableSlotsWidget extends WidgetWithBounds { - private Rectangle bounds; - private List widgets; - private final ScrollingContainer scrolling = new ScrollingContainer() { - @Override - public Rectangle getBounds() { - Rectangle bounds = ScrollableSlotsWidget.this.getBounds(); - return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); - } - - @Override - public int getMaxScrollHeight() { - return Mth.ceil(widgets.size() / 8f) * 18; - } - }; - - public ScrollableSlotsWidget(Rectangle bounds, List widgets) { - this.bounds = Objects.requireNonNull(bounds); - this.widgets = Lists.newArrayList(widgets); - } - - @Override - public boolean mouseScrolled(double double_1, double double_2, double double_3) { - if (containsMouse(double_1, double_2)) { - scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); - return true; - } - return false; - } - - @Override - public Rectangle getBounds() { - return bounds; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (scrolling.updateDraggingState(mouseX, mouseY, button)) - return true; - return super.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) - return true; - return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - scrolling.updatePosition(delta); - Rectangle innerBounds = scrolling.getScissorBounds(); - ScissorsHandler.INSTANCE.scissor(innerBounds); - for (int y = 0; y < Mth.ceil(widgets.size() / 8f); y++) { - for (int x = 0; x < 8; x++) { - int index = y * 8 + x; - if (widgets.size() <= index) - break; - Slot widget = widgets.get(index); - widget.getBounds().setLocation(bounds.x + 1 + x * 18, (int) (bounds.y + 1 + y * 18 - scrolling.scrollAmount)); - widget.rende