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));
}
Aggregations