From bac7925a1aa88404f5911ba18b52f52c7cf27ef2 Mon Sep 17 00:00:00 2001 From: nad <58147198+nad2040@users.noreply.github.com> Date: Sat, 8 Jul 2023 09:52:00 -0400 Subject: [PATCH] FIX: must have tnt to drop tnt --- .../elytrabombing/mixin/ItemMixin.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java b/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java index bfc7514..6ad2258 100644 --- a/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java +++ b/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java @@ -29,43 +29,43 @@ public class ItemMixin { public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { if (user.isFallFlying()) { ElytraBombingMod.LOGGER.info("right click action detected"); - ItemStack item = user.getStackInHand(hand); - Hand other_hand = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; - Vec3d position, velocity; - if (item.isOf(Items.FLINT_AND_STEEL)) { - ItemStack tnt = user.getStackInHand(other_hand); - if (!tnt.isOf(Items.TNT)) cir.setReturnValue(TypedActionResult.pass(user.getStackInHand(hand))); - position = user.getPos(); - velocity = user.getVelocity(); + Hand other_hand = (hand == Hand.MAIN_HAND) ? Hand.OFF_HAND : Hand.MAIN_HAND; + ElytraBombingMod.LOGGER.info("hand is " + ((hand == Hand.MAIN_HAND) ? "main hand" : "off hand")); + ElytraBombingMod.LOGGER.info("other hand is " + ((other_hand == Hand.MAIN_HAND) ? "main hand" : "off hand")); + + ItemStack usedItemStack = user.getStackInHand(hand), otherItemStack = user.getStackInHand(other_hand); + ElytraBombingMod.LOGGER.info("used item: " + usedItemStack); + ElytraBombingMod.LOGGER.info("other item: " + otherItemStack); + + Vec3d position = user.getPos(), velocity = user.getVelocity(); + ElytraBombingMod.LOGGER.info("player pos: " + position); + ElytraBombingMod.LOGGER.info("player vel: " + velocity); + if (!world.isClient && usedItemStack.isOf(Items.FLINT_AND_STEEL) && otherItemStack.isOf(Items.TNT)) { TntEntity tntEntity = new TntEntity(world, position.x, position.y, position.z, user); tntEntity.setVelocity(velocity.multiply(1.2)); world.spawnEntity(tntEntity); world.playSound(null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0f, 1.0f); world.emitGameEvent(user, GameEvent.PRIME_FUSE, position); if (!user.getAbilities().creativeMode) { - item.damage(1, user, p -> p.sendToolBreakStatus(hand)); - tnt.decrement(1); + usedItemStack.damage(1, user, p -> p.sendToolBreakStatus(hand)); + otherItemStack.decrement(1); } user.incrementStat(Stats.USED.getOrCreateStat((FlintAndSteelItem) (Object) this)); cir.setReturnValue(TypedActionResult.success(user.getStackInHand(hand), world.isClient())); - } else if (item.isOf(Items.ANVIL) || item.isOf(Items.CHIPPED_ANVIL) || item.isOf(Items.DAMAGED_ANVIL)) { - if (!user.getStackInHand(other_hand).isEmpty()) - cir.setReturnValue(TypedActionResult.pass(user.getStackInHand(hand))); - position = user.getPos(); - velocity = user.getVelocity(); + } else if (!world.isClient && (usedItemStack.isOf(Items.ANVIL) || usedItemStack.isOf(Items.CHIPPED_ANVIL) || usedItemStack.isOf(Items.DAMAGED_ANVIL)) && otherItemStack.isEmpty()) { FallingBlockEntity anvilEntity = null; - if (item.isOf(Items.ANVIL)) + if (usedItemStack.isOf(Items.ANVIL)) anvilEntity = FallingBlockEntity.spawnFromBlock(world, new BlockPos(ElytraBombingMod.VEC3D_TO_3I(position)), Blocks.ANVIL.getDefaultState()); - else if (item.isOf(Items.CHIPPED_ANVIL)) + else if (usedItemStack.isOf(Items.CHIPPED_ANVIL)) anvilEntity = FallingBlockEntity.spawnFromBlock(world, new BlockPos(ElytraBombingMod.VEC3D_TO_3I(position)), Blocks.CHIPPED_ANVIL.getDefaultState()); - else if (item.isOf(Items.DAMAGED_ANVIL)) + else if (usedItemStack.isOf(Items.DAMAGED_ANVIL)) anvilEntity = FallingBlockEntity.spawnFromBlock(world, new BlockPos(ElytraBombingMod.VEC3D_TO_3I(position)), Blocks.DAMAGED_ANVIL.getDefaultState()); assert anvilEntity != null; anvilEntity.setVelocity(velocity.multiply(1.2)); world.spawnEntity(anvilEntity); world.playSound(null, anvilEntity.getX(), anvilEntity.getY(), anvilEntity.getZ(), SoundEvents.BLOCK_ANVIL_FALL, SoundCategory.BLOCKS, 1.0f, 1.0f); if (!user.getAbilities().creativeMode) { - item.decrement(1); + usedItemStack.decrement(1); } } }