diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java index 1047d836..423322a1 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java @@ -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"); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java index fc714d24..fee11ea2 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java @@ -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 action;