aboutsummaryrefslogtreecommitdiff
path: root/forge/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-06-28 17:37:28 +0800
committershedaniel <daniel@shedaniel.me>2022-06-28 18:04:36 +0800
commit404113a779046ff6737639080b65ec0c8a01ceef (patch)
treeeb7b8fe7d0c51ed93b7fda5d1b28b9c99db5412e /forge/src
parentad4340ec49d11f7a440a6cef911e6f963fe8402f (diff)
downloadRoughlyEnoughItems-404113a779046ff6737639080b65ec0c8a01ceef.tar.gz
RoughlyEnoughItems-404113a779046ff6737639080b65ec0c8a01ceef.tar.bz2
RoughlyEnoughItems-404113a779046ff6737639080b65ec0c8a01ceef.zip
Fix #962
Diffstat (limited to 'forge/src')
-rw-r--r--forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java58
-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.java100
-rw-r--r--forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagManager.java53
-rw-r--r--forge/src/main/resources/META-INF/accesstransformer.cfg6
-rw-r--r--forge/src/main/resources/rei.mixins.json4
6 files changed, 309 insertions, 1 deletions
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
new file mode 100644
index 000000000..9babafd70
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinPacketEncoder.java
@@ -0,0 +1,58 @@
+/*
+ * 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 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.protocol.Packet;
+import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(PacketEncoder.class)
+public class MixinPacketEncoder {
+ @Inject(method = "encode", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/Packet;isSkippable()Z"))
+ private void failedToEncode(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf, CallbackInfo ci) {
+ if (packet instanceof ClientboundUpdateRecipesPacket) {
+ MinecraftServer server = GameInstance.getServer();
+ String issue = "REI: Server failed to synchronize recipe data with the client! " +
+ "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);
+ }
+ });
+ 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
new file mode 100644
index 000000000..f8819ba45
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagBuilder.java
@@ -0,0 +1,89 @@
+/*
+ * 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
new file mode 100644
index 000000000..d6c164b86
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagLoader.java
@@ -0,0 +1,100 @@
+/*
+ * 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.google.common.base.Stopwatch;
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import it.unimi.dsi.fastutil.ints.IntList;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+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.TagLoader;
+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.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+@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) {
+ 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());
+ }
+ ResourceKey<? extends Registry<?>> resourceKey = TagNodes.TAG_DIR_MAP.get(directory);
+ if (resourceKey == null) return;
+ TagNodes.TAG_DATA_MAP.put(resourceKey, new HashMap<>());
+ Map<ResourceLocation, TagNodes.TagData> tagDataMap = TagNodes.TAG_DATA_MAP.get(resourceKey);
+ 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())
+ .entrySet().iterator();
+
+ if (!entryIterator.hasNext()) return;
+
+ while (entryIterator.hasNext()) {
+ Map.Entry<Tag<?>, TagNodes.RawTagData> entry = entryIterator.next();
+ Tag<?> tag = entry.getKey();
+ entryIterator.remove();
+
+ if (registry != null) {
+ ResourceLocation tagLoc = inverseMap.get(tag);
+
+ if (tagLoc != null) {
+ TagNodes.RawTagData rawTagData = entry.getValue();
+ IntList elements = new IntArrayList();
+ for (ResourceLocation element : rawTagData.otherElements()) {
+ T t = registry.get(element);
+ if (t != null) {
+ elements.add(registry.getId(t));
+ }
+ }
+ tagDataMap.put(tagLoc, new TagNodes.TagData(elements, rawTagData.otherTags()));
+ }
+ }
+ }
+
+ RoughlyEnoughItemsCore.LOGGER.info("Processed %d tags in %s for %s", tagDataMap.size(), stopwatch.stop(), resourceKey.location());
+ }
+}
diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagManager.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagManager.java
new file mode 100644
index 000000000..f53755004
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinTagManager.java
@@ -0,0 +1,53 @@
+/*
+ * 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 me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
+import net.minecraft.core.Registry;
+import net.minecraft.core.RegistryAccess;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.server.packs.resources.ResourceManager;
+import net.minecraft.tags.TagManager;
+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.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+
+@Mixin(TagManager.class)
+public abstract class MixinTagManager<T> {
+ @Shadow
+ public static String getTagDir(ResourceKey<? extends Registry<?>> resourceKey) {
+ return null;
+ }
+
+ @Inject(method = "createLoader", at = @At("HEAD"))
+ private void load(ResourceManager resourceManager, Executor executor, RegistryAccess.RegistryEntry<T> registryEntry, CallbackInfoReturnable<CompletableFuture<TagManager.LoadResult<T>>> cir) {
+ ResourceKey<? extends Registry<T>> resourceKey = registryEntry.key();
+ TagNodes.TAG_DIR_MAP.put(getTagDir(resourceKey), resourceKey);
+ }
+}
diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg
index f43fc89ba..3f42b5757 100644
--- a/forge/src/main/resources/META-INF/accesstransformer.cfg
+++ b/forge/src/main/resources/META-INF/accesstransformer.cfg
@@ -36,4 +36,8 @@ public net.minecraft.client.gui.screens.Screen m_169383_(Lcom/mojang/blaze3d/ver
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 \ No newline at end of file
+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
diff --git a/forge/src/main/resources/rei.mixins.json b/forge/src/main/resources/rei.mixins.json
index 16b67049b..dbb1dc75c 100644
--- a/forge/src/main/resources/rei.mixins.json
+++ b/forge/src/main/resources/rei.mixins.json
@@ -8,6 +8,10 @@
"MixinRecipeToast"
],
"mixins": [
+ "MixinPacketEncoder",
+ "MixinTagBuilder",
+ "MixinTagLoader",
+ "MixinTagManager"
],
"injectors": {
"maxShiftBy": 5,