Hydrotermal vent ticks fix
This commit is contained in:
parent
93ca944472
commit
e9e39f7152
2 changed files with 48 additions and 40 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
|
||||
return BlockEntityHydrothermalVent::tick;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
public static <T extends BlockEntity> 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) {
|
||||
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();
|
||||
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);
|
||||
|
||||
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(mutable.offset(-1, 0, -1), mutable.offset(1, height, 1));
|
||||
AABB box = new AABB(POS.offset(-1, 0, -1), POS.offset(1, height, 1));
|
||||
List<LivingEntity> 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;
|
||||
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 - (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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue