mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
snow creator, part 2
This commit is contained in:
parent
93d65914b7
commit
d2d2161d04
2 changed files with 61 additions and 13 deletions
|
@ -2,15 +2,24 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.passive.SnowGolemEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
|
||||
public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTileEntity {
|
||||
|
||||
private int snowmanCount;
|
||||
|
||||
public TileEntitySnowCreator() {
|
||||
super(ModTileEntities.SNOW_CREATOR);
|
||||
}
|
||||
|
@ -35,21 +44,34 @@ public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTi
|
|||
if (this.world.getGameTime() % 10 != 0)
|
||||
return;
|
||||
|
||||
BlockPos pos = this.pos.add(MathHelper.nextInt(this.world.rand, -range, range), 0, MathHelper.nextInt(this.world.rand, -range, range));
|
||||
pos = this.world.getHeight(Heightmap.Type.MOTION_BLOCKING, pos);
|
||||
BlockPos down = pos.down();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
BlockPos pos = this.pos.add(MathHelper.nextInt(this.world.rand, -range, range), 0, MathHelper.nextInt(this.world.rand, -range, range));
|
||||
pos = this.world.getHeight(Heightmap.Type.MOTION_BLOCKING, pos);
|
||||
BlockPos down = pos.down();
|
||||
|
||||
Fluid fluid = this.world.getFluidState(down).getFluid();
|
||||
if (fluid == Fluids.WATER) {
|
||||
this.world.setBlockState(down, Blocks.ICE.getDefaultState());
|
||||
} else if (Blocks.SNOW.getDefaultState().isValidPosition(this.world, pos)) {
|
||||
this.world.setBlockState(pos, Blocks.SNOW.getDefaultState());
|
||||
} else {
|
||||
return;
|
||||
Fluid fluid = this.world.getFluidState(down).getFluid();
|
||||
if (fluid == Fluids.WATER) {
|
||||
this.world.setBlockState(down, Blocks.ICE.getDefaultState());
|
||||
} else if (Blocks.SNOW.getDefaultState().isValidPosition(this.world, pos)) {
|
||||
this.world.setBlockState(pos, Blocks.SNOW.getDefaultState());
|
||||
|
||||
if (this.snowmanCount < range / 2 && this.world.rand.nextFloat() >= 0.995F) {
|
||||
this.snowmanCount++;
|
||||
Entity golem = new SnowGolemEntity(EntityType.SNOW_GOLEM, this.world);
|
||||
golem.setPosition(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
|
||||
this.world.addEntity(golem);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos auraPos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos);
|
||||
IAuraChunk.getAuraChunk(this.world, auraPos).drainAura(auraPos, 300);
|
||||
|
||||
PacketHandler.sendToAllAround(this.world, this.pos, 32,
|
||||
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.SNOW_CREATOR));
|
||||
break;
|
||||
}
|
||||
|
||||
BlockPos auraPos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos);
|
||||
IAuraChunk.getAuraChunk(this.world, auraPos).drainAura(auraPos, 300);
|
||||
} else {
|
||||
if (this.world.getGameTime() % 30 != 0)
|
||||
return;
|
||||
|
@ -66,4 +88,18 @@ public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNBT(CompoundNBT compound, SaveType type) {
|
||||
super.writeNBT(compound, type);
|
||||
if (type == SaveType.TILE)
|
||||
compound.putInt("snowman_count", this.snowmanCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(CompoundNBT compound, SaveType type) {
|
||||
super.readNBT(compound, type);
|
||||
if (type == SaveType.TILE)
|
||||
this.snowmanCount = compound.getInt("snowman_count");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,6 +459,18 @@ public class PacketParticles {
|
|||
message.posZ + world.rand.nextGaussian() * 0.15F,
|
||||
0, 0, 0, 0x42e9f5, 1 + world.rand.nextFloat() * 2, 40, 0, false, true
|
||||
);
|
||||
}),
|
||||
SNOW_CREATOR((message, world) -> {
|
||||
BlockPos pos = new BlockPos(message.posX, message.posY, message.posZ);
|
||||
int color = IAuraChunk.getAuraChunk(world, pos).getType().getColor();
|
||||
for (int i = world.rand.nextInt(3) + 1; i > 0; i--)
|
||||
NaturesAuraAPI.instance().spawnParticleStream(
|
||||
message.posX + (float) world.rand.nextGaussian() * 5,
|
||||
message.posY + world.rand.nextFloat() * 5,
|
||||
message.posZ + (float) world.rand.nextGaussian() * 5,
|
||||
message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F,
|
||||
0.25F, color, 0.5F + world.rand.nextFloat()
|
||||
);
|
||||
});
|
||||
|
||||
public final BiConsumer<PacketParticles, World> action;
|
||||
|
|
Loading…
Reference in a new issue