Skip to content

Commit

Permalink
FIX: must have tnt to drop tnt
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2040 committed Jul 8, 2023
1 parent cb1d18a commit bac7925
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,43 @@ public class ItemMixin {
public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> 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);
}
}
}
Expand Down

0 comments on commit bac7925

Please sign in to comment.