aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-30 18:33:57 +0200
committernea <nea@nea.moe>2023-05-30 18:33:57 +0200
commit2ff8c59c74fb138f475a5ec309d57fc92fc79bf4 (patch)
tree2fd24aa8e05ab28a491b39349874ab4d2478d3b6 /src/main/java/moe/nea/firmament
parent6b124ec9afe589d4a39e874d086434c6ea0043f5 (diff)
downloadFirmament-2ff8c59c74fb138f475a5ec309d57fc92fc79bf4.tar.gz
Firmament-2ff8c59c74fb138f475a5ec309d57fc92fc79bf4.tar.bz2
Firmament-2ff8c59c74fb138f475a5ec309d57fc92fc79bf4.zip
Fix spawn egg data fixer
Diffstat (limited to 'src/main/java/moe/nea/firmament')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/MixinEntityIdFix.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/MixinEntityIdFix.java b/src/main/java/moe/nea/firmament/mixins/MixinEntityIdFix.java
index 1d5e312..c1c9868 100644
--- a/src/main/java/moe/nea/firmament/mixins/MixinEntityIdFix.java
+++ b/src/main/java/moe/nea/firmament/mixins/MixinEntityIdFix.java
@@ -1,4 +1,32 @@
package moe.nea.firmament.mixins;
-public class MixinEntityIdFix {
+import com.mojang.datafixers.DataFix;
+import com.mojang.datafixers.TypeRewriteRule;
+import com.mojang.datafixers.schemas.Schema;
+import com.mojang.datafixers.util.Pair;
+import net.minecraft.datafixer.TypeReferences;
+import net.minecraft.datafixer.fix.EntityIdFix;
+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.Map;
+
+@Mixin(EntityIdFix.class)
+public abstract class MixinEntityIdFix extends DataFix {
+ @Shadow
+ @Final
+ private static Map<String, String> RENAMED_ENTITIES;
+
+ public MixinEntityIdFix(Schema outputSchema, boolean changesType) {
+ super(outputSchema, changesType);
+ }
+
+ @Inject(method = "makeRule", at = @At("RETURN"), cancellable = true)
+ public void onMakeRule(CallbackInfoReturnable<TypeRewriteRule> cir) {
+ cir.setReturnValue(TypeRewriteRule.seq(fixTypeEverywhere("EntityIdFix", getInputSchema().findChoiceType(TypeReferences.ENTITY), getOutputSchema().findChoiceType(TypeReferences.ENTITY), dynamicOps -> pair -> ((Pair) pair).mapFirst(string -> RENAMED_ENTITIES.getOrDefault(string, (String) string))), convertUnchecked("Fix Type", getInputSchema().getType(TypeReferences.ITEM_STACK), getOutputSchema().getType(TypeReferences.ITEM_STACK))));
+ }
}