|
| 1 | +package net.errorcraft.codecium.mixin.minecraft.util.dynamic; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.sugar.Local; |
| 4 | +import net.minecraft.util.dynamic.Codecs; |
| 5 | +import org.objectweb.asm.Opcodes; |
| 6 | +import org.spongepowered.asm.mixin.Mixin; |
| 7 | +import org.spongepowered.asm.mixin.injection.At; |
| 8 | +import org.spongepowered.asm.mixin.injection.ModifyArg; |
| 9 | +import org.spongepowered.asm.mixin.injection.Slice; |
| 10 | + |
| 11 | +import java.util.function.Function; |
| 12 | +import java.util.function.Supplier; |
| 13 | + |
| 14 | +@Mixin(Codecs.class) |
| 15 | +public class CodecsExtender { |
| 16 | + @ModifyArg( |
| 17 | + method = "method_56907", |
| 18 | + at = @At( |
| 19 | + value = "INVOKE", |
| 20 | + target = "Lcom/mojang/serialization/DataResult;error(Ljava/util/function/Supplier;)Lcom/mojang/serialization/DataResult;", |
| 21 | + remap = false |
| 22 | + ) |
| 23 | + ) |
| 24 | + private static Supplier<String> unsignedByteTooLarge(Supplier<String> message, @Local(argsOnly = true) final Integer value) { |
| 25 | + return () -> "Unsigned byte must be at most 255: " + value; |
| 26 | + } |
| 27 | + |
| 28 | + @ModifyArg( |
| 29 | + method = "<clinit>", |
| 30 | + at = @At( |
| 31 | + value = "INVOKE", |
| 32 | + target = "Lnet/minecraft/util/dynamic/Codecs;rangedInt(IILjava/util/function/Function;)Lcom/mojang/serialization/Codec;", |
| 33 | + ordinal = 0 |
| 34 | + ), |
| 35 | + slice = @Slice( |
| 36 | + from = @At( |
| 37 | + value = "FIELD", |
| 38 | + target = "Lnet/minecraft/util/dynamic/Codecs;UNSIGNED_BYTE:Lcom/mojang/serialization/Codec;", |
| 39 | + opcode = Opcodes.PUTSTATIC |
| 40 | + ) |
| 41 | + ) |
| 42 | + ) |
| 43 | + private static Function<Integer, String> nonNegativeInteger(Function<Integer, String> messageFactory) { |
| 44 | + return value -> "Integer must be non-negative: " + value; |
| 45 | + } |
| 46 | + |
| 47 | + @ModifyArg( |
| 48 | + method = "<clinit>", |
| 49 | + at = @At( |
| 50 | + value = "INVOKE", |
| 51 | + target = "Lnet/minecraft/util/dynamic/Codecs;rangedInt(IILjava/util/function/Function;)Lcom/mojang/serialization/Codec;", |
| 52 | + ordinal = 0 |
| 53 | + ), |
| 54 | + slice = @Slice( |
| 55 | + from = @At( |
| 56 | + value = "FIELD", |
| 57 | + target = "Lnet/minecraft/util/dynamic/Codecs;NON_NEGATIVE_INT:Lcom/mojang/serialization/Codec;", |
| 58 | + opcode = Opcodes.PUTSTATIC |
| 59 | + ) |
| 60 | + ) |
| 61 | + ) |
| 62 | + private static Function<Integer, String> positiveInteger(Function<Integer, String> messageFactory) { |
| 63 | + return value -> "Integer must be positive: " + value; |
| 64 | + } |
| 65 | + |
| 66 | + @ModifyArg( |
| 67 | + method = "<clinit>", |
| 68 | + at = @At( |
| 69 | + value = "INVOKE", |
| 70 | + target = "Lnet/minecraft/util/dynamic/Codecs;rangedInclusiveFloat(FFLjava/util/function/Function;)Lcom/mojang/serialization/Codec;" |
| 71 | + ) |
| 72 | + ) |
| 73 | + private static Function<Float, String> nonNegativeFloat(Function<Float, String> messageFactory) { |
| 74 | + return value -> "Float must be non-negative: " + value; |
| 75 | + } |
| 76 | + |
| 77 | + @ModifyArg( |
| 78 | + method = "<clinit>", |
| 79 | + at = @At( |
| 80 | + value = "INVOKE", |
| 81 | + target = "Lnet/minecraft/util/dynamic/Codecs;rangedFloat(FFLjava/util/function/Function;)Lcom/mojang/serialization/Codec;" |
| 82 | + ) |
| 83 | + ) |
| 84 | + private static Function<Float, String> positiveFloat(Function<Float, String> messageFactory) { |
| 85 | + return value -> "Float must be positive: " + value; |
| 86 | + } |
| 87 | +} |
0 commit comments