Search in sources :

Example 1 with TNTBlock

use of net.minecraft.block.TNTBlock in project Mekanism by mekanism.

the class EntityFlame method onHitBlock.

@Override
protected void onHitBlock(@Nonnull BlockRayTraceResult blockRayTrace) {
    super.onHitBlock(blockRayTrace);
    BlockPos hitPos = blockRayTrace.getBlockPos();
    Direction hitSide = blockRayTrace.getDirection();
    BlockState hitState = level.getBlockState(hitPos);
    boolean hitFluid = !hitState.getFluidState().isEmpty();
    if (!level.isClientSide && MekanismConfig.general.aestheticWorldDamage.get() && !hitFluid) {
        if (mode == FlamethrowerMode.HEAT) {
            Entity owner = getOwner();
            if (owner instanceof PlayerEntity) {
                smeltBlock((PlayerEntity) owner, hitState, hitPos, hitSide);
            }
        } else if (mode == FlamethrowerMode.INFERNO) {
            Entity owner = getOwner();
            BlockPos sidePos = hitPos.relative(hitSide);
            if (CampfireBlock.canLight(hitState)) {
                tryPlace(owner, hitPos, hitSide, hitState.setValue(BlockStateProperties.LIT, true));
            } else if (AbstractFireBlock.canBePlacedAt(level, sidePos, hitSide)) {
                tryPlace(owner, sidePos, hitSide, AbstractFireBlock.getState(level, sidePos));
            } else if (hitState.isFlammable(level, hitPos, hitSide)) {
                // TODO: Is there some event we should/can be firing here?
                hitState.catchFire(level, hitPos, hitSide, owner instanceof LivingEntity ? (LivingEntity) owner : null);
                if (hitState.getBlock() instanceof TNTBlock) {
                    level.removeBlock(hitPos, false);
                }
            }
        }
    }
    if (hitFluid) {
        spawnParticlesAt(blockPosition());
        playSound(SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F);
    }
    remove();
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.item.ItemEntity) BlockState(net.minecraft.block.BlockState) TNTBlock(net.minecraft.block.TNTBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

BlockState (net.minecraft.block.BlockState)1 TNTBlock (net.minecraft.block.TNTBlock)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)1 Direction (net.minecraft.util.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1