mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Added particle effects to cloud blocks and break clouds when falling on them from a tall height
This commit is contained in:
parent
9ec8568f49
commit
64515ac808
5 changed files with 54 additions and 0 deletions
|
@ -13,9 +13,12 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
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
|
||||
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
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
|
||||
|
|
|
@ -28,6 +28,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
|
|||
|
||||
public CloudSlabBlock(Settings settings, boolean meltable, @Nullable Supplier<Soakable> soggyBlock) {
|
||||
super(settings, meltable, soggyBlock);
|
||||
setDefaultState(getDefaultState().with(SlabBlock.TYPE, SlabType.BOTTOM));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,6 +47,7 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
|
|||
|
||||
@Override
|
||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||
super.randomDisplayTick(state, world, pos, random);
|
||||
Soakable.addMoistureParticles(state, world, pos, random);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
|
|||
|
||||
@Override
|
||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||
super.randomDisplayTick(state, world, pos, random);
|
||||
Soakable.addMoistureParticles(state, world, pos, random);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ public class UnstableCloudBlock extends CloudBlock {
|
|||
|
||||
@Override
|
||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||
super.randomDisplayTick(state, world, pos, random);
|
||||
int charge = state.get(CHARGE);
|
||||
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);
|
||||
|
@ -49,6 +50,11 @@ public class UnstableCloudBlock extends CloudBlock {
|
|||
}
|
||||
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) {
|
||||
world.setBlockState(pos, state.cycle(CHARGE));
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue