Added particle effects to cloud blocks and break clouds when falling on them from a tall height

This commit is contained in:
Sollace 2023-10-19 16:12:48 +01:00
parent 9ec8568f49
commit 64515ac808
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
5 changed files with 54 additions and 0 deletions

View file

@ -13,9 +13,12 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.shape.VoxelShapes;
@ -42,9 +45,51 @@ public class CloudBlock extends TransparentBlock {
} }
} }
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (world.random.nextInt(150) == 0) {
generateSurfaceParticles(world, state, pos, ShapeContext.absent(), 1);
}
}
@Override @Override
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) { public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
entity.handleFallDamage(fallDistance, 0, world.getDamageSources().fall()); entity.handleFallDamage(fallDistance, 0, world.getDamageSources().fall());
generateSurfaceParticles(world, state, pos, ShapeContext.of(entity), 9);
if (fallDistance > 7) {
world.breakBlock(pos, true);
}
}
@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if (world.random.nextInt(15) == 0) {
generateSurfaceParticles(world, state, pos, ShapeContext.of(entity), 1);
}
}
protected void generateSurfaceParticles(World world, BlockState state, BlockPos pos, ShapeContext context, int count) {
VoxelShape shape = getCollisionShape(state, world, pos, context);
Random rng = world.random;
Box box = shape.getBoundingBox();
for (int i = 0; i < count; i++) {
world.addParticle(ParticleTypes.CLOUD,
pos.getX() + MathHelper.lerp(rng.nextFloat(), box.minX, box.maxX),
pos.getY() + box.maxY,
pos.getZ() + MathHelper.lerp(rng.nextFloat(), box.minZ, box.maxZ), 0, 0, 0);
world.addParticle(ParticleTypes.CLOUD,
pos.getX() + (rng.nextBoolean() ? box.minX : box.maxX),
pos.getY() + MathHelper.lerp(rng.nextFloat(), box.minY, box.maxY),
pos.getZ() + MathHelper.lerp(rng.nextFloat(), box.minZ, box.maxZ), 0, 0, 0);
world.addParticle(ParticleTypes.CLOUD,
pos.getX() + MathHelper.lerp(rng.nextFloat(), box.minX, box.maxX),
pos.getY() + MathHelper.lerp(rng.nextFloat(), box.minY, box.maxY),
pos.getZ() + (rng.nextBoolean() ? box.minZ : box.maxZ), 0, 0, 0);
}
} }
@Override @Override

View file

@ -28,6 +28,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
public CloudSlabBlock(Settings settings, boolean meltable, @Nullable Supplier<Soakable> soggyBlock) { public CloudSlabBlock(Settings settings, boolean meltable, @Nullable Supplier<Soakable> soggyBlock) {
super(settings, meltable, soggyBlock); super(settings, meltable, soggyBlock);
setDefaultState(getDefaultState().with(SlabBlock.TYPE, SlabType.BOTTOM));
} }
@Override @Override

View file

@ -47,6 +47,7 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
@Override @Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
Soakable.addMoistureParticles(state, world, pos, random); Soakable.addMoistureParticles(state, world, pos, random);
} }

View file

@ -48,6 +48,7 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
@Override @Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
Soakable.addMoistureParticles(state, world, pos, random); Soakable.addMoistureParticles(state, world, pos, random);
} }

View file

@ -34,6 +34,7 @@ public class UnstableCloudBlock extends CloudBlock {
@Override @Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
int charge = state.get(CHARGE); int charge = state.get(CHARGE);
if (charge > 0) { if (charge > 0) {
world.addParticle(new LightningBoltParticleEffect(true, 10, 1, 0.6F + (charge / (float)MAX_CHARGE) * 0.4F, Optional.empty()), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, 0); world.addParticle(new LightningBoltParticleEffect(true, 10, 1, 0.6F + (charge / (float)MAX_CHARGE) * 0.4F, Optional.empty()), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, 0);
@ -49,6 +50,11 @@ public class UnstableCloudBlock extends CloudBlock {
} }
world.playSound(null, pos, SoundEvents.BLOCK_WOOL_HIT, SoundCategory.BLOCKS, 1, 1); world.playSound(null, pos, SoundEvents.BLOCK_WOOL_HIT, SoundCategory.BLOCKS, 1, 1);
if (fallDistance > 3) {
world.breakBlock(pos, true);
return;
}
if (state.get(CHARGE) < MAX_CHARGE) { if (state.get(CHARGE) < MAX_CHARGE) {
world.setBlockState(pos, state.cycle(CHARGE)); world.setBlockState(pos, state.cycle(CHARGE));
} else { } else {