--- a/net/minecraft/world/level/block/TntBlock.java +++ b/net/minecraft/world/level/block/TntBlock.java @@ -6,7 +6,7 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.world.InteractionHand; +import net.minecraft.world.EnumHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -19,93 +19,109 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.BlockHitResult; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.block.TNTPrimeEvent.PrimeCause; +// CraftBukkit end public class TntBlock extends Block { + public static final MapCodec CODEC = simpleCodec(TntBlock::new); public static final BooleanProperty UNSTABLE = BlockStateProperties.UNSTABLE; @Override public MapCodec codec() { - return CODEC; + return TntBlock.CODEC; } public TntBlock(BlockBehaviour.Properties properties) { super(properties); - this.registerDefaultState(this.defaultBlockState().setValue(UNSTABLE, Boolean.valueOf(false))); + this.registerDefaultState((IBlockData) this.defaultBlockState().setValue(TntBlock.UNSTABLE, false)); } @Override - public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) { + public void onPlace(IBlockData state, Level level, BlockPos pos, IBlockData oldState, boolean isMoving) { if (!oldState.is(state.getBlock())) { - if (level.hasNeighborSignal(pos)) { + if (level.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent explode(level, pos); level.removeBlock(pos, false); } + } } @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) { - if (level.hasNeighborSignal(pos)) { + public void neighborChanged(IBlockData state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) { + if (level.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.REDSTONE, null, fromPos)) { // CraftBukkit - TNTPrimeEvent explode(level, pos); level.removeBlock(pos, false); } + } @Override - public BlockState playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) { - if (!level.isClientSide() && !player.isCreative() && blockState.getValue(UNSTABLE)) { - explode(level, blockPos); + public IBlockData playerWillDestroy(Level world, BlockPos blockposition, IBlockData iblockdata, Player entityhuman) { + if (!world.isClientSide() && !entityhuman.isCreative() && (Boolean) iblockdata.getValue(TntBlock.UNSTABLE) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.BLOCK_BREAK, entityhuman, null)) { // CraftBukkit - TNTPrimeEvent + explode(world, blockposition); } - return super.playerWillDestroy(level, blockPos, blockState, player); + return super.playerWillDestroy(world, blockposition, iblockdata, entityhuman); } @Override public void wasExploded(Level level, BlockPos pos, Explosion explosion) { if (!level.isClientSide) { - PrimedTnt primedTnt = new PrimedTnt( - level, (double)pos.getX() + 0.5, (double)pos.getY(), (double)pos.getZ() + 0.5, explosion.getIndirectSourceEntity() - ); - int fuse = primedTnt.getFuse(); - primedTnt.setFuse((short)(level.random.nextInt(fuse / 4) + fuse / 8)); - level.addFreshEntity(primedTnt); + PrimedTnt entitytntprimed = new PrimedTnt(level, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity()); + int i = entitytntprimed.getFuse(); + + entitytntprimed.setFuse((short) (level.random.nextInt(i / 4) + i / 8)); + level.addFreshEntity(entitytntprimed); } } public static void explode(Level level, BlockPos pos) { - explode(level, pos, null); + explode(level, pos, (LivingEntity) null); } private static void explode(Level level, BlockPos pos, @Nullable LivingEntity entity) { if (!level.isClientSide) { - PrimedTnt primedTnt = new PrimedTnt(level, (double)pos.getX() + 0.5, (double)pos.getY(), (double)pos.getZ() + 0.5, entity); - level.addFreshEntity(primedTnt); - level.playSound(null, primedTnt.getX(), primedTnt.getY(), primedTnt.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F); - level.gameEvent(entity, GameEvent.PRIME_FUSE, pos); + PrimedTnt entitytntprimed = new PrimedTnt(level, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, entity); + + level.addFreshEntity(entitytntprimed); + level.playSound((Player) null, entitytntprimed.getX(), entitytntprimed.getY(), entitytntprimed.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F); + level.gameEvent((Entity) entity, GameEvent.PRIME_FUSE, pos); } } @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - ItemStack itemInHand = player.getItemInHand(hand); - if (!itemInHand.is(Items.FLINT_AND_STEEL) && !itemInHand.is(Items.FIRE_CHARGE)) { + public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) { + ItemStack itemstack = player.getItemInHand(hand); + + if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) { return super.use(state, level, pos, player, hand, hit); } else { + // CraftBukkit start - TNTPrimeEvent + if (!CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.PLAYER, player, null)) { + return InteractionResult.CONSUME; + } + // CraftBukkit end explode(level, pos, player); level.setBlock(pos, Blocks.AIR.defaultBlockState(), 11); - Item item = itemInHand.getItem(); + Item item = itemstack.getItem(); + if (!player.isCreative()) { - if (itemInHand.is(Items.FLINT_AND_STEEL)) { - itemInHand.hurtAndBreak(1, player, user -> user.broadcastBreakEvent(hand)); + if (itemstack.is(Items.FLINT_AND_STEEL)) { + itemstack.hurtAndBreak(1, player, (entityhuman1) -> { + entityhuman1.broadcastBreakEvent(hand); + }); } else { - itemInHand.shrink(1); + itemstack.shrink(1); } } @@ -115,15 +131,22 @@ } @Override - public void onProjectileHit(Level level, BlockState state, BlockHitResult hit, Projectile projectile) { + public void onProjectileHit(Level level, IBlockData state, BlockHitResult hit, Projectile projectile) { if (!level.isClientSide) { - BlockPos blockPos = hit.getBlockPos(); - Entity owner = projectile.getOwner(); - if (projectile.isOnFire() && projectile.mayInteract(level, blockPos)) { - explode(level, blockPos, owner instanceof LivingEntity ? (LivingEntity)owner : null); - level.removeBlock(blockPos, false); + BlockPos blockposition = hit.getBlockPos(); + Entity entity = projectile.getOwner(); + + if (projectile.isOnFire() && projectile.mayInteract(level, blockposition)) { + // CraftBukkit start + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(level, blockposition, PrimeCause.PROJECTILE, projectile, null)) { + return; + } + // CraftBukkit end + explode(level, blockposition, entity instanceof LivingEntity ? (LivingEntity) entity : null); + level.removeBlock(blockposition, false); } } + } @Override @@ -132,7 +155,7 @@ } @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(UNSTABLE); + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(TntBlock.UNSTABLE); } }