Skip to content

Commit

Permalink
TNT现在可以被钻石打火姬点燃了
Browse files Browse the repository at this point in the history
  • Loading branch information
YipKei committed Aug 6, 2024
1 parent e74843a commit 4f84233
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yipkei.vanilladdition.handler;

public class TntMixinHandler {
public static final ThreadLocal<Boolean> IS_JUDGMENT_CHECK = new ThreadLocal<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static RegistryKey<LootTable> registerLootTable(RegistryKey<LootTable> 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<RegistryKey<LootTable>> getAll() {
Expand Down
32 changes: 23 additions & 9 deletions src/main/java/com/yipkei/vanilladdition/mixin/TntBlockMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ItemActionResult> 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<ItemActionResult> 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<ItemActionResult> cir){
TntMixinHandler.IS_JUDGMENT_CHECK.remove();
}




}
1 change: 1 addition & 0 deletions src/main/resources/vanilla-addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"SmithingScreenHandlerMixin",
"SnowGolemEntityMixin",
"SpawnHelperMixin",
"TntBlockMixin",
"TranslucentBlockMixin",
"WolfEntityMixin"
],
Expand Down

0 comments on commit 4f84233

Please sign in to comment.