From 535154a1a0d6d87fea37f514ec66aeea4310520e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 25 Jun 2023 10:00:32 +0700 Subject: [PATCH] fard --- .../DecoratedPotBlockEntitySherdsMixin.java | 22 +++++++++++++++++++ .../chipmunkmod/mixin/IdentifierMixin.java | 7 ++++++ src/main/resources/chipmunkmod.mixins.json | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java new file mode 100644 index 0000000..cb5b5ac --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java @@ -0,0 +1,22 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.block.entity.DecoratedPotBlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; +import net.minecraft.util.Identifier; +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.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +// https://github.com/LunaWasFlaggedAgain/Mojang-ResourceLocation-Challenge/blob/main/src/main/java/com/github/lunawasflaggedagain/mojangresourcelocationchallenge/mixin/DecoratedPotBlockEntitySherdsMixin.java +@Mixin(DecoratedPotBlockEntity.Sherds.class) +public class DecoratedPotBlockEntitySherdsMixin { + @Inject(method = "getSherd(Lnet/minecraft/nbt/NbtList;I)Lnet/minecraft/item/Item;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;(Ljava/lang/String;)V"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private static void getSherd(NbtList list, int index, CallbackInfoReturnable cir, NbtElement nbtElement) { + if (!Identifier.isValid(nbtElement.asString())) cir.setReturnValue(Items.BRICK); + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java index 48faf18..e7b24eb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java @@ -15,6 +15,13 @@ public class IdentifierMixin { cir.cancel(); } + @Inject(method = "isNamespaceValid", at = @At("HEAD"), cancellable = true) + private static void isNamespaceValid (String namespace, CallbackInfoReturnable cir) { + cir.setReturnValue(true); + + cir.cancel(); + } + @Inject(method = "validateNamespace", at = @At("HEAD"), cancellable = true) private static void validateNamespace(String namespace, String path, CallbackInfoReturnable cir) { cir.setReturnValue(namespace); diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 330c33b..c6bbf21 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -19,7 +19,8 @@ "NbtIoMixin", "KeyboardInputMixin", "ElderGuardianAppearanceParticleMixin", - "IdentifierMixin" + "IdentifierMixin", + "DecoratedPotBlockEntitySherdsMixin" ], "injectors": { "defaultRequire": 1