From 1f6137d24153b62c42da129ce5d6373bbf78ee34 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 14 Dec 2020 00:10:26 +0800 Subject: The big refactor Signed-off-by: shedaniel --- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 121 ++++++------- .../plugin/beacon/DefaultBeaconBaseCategory.java | 182 -------------------- .../plugin/beacon/DefaultBeaconBaseDisplay.java | 65 ------- .../beacon/base/DefaultBeaconBaseCategory.java | 187 +++++++++++++++++++++ .../beacon/base/DefaultBeaconBaseDisplay.java | 65 +++++++ .../payment/DefaultBeaconPaymentCategory.java | 183 ++++++++++++++++++++ .../payment/DefaultBeaconPaymentDisplay.java | 66 ++++++++ .../DefaultBeaconPaymentCategory.java | 182 -------------------- .../DefaultBeaconPaymentDisplay.java | 65 ------- .../plugin/blasting/DefaultBlastingDisplay.java | 1 - .../rei/plugin/brewing/BrewingRecipe.java | 2 - .../rei/plugin/brewing/DefaultBrewingCategory.java | 10 +- .../rei/plugin/brewing/DefaultBrewingDisplay.java | 21 +-- .../plugin/brewing/RegisteredBrewingRecipe.java | 2 - .../plugin/campfire/DefaultCampfireCategory.java | 8 +- .../plugin/campfire/DefaultCampfireDisplay.java | 16 +- .../composting/DefaultCompostingCategory.java | 20 ++- .../composting/DefaultCompostingDisplay.java | 17 +- .../rei/plugin/cooking/DefaultCookingCategory.java | 12 +- .../rei/plugin/cooking/DefaultCookingDisplay.java | 33 +--- .../plugin/crafting/DefaultCraftingCategory.java | 9 +- .../plugin/crafting/DefaultCraftingDisplay.java | 9 +- .../rei/plugin/crafting/DefaultCustomDisplay.java | 18 +- .../rei/plugin/crafting/DefaultShapedDisplay.java | 16 +- .../plugin/crafting/DefaultShapelessDisplay.java | 16 +- .../plugin/favorites/GameModeFavoriteEntry.java | 8 +- .../rei/plugin/fuel/DefaultFuelCategory.java | 13 +- .../rei/plugin/fuel/DefaultFuelDisplay.java | 11 +- .../information/DefaultInformationCategory.java | 18 +- .../information/DefaultInformationDisplay.java | 14 +- .../rei/plugin/pathing/DefaultPathingCategory.java | 8 +- .../rei/plugin/pathing/DefaultPathingDisplay.java | 19 ++- .../plugin/smelting/DefaultSmeltingDisplay.java | 1 - .../plugin/smithing/DefaultSmithingCategory.java | 7 +- .../plugin/smithing/DefaultSmithingDisplay.java | 23 +-- .../rei/plugin/smoking/DefaultSmokingDisplay.java | 1 - .../stonecutting/DefaultStoneCuttingCategory.java | 8 +- .../stonecutting/DefaultStoneCuttingDisplay.java | 16 +- .../plugin/stripping/DefaultStrippingCategory.java | 7 +- .../plugin/stripping/DefaultStrippingDisplay.java | 19 ++- .../rei/plugin/tilling/DefaultTillingCategory.java | 8 +- .../rei/plugin/tilling/DefaultTillingDisplay.java | 19 ++- 42 files changed, 763 insertions(+), 763 deletions(-) delete mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java delete mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java create mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentDisplay.java delete mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon_payment/DefaultBeaconPaymentCategory.java delete mode 100644 RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon_payment/DefaultBeaconPaymentDisplay.java (limited to 'RoughlyEnoughItems-default-plugin/src/main/java') diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index e89dba219..c8da92e8a 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -29,18 +29,19 @@ import com.google.common.collect.Sets; import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import it.unimi.dsi.fastutil.objects.ReferenceSet; +import me.shedaniel.architectury.hooks.FluidStackHooks; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.entry.EntryStacks; import me.shedaniel.rei.api.favorites.FavoriteEntry; import me.shedaniel.rei.api.favorites.FavoriteEntryType; import me.shedaniel.rei.api.fluid.FluidSupportProvider; -import me.shedaniel.rei.api.fractions.Fraction; import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.plugin.autocrafting.DefaultRecipeBookHandler; -import me.shedaniel.rei.plugin.beacon.DefaultBeaconBaseCategory; -import me.shedaniel.rei.plugin.beacon.DefaultBeaconBaseDisplay; -import me.shedaniel.rei.plugin.beacon_payment.DefaultBeaconPaymentCategory; -import me.shedaniel.rei.plugin.beacon_payment.DefaultBeaconPaymentDisplay; +import me.shedaniel.rei.plugin.beacon.base.DefaultBeaconBaseCategory; +import me.shedaniel.rei.plugin.beacon.base.DefaultBeaconBaseDisplay; +import me.shedaniel.rei.plugin.beacon.payment.DefaultBeaconPaymentCategory; +import me.shedaniel.rei.plugin.beacon.payment.DefaultBeaconPaymentDisplay; import me.shedaniel.rei.plugin.blasting.DefaultBlastingDisplay; import me.shedaniel.rei.plugin.brewing.DefaultBrewingCategory; import me.shedaniel.rei.plugin.brewing.DefaultBrewingDisplay; @@ -75,6 +76,7 @@ import me.shedaniel.rei.plugin.tilling.DefaultTillingCategory; import me.shedaniel.rei.plugin.tilling.DefaultTillingDisplay; import me.shedaniel.rei.plugin.tilling.DummyHoeItem; import me.shedaniel.rei.utils.CollectionUtils; +import me.shedaniel.rei.utils.EntryStackCompoundList; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -157,7 +159,7 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { } @Override - public void registerInformation(List entryStacks, Component name, UnaryOperator> textBuilder) { + public void registerInformation(List> entryStacks, Component name, UnaryOperator> textBuilder) { registerInfoDisplay(DefaultInformationDisplay.createFromEntries(entryStacks, name).lines(textBuilder.apply(Lists.newArrayList()))); } @@ -176,20 +178,20 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { } if (stacks != null) { for (ItemStack stack : entryRegistry.appendStacksForItem(item)) { - entryRegistry.registerEntry(EntryStack.create(stack)); + entryRegistry.registerEntry(EntryStacks.of(stack)); } } else - entryRegistry.registerEntry(EntryStack.create(item)); + entryRegistry.registerEntry(EntryStacks.of(item)); } - EntryStack stack = EntryStack.create(Items.ENCHANTED_BOOK); - List enchantments = new ArrayList<>(); + EntryStack stack = EntryStacks.of(Items.ENCHANTED_BOOK); + List> enchantments = new ArrayList<>(); for (Enchantment enchantment : Registry.ENCHANTMENT) { IntConsumer consumer = level -> { Map map = new HashMap<>(); map.put(enchantment, level); ItemStack itemStack = new ItemStack(Items.ENCHANTED_BOOK); EnchantmentHelper.setEnchantments(map, itemStack); - enchantments.add(EntryStack.create(itemStack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + enchantments.add(EntryStacks.of(itemStack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); }; if (enchantment.getMaxLevel() - enchantment.getMinLevel() >= 10) { consumer.accept(enchantment.getMinLevel()); @@ -201,7 +203,7 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { entryRegistry.registerEntriesAfter(stack, enchantments); for (Fluid fluid : Registry.FLUID) { if (!fluid.defaultFluidState().isEmpty() && fluid.defaultFluidState().isSource()) - entryRegistry.registerEntry(EntryStack.create(fluid)); + entryRegistry.registerEntry(EntryStacks.of(fluid)); } } @@ -209,9 +211,9 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { public void registerPluginCategories(RecipeHelper recipeHelper) { recipeHelper.registerCategories( new DefaultCraftingCategory(), - new DefaultCookingCategory(SMELTING, EntryStack.create(Items.FURNACE), "category.rei.smelting"), - new DefaultCookingCategory(SMOKING, EntryStack.create(Items.SMOKER), "category.rei.smoking"), - new DefaultCookingCategory(BLASTING, EntryStack.create(Items.BLAST_FURNACE), "category.rei.blasting"), new DefaultCampfireCategory(), + new DefaultCookingCategory(SMELTING, EntryStacks.of(Items.FURNACE), "category.rei.smelting"), + new DefaultCookingCategory(SMOKING, EntryStacks.of(Items.SMOKER), "category.rei.smoking"), + new DefaultCookingCategory(BLASTING, EntryStacks.of(Items.BLAST_FURNACE), "category.rei.blasting"), new DefaultCampfireCategory(), new DefaultStoneCuttingCategory(), new DefaultFuelCategory(), new DefaultBrewingCategory(), @@ -237,23 +239,24 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { recipeHelper.registerRecipes(STONE_CUTTING, StonecutterRecipe.class, DefaultStoneCuttingDisplay::new); recipeHelper.registerRecipes(SMITHING, UpgradeRecipe.class, DefaultSmithingDisplay::new); for (Map.Entry entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) { - recipeHelper.registerDisplay(new DefaultFuelDisplay(EntryStack.create(entry.getKey()), entry.getValue())); + recipeHelper.registerDisplay(new DefaultFuelDisplay(EntryStacks.of(entry.getKey()), entry.getValue())); } - List arrowStack = Collections.singletonList(EntryStack.create(Items.ARROW)); + List> arrowStack = Collections.singletonList(EntryStacks.of(Items.ARROW)); ReferenceSet registeredPotions = new ReferenceOpenHashSet<>(); - EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getItem() == Items.LINGERING_POTION).forEach(entry -> { - Potion potion = PotionUtils.getPotion(entry.getItemStack()); + EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValue() == Items.LINGERING_POTION).forEach(entry -> { + ItemStack itemStack = (ItemStack) entry.getValue(); + Potion potion = PotionUtils.getPotion(itemStack); if (registeredPotions.add(potion)) { - List> input = new ArrayList<>(); + EntryStackCompoundList input = new EntryStackCompoundList(); for (int i = 0; i < 4; i++) input.add(arrowStack); - input.add(Collections.singletonList(EntryStack.create(entry.getItemStack()))); + input.add(Collections.singletonList(EntryStacks.of(itemStack))); for (int i = 0; i < 4; i++) input.add(arrowStack); ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8); PotionUtils.setPotion(outputStack, potion); - PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(entry.getItemStack())); - List output = Collections.singletonList(EntryStack.create(outputStack).addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(itemStack)); + List> output = Collections.singletonList(EntryStacks.of(outputStack).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); recipeHelper.registerDisplay(new DefaultCustomDisplay(null, input, output)); } }); @@ -268,13 +271,13 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { i++; } DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - recipeHelper.registerDisplay(new DefaultStrippingDisplay(EntryStack.create(set.getKey()), EntryStack.create(set.getValue()))); + recipeHelper.registerDisplay(new DefaultStrippingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue()))); }); DummyHoeItem.getTilledBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - recipeHelper.registerDisplay(new DefaultTillingDisplay(EntryStack.create(set.getKey()), EntryStack.create(set.getValue().getBlock()))); + recipeHelper.registerDisplay(new DefaultTillingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); }); DummyShovelItem.getPathBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - recipeHelper.registerDisplay(new DefaultPathingDisplay(EntryStack.create(set.getKey()), EntryStack.create(set.getValue().getBlock()))); + recipeHelper.registerDisplay(new DefaultPathingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); }); recipeHelper.registerDisplay(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.getValues()), ItemStack::new))); recipeHelper.registerDisplay(new DefaultBeaconPaymentDisplay(CollectionUtils.map(Lists.newArrayList(ItemTags.BEACON_PAYMENT_ITEMS.getValues()), ItemStack::new))); @@ -316,11 +319,11 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { EntryRegistry.getInstance().getEntryStacks().forEach(this::applyPotionTransformer); for (List displays : RecipeHelper.getInstance().getAllRecipesNoHandlers().values()) { for (RecipeDisplay display : displays) { - for (List entries : display.getInputEntries()) - for (EntryStack stack : entries) + for (List> entries : display.getInputEntries()) + for (EntryStack stack : entries) applyPotionTransformer(stack); - for (List entries : display.getResultingEntries()) - for (EntryStack stack : entries) + for (List> entries : display.getResultingEntries()) + for (EntryStack stack : entries) applyPotionTransformer(stack); } } @@ -328,9 +331,9 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { LOGGER.info("Applied Check Tags for potion in %dms.", time); } - private void applyPotionTransformer(EntryStack stack) { - if (stack.getItem() instanceof PotionItem) - stack.addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); + private void applyPotionTransformer(EntryStack stack) { + if (stack.getValue() instanceof PotionItem) + stack.setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); } @Override @@ -355,46 +358,46 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { public void registerOthers(RecipeHelper recipeHelper) { recipeHelper.registerAutoCraftingHandler(new DefaultRecipeBookHandler()); - recipeHelper.registerWorkingStations(CRAFTING, EntryStack.create(Items.CRAFTING_TABLE)); - recipeHelper.registerWorkingStations(SMELTING, EntryStack.create(Items.FURNACE)); - recipeHelper.registerWorkingStations(SMOKING, EntryStack.create(Items.SMOKER)); - recipeHelper.registerWorkingStations(BLASTING, EntryStack.create(Items.BLAST_FURNACE)); - recipeHelper.registerWorkingStations(CAMPFIRE, EntryStack.create(Items.CAMPFIRE), EntryStack.create(Items.SOUL_CAMPFIRE)); - recipeHelper.registerWorkingStations(FUEL, EntryStack.create(Items.FURNACE), EntryStack.create(Items.SMOKER), EntryStack.create(Items.BLAST_FURNACE)); - recipeHelper.registerWorkingStations(BREWING, EntryStack.create(Items.BREWING_STAND)); - recipeHelper.registerWorkingStations(STONE_CUTTING, EntryStack.create(Items.STONECUTTER)); - recipeHelper.registerWorkingStations(COMPOSTING, EntryStack.create(Items.COMPOSTER)); - recipeHelper.registerWorkingStations(SMITHING, EntryStack.create(Items.SMITHING_TABLE)); - recipeHelper.registerWorkingStations(BEACON, EntryStack.create(Items.BEACON)); - recipeHelper.registerWorkingStations(BEACON_PAYMENT, EntryStack.create(Items.BEACON)); + recipeHelper.registerWorkingStations(CRAFTING, EntryStacks.of(Items.CRAFTING_TABLE)); + recipeHelper.registerWorkingStations(SMELTING, EntryStacks.of(Items.FURNACE)); + recipeHelper.registerWorkingStations(SMOKING, EntryStacks.of(Items.SMOKER)); + recipeHelper.registerWorkingStations(BLASTING, EntryStacks.of(Items.BLAST_FURNACE)); + recipeHelper.registerWorkingStations(CAMPFIRE, EntryStacks.of(Items.CAMPFIRE), EntryStacks.of(Items.SOUL_CAMPFIRE)); + recipeHelper.registerWorkingStations(FUEL, EntryStacks.of(Items.FURNACE), EntryStacks.of(Items.SMOKER), EntryStacks.of(Items.BLAST_FURNACE)); + recipeHelper.registerWorkingStations(BREWING, EntryStacks.of(Items.BREWING_STAND)); + recipeHelper.registerWorkingStations(STONE_CUTTING, EntryStacks.of(Items.STONECUTTER)); + recipeHelper.registerWorkingStations(COMPOSTING, EntryStacks.of(Items.COMPOSTER)); + recipeHelper.registerWorkingStations(SMITHING, EntryStacks.of(Items.SMITHING_TABLE)); + recipeHelper.registerWorkingStations(BEACON, EntryStacks.of(Items.BEACON)); + recipeHelper.registerWorkingStations(BEACON_PAYMENT, EntryStacks.of(Items.BEACON)); Set axes = Sets.newHashSet(), hoes = Sets.newHashSet(), shovels = Sets.newHashSet(); - EntryRegistry.getInstance().getEntryStacks().filter(stack -> stack.getType() == EntryStack.Type.ITEM).map(EntryStack::getItem).forEach(item -> { + EntryRegistry.getInstance().getEntryStacks().filter(stack -> stack.getValueType() == ItemStack.class).map(stack -> ((ItemStack) stack.getValue()).getItem()).forEach(item -> { if (item instanceof AxeItem && axes.add(item)) { - recipeHelper.registerWorkingStations(STRIPPING, EntryStack.create(item)); + recipeHelper.registerWorkingStations(STRIPPING, EntryStacks.of(item)); } if (item instanceof HoeItem && hoes.add(item)) { - recipeHelper.registerWorkingStations(TILLING, EntryStack.create(item)); + recipeHelper.registerWorkingStations(TILLING, EntryStacks.of(item)); } if (item instanceof ShovelItem && shovels.add(item)) { - recipeHelper.registerWorkingStations(PATHING, EntryStack.create(item)); + recipeHelper.registerWorkingStations(PATHING, EntryStacks.of(item)); } }); Tag axesTag = Minecraft.getInstance().getConnection().getTags().getItems().getTag(new ResourceLocation("c", "axes")); if (axesTag != null) { for (Item item : axesTag.getValues()) { - if (axes.add(item)) recipeHelper.registerWorkingStations(STRIPPING, EntryStack.create(item)); + if (axes.add(item)) recipeHelper.registerWorkingStations(STRIPPING, EntryStacks.of(item)); } } Tag hoesTag = Minecraft.getInstance().getConnection().getTags().getItems().getTag(new ResourceLocation("c", "hoes")); if (hoesTag != null) { for (Item item : hoesTag.getValues()) { - if (hoes.add(item)) recipeHelper.registerWorkingStations(TILLING, EntryStack.create(item)); + if (hoes.add(item)) recipeHelper.registerWorkingStations(TILLING, EntryStacks.of(item)); } } Tag shovelsTag = Minecraft.getInstance().getConnection().getTags().getItems().getTag(new ResourceLocation("c", "shovels")); if (shovelsTag != null) { for (Item item : shovelsTag.getValues()) { - if (shovels.add(item)) recipeHelper.registerWorkingStations(PATHING, EntryStack.create(item)); + if (shovels.add(item)) recipeHelper.registerWorkingStations(PATHING, EntryStacks.of(item)); } } recipeHelper.removeAutoCraftButton(FUEL); @@ -408,16 +411,16 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { recipeHelper.registerContainerClickArea(new Rectangle(78, 32, 28, 23), FurnaceScreen.class, SMELTING); recipeHelper.registerContainerClickArea(new Rectangle(78, 32, 28, 23), SmokerScreen.class, SMOKING); recipeHelper.registerContainerClickArea(new Rectangle(78, 32, 28, 23), BlastFurnaceScreen.class, BLASTING); - FluidSupportProvider.getInstance().registerProvider(itemStack -> { - Item item = itemStack.getItem(); - if (item instanceof BucketItem) - return InteractionResultHolder.success(Stream.of(EntryStack.create(((BucketItem) item).content, Fraction.ofWhole(1)))); + FluidSupportProvider.getInstance().registerProvider(entry -> { + ItemStack stack = entry.getValue(); + if (stack.getItem() instanceof BucketItem) + return InteractionResultHolder.success(Stream.of(EntryStacks.of(((BucketItem) stack.getItem()).content, FluidStackHooks.bucketAmount()))); return InteractionResultHolder.pass(null); }); // SubsetsRegistry subsetsRegistry = SubsetsRegistry.INSTANCE; -// subsetsRegistry.registerPathEntry("roughlyenoughitems:food", EntryStack.create(Items.MILK_BUCKET)); -// subsetsRegistry.registerPathEntry("roughlyenoughitems:food/roughlyenoughitems:cookies", EntryStack.create(Items.COOKIE)); - +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food", EntryStacks.of(Items.MILK_BUCKET)); +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food/roughlyenoughitems:cookies", EntryStacks.of(Items.COOKIE)); + FavoriteEntryType.registry().register(GameModeFavoriteEntry.ID, GameModeFavoriteEntry.Type.INSTANCE); FavoriteEntryType.registry().getOrCrateSection(new TranslatableComponent(GameModeFavoriteEntry.TRANSLATION_KEY)) .add(Arrays.stream(GameType.values()).map(GameModeFavoriteEntry.Type.INSTANCE::fromArgs).toArray(FavoriteEntry[]::new)); diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java deleted file mode 100644 index 4f7f64963..000000000 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/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; - -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.EntryStack; -import me.shedaniel.rei.api.REIHelper; -import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.widgets.Slot; -import me.shedaniel.rei.api.widgets.Widgets; -import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.widget.Widget; -import me.shedaniel.rei.gui.widget.WidgetWithBounds; -import me.shedaniel.rei.plugin.DefaultPlugin; -import me.shedaniel.rei.utils.CollectionUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.level.block.Blocks; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Objects; - -public class DefaultBeaconBaseCategory implements RecipeCategory { - @Override - public @NotNull ResourceLocation getIdentifier() { - return DefaultPlugin.BEACON; - } - - @Override - public @NotNull String getCategoryName() { - return I18n.get("category.rei.beacon_base"); - } - - @Override - public @NotNull EntryStack getLogo() { - return EntryStack.create(Blocks.BEACON); - } - - @Override - public @NotNull RecipeEntry getSimpleRenderer(DefaultBeaconBaseDisplay recipe) { - String name = getCategoryName(); - return new RecipeEntry() { - @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 @NotNull List setupDisplay(DefaultBeaconBaseDisplay display, Rectangle bounds) { - List widgets = Lists.newArrayList(); - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 8, bounds.y + 3)).entry(getLogo())); - 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 getFixedRecipesPerPage() { - 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; - } - - @NotNull - @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/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java deleted file mode 100644 index 603ef2dea..000000000 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseDisplay.java +++ /dev/null @@ -1,65 +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; - -import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.api.RecipeDisplay; -import me.shedaniel.rei.plugin.DefaultPlugin; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class DefaultBeaconBaseDisplay implements RecipeDisplay { - - private List entries; - - public DefaultBeaconBaseDisplay(List entries) { - this.entries = EntryStack.ofItemStacks(entries); - } - - @Override - public @NotNull List> getInputEntries() { - return Collections.singletonList(entries); - } - - public List getEntries() { - return entries; - } - - @Override - public @NotNull List> getResultingEntries() { - return Collections.emptyList(); - } - - @Override - public @NotNull ResourceLocation getRecipeCategory() { - return DefaultPlugin.BEACON; - } -} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java new file mode 100644 index 000000000..08ad35567 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseCategory.java @@ -0,0 +1,187 @@ +/* + * 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.REIHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.Renderer; +import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.api.widgets.Slot; +import me.shedaniel.rei.api.widgets.Tooltip; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.entries.RecipeRenderer; +import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.shedaniel.rei.plugin.DefaultPlugin; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; + +public class DefaultBeaconBaseCategory implements RecipeCategory { + @Override + public @NotNull ResourceLocation getIdentifier() { + return DefaultPlugin.BEACON; + } + + @Override + @NotNull + public String getCategoryName() { + return I18n.get("category.rei.beacon_base"); + } + + @Override + @NotNull + public Renderer getLogo() { + return EntryStacks.of(Blocks.BEACON); + } + + @Override + public @NotNull RecipeRenderer getSimpleRenderer(DefaultBeaconBaseDisplay recipe) { + String name = getCategoryName(); + return new RecipeRenderer() { + @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 @NotNull 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 getFixedRecipesPerPage() { + 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; + } + + @NotNull + @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/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java new file mode 100644 index 000000000..0ddbd7e09 --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/base/DefaultBeaconBaseDisplay.java @@ -0,0 +1,65 @@ +/* + * 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.EntryStack; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class DefaultBeaconBaseDisplay implements RecipeDisplay { + private List> entries; + + public DefaultBeaconBaseDisplay(List entries) { + this.entries = EntryStacks.ofItemStacks(entries); + } + + @Override + public @NotNull List>> getInputEntries() { + return Collections.singletonList(entries); + } + + public List> getEntries() { + return entries; + } + + @Override + public @NotNull List>> getResultingEntries() { + return Collections.emptyList(); + } + + @Override + public @NotNull ResourceLocation getRecipeCategory() { + return DefaultPlugin.BEACON; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java new file mode 100644 index 000000000..bba02c60c --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentCategory.java @@ -0,0 +1,183 @@ +/* + * 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.REIHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.Renderer; +import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.api.widgets.Slot; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.entries.RecipeRenderer; +import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.shedaniel.rei.plugin.DefaultPlugin; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Objects; + +public class DefaultBeaconPaymentCategory implements RecipeCategory { + @Override + public @NotNull ResourceLocation getIdentifier() { + return DefaultPlugin.BEACON_PAYMENT; + } + + @Override + public @NotNull String getCategoryName() { + return I18n.get("category.rei.beacon_payment"); + } + + @Override + public @NotNull Renderer getLogo() { + return EntryStacks.of(Blocks.BEACON); + } + + @Override + public @NotNull RecipeRenderer getSimpleRenderer(DefaultBeaconPaymentDisplay recipe) { + String name = getCategoryName(); + return new RecipeRenderer() { + @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 @NotNull 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 getFixedRecipesPerPage() { + 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; + } + + @NotNull + @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/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentDisplay.java new file mode 100644 index 000000000..d621d097e --- /dev/null +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon/payment/DefaultBeaconPaymentDisplay.java @@ -0,0 +1,66 @@ +/* + * 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 me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.plugin.DefaultPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class DefaultBeaconPaymentDisplay implements RecipeDisplay { + + private List> entries; + + public DefaultBeaconPaymentDisplay(List entries) { + this.entries = EntryStacks.ofItemStacks(entries); + } + + @Override + public @NotNull List>> getInputEntries() { + return Collections.singletonList(entries); + } + + public List> getEntries() { + return entries; + } + + @Override + public @NotNull List>> getResultingEntries() { + return Collections.emptyList(); + } + + @Override + public @NotNull ResourceLocation getRecipeCategory() { + return DefaultPlugin.BEACON_PAYMENT; + } +} diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon_payment/DefaultBeaconPaymentCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/beacon_payment/DefaultBeaconPaymentCategory.java deleted file mode 100644 index 1a3baa681..000000000 --- a/RoughlyEnoughItems-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.EntryStack; -import me.shedaniel.rei.api.REIHelper; -import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.widgets.Slot; -import me.shedaniel.rei.api.widgets.Widgets; -import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.widget.Widget; -import me.shedaniel.rei.gui.widget.WidgetWithBounds; -import me.shedaniel.rei.plugin.DefaultPlugin; -import me.shedaniel.rei.utils.CollectionUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.level.block.Blocks; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Objects; - -public class DefaultBeaconPaymentCategory implements RecipeCategory { - @Override - public @NotNull ResourceLocation getIdentifier() { - return DefaultPlugin.BEACON_PAYMENT; - } - - @Override - public @NotNull String getCategoryName() { - return I18n.get("category.rei.beacon_payment"); - } - - @Override - public @NotNull EntryStack getLogo() { - return EntryStack.create(Blocks.BEACON); - } - - @Override - public @NotNull RecipeEntry getSimpleRenderer(DefaultBeaconPaymentDisplay recipe) { - String name = getCategoryName(); - return new RecipeEntry() { - @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 @NotNull List setupDisplay(DefaultBeaconPaymentDisplay display, Rectangle bounds) { - List widgets = Lists.newArrayList(); - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 8, bounds.y + 3)).entry(getLogo())); - 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 getFixedRecipesPerPage() { - 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; - } - - @NotNull - @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(); - Sci