diff --git a/src/main/java/com/yipkei/vanilladdition/handler/TntMixinHandler.java b/src/main/java/com/yipkei/vanilladdition/handler/TntMixinHandler.java new file mode 100644 index 0000000..38f71c3 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/handler/TntMixinHandler.java @@ -0,0 +1,5 @@ +package com.yipkei.vanilladdition.handler; + +public class TntMixinHandler { + public static final ThreadLocal IS_JUDGMENT_CHECK = new ThreadLocal<>(); +} diff --git a/src/main/java/com/yipkei/vanilladdition/init/ModLootTables.java b/src/main/java/com/yipkei/vanilladdition/init/ModLootTables.java index 3bd015e..9016f3e 100644 --- a/src/main/java/com/yipkei/vanilladdition/init/ModLootTables.java +++ b/src/main/java/com/yipkei/vanilladdition/init/ModLootTables.java @@ -108,7 +108,7 @@ private static RegistryKey registerLootTable(RegistryKey k if (MOD_LOOT_TABLES.add(key)){ return key; } - throw new IllegalArgumentException(String.valueOf(key.getValue()) + " is already a registered built-in loot table"); + throw new IllegalArgumentException(key.getValue() + " is already a registered built-in loot table"); } public static Set> getAll() { diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/TntBlockMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/TntBlockMixin.java index 26af49a..f60268d 100644 --- a/src/main/java/com/yipkei/vanilladdition/mixin/TntBlockMixin.java +++ b/src/main/java/com/yipkei/vanilladdition/mixin/TntBlockMixin.java @@ -1,10 +1,12 @@ package com.yipkei.vanilladdition.mixin; -import net.minecraft.block.Block; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.yipkei.vanilladdition.handler.TntMixinHandler; import net.minecraft.block.BlockState; import net.minecraft.block.TntBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.registry.tag.ItemTags; import net.minecraft.util.Hand; import net.minecraft.util.ItemActionResult; @@ -17,17 +19,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(TntBlock.class) -public class TntBlockMixin extends Block { - public TntBlockMixin(Settings settings) { - super(settings); - } +public class TntBlockMixin { - @Inject(method = "onUseWithItem", at = @At("HEAD"), cancellable = true) + @Inject(method = "onUseWithItem", at = @At("HEAD")/*, cancellable = true*/) private void replaceJudgment(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir){ - if (!stack.isIn(ItemTags.CREEPER_IGNITERS)) { - cir.setReturnValue(super.onUseWithItem(stack, state, world, pos, player, hand, hit)); - } + TntMixinHandler.IS_JUDGMENT_CHECK.set(true); + } + + @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/TntBlock;primeTnt(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/LivingEntity;)V")) + private void setPass(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir){ + TntMixinHandler.IS_JUDGMENT_CHECK.set(false); + } + + @ModifyExpressionValue(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z")) + private boolean replaceItemJudgment(boolean original, ItemStack stack){ + return TntMixinHandler.IS_JUDGMENT_CHECK.get() ? stack.isIn(ItemTags.CREEPER_IGNITERS) : stack.isIn(ItemTags.CREEPER_IGNITERS) && !stack.isOf(Items.FIRE_CHARGE); } + @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V")) + private void clearStat(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir){ + TntMixinHandler.IS_JUDGMENT_CHECK.remove(); + } + + + } diff --git a/src/main/resources/vanilla-addition.mixins.json b/src/main/resources/vanilla-addition.mixins.json index 9591208..61423db 100644 --- a/src/main/resources/vanilla-addition.mixins.json +++ b/src/main/resources/vanilla-addition.mixins.json @@ -17,6 +17,7 @@ "SmithingScreenHandlerMixin", "SnowGolemEntityMixin", "SpawnHelperMixin", + "TntBlockMixin", "TranslucentBlockMixin", "WolfEntityMixin" ],