diff options
Diffstat (limited to 'default-plugin/src/main/java/me/shedaniel/rei')
11 files changed, 236 insertions, 143 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index 3500f4ce7..6280e533d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -26,12 +26,12 @@ package me.shedaniel.rei.plugin.client; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import dev.architectury.event.EventResult; -import dev.architectury.networking.NetworkManager; -import it.unimi.dsi.fastutil.objects.Object2FloatMap; 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.event.EventResult; +import me.shedaniel.architectury.mixin.FluidTagsAccessor; +import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; @@ -86,8 +86,6 @@ import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; -import net.minecraft.tags.Tag; -import net.minecraft.tags.TagCollection; import net.minecraft.world.item.*; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionBrewing; @@ -213,7 +211,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin } private static EntryIngredient getTag(ResourceLocation tagId) { - return EntryIngredients.ofItemTag(TagKey.create(Registry.ITEM_REGISTRY, tagId)); + return EntryIngredients.ofItemTag(tagId); } @Override @@ -229,17 +227,6 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin registry.registerRecipeFiller(UpgradeRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::new); registry.registerFiller(AnvilRecipe.class, DefaultAnvilDisplay::new); registry.registerFiller(BrewingRecipe.class, DefaultBrewingDisplay::new); - registry.registerFiller(TagKey.class, tagKey -> { - if (tagKey.isFor(Registry.ITEM_REGISTRY)) { - return DefaultTagDisplay.ofItems(tagKey); - } else if (tagKey.isFor(Registry.BLOCK_REGISTRY)) { - return DefaultTagDisplay.ofItems(tagKey); - } else if (tagKey.isFor(Registry.FLUID_REGISTRY)) { - return DefaultTagDisplay.ofFluids(tagKey); - } - - return null; - }); for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) { registry.add(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue())); } @@ -277,7 +264,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin DummyShovelItem.getPathBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { registry.add(new DefaultPathingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); }); - registry.add(new DefaultBeaconBaseDisplay(Collections.singletonList(EntryIngredients.ofItemTag(BlockTags.BEACON_BASE_BLOCKS)), Collections.emptyList())); + registry.add(new DefaultBeaconBaseDisplay(Collections.singletonList(EntryIngredients.ofBlockTag(BlockTags.BEACON_BASE_BLOCKS)), Collections.emptyList())); registry.add(new DefaultBeaconPaymentDisplay(Collections.singletonList(EntryIngredients.ofItemTag(ItemTags.BEACON_PAYMENT_ITEMS)), Collections.emptyList())); if (Platform.isFabric()) { Set<Potion> potions = Sets.newLinkedHashSet(); @@ -312,8 +299,14 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin registerForgePotions(registry, this); } - for (Registry<?> reg : Registry.REGISTRY) { - reg.getTags().forEach(tagPair -> registry.add(tagPair.getFirst())); + for (ResourceLocation tag : ItemTags.getAllTags().getAvailableTags()) { + registry.add(DefaultTagDisplay.ofItems(tag)); + } + for (ResourceLocation tag : BlockTags.getAllTags().getAvailableTags()) { + registry.add(DefaultTagDisplay.ofBlocks(tag)); + } + for (ResourceLocation tag : FluidTagsAccessor.getHelper().getAllTags().getAvailableTags()) { + registry.add(DefaultTagDisplay.ofFluids(tag)); } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java index d0312275b..eb5a1fed2 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java @@ -46,7 +46,6 @@ import me.shedaniel.rei.plugin.common.displays.tag.TagNode; import me.shedaniel.rei.plugin.common.displays.tag.TagNodes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; @@ -56,6 +55,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.function.Function; public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, ?>> { @@ -123,7 +123,7 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, TagNode<?>[] tagNode = new TagNode[]{null}; widgets.add(Widgets.withTranslate(Widgets.delegateWithBounds(() -> delegate[0]), 0, 0, 20)); - TagNodes.create(display.getKey(), dataResult -> { + TagNodes.create(display.getTagCollectionId(), display.getTagCollection(), display.getRegistry(), display.getKey(), dataResult -> { if (dataResult.error().isPresent()) { delegate[0] = Widgets.withBounds(Widgets.concat( Widgets.createLabel(new Point(innerBounds.getCenterX(), innerBounds.getCenterY() - 8), new TextComponent("Failed to resolve tags!")), @@ -132,9 +132,9 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, } else { tagNode[0] = dataResult.result().get(); //noinspection rawtypes - Function<? extends Holder<?>, ? extends EntryStack<?>> displayMapper = display.getMapper(); - Function<Holder<?>, EntryStack<?>> mapper = holder -> { - EntryStack<?> stack = ((Function<Holder<?>, EntryStack<?>>) displayMapper).apply(holder); + Function<?, ? extends EntryStack<?>> displayMapper = display.getMapper(); + Function<?, EntryStack<?>> mapper = value -> { + EntryStack<?> stack = ((Function<Object, EntryStack<?>>) displayMapper).apply(value); if (stack.isEmpty()) { return ClientEntryStacks.of(new AbstractRenderer() { @Override @@ -149,13 +149,13 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, @Override @Nullable public Tooltip getTooltip(TooltipContext context) { - return Tooltip.create(context.getPoint(), new TextComponent(holder.unwrapKey().map(key -> key.location().toString()).orElse("null"))); + return Tooltip.create(context.getPoint(), new TextComponent(Optional.ofNullable(stack.getIdentifier()).map(ResourceLocation::toString).orElse("null"))); } }); } return stack; }; - delegate[0] = Widgets.overflowed(overflowBounds, Widgets.padded(16, new TagTreeWidget(tagNode[0], mapper, overflowBounds))); + delegate[0] = Widgets.overflowed(overflowBounds, Widgets.padded(16, new TagTreeWidget(display.getTagCollection(), tagNode[0], mapper, overflowBounds))); } }); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java index 337814c9e..70350b2b1 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.plugin.client.categories.tag; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Slot; @@ -33,11 +32,11 @@ import me.shedaniel.rei.api.client.util.MatrixUtils; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.plugin.common.displays.tag.TagNode; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.core.Holder; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagCollection; import java.util.Collections; import java.util.List; @@ -50,7 +49,7 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> { private final Slot slot; private final List<? extends GuiEventListener> children; - public ReferenceTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) { + public ReferenceTagNodeWidget(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) { this.node = node; this.overflowBounds = overflowBounds; this.bounds = new Rectangle(0, 0, 24, 23); @@ -58,7 +57,7 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> { .disableBackground() .disableHighlight() .disableTooltips() - .entries(EntryIngredients.ofTag(node.getReference(), mapper)); + .entries(EntryIngredients.ofTag(tagCollection, node.getReference(), mapper)); this.children = Collections.singletonList(this.slot); } @@ -70,13 +69,12 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> { @Override public void render(PoseStack poses, int mouseX, int mouseY, float delta) { if (this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), getBounds()))) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, new ResourceLocation("textures/gui/advancements/widgets.png")); + Minecraft.getInstance().getTextureManager().bind(new ResourceLocation("textures/gui/advancements/widgets.png")); this.blit(poses, bounds.x, bounds.y, 1, 128 + 27, 24, 24); this.slot.getBounds().setLocation(bounds.getCenterX() - this.slot.getBounds().getWidth() / 2, bounds.y + (bounds.height - this.slot.getBounds().getHeight()) / 2 + 1); this.slot.render(poses, mouseX, mouseY, delta); if (this.containsMouse(mouseX, mouseY)) { - Tooltip.create(new TextComponent("#" + this.node.getReference().location().toString())).queue(); + Tooltip.create(new TextComponent("#" + this.node.getReference().toString())).queue(); } } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java index c1003e63c..b5fa00cb2 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java @@ -27,14 +27,14 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.plugin.common.displays.tag.TagNode; -import net.minecraft.core.Holder; +import net.minecraft.tags.TagCollection; import java.util.function.Function; public abstract class TagNodeWidget<S, T> extends WidgetWithBounds { - static <S, T> TagNodeWidget<S, T> create(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) { + static <S, T> TagNodeWidget<S, T> create(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) { if (node.getReference() != null) { - return new ReferenceTagNodeWidget<>(node, mapper, overflowBounds); + return new ReferenceTagNodeWidget<>(tagCollection, node, mapper, overflowBounds); } else if (node.getValue() != null) { return new ValueTagNodeWidget<>(node, mapper, overflowBounds); } else { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java index 3733fbedf..cccfadb3d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java @@ -30,11 +30,12 @@ import me.shedaniel.rei.api.client.util.MatrixUtils; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.plugin.common.displays.tag.TagNode; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.core.Holder; +import net.minecraft.tags.TagCollection; import java.util.ArrayList; import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; import java.util.stream.Stream; public class TagTreeWidget<S, T> extends WidgetWithBounds { @@ -45,13 +46,13 @@ public class TagTreeWidget<S, T> extends WidgetWithBounds { private final List<TagTreeWidget<S, T>> childWidgets; private final List<WidgetWithBounds> children; - public TagTreeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) { + public TagTreeWidget(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) { this.node = node; this.overflowBounds = overflowBounds; - this.rootWidget = TagNodeWidget.create(node, mapper, overflowBounds); + this.rootWidget = TagNodeWidget.create(tagCollection, node, mapper, overflowBounds); this.childWidgets = new ArrayList<>(); for (TagNode<S> childNode : node.children()) { - TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(childNode, mapper, overflowBounds); + TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(tagCollection, childNode, mapper, overflowBounds); childWidget.getBounds().y = rootWidget.getBounds().getMaxY() + 16; this.childWidgets.add(childWidget); } @@ -61,7 +62,7 @@ public class TagTreeWidget<S, T> extends WidgetWithBounds { childWidget.getBounds().x = rootWidget.getBounds().getCenterX() - childrenTotalWidth / 2 + x; x += childWidget.getBounds().width + 6; } - this.children = Stream.concat(Stream.of(this.rootWidget), this.childWidgets.stream()).toList(); + this.children = Stream.concat(Stream.of(this.rootWidget), this.childWidgets.stream()).collect(Collectors.toList()); this.bounds = new Rectangle(this.children.stream() .map(WidgetWithBounds::getBounds) .reduce(Rectangle::union) diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java index f2daae995..214ec9a37 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java @@ -33,10 +33,9 @@ import me.shedaniel.rei.api.client.util.MatrixUtils; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.plugin.common.displays.tag.TagNode; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -48,9 +47,9 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> { private final List<? extends GuiEventListener> children; private final Rectangle overflowBounds; - public ValueTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) { + public ValueTagNodeWidget(TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) { this.overflowBounds = overflowBounds; - HolderSet<S> holders = node.getValue(); + Collection<S> holders = node.getValue(); int width = Math.min(4, holders.size()); int height = Math.max((int) Math.ceil(holders.size() * 1.0 / width), 1); this.bounds = new Rectangle(0, 0, 16 * width + 12, 16 * height + 12); @@ -61,7 +60,7 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> { this.widgets = new ArrayList<>(); this.widgets.add(background); this.widgets.add(slotBackground); - for (Holder<S> holder : holders) { + for (S holder : holders) { int x = i % width; int y = i / width; Slot slot = Widgets.createSlot(new Rectangle(x * 16 + 5, y * 16 + 5, 18, 18)) @@ -88,8 +87,8 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> { poses.translate(bounds.x, bounds.y, 0); Point mouse = new Point(mouseX - bounds.x, mouseY - bounds.y); for (Widget widget : this.widgets) { - if (!(widget instanceof WidgetWithBounds withBounds) || - this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), withBounds.getBounds()))) { + if (!(widget instanceof WidgetWithBounds) || + this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), ((WidgetWithBounds) widget).getBounds()))) { widget.render(poses, mouse.x, mouse.y, delta); } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java index ee629e6ec..5c39c19e1 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java @@ -23,11 +23,8 @@ package me.shedaniel.rei.plugin.common; -import dev.architectury.injectables.annotations.ExpectPlatform; -import dev.architectury.injectables.annotations.PlatformOnly; import me.shedaniel.architectury.event.CompoundEventResult; import me.shedaniel.architectury.hooks.FluidStackHooks; -import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.NbtType; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; import me.shedaniel.rei.api.common.entry.comparison.EntryComparator; @@ -57,6 +54,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.Fluids; import org.jetbrains.annotations.ApiStatus; import java.util.function.Function; @@ -74,13 +72,13 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { Function<ItemStack, ListTag> enchantmentTag = stack -> { CompoundTag tag = stack.getTag(); if (tag == null) return null; - if (!tag.contains("Enchantments", Tag.TAG_LIST)) { - if (tag.contains("StoredEnchantments", Tag.TAG_LIST)) { - return tag.getList("StoredEnchantments", Tag.TAG_COMPOUND); + if (!tag.contains("Enchantments", NbtType.LIST)) { + if (tag.contains("StoredEnchantments", NbtType.LIST)) { + return tag.getList("StoredEnchantments", NbtType.COMPOUND); } return null; } - return tag.getList("Enchantments", Tag.TAG_COMPOUND); + return tag.getList("Enchantments", NbtType.COMPOUND); }; registry.register((context, stack) -> nbtHasher.hash(context, enchantmentTag.apply(stack)), Items.ENCHANTED_BOOK); registry.registerNbt(Items.POTION); @@ -95,7 +93,8 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { ItemStack stack = entry.getValue(); Item item = stack.getItem(); if (item instanceof BucketItem) { - Fluid fluid = FluidBucketHooks.getFluid((BucketItem) item); + // Fluid fluid = FluidBucketHooks.getFluid((BucketItem) item); + Fluid fluid = Fluids.WATER; if (fluid != null) { return CompoundEventResult.interruptTrue(Stream.of(EntryStacks.of(fluid, FluidStackHooks.bucketAmount()))); } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java index 4ac5263ea..8a20e943c 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java @@ -23,9 +23,8 @@ package me.shedaniel.rei.plugin.common.displays.crafting; -import dev.architectury.platform.Platform; -import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; -import it.unimi.dsi.fastutil.ints.IntIntPair; +import com.mojang.datafixers.util.Pair; +import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; @@ -68,7 +67,7 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD static { try { - Class.forName("me.shedaniel.rei.plugin.common.displays.crafting.%s.DefaultCraftingDisplayImpl".formatted(Platform.isForge() ? "forge" : "fabric")) + Class.forName(String.format("me.shedaniel.rei.plugin.common.displays.crafting.%s.DefaultCraftingDisplayImpl", Platform.isForge() ? "forge" : "fabric")) .getDeclaredMethod("registerPlatformSizeProvider") .invoke(null); } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) { @@ -162,11 +161,14 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD return BasicDisplay.Serializer.<DefaultCraftingDisplay<?>>of((input, output, location, tag) -> { if (tag.contains("REIRecipeType")) { String type = tag.getString("REIRecipeType"); - return switch (type) { - case "Shapeless" -> DefaultCustomShapelessDisplay.simple(input, output, location); - case "Shaped" -> DefaultCustomShapedDisplay.simple(input, output, tag.getInt("RecipeWidth"), tag.getInt("RecipeHeight"), location); - default -> throw new IllegalArgumentException("Unknown recipe type: " + type); - }; + switch (type) { + case "Shapeless": + return DefaultCustomShapelessDisplay.simple(input, output, location); + case "Shaped": + return DefaultCustomShapedDisplay.simple(input, output, tag.getInt("RecipeWidth"), tag.getInt("RecipeHeight"), location); + default: + throw new IllegalArgumentException("Unknown recipe type: " + type); + } } else { return DefaultCustomDisplay.simple(input, output, location); } @@ -195,7 +197,7 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD int inputWidth = getInputWidth(craftingWidth, craftingHeight); int inputHeight = getInputHeight(craftingWidth, craftingHeight); - Map<IntIntPair, InputIngredient<EntryStack<?>>> grid = new HashMap<>(); + Map<Pair<Integer, Integer>, InputIngredient<EntryStack<?>>> grid = new HashMap<>(); List<EntryIngredient> inputEntries = getInputEntries(); for (int i = 0; i < inputEntries.size(); i++) { @@ -204,7 +206,7 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD continue; } int index = getSlotWithSize(inputWidth, i, craftingWidth); - grid.put(new IntIntImmutablePair(i % inputWidth, i / inputWidth), InputIngredient.of(index, stacks)); + grid.put(new Pair<>(i % inputWidth, i / inputWidth), InputIngredient.of(index, stacks)); } List<InputIngredient<EntryStack<?>>> list = new ArrayList<>(craftingWidth * craftingHeight); @@ -214,7 +216,7 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD for (int x = 0; x < craftingWidth; x++) { for (int y = 0; y < craftingHeight; y++) { - InputIngredient<EntryStack<?>> ingredient = grid.get(new IntIntImmutablePair(x, y)); + InputIngredient<EntryStack<?>> ingredient = grid.get(new Pair<>(x, y)); if (ingredient != null) { int index = craftingWidth * y + x; list.set(index, ingredient); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/DefaultTagDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/DefaultTagDisplay.java index 272072d5b..232d4a72d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/DefaultTagDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/DefaultTagDisplay.java @@ -23,7 +23,8 @@ package me.shedaniel.rei.plugin.common.displays.tag; -import dev.architectury.fluid.FluidStack; +import me.shedaniel.architectury.fluid.FluidStack; +import me.shedaniel.architectury.mixin.FluidTagsAccessor; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; @@ -32,11 +33,14 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.plugin.common.BuiltinPlugin; -import net.minecraft.core.Holder; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagCollection; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.ApiStatus; @@ -46,30 +50,44 @@ import java.util.function.Function; @ApiStatus.Experimental public class DefaultTagDisplay<S, T> implements Display { - private final TagKey<S> key; - private final Function<Holder<S>, EntryStack<T>> mapper; + private final TagCollection<S> tagCollection; + private final String tagCollectionId; + private final ResourceLocation key; + private final Registry<S> registry; + private final Function<S, EntryStack<T>> mapper; private final List<EntryIngredient> ingredients; - public DefaultTagDisplay(TagKey<S> key, Function<Holder<S>, EntryStack<T>> mapper) { + public DefaultTagDisplay(TagCollection<S> tagCollection, String tagCollectionId, ResourceLocation key, Registry<S> registry, Function<S, EntryStack<T>> mapper) { + this.tagCollection = tagCollection; + this.tagCollectionId = tagCollectionId; this.key = key; + this.registry = registry; this.mapper = mapper; - this.ingredients = CollectionUtils.map(EntryIngredients.ofTag(key, mapper), EntryIngredient::of); + this.ingredients = CollectionUtils.map(EntryIngredients.ofTag(tagCollection, key, mapper), EntryIngredient::of); } - public static DefaultTagDisplay<ItemLike, ItemStack> ofItems(TagKey<ItemLike> key) { - return new DefaultTagDisplay<>(key, DefaultTagDisplay::extractItem); + public static DefaultTagDisplay<Item, ItemStack> ofItems(ResourceLocation key) { + return new DefaultTagDisplay<>(ItemTags.getAllTags(), "items", key, Registry.ITEM, DefaultTagDisplay::extractItem); } - public static DefaultTagDisplay<Fluid, FluidStack> ofFluids(TagKey<Fluid> key) { - return new DefaultTagDisplay<>(key, DefaultTagDisplay::extractFluid); + public static DefaultTagDisplay<Block, ItemStack> ofBlocks(ResourceLocation key) { + return new DefaultTagDisplay<>(BlockTags.getAllTags(), "blocks", key, Registry.BLOCK, DefaultTagDisplay::extractBlock); } - private static EntryStack<ItemStack> extractItem(Holder<ItemLike> holder) { - return EntryStacks.of(holder.value()); + public static DefaultTagDisplay<Fluid, FluidStack> ofFluids(ResourceLocation key) { + return new DefaultTagDisplay<>(FluidTagsAccessor.getHelper().getAllTags(), "fluids", key, Registry.FLUID, DefaultTagDisplay::extractFluid); } - private static EntryStack<FluidStack> extractFluid(Holder<Fluid> holder) { - return EntryStacks.of(holder.value()); + private static EntryStack<ItemStack> extractItem(Item holder) { + return EntryStacks.of(holder); + } + + private static EntryStack<ItemStack> extractBlock(Block holder) { + return EntryStacks.of(holder); + } + + private static EntryStack<FluidStack> extractFluid(Fluid holder) { + return EntryStacks.of(holder); } @Override @@ -89,14 +107,26 @@ public class DefaultTagDisplay<S, T> implements Display { @Override public Optional<ResourceLocation> getDisplayLocation() { - return Optional.of(key.location()); + return Optional.of(key); + } + + public String getTagCollectionId() { + return tagCollectionId; + } + + public TagCollection<S> getTagCollection() { + return tagCollection; } - public TagKey<S> getKey() { + public ResourceLocation getKey() { return key; } - public Function<Holder<S>, EntryStack<T>> getMapper() { + public Registry<S> getRegistry() { + return registry; + } + + public Function<S, EntryStack<T>> getMapper() { return mapper; } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java index 46d9aa3b4..d67c942a8 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java @@ -23,13 +23,12 @@ package me.shedaniel.rei.plugin.common.displays.tag; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; -import net.minecraft.tags.TagKey; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -41,11 +40,11 @@ public abstract class TagNode<T> { this.children = new ArrayList<>(); } - public static <T> TagNode<T> ofValues(HolderSet<T> value) { + public static <T> TagNode<T> ofValues(Collection<T> value) { return new ValuesTagNode<>(value); } - public static <T> TagNode<T> ofReference(TagKey<T> key) { + public static <T> TagNode<T> ofReference(ResourceLocation key) { return new ReferenceTagNode<>(key); } @@ -57,11 +56,11 @@ public abstract class TagNode<T> { children.add(child); } - public void addValuesChild(HolderSet<T> child) { + public void addValuesChild(Collection<T> child) { children.add(ofValues(child)); } - public void addReferenceChild(TagKey<T> child) { + public void addReferenceChild(ResourceLocation child) { children.add(ofReference(child)); } @@ -86,55 +85,55 @@ public abstract class TagNode<T> { protected abstract void asT |
