From d5663577de23aaeefe61067a10d1165bb0e27f61 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 1 Aug 2020 18:08:57 +0100 Subject: [PATCH] Fix vanilla datafixer bug causing block entity translation to fail --- .../multiconnect/impl/Utils.java | 13 ------- .../mixin/bridge/MixinSchemas.java | 37 +++++++++++++++++++ src/main/resources/multiconnect.mixins.json | 1 + 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 src/main/java/net/earthcomputer/multiconnect/mixin/bridge/MixinSchemas.java diff --git a/src/main/java/net/earthcomputer/multiconnect/impl/Utils.java b/src/main/java/net/earthcomputer/multiconnect/impl/Utils.java index 3bcb7ba3..8c3ced9e 100644 --- a/src/main/java/net/earthcomputer/multiconnect/impl/Utils.java +++ b/src/main/java/net/earthcomputer/multiconnect/impl/Utils.java @@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableMap; import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFixer; -import com.mojang.datafixers.TypeRewriteRule; import com.mojang.serialization.Dynamic; import com.mojang.serialization.DynamicOps; import net.earthcomputer.multiconnect.connect.ConnectionMode; @@ -28,7 +27,6 @@ import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.SimpleRegistry; -import java.lang.reflect.Field; import java.util.Comparator; import java.util.List; import java.util.function.Function; @@ -50,17 +48,6 @@ public static T datafix(DSL.TypeReference type, DynamicOps ops, T old) { return translated.getValue(); } - @SuppressWarnings("unchecked") - public static List getRules(TypeRewriteRule.Seq seq) { - try { - Field field = TypeRewriteRule.Seq.class.getDeclaredField("rules"); - field.setAccessible(true); - return (List) field.get(seq); - } catch (ReflectiveOperationException e) { - throw new AssertionError(e); - } - } - @SafeVarargs public static Comparator orderBy(Function mapper, U... order) { ImmutableMap.Builder indexBuilder = ImmutableMap.builder(); diff --git a/src/main/java/net/earthcomputer/multiconnect/mixin/bridge/MixinSchemas.java b/src/main/java/net/earthcomputer/multiconnect/mixin/bridge/MixinSchemas.java new file mode 100644 index 00000000..b4c3988c --- /dev/null +++ b/src/main/java/net/earthcomputer/multiconnect/mixin/bridge/MixinSchemas.java @@ -0,0 +1,37 @@ +package net.earthcomputer.multiconnect.mixin.bridge; + +import com.mojang.datafixers.DataFixUtils; +import com.mojang.datafixers.DataFixerBuilder; +import com.mojang.datafixers.schemas.Schema; +import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; +import net.minecraft.datafixer.Schemas; +import net.minecraft.datafixer.TypeReferences; +import net.minecraft.datafixer.fix.ChoiceTypesFix; +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.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.lang.reflect.Field; + +@Mixin(Schemas.class) +public class MixinSchemas { + @SuppressWarnings("unchecked") + @Inject(method = "build", + slice = @Slice(from = @At(value = "CONSTANT", args = "intValue=1466")), + at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/DataFixerBuilder;addFixer(Lcom/mojang/datafixers/DataFix;)V", ordinal = 0, remap = false)) + private static void fixBlockEntityType(DataFixerBuilder builder, CallbackInfo ci) { + Int2ObjectSortedMap schemas; + try { + Field field = DataFixerBuilder.class.getDeclaredField("schemas"); + field.setAccessible(true); + schemas = (Int2ObjectSortedMap) field.get(builder); + } catch (ReflectiveOperationException e) { + throw new AssertionError(e); + } + + Schema schema1466 = schemas.get(DataFixUtils.makeKey(1466, 0)); + builder.addFixer(new ChoiceTypesFix(schema1466, "multiconnect: fix block entity type", TypeReferences.BLOCK_ENTITY)); + } +} diff --git a/src/main/resources/multiconnect.mixins.json b/src/main/resources/multiconnect.mixins.json index c5f49fc1..9612bd99 100644 --- a/src/main/resources/multiconnect.mixins.json +++ b/src/main/resources/multiconnect.mixins.json @@ -23,6 +23,7 @@ "bridge.MixinNetworkState", "bridge.MixinPacketHandler", "bridge.MixinParticleManager", + "bridge.MixinSchemas", "bridge.MixinSimpleRegistry", "bridge.MixinStatType", "bridge.MixinTranslationStorage",