blob: 8503411ccf566b66127243156151ece698109be9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package moe.nea.firmament.mixins;
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.util.datafix.fixes.References;
import net.minecraft.util.datafix.fixes.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;
// TODO: rework this
@Mixin(EntityIdFix.class)
public abstract class DFUEntityIdFixPatch extends DataFix {
@Shadow
@Final
private static Map<String, String> ID_MAP;
public DFUEntityIdFixPatch(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(References.ENTITY), getOutputSchema().findChoiceType(References.ENTITY), dynamicOps -> pair -> ((Pair) pair).mapFirst(string -> ID_MAP.getOrDefault(string, (String) string))), convertUnchecked("Fix Type", getInputSchema().getType(References.ITEM_STACK), getOutputSchema().getType(References.ITEM_STACK))));
}
}
|