132 lines
5.2 KiB
Java
132 lines
5.2 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.entity.projectile.AbstractArrow;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.item.PrimedTnt;
|
|
import net.minecraft.world.level.Explosion;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
|
|
public class TntBlock extends Block {
|
|
public static final BooleanProperty UNSTABLE;
|
|
|
|
public TntBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)TntBlock.UNSTABLE, false));
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (byg4.getBlock() == byg1.getBlock()) {
|
|
return;
|
|
}
|
|
if (bjt.hasNeighborSignal(fk)) {
|
|
explode(bjt, fk);
|
|
bjt.removeBlock(fk, false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void neighborChanged(final BlockState byg, final Level bjt, final BlockPos fk3, final Block bpe, final BlockPos fk5, final boolean boolean6) {
|
|
if (bjt.hasNeighborSignal(fk3)) {
|
|
explode(bjt, fk3);
|
|
bjt.removeBlock(fk3, false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void playerWillDestroy(final Level bjt, final BlockPos fk, final BlockState byg, final Player ayg) {
|
|
if (!bjt.isClientSide() && !ayg.isCreative() && byg.<Boolean>getValue((Property<Boolean>)TntBlock.UNSTABLE)) {
|
|
explode(bjt, fk);
|
|
}
|
|
super.playerWillDestroy(bjt, fk, byg, ayg);
|
|
}
|
|
|
|
@Override
|
|
public void wasExploded(final Level bjt, final BlockPos fk, final Explosion bjm) {
|
|
if (bjt.isClientSide) {
|
|
return;
|
|
}
|
|
final PrimedTnt avz5 = new PrimedTnt(bjt, fk.getX() + 0.5f, fk.getY(), fk.getZ() + 0.5f, bjm.getSourceMob());
|
|
avz5.setFuse((short)(bjt.random.nextInt(avz5.getLife() / 4) + avz5.getLife() / 8));
|
|
bjt.addFreshEntity(avz5);
|
|
}
|
|
|
|
public static void explode(final Level bjt, final BlockPos fk) {
|
|
explode(bjt, fk, null);
|
|
}
|
|
|
|
private static void explode(final Level bjt, final BlockPos fk, @Nullable final LivingEntity akw) {
|
|
if (bjt.isClientSide) {
|
|
return;
|
|
}
|
|
final PrimedTnt avz4 = new PrimedTnt(bjt, fk.getX() + 0.5, fk.getY(), fk.getZ() + 0.5, akw);
|
|
bjt.addFreshEntity(avz4);
|
|
bjt.playSound(null, avz4.getX(), avz4.getY(), avz4.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0f, 1.0f);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
final ItemStack bek8 = ayg.getItemInHand(ajh);
|
|
final Item bef9 = bek8.getItem();
|
|
if (bef9 == Items.FLINT_AND_STEEL || bef9 == Items.FIRE_CHARGE) {
|
|
explode(bjt, fk, ayg);
|
|
bjt.setBlock(fk, Blocks.AIR.defaultBlockState(), 11);
|
|
if (!ayg.isCreative()) {
|
|
if (bef9 == Items.FLINT_AND_STEEL) {
|
|
bek8.<Player>hurtAndBreak(1, ayg, ayg -> ayg.broadcastBreakEvent(ajh));
|
|
}
|
|
else {
|
|
bek8.shrink(1);
|
|
}
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return super.use(byg, bjt, fk, ayg, ajh, cvd);
|
|
}
|
|
|
|
@Override
|
|
public void onProjectileHit(final Level bjt, final BlockState byg, final BlockHitResult cvd, final Entity akn) {
|
|
if (!bjt.isClientSide && akn instanceof AbstractArrow) {
|
|
final AbstractArrow ayk6 = (AbstractArrow)akn;
|
|
final Entity akn2 = ayk6.getOwner();
|
|
if (ayk6.isOnFire()) {
|
|
final BlockPos fk8 = cvd.getBlockPos();
|
|
explode(bjt, fk8, (akn2 instanceof LivingEntity) ? ((LivingEntity)akn2) : null);
|
|
bjt.removeBlock(fk8, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean dropFromExplosion(final Explosion bjm) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(TntBlock.UNSTABLE);
|
|
}
|
|
|
|
static {
|
|
UNSTABLE = BlockStateProperties.UNSTABLE;
|
|
}
|
|
}
|