Search in sources :

Example 1 with LavaFluid

use of net.minecraft.world.level.material.LavaFluid in project MoreBoots by North-West-Wind.

the class WaterBootsItem method onLivingUpdate.

@Override
public void onLivingUpdate(final LivingEvent.LivingUpdateEvent event) {
    LivingEntity entity = event.getEntityLiving();
    ItemStack boots = entity.getItemBySlot(EquipmentSlot.FEET);
    Vec3 pos = entity.position();
    BlockPos blockPos = new BlockPos(pos);
    BlockPos under = blockPos.below();
    FluidState underneath = entity.level.getFluidState(under);
    BlockState underneathBlock = entity.level.getBlockState(under);
    if (underneath.getType() instanceof LavaFluid && !(underneathBlock.getBlock() instanceof SimpleWaterloggedBlock)) {
        LavaFluid lava = (LavaFluid) underneath.getType();
        if (lava.isSource(underneath))
            entity.level.setBlockAndUpdate(under, Blocks.OBSIDIAN.defaultBlockState());
        else
            entity.level.setBlockAndUpdate(under, Blocks.COBBLESTONE.defaultBlockState());
        entity.playSound(SoundEvents.LAVA_EXTINGUISH, 1, 1);
        boots.hurtAndBreak(1, entity, playerEntity -> playerEntity.playSound(SoundEvents.ITEM_BREAK, 1, 1));
    } else if (entity.level.getBlockState(blockPos).getBlock().equals(Blocks.FIRE))
        entity.level.setBlockAndUpdate(blockPos, Blocks.AIR.defaultBlockState());
    if (entity.isInWater() && boots.getMaxDamage() - boots.getDamageValue() > 0 && entity.getRandom().nextInt(10) == 0)
        boots.setDamageValue(Math.max(boots.getDamageValue() - 2, 0));
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) FluidState(net.minecraft.world.level.material.FluidState) LavaFluid(net.minecraft.world.level.material.LavaFluid)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 ItemStack (net.minecraft.world.item.ItemStack)1 SimpleWaterloggedBlock (net.minecraft.world.level.block.SimpleWaterloggedBlock)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 FluidState (net.minecraft.world.level.material.FluidState)1 LavaFluid (net.minecraft.world.level.material.LavaFluid)1 Vec3 (net.minecraft.world.phys.Vec3)1