aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java15
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinTagLoader.java8
-rw-r--r--forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java5
-rw-r--r--forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagBuilder.java89
-rw-r--r--forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java62
-rw-r--r--forge/src/main/resources/META-INF/accesstransformer.cfg5
-rw-r--r--forge/src/main/resources/rei.mixins.json1
-rw-r--r--gradle.properties2
8 files changed, 66 insertions, 121 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
index 21e5401d0..44bb9da1f 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
@@ -138,7 +138,7 @@ public class CollectionUtils {
}
return l;
}
-
+
public static <T, R> Set<R> mapToSet(Collection<T> list, Function<T, R> function) {
Set<R> l = new HashSet<>(list.size() + 1);
for (T t : list) {
@@ -146,7 +146,7 @@ public class CollectionUtils {
}
return l;
}
-
+
public static <T, R> Set<R> mapToSet(Iterable<T> list, Function<T, R> function) {
Set<R> l = new HashSet<>();
for (T t : list) {
@@ -349,6 +349,17 @@ public class CollectionUtils {
return sum;
}
+ public static <T> List<T> distinctToList(Iterable<T> list) {
+ List<T> newList = new ArrayList<>();
+ Set<T> set = new HashSet<>();
+ for (T t : list) {
+ if (set.add(t)) {
+ newList.add(t);
+ }
+ }
+ return newList;
+ }
+
public static <T> Iterable<List<T>> partition(List<T> list, int size) {
return () -> new UnmodifiableIterator<List<T>>() {
int i = 0;
diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinTagLoader.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinTagLoader.java
index c866f7ea5..d36f0fe94 100644
--- a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinTagLoader.java
+++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinTagLoader.java
@@ -24,16 +24,12 @@
package me.shedaniel.rei.mixin.fabric;
import com.google.common.base.Stopwatch;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.Comparators;
-import com.google.common.collect.HashBiMap;
import com.mojang.datafixers.util.Either;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
-import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps;
-import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
@@ -130,7 +126,7 @@ public class MixinTagLoader<T> {
}
}
- dataMap.put(new TagNodes.CollectionWrapper<>(tag), new TagNodes.RawTagData(otherElements, otherTags));
+ dataMap.put(new TagNodes.CollectionWrapper<>(tag), new TagNodes.RawTagData(CollectionUtils.distinctToList(otherElements), CollectionUtils.distinctToList(otherTags)));
}
}
}
diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java
index 9babafd70..ca41022eb 100644
--- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java
@@ -27,9 +27,8 @@ import dev.architectury.utils.GameInstance;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.ChatFormatting;
-import net.minecraft.Util;
import net.minecraft.network.PacketEncoder;
-import net.minecraft.network.chat.TextComponent;
+import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
import net.minecraft.server.MinecraftServer;
@@ -49,7 +48,7 @@ public class MixinPacketEncoder {
"Please check the server console log for errors, this breaks REI and vanilla recipe books!";
server.execute(() -> {
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
- player.sendMessage(new TextComponent(issue).withStyle(ChatFormatting.RED), Util.NIL_UUID);
+ player.sendSystemMessage(Component.literal(issue).withStyle(ChatFormatting.RED));
}
});
System.out.println(issue);
diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagBuilder.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagBuilder.java
deleted file mode 100644
index f8819ba45..000000000
--- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagBuilder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This file is licensed under the MIT License, part of Roughly Enough Items.
- * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package me.shedaniel.rei.mixin.forge;
-
-import com.mojang.datafixers.util.Either;
-import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
-import net.minecraft.core.Registry;
-import net.minecraft.resources.ResourceKey;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraft.tags.Tag;
-import org.spongepowered.asm.mixin.Final;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-
-@Mixin(Tag.Builder.class)
-public class MixinTagBuilder<T> {
- @Shadow @Final private List<Tag.BuilderEntry> entries;
-
- @Inject(method = "build", at = @At("RETURN"))
- private void load(Function<ResourceLocation, Tag<T>> tagResolver, Function<ResourceLocation, T> valueResolver, CallbackInfoReturnable<Either<Collection<Tag.BuilderEntry>, Tag<T>>> cir) {
- Tag<T> tag = cir.getReturnValue().right().orElse(null);
- if (tag != null) {
- String currentTagDirectory = TagNodes.CURRENT_TAG_DIR.get();
- if (currentTagDirectory == null) return;
- ResourceKey<? extends Registry<?>> resourceKey = TagNodes.TAG_DIR_MAP.get(currentTagDirectory);
- if (resourceKey == null) return;
- Map<Tag<?>, TagNodes.RawTagData> dataMap = TagNodes.RAW_TAG_DATA_MAP.get(currentTagDirectory);
- if (dataMap == null) return;
- List<ResourceLocation> otherElements = new ArrayList<>();
- List<ResourceLocation> otherTags = new ArrayList<>();
-
- for (Tag.BuilderEntry builderEntry : this.entries) {
- if (builderEntry.entry() instanceof Tag.OptionalTagEntry tagEntry) {
- Tag<T> apply = tagResolver.apply(tagEntry.id);
- if (apply != null) {
- otherTags.add(tagEntry.id);
- }
- } else if (builderEntry.entry() instanceof Tag.TagEntry tagEntry) {
- Tag<T> apply = tagResolver.apply(tagEntry.id);
- if (apply != null) {
- otherTags.add(tagEntry.id);
- }
- } else if (builderEntry.entry() instanceof Tag.OptionalElementEntry tagEntry) {
- T apply = valueResolver.apply(tagEntry.id);
- if (apply != null) {
- otherElements.add(tagEntry.id);
- }
- } else if (builderEntry.entry() instanceof Tag.ElementEntry tagEntry) {
- T apply = valueResolver.apply(tagEntry.id);
- if (apply != null) {
- otherElements.add(tagEntry.id);
- }
- }
- }
-
- dataMap.put(tag, new TagNodes.RawTagData(otherElements, otherTags));
- }
- }
-}
diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java
index d6c164b86..5ea4eced8 100644
--- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java
@@ -24,14 +24,17 @@
package me.shedaniel.rei.mixin.forge;
import com.google.common.base.Stopwatch;
+import com.mojang.datafixers.util.Either;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
-import net.minecraft.tags.Tag;
+import net.minecraft.tags.TagEntry;
import net.minecraft.tags.TagLoader;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -40,26 +43,23 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
@Mixin(TagLoader.class)
public class MixinTagLoader<T> {
@Shadow @Final private String directory;
- @Inject(method = "build", at = @At("HEAD"))
- private void load(Map<ResourceLocation, Tag.Builder> map, CallbackInfoReturnable<Map<ResourceLocation, Tag<T>>> cir) {
+ @Inject(method = "build(Ljava/util/Map;)Ljava/util/Map;", at = @At("HEAD"))
+ private void load(Map<ResourceLocation, TagLoader.EntryWithSource> map, CallbackInfoReturnable<Map<ResourceLocation, Collection<T>>> cir) {
TagNodes.RAW_TAG_DATA_MAP.put(directory, new HashMap<>());
TagNodes.CURRENT_TAG_DIR.set(directory);
}
- @Inject(method = "build", at = @At("RETURN"))
- private void loadPost(Map<ResourceLocation, Tag.Builder> map, CallbackInfoReturnable<Map<ResourceLocation, Tag<T>>> cir) {
- Map<Tag<T>, ResourceLocation> inverseMap = new HashMap<>(cir.getReturnValue().size());
- for (Map.Entry<ResourceLocation, Tag<T>> entry : cir.getReturnValue().entrySet()) {
- inverseMap.put(entry.getValue(), entry.getKey());
+ @Inject(method = "build(Ljava/util/Map;)Ljava/util/Map;", at = @At("RETURN"))
+ private void loadPost(Map<ResourceLocation, TagLoader.EntryWithSource> map, CallbackInfoReturnable<Map<ResourceLocation, Collection<T>>> cir) {
+ Map<TagNodes.CollectionWrapper<T>, ResourceLocation> inverseMap = new HashMap<>(cir.getReturnValue().size());
+ for (Map.Entry<ResourceLocation, Collection<T>> entry : cir.getReturnValue().entrySet()) {
+ inverseMap.put(new TagNodes.CollectionWrapper<>(entry.getValue()), entry.getKey());
}
ResourceKey<? extends Registry<?>> resourceKey = TagNodes.TAG_DIR_MAP.get(directory);
if (resourceKey == null) return;
@@ -68,14 +68,14 @@ public class MixinTagLoader<T> {
Registry<T> registry = ((Registry<Registry<T>>) Registry.REGISTRY).get((ResourceKey<Registry<T>>) resourceKey);
Stopwatch stopwatch = Stopwatch.createStarted();
- Iterator<Map.Entry<Tag<?>, TagNodes.RawTagData>> entryIterator = TagNodes.RAW_TAG_DATA_MAP.getOrDefault(directory, Collections.emptyMap())
+ Iterator<Map.Entry<TagNodes.CollectionWrapper<?>, TagNodes.RawTagData>> entryIterator = TagNodes.RAW_TAG_DATA_MAP.getOrDefault(directory, Reference2ObjectMaps.emptyMap())
.entrySet().iterator();
if (!entryIterator.hasNext()) return;
while (entryIterator.hasNext()) {
- Map.Entry<Tag<?>, TagNodes.RawTagData> entry = entryIterator.next();
- Tag<?> tag = entry.getKey();
+ Map.Entry<TagNodes.CollectionWrapper<?>, TagNodes.RawTagData> entry = entryIterator.next();
+ TagNodes.CollectionWrapper<?> tag = entry.getKey();
entryIterator.remove();
if (registry != null) {
@@ -97,4 +97,36 @@ public class MixinTagLoader<T> {
RoughlyEnoughItemsCore.LOGGER.info("Processed %d tags in %s for %s", tagDataMap.size(), stopwatch.stop(), resourceKey.location());
}
+
+ @Inject(method = "build(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/List;)Lcom/mojang/datafixers/util/Either;", at = @At("RETURN"))
+ private void load(TagEntry.Lookup<T> lookup, List<TagLoader.EntryWithSource> entries, CallbackInfoReturnable<Either<Collection<TagLoader.EntryWithSource>, Collection<T>>> cir) {
+ Collection<T> tag = cir.getReturnValue().right().orElse(null);
+ if (tag != null) {
+ String currentTagDirectory = TagNodes.CURRENT_TAG_DIR.get();
+ if (currentTagDirectory == null) return;
+ ResourceKey<? extends Registry<?>> resourceKey = TagNodes.TAG_DIR_MAP.get(currentTagDirectory);
+ if (resourceKey == null) return;
+ Map<TagNodes.CollectionWrapper<?>, TagNodes.RawTagData> dataMap = TagNodes.RAW_TAG_DATA_MAP.get(currentTagDirectory);
+ if (dataMap == null) return;
+ List<ResourceLocation> otherElements = new ArrayList<>();
+ List<ResourceLocation> otherTags = new ArrayList<>();
+
+ for (TagLoader.EntryWithSource builderEntry : entries) {
+ TagEntry entry = builderEntry.entry();
+ if (entry.tag) {
+ Collection<T> apply = lookup.tag(entry.getId());
+ if (apply != null) {
+ otherTags.add(entry.getId());
+ }
+ } else {
+ T apply = lookup.element(entry.getId());
+ if (apply != null) {
+ otherElements.add(entry.getId());
+ }
+ }
+ }
+
+ dataMap.put(new TagNodes.CollectionWrapper<>(tag), new TagNodes.RawTagData(CollectionUtils.distinctToList(otherElements), CollectionUtils.distinctToList(otherTags)));
+ }
+ }
}
diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg
index 3f42b5757..5d520302f 100644
--- a/forge/src/main/resources/META-INF/accesstransformer.cfg
+++ b/forge/src/main/resources/META-INF/accesstransformer.cfg
@@ -37,7 +37,4 @@ public net.minecraft.client.gui.screens.Screen tooltipStack
public net.minecraft.client.renderer.RenderType m_173209_(Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType;
public net.minecraft.client.renderer.RenderType$OutlineProperty
public net.minecraft.client.renderer.RenderType$CompositeState
-public net.minecraft.tags.Tag$OptionalTagEntry f_13373_ # id
-public net.minecraft.tags.Tag$TagEntry f_13383_ # id
-public net.minecraft.tags.Tag$OptionalElementEntry f_13363_ # id
-public net.minecraft.tags.Tag$ElementEntry f_13349_ # id \ No newline at end of file
+public net.minecraft.tags.TagEntry f_215914_ # tag \ No newline at end of file
diff --git a/forge/src/main/resources/rei.mixins.json b/forge/src/main/resources/rei.mixins.json
index dbb1dc75c..1eabc9229 100644
--- a/forge/src/main/resources/rei.mixins.json
+++ b/forge/src/main/resources/rei.mixins.json
@@ -9,7 +9,6 @@
],
"mixins": [
"MixinPacketEncoder",
- "MixinTagBuilder",
"MixinTagLoader",
"MixinTagManager"
],
diff --git a/gradle.properties b/gradle.properties
index 57ac5c18a..53ea73bae 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,7 +4,7 @@ unstable=false
supported_version=1.19
minecraft_version=1.19
forgeEnabled=true
-forge_version=41.0.1
+forge_version=41.0.61
fabricloader_version=0.14.6
cloth_config_version=7.0.69
modmenu_version=4.0.0