aboutsummaryrefslogtreecommitdiff
path: root/default-plugin/src/main/java/me/shedaniel/rei/plugin/common
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-05-29 23:17:20 +0800
committershedaniel <daniel@shedaniel.me>2023-05-29 23:17:20 +0800
commit1e869aeac83d1627a6cae32a3b53b7d17bd3d7b8 (patch)
tree9ff780b6f52c8a6c216698242e8604568dc1df92 /default-plugin/src/main/java/me/shedaniel/rei/plugin/common
parent48ed02b1ed057d2b7502cca575f640a595959cf5 (diff)
downloadRoughlyEnoughItems-feature/6.7.tar.gz
RoughlyEnoughItems-feature/6.7.tar.bz2
RoughlyEnoughItems-feature/6.7.zip
Fix compile errorsfeature/6.7
Diffstat (limited to 'default-plugin/src/main/java/me/shedaniel/rei/plugin/common')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java15
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java26
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/DefaultTagDisplay.java68
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java43
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java136
5 files changed, 195 insertions, 93 deletions
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 asText(String prefix, StringBuilder builder);
@Nullable
- public HolderSet<T> getValue() {
+ public Collection<T> getValue() {
return null;
}
@Nullable
- public TagKey<T> getReference() {
+ public ResourceLocation getReference() {
return null;
}
private static class ValuesTagNode<T> extends TagNode<T> {
- private final HolderSet<T> value;
+ private final Collection<T> value;
- public ValuesTagNode(HolderSet<T> value) {
+ public ValuesTagNode(Collection<T> value) {
this.value = value;
}
@Override
- public HolderSet<T> getValue() {
+ public Collection<T> getValue() {
return value;
}
@Override
protected void asText(String prefix, StringBuilder builder) {
- for (Holder<T> 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<T> extends TagNode<T> {
- private final TagKey<T> key;
+ private final ResourceLocation key;
- public ReferenceTagNode(TagKey<T> key) {
+ public ReferenceTagNode(ResourceLocation key) {
this.key = key;
}
@Override
- public TagKey<T> 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<String, ResourceKey<? extends Registry<?>>> TAG_DIR_MAP = new HashMap<>();
public static final ThreadLocal<String> CURRENT_TAG_DIR = new ThreadLocal<>();
public static final Map<String, Map<Tag<?>, RawTagData>> RAW_TAG_DATA_MAP = new ConcurrentHashMap<>();
- public static final Map<ResourceKey<? extends Registry<?>>, Map<ResourceLocation, TagData>> TAG_DATA_MAP = new HashMap<>();
- public static Map<ResourceKey<? extends Registry<?>>, Consumer<Consumer<DataResult<Map<ResourceLocation, TagData>>>>> requestedTags = new HashMap<>();
+ public static final Map<String, Map<ResourceLocation, TagData>> TAG_DATA_MAP = new HashMap<>();
+ public static Map<String, Consumer<Consumer<DataResult<Map<ResourceLocation, TagData>>>>> requestedTags = new HashMap<>();
- public record RawTagData(List<ResourceLocation> otherElements, List<ResourceLocation> otherTags) {
+ public static final class RawTagData {
+ private final List<ResourceLocation> otherElements;
+ private final List<ResourceLocation> otherTags;
+
+ public RawTagData(List<ResourceLocation> otherElements, List<ResourceLocation> otherTags) {
+ this.otherElements = otherElements;
+ this.otherTags = otherTags;
+ }
+
+ public List<ResourceLocation> otherElements() {
+ return otherElements;
+ }
+
+ public List<ResourceLocation> 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<ResourceLocation> otherTags) {
+ public static final class TagData {
+ private final IntList otherElements;
+ private final List<ResourceLocation> otherTags;
+
+ public TagData(IntList otherElements, List<ResourceLocation> 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<ResourceLocation> 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<? extends Registry<?>> resourceKey = ResourceKey.createRegistryKey(buf.readResourceLocation());
+ String resourceKey = buf.readUtf();
FriendlyByteBuf newBuf = new FriendlyByteBuf(Unpooled.buffer());
newBuf.writeUUID(uuid);
Map<ResourceLocation, TagData> dataMap = TAG_DATA_MAP.getOrDefault(resourceKey, Collections.emptyMap());
@@ -119,7 +192,7 @@ public class TagNodes {
}
@Environment(EnvType.CLIENT)
- public static void requestTagData(ResourceKey<? extends Registry<?>> resourceKey, Consumer<DataResult<Map<ResourceLocation, TagData>>> callback) {
+ public static void requestTagData(String resourceKey, Consumer<DataResult<Map<ResourceLocation, TagData>>> 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<Consumer<DataResult<Map<ResourceLocation, TagData>>>> callbacks = new CopyOnWriteArrayList<>();
@@ -149,11 +222,11 @@ public class TagNodes {
private static class Client {
public static UUID nextUUID;
- public static ResourceKey<? extends Registry<?>> nextResourceKey;
+ public static String nextResourceKey;
public static Consumer<DataResult<Map<ResourceLocation, TagData>>> 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 <T> void create(TagKey<T> tagKey, Consumer<DataResult<TagNode<T>>> callback) {
- Registry<T> registry = ((Registry<Registry<T>>) Registry.REGISTRY).get((ResourceKey<Registry<T>>) 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 <T> void create(String tagCollectionId, TagCollection<? extends T> tagCollection, Registry<? extends T> registry, ResourceLocation tagKey, Consumer<DataResult<TagNode<T>>> 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 <T> Optional<DataResult<TagNode<T>>> resolveTag(TagKey<T> tagKey, Registry<T> registry, Map<ResourceLocation, TagData> tagDataMap) {
- TagData tagData = tagDataMap.get(tagKey.location());
+ private static <T> Optional<DataResult<TagNode<T>>> resolveTag(ResourceLocation tagKey, TagCollection<? extends T> tagCollection, Registry<? extends T> registry, Map<ResourceLocation, TagData> tagDataMap) {
+ TagData tagData = tagDataMap.get(tagKey);
if (tagData == null) return Optional.empty();
TagNode<T> self = TagNode.ofReference(tagKey);
- List<Holder<T>> holders = new ArrayList<>();
+ List<T> holders = new ArrayList<>();
for (int element : tagData.otherElements()) {
- Optional<Holder<T>> 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<T> childTagKey = TagKey.create(tagKey.registry(), childTagId);
- if (registry.getTag(childTagKey).isPresent()) {
- Optional<DataResult<TagNode<T>>> resultOptional = resolveTag(childTagKey, registry, tagDataMap);
+ if (tagCollection.getAvailableTags().contains(childTagId)) {
+ Optional<DataResult<TagNode<T>>> resultOptional = resolveTag(childTagId, tagCollection, registry, tagDataMap);
if (resultOptional.isPresent()) {
DataResult<TagNode<T>> 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());
}
}