snow creator, part 2

This commit is contained in:
Ellpeck 2020-02-02 22:50:02 +01:00
parent 93d65914b7
commit d2d2161d04
2 changed files with 61 additions and 13 deletions

View file

@ -2,15 +2,24 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; 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.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.Fluid;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.gen.Heightmap; import net.minecraft.world.gen.Heightmap;
public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTileEntity { public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTileEntity {
private int snowmanCount;
public TileEntitySnowCreator() { public TileEntitySnowCreator() {
super(ModTileEntities.SNOW_CREATOR); super(ModTileEntities.SNOW_CREATOR);
} }
@ -35,6 +44,7 @@ public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTi
if (this.world.getGameTime() % 10 != 0) if (this.world.getGameTime() % 10 != 0)
return; return;
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)); 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); pos = this.world.getHeight(Heightmap.Type.MOTION_BLOCKING, pos);
BlockPos down = pos.down(); BlockPos down = pos.down();
@ -44,12 +54,24 @@ public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTi
this.world.setBlockState(down, Blocks.ICE.getDefaultState()); this.world.setBlockState(down, Blocks.ICE.getDefaultState());
} else if (Blocks.SNOW.getDefaultState().isValidPosition(this.world, pos)) { } else if (Blocks.SNOW.getDefaultState().isValidPosition(this.world, pos)) {
this.world.setBlockState(pos, Blocks.SNOW.getDefaultState()); 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 { } else {
return; continue;
} }
BlockPos auraPos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos); BlockPos auraPos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos);
IAuraChunk.getAuraChunk(this.world, auraPos).drainAura(auraPos, 300); 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;
}
} else { } else {
if (this.world.getGameTime() % 30 != 0) if (this.world.getGameTime() % 30 != 0)
return; 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");
}
} }

View file

@ -459,6 +459,18 @@ public class PacketParticles {
message.posZ + world.rand.nextGaussian() * 0.15F, message.posZ + world.rand.nextGaussian() * 0.15F,
0, 0, 0, 0x42e9f5, 1 + world.rand.nextFloat() * 2, 40, 0, false, true 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; public final BiConsumer<PacketParticles, World> action;