From 1e869aeac83d1627a6cae32a3b53b7d17bd3d7b8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 29 May 2023 23:17:20 +0800 Subject: Fix compile errors --- .../rei/plugin/client/DefaultClientPlugin.java | 33 ++--- .../client/categories/tag/DefaultTagCategory.java | 14 +-- .../categories/tag/ReferenceTagNodeWidget.java | 14 +-- .../client/categories/tag/TagNodeWidget.java | 6 +- .../client/categories/tag/TagTreeWidget.java | 11 +- .../client/categories/tag/ValueTagNodeWidget.java | 13 +- .../shedaniel/rei/plugin/common/DefaultPlugin.java | 15 ++- .../displays/crafting/DefaultCraftingDisplay.java | 26 ++-- .../common/displays/tag/DefaultTagDisplay.java | 68 ++++++++--- .../rei/plugin/common/displays/tag/TagNode.java | 43 ++++--- .../rei/plugin/common/displays/tag/TagNodes.java | 136 ++++++++++++++++----- 11 files changed, 236 insertions(+), 143 deletions(-) (limited to 'default-plugin/src/main/java') 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 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 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> { @@ -123,7 +123,7 @@ public class DefaultTagCategory implements DisplayCategory[] 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, ? extends EntryStack> displayMapper = display.getMapper(); - Function, EntryStack> mapper = holder -> { - EntryStack stack = ((Function, EntryStack>) displayMapper).apply(holder); + Function> displayMapper = display.getMapper(); + Function> mapper = value -> { + EntryStack stack = ((Function>) displayMapper).apply(value); if (stack.isEmpty()) { return ClientEntryStacks.of(new AbstractRenderer() { @Override @@ -149,13 +149,13 @@ public class DefaultTagCategory implements DisplayCategory 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 extends TagNodeWidget { private final Slot slot; private final List children; - public ReferenceTagNodeWidget(TagNode node, Function, EntryStack> mapper, Rectangle overflowBounds) { + public ReferenceTagNodeWidget(TagCollection tagCollection, TagNode node, Function> mapper, Rectangle overflowBounds) { this.node = node; this.overflowBounds = overflowBounds; this.bounds = new Rectangle(0, 0, 24, 23); @@ -58,7 +57,7 @@ public class ReferenceTagNodeWidget extends TagNodeWidget { .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 extends TagNodeWidget { @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 extends WidgetWithBounds { - static TagNodeWidget create(TagNode node, Function, EntryStack> mapper, Rectangle overflowBounds) { + static TagNodeWidget create(TagCollection tagCollection, TagNode node, Function> 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 extends WidgetWithBounds { @@ -45,13 +46,13 @@ public class TagTreeWidget extends WidgetWithBounds { private final List> childWidgets; private final List children; - public TagTreeWidget(TagNode node, Function, EntryStack> mapper, Rectangle overflowBounds) { + public TagTreeWidget(TagCollection tagCollection, TagNode node, Function> 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 childNode : node.children()) { - TagTreeWidget childWidget = new TagTreeWidget<>(childNode, mapper, overflowBounds); + TagTreeWidget 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 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 extends TagNodeWidget { private final List children; private final Rectangle overflowBounds; - public ValueTagNodeWidget(TagNode node, Function, EntryStack> mapper, Rectangle overflowBounds) { + public ValueTagNodeWidget(TagNode node, Function> mapper, Rectangle overflowBounds) { this.overflowBounds = overflowBounds; - HolderSet holders = node.getValue(); + Collection 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 extends TagNodeWidget { this.widgets = new ArrayList<>(); this.widgets.add(background); this.widgets.add(slotBackground); - for (Holder 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 extends TagNodeWidget { 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 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> 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> extends BasicD return BasicDisplay.Serializer.>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> extends BasicD int inputWidth = getInputWidth(craftingWidth, craftingHeight); int inputHeight = getInputHeight(craftingWidth, craftingHeight); - Map>> grid = new HashMap<>(); + Map, InputIngredient>> grid = new HashMap<>(); List inputEntries = getInputEntries(); for (int i = 0; i < inputEntries.size(); i++) { @@ -204,7 +206,7 @@ public abstract class DefaultCraftingDisplay> 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>> list = new ArrayList<>(craftingWidth * craftingHeight); @@ -214,7 +216,7 @@ public abstract class DefaultCraftingDisplay> extends BasicD for (int x = 0; x < craftingWidth; x++) { for (int y = 0; y < craftingHeight; y++) { - InputIngredient> ingredient = grid.get(new IntIntImmutablePair(x, y)); + InputIngredient> 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 implements Display { - private final TagKey key; - private final Function, EntryStack> mapper; + private final TagCollection tagCollection; + private final String tagCollectionId; + private final ResourceLocation key; + private final Registry registry; + private final Function> mapper; private final List ingredients; - public DefaultTagDisplay(TagKey key, Function, EntryStack> mapper) { + public DefaultTagDisplay(TagCollection tagCollection, String tagCollectionId, ResourceLocation key, Registry registry, Function> 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 ofItems(TagKey key) { - return new DefaultTagDisplay<>(key, DefaultTagDisplay::extractItem); + public static DefaultTagDisplay ofItems(ResourceLocation key) { + return new DefaultTagDisplay<>(ItemTags.getAllTags(), "items", key, Registry.ITEM, DefaultTagDisplay::extractItem); } - public static DefaultTagDisplay ofFluids(TagKey key) { - return new DefaultTagDisplay<>(key, DefaultTagDisplay::extractFluid); + public static DefaultTagDisplay ofBlocks(ResourceLocation key) { + return new DefaultTagDisplay<>(BlockTags.getAllTags(), "blocks", key, Registry.BLOCK, DefaultTagDisplay::extractBlock); } - private static EntryStack extractItem(Holder holder) { - return EntryStacks.of(holder.value()); + public static DefaultTagDisplay ofFluids(ResourceLocation key) { + return new DefaultTagDisplay<>(FluidTagsAccessor.getHelper().getAllTags(), "fluids", key, Registry.FLUID, DefaultTagDisplay::extractFluid); } - private static EntryStack extractFluid(Holder holder) { - return EntryStacks.of(holder.value()); + private static EntryStack extractItem(Item holder) { + return EntryStacks.of(holder); + } + + private static EntryStack extractBlock(Block holder) { + return EntryStacks.of(holder); + } + + private static EntryStack extractFluid(Fluid holder) { + return EntryStacks.of(holder); } @Override @@ -89,14 +107,26 @@ public class DefaultTagDisplay implements Display { @Override public Optional getDisplayLocation() { - return Optional.of(key.location()); + return Optional.of(key); + } + + public String getTagCollectionId() { + return tagCollectionId; + } + + public TagCollection getTagCollection() { + return tagCollection; } - public TagKey getKey() { + public ResourceLocation getKey() { return key; } - public Function, EntryStack> getMapper() { + public Registry getRegistry() { + return registry; + } + + public Function> 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 { this.children = new ArrayList<>(); } - public static TagNode ofValues(HolderSet value) { + public static TagNode ofValues(Collection value) { return new ValuesTagNode<>(value); } - public static TagNode ofReference(TagKey key) { + public static TagNode ofReference(ResourceLocation key) { return new ReferenceTagNode<>(key); } @@ -57,11 +56,11 @@ public abstract class TagNode { children.add(child); } - public void addValuesChild(HolderSet child) { + public void addValuesChild(Collection child) { children.add(ofValues(child)); } - public void addReferenceChild(TagKey child) { + public void addReferenceChild(ResourceLocation child) { children.add(ofReference(child)); } @@ -86,55 +85,55 @@ public abstract class TagNode { protected abstract void asText(String prefix, StringBuilder builder); @Nullable - public HolderSet getValue() { + public Collection getValue() { return null; } @Nullable - public TagKey getReference() { + public ResourceLocation getReference() { return null; } private static class ValuesTagNode extends TagNode { - private final HolderSet value; + private final Collection value; - public ValuesTagNode(HolderSet value) { + public ValuesTagNode(Collection value) { this.value = value; } @Override - public HolderSet getValue() { + public Collection getValue() { return value; } @Override protected void asText(String prefix, StringBuilder builder) { - for (Holder holder : value) { - holder.unwrapKey().ifPresent(key -> { - builder.append(prefix); - builder.append(key.location().toString()); - builder.append('\n'); - }); + for (T holder : value) { +// holder.unwrapKey().ifPresent(key -> { +// builder.append(prefix); +// builder.append(key.location().toString()); +// builder.append('\n'); +// }); } } } private static class ReferenceTagNode extends TagNode { - private final TagKey key; + private final ResourceLocation key; - public ReferenceTagNode(TagKey key) { + public ReferenceTagNode(ResourceLocation key) { this.key = key; } @Override - public TagKey getReference() { + public ResourceLocation getReference() { return key; } @Override protected void asText(String prefix, StringBuilder builder) { builder.append(prefix); - builder.append(key.location()); + builder.append(key); builder.append('\n'); } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java index 3823c497d..2911b883a 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java @@ -24,26 +24,24 @@ package me.shedaniel.rei.plugin.common.displays.tag; import com.mojang.serialization.DataResult; -import dev.architectury.event.events.client.ClientLifecycleEvent; -import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.transformers.SplitPacketTransformer; -import dev.architectury.utils.Env; -import dev.architectury.utils.EnvExecutor; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import me.shedaniel.architectury.event.events.client.ClientLifecycleEvent; +import me.shedaniel.architectury.networking.NetworkManager; +import me.shedaniel.architectury.networking.transformers.SplitPacketTransformer; +import me.shedaniel.architectury.utils.Env; +import me.shedaniel.architectury.utils.EnvExecutor; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.Tag; -import net.minecraft.tags.TagKey; +import net.minecraft.tags.TagCollection; import org.jetbrains.annotations.ApiStatus; import java.util.*; @@ -59,13 +57,58 @@ public class TagNodes { public static final Map>> TAG_DIR_MAP = new HashMap<>(); public static final ThreadLocal CURRENT_TAG_DIR = new ThreadLocal<>(); public static final Map, RawTagData>> RAW_TAG_DATA_MAP = new ConcurrentHashMap<>(); - public static final Map>, Map> TAG_DATA_MAP = new HashMap<>(); - public static Map>, Consumer>>>> requestedTags = new HashMap<>(); + public static final Map> TAG_DATA_MAP = new HashMap<>(); + public static Map>>>> requestedTags = new HashMap<>(); - public record RawTagData(List otherElements, List otherTags) { + public static final class RawTagData { + private final List otherElements; + private final List otherTags; + + public RawTagData(List otherElements, List otherTags) { + this.otherElements = otherElements; + this.otherTags = otherTags; + } + + public List otherElements() { + return otherElements; + } + + public List otherTags() { + return otherTags; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + RawTagData that = (RawTagData) obj; + return Objects.equals(this.otherElements, that.otherElements) && + Objects.equals(this.otherTags, that.otherTags); + } + + @Override + public int hashCode() { + return Objects.hash(otherElements, otherTags); + } + + @Override + public String toString() { + return "RawTagData[" + + "otherElements=" + otherElements + ", " + + "otherTags=" + otherTags + ']'; + } + } - public record TagData(IntList otherElements, List otherTags) { + public static final class TagData { + private final IntList otherElements; + private final List otherTags; + + public TagData(IntList otherElements, List otherTags) { + this.otherElements = otherElements; + this.otherTags = otherTags; + } + private static TagData fromNetwork(FriendlyByteBuf buf) { int count = buf.readVarInt(); IntList otherElements = new IntArrayList(count + 1); @@ -90,6 +133,36 @@ public class TagNodes { writeResourceLocation(buf, tag); } } + + public IntList otherElements() { + return otherElements; + } + + public List otherTags() { + return otherTags; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + TagData that = (TagData) obj; + return Objects.equals(this.otherElements, that.otherElements) && + Objects.equals(this.otherTags, that.otherTags); + } + + @Override + public int hashCode() { + return Objects.hash(otherElements, otherTags); + } + + @Override + public String toString() { + return "TagData[" + + "otherElements=" + otherElements + ", " + + "otherTags=" + otherTags + ']'; + } + } private static void writeResourceLocation(FriendlyByteBuf buf, ResourceLocation location) { @@ -105,7 +178,7 @@ public class TagNodes { NetworkManager.registerReceiver(NetworkManager.c2s(), REQUEST_TAGS_PACKET_C2S, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> { UUID uuid = buf.readUUID(); - ResourceKey> resourceKey = ResourceKey.createRegistryKey(buf.readResourceLocation()); + String resourceKey = buf.readUtf(); FriendlyByteBuf newBuf = new FriendlyByteBuf(Unpooled.buffer()); newBuf.writeUUID(uuid); Map dataMap = TAG_DATA_MAP.getOrDefault(resourceKey, Collections.emptyMap()); @@ -119,7 +192,7 @@ public class TagNodes { } @Environment(EnvType.CLIENT) - public static void requestTagData(ResourceKey> resourceKey, Consumer>> callback) { + public static void requestTagData(String resourceKey, Consumer>> callback) { if (Minecraft.getInstance().getSingleplayerServer() != null) { callback.accept(DataResult.success(TAG_DATA_MAP.get(resourceKey))); } else if (!NetworkManager.canServerReceive(REQUEST_TAGS_PACKET_C2S)) { @@ -131,7 +204,7 @@ public class TagNodes { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); UUID uuid = UUID.randomUUID(); buf.writeUUID(uuid); - buf.writeResourceLocation(resourceKey.location()); + buf.writeUtf(resourceKey); Client.nextUUID = uuid; Client.nextResourceKey = resourceKey; List>>> callbacks = new CopyOnWriteArrayList<>(); @@ -149,11 +222,11 @@ public class TagNodes { private static class Client { public static UUID nextUUID; - public static ResourceKey> nextResourceKey; + public static String nextResourceKey; public static Consumer>> nextCallback; private static void init() { - ClientLifecycleEvent.CLIENT_LEVEL_LOAD.register(world -> { + ClientLifecycleEvent.CLIENT_WORLD_LOAD.register(world -> { requestedTags.clear(); }); NetworkManager.registerReceiver(NetworkManager.s2c(), REQUEST_TAGS_PACKET_S2C, (buf, context) -> { @@ -176,35 +249,34 @@ public class TagNodes { } } - public static void create(TagKey tagKey, Consumer>> callback) { - Registry registry = ((Registry>) Registry.REGISTRY).get((ResourceKey>) tagKey.registry()); - requestTagData(tagKey.registry(), result -> { - callback.accept(result.flatMap(dataMap -> dataMap != null ? resolveTag(tagKey, registry, dataMap).orElse(DataResult.error("No tag data")) : DataResult.error("No tag data"))); + public static void create(String tagCollectionId, TagCollection tagCollection, Registry registry, ResourceLocation tagKey, Consumer>> callback) { + requestTagData(tagCollectionId, result -> { + callback.accept(result.flatMap(dataMap -> dataMap != null ? resolveTag(tagKey, tagCollection, registry, dataMap).orElse(DataResult.error("No tag data")) : DataResult.error("No tag data"))); }); } - private static Optional>> resolveTag(TagKey tagKey, Registry registry, Map tagDataMap) { - TagData tagData = tagDataMap.get(tagKey.location()); + private static Optional>> resolveTag(ResourceLocation tagKey, TagCollection tagCollection, Registry registry, Map tagDataMap) { + TagData tagData = tagDataMap.get(tagKey); if (tagData == null) return Optional.empty(); TagNode self = TagNode.ofReference(tagKey); - List> holders = new ArrayList<>(); + List holders = new ArrayList<>(); for (int element : tagData.otherElements()) { - Optional> holder = registry.getHolder(element); - if (holder.isPresent()) { - holders.add(holder.get()); + T holder = registry.byId(element); + if (holder != null) { + holders.add(holder); } } if (!holders.isEmpty()) { - self.addValuesChild(HolderSet.direct(holders)); + self.addValuesChild(holders); } for (ResourceLocation childTagId : tagData.otherTags()) { - TagKey childTagKey = TagKey.create(tagKey.registry(), childTagId); - if (registry.getTag(childTagKey).isPresent()) { - Optional>> resultOptional = resolveTag(childTagKey, registry, tagDataMap); + if (tagCollection.getAvailableTags().contains(childTagId)) { + Optional>> resultOptional = resolveTag(childTagId, tagCollection, registry, tagDataMap); if (resultOptional.isPresent()) { DataResult> result = resultOptional.get(); - if (result.error().isPresent()) return Optional.of(DataResult.error(result.error().get().message())); + if (result.error().isPresent()) + return Optional.of(DataResult.error(result.error().get().message())); self.addChild(result.result().get()); } } -- cgit