Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix vanilla datafixer bug causing block entity translation to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Aug 1, 2020
1 parent 9189f3b commit d566357
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/main/java/net/earthcomputer/multiconnect/impl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -50,17 +48,6 @@ public static <T> T datafix(DSL.TypeReference type, DynamicOps<T> ops, T old) {
return translated.getValue();
}

@SuppressWarnings("unchecked")
public static List<TypeRewriteRule> getRules(TypeRewriteRule.Seq seq) {
try {
Field field = TypeRewriteRule.Seq.class.getDeclaredField("rules");
field.setAccessible(true);
return (List<TypeRewriteRule>) field.get(seq);
} catch (ReflectiveOperationException e) {
throw new AssertionError(e);
}
}

@SafeVarargs
public static <T, U> Comparator<T> orderBy(Function<T, U> mapper, U... order) {
ImmutableMap.Builder<U, Integer> indexBuilder = ImmutableMap.builder();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Schema> schemas;
try {
Field field = DataFixerBuilder.class.getDeclaredField("schemas");
field.setAccessible(true);
schemas = (Int2ObjectSortedMap<Schema>) 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));
}
}
1 change: 1 addition & 0 deletions src/main/resources/multiconnect.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"bridge.MixinNetworkState",
"bridge.MixinPacketHandler",
"bridge.MixinParticleManager",
"bridge.MixinSchemas",
"bridge.MixinSimpleRegistry",
"bridge.MixinStatType",
"bridge.MixinTranslationStorage",
Expand Down

0 comments on commit d566357

Please sign in to comment.