mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Implement proper behaviour for the unstable cloud block
This commit is contained in:
parent
84cb3de5e3
commit
9100e52981
2 changed files with 41 additions and 12 deletions
|
@ -2,13 +2,18 @@ package com.minelittlepony.unicopia.block.cloud;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.mob.StormCloudEntity;
|
||||
import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect;
|
||||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.LightningRodBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.StateManager;
|
||||
|
@ -16,7 +21,11 @@ import net.minecraft.state.property.IntProperty;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
import net.minecraft.world.poi.PointOfInterestStorage;
|
||||
import net.minecraft.world.poi.PointOfInterestTypes;
|
||||
|
||||
public class UnstableCloudBlock extends CloudBlock {
|
||||
private static final int MAX_CHARGE = 6;
|
||||
|
@ -59,21 +68,39 @@ public class UnstableCloudBlock extends CloudBlock {
|
|||
world.setBlockState(pos, state.cycle(CHARGE));
|
||||
} else {
|
||||
world.setBlockState(pos, state.with(CHARGE, 0));
|
||||
BlockPos shockPosition = pos.add(world.random.nextInt(10) - 5, -world.random.nextInt(10), world.random.nextInt(10) - 5);
|
||||
|
||||
world.addImportantParticle(
|
||||
|
||||
if (world instanceof ServerWorld sw) {
|
||||
Optional<BlockPos> lightningRodPos = sw.getPointOfInterestStorage().getNearestPosition(
|
||||
poiType -> poiType.matchesKey(PointOfInterestTypes.LIGHTNING_ROD),
|
||||
innerPos -> innerPos.getY() == world.getTopY(Heightmap.Type.WORLD_SURFACE, innerPos.getX(), innerPos.getZ()) - 1,
|
||||
pos, 10, PointOfInterestStorage.OccupationStatus.ANY
|
||||
);
|
||||
BlockPos shockPosition = lightningRodPos.or(() -> {
|
||||
return sw.getOtherEntities(entity, new Box(pos.down()).expand(5, 0, 5).stretch(0, -10, 0)).stream().findAny().map(Entity::getBlockPos);
|
||||
}).orElseGet(() -> StormCloudEntity.findSurfaceBelow(sw, pos.add(world.random.nextInt(10) - 5, -world.random.nextInt(10), world.random.nextInt(10) - 5)).toImmutable());
|
||||
|
||||
ParticleUtils.spawnParticle(world,
|
||||
new LightningBoltParticleEffect(false, 10, 6, 0.3F, Optional.of(shockPosition.toCenterPos())),
|
||||
true,
|
||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5,
|
||||
0, 0, 0
|
||||
);
|
||||
world.getOtherEntities(null, new Box(shockPosition).expand(2)).forEach(e -> {
|
||||
e.damage(entity.getDamageSources().lightningBolt(), 1);
|
||||
});
|
||||
lightningRodPos.ifPresent(rodPos -> {
|
||||
BlockState rod = sw.getBlockState(rodPos);
|
||||
if (rod.isOf(Blocks.LIGHTNING_ROD)) {
|
||||
((LightningRodBlock)rod.getBlock()).setPowered(rod, sw, rodPos);
|
||||
}
|
||||
});
|
||||
LightningEntity.cleanOxidation(world, shockPosition);
|
||||
entity.emitGameEvent(GameEvent.LIGHTNING_STRIKE);
|
||||
|
||||
if (world.isAir(shockPosition) && world.getBlockState(shockPosition.down()).isBurnable()) {
|
||||
world.setBlockState(shockPosition, Blocks.FIRE.getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,3 +17,5 @@ accessible field net/minecraft/entity/mob/CreeperEntity IGNITED
|
|||
accessible method net/minecraft/client/render/RenderLayer$MultiPhase getPhases ()Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;
|
||||
accessible method net/minecraft/client/render/RenderPhase$TextureBase getId ()Ljava/util/Optional;
|
||||
accessible field net/minecraft/client/render/RenderLayer$MultiPhaseParameters texture Lnet/minecraft/client/render/RenderPhase$TextureBase;
|
||||
|
||||
accessible method net/minecraft/entity/LightningEntity cleanOxidation (Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V
|
Loading…
Reference in a new issue