diff --git a/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java b/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java index 583579f0..6b5eba5e 100644 --- a/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java +++ b/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java @@ -22,6 +22,8 @@ import net.minecraft.world.level.block.LiquidBlockContainer; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -130,16 +132,17 @@ public class HydrothermalVentBlock extends BaseBlockNotFull implements EntityBlo @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { super.animateTick(state, world, pos, random); - if (random.nextBoolean()) { + if (!state.getValue(ACTIVATED) && random.nextBoolean()) { double x = pos.getX() + random.nextDouble(); double y = pos.getY() + 0.9 + random.nextDouble() * 0.3; double z = pos.getZ() + random.nextDouble(); - if (state.getValue(ACTIVATED)) { - world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); - } - else { - world.addParticle(ParticleTypes.LARGE_SMOKE, x, y, z, 0, 0, 0); - } + world.addParticle(ParticleTypes.LARGE_SMOKE, x, y, z, 0, 0, 0); } } + + @Nullable + @Override + public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { + return BlockEntityHydrothermalVent::tick; + } } diff --git a/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java index 710bac7c..1e44f1b5 100644 --- a/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java +++ b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java @@ -22,46 +22,51 @@ import ru.betterend.registry.EndParticles; import java.util.List; public class BlockEntityHydrothermalVent extends BlockEntity { - private final static Vec3 POSITIVE_Y = new Vec3(0.0f, 1.0f, 0.0f); + private static final MutableBlockPos POS = new MutableBlockPos(); public BlockEntityHydrothermalVent(BlockPos blockPos, BlockState blockState) { super(EndBlockEntities.HYDROTHERMAL_VENT, blockPos, blockState); } - public static void tick(Level level, BlockPos worldPosition, BlockState state, BlockEntityHydrothermalVent blockEntity) { - if (level != null) { - if (state.is(EndBlocks.HYDROTHERMAL_VENT)) { - boolean active = state.getValue(HydrothermalVentBlock.ACTIVATED); - if (active && level.random.nextInt(20) == 0) { - double x = worldPosition.getX() + level.random.nextDouble(); - double y = worldPosition.getY() + 0.9 + level.random.nextDouble() * 0.3; - double z = worldPosition.getZ() + level.random.nextDouble(); - if (state.getValue(HydrothermalVentBlock.WATERLOGGED)) { - level.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); - } - else { - level.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); - } - } - MutableBlockPos mutable = worldPosition.mutable().move(Direction.UP); - int height = active ? 85 : 25; - AABB box = new AABB(mutable.offset(-1, 0, -1), mutable.offset(1, height, 1)); - List entities = level.getEntitiesOfClass(LivingEntity.class, box); - if (entities.size() > 0) { - while (mutable.getY() < box.maxY) { - BlockState blockState = level.getBlockState(mutable); - if (blockState.isSolidRender(level, mutable)) break; - if (blockState.isAir()) { - double mult = active ? 3.0 : 5.0; - float force = (float) ((1.0 - (mutable.getY() / box.maxY)) / mult); - entities.stream().filter(entity -> (int) entity.getY() == mutable.getY() && - blockEntity.hasElytra(entity) && entity.isFallFlying()) - .forEach(entity -> entity.moveRelative(force, POSITIVE_Y)); - } - mutable.move(Direction.UP); - } + public static void tick(Level level, BlockPos worldPosition, BlockState state, T uncastedEntity) { + if (level != null && uncastedEntity instanceof BlockEntityHydrothermalVent && state.is(EndBlocks.HYDROTHERMAL_VENT)) { + BlockEntityHydrothermalVent blockEntity = (BlockEntityHydrothermalVent) uncastedEntity; + if (level.isClientSide()) { + clientTick(level, worldPosition, state, blockEntity); + } + else { + serverTick(level, worldPosition, state, blockEntity); + } + } + } + + private static void clientTick(Level level, BlockPos worldPosition, BlockState state, BlockEntityHydrothermalVent blockEntity) { + boolean active = state.getValue(HydrothermalVentBlock.ACTIVATED); + if (active && level.random.nextInt(20) == 0 && state.getValue(HydrothermalVentBlock.WATERLOGGED)) { + double x = worldPosition.getX() + level.random.nextDouble(); + double y = worldPosition.getY() + 0.9 + level.random.nextDouble() * 0.3; + double z = worldPosition.getZ() + level.random.nextDouble(); + level.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); + } + } + + private static void serverTick(Level level, BlockPos worldPosition, BlockState state, BlockEntityHydrothermalVent blockEntity) { + boolean active = state.getValue(HydrothermalVentBlock.ACTIVATED); + POS.set(worldPosition).move(Direction.UP); + int height = active ? 85 : 25; + AABB box = new AABB(POS.offset(-1, 0, -1), POS.offset(1, height, 1)); + List entities = level.getEntitiesOfClass(LivingEntity.class, box); + if (entities.size() > 0) { + while (POS.getY() < box.maxY) { + BlockState blockState = level.getBlockState(POS); + if (blockState.isSolidRender(level, POS)) break; + if (blockState.isAir()) { + double mult = active ? 3.0 : 5.0; + float force = (float) ((1.0 - (POS.getY() / box.maxY)) / mult); + entities.stream().filter(entity -> (int) entity.getY() == POS.getY() && blockEntity.hasElytra(entity) && entity.isFallFlying()).forEach(entity -> entity.moveRelative(force, POSITIVE_Y)); } + POS.move(Direction.UP); } } }