Moved existing sphere gen to new system
This commit is contained in:
parent
7399caa896
commit
2163ac7119
1 changed files with 28 additions and 54 deletions
|
@ -2,14 +2,13 @@ package cr0s.warpdrive.world;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.conf.WarpDriveConfig;
|
||||
import cr0s.warpdrive.conf.structures.Orb;
|
||||
import cr0s.warpdrive.data.JumpBlock;
|
||||
|
||||
/*
|
||||
|
@ -47,12 +46,6 @@ public final class EntitySphereGen extends Entity {
|
|||
public int zCoord;
|
||||
|
||||
private int radius;
|
||||
private Block defaultBlock;
|
||||
private boolean hollow;
|
||||
private boolean fillingSphere; // new sphere blocks does not replace
|
||||
// existing blocks (for gases & moons)
|
||||
private boolean generateOres; // generate random surface blocks (ores) or
|
||||
// fixed blockID
|
||||
private int gasColor;
|
||||
|
||||
private final int BLOCKS_PER_TICK = 5000;
|
||||
|
@ -69,12 +62,14 @@ public final class EntitySphereGen extends Entity {
|
|||
|
||||
private ArrayList<JumpBlock> blocks;
|
||||
private int defaultMeta;
|
||||
private Orb orb;
|
||||
private boolean replace;
|
||||
|
||||
public EntitySphereGen(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntitySphereGen(World world, int x, int y, int z, int radius, Block block, int blockMeta, boolean hollow, boolean fillingSphere, boolean generateOres) {
|
||||
public EntitySphereGen(World world, int x, int y, int z, int radius, Orb orb, boolean replace) {
|
||||
super(world);
|
||||
this.xCoord = x;
|
||||
this.posX = x;
|
||||
|
@ -82,17 +77,14 @@ public final class EntitySphereGen extends Entity {
|
|||
this.posY = y;
|
||||
this.zCoord = z;
|
||||
this.posZ = z;
|
||||
this.radius = radius;
|
||||
this.hollow = hollow;
|
||||
this.fillingSphere = fillingSphere;
|
||||
this.generateOres = generateOres;
|
||||
this.gasColor = worldObj.rand.nextInt(12);
|
||||
this.radius = radius;
|
||||
this.state = STATE_SAVING;
|
||||
this.pregenSize = (int) Math.ceil(Math.PI * 4.0F / 3.0F * Math.pow(radius + 1, 3));
|
||||
blocks = new ArrayList<JumpBlock>(this.pregenSize);
|
||||
this.defaultBlock = block;
|
||||
this.defaultMeta = blockMeta;
|
||||
this.ticksDelay = world.rand.nextInt(60);
|
||||
this.orb = orb;
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
public void killEntity() {
|
||||
|
@ -150,57 +142,43 @@ public final class EntitySphereGen extends Entity {
|
|||
private void tickScheduleBlocks() {
|
||||
// LocalProfiler.start("EntitySphereGen.tickScheduleBlocks");
|
||||
radius += 0.5D; // Radius from center of block
|
||||
double radiusSq = radius * radius; // Optimization to avoid square roots
|
||||
double radius1Sq = (radius - 1.0D) * (radius - 1.0D); // for hollow
|
||||
// sphere
|
||||
int ceilRadius = (int) Math.ceil(radius);
|
||||
|
||||
// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 =
|
||||
// r^2
|
||||
Block block = defaultBlock;
|
||||
for (int x = 0; x <= ceilRadius; x++) {
|
||||
double x2 = (x + 0.5D) * (x + 0.5D);
|
||||
for (int y = 0; y <= ceilRadius; y++) {
|
||||
double y2 = (y + 0.5D) * (y + 0.5D);
|
||||
for (int z = 0; z <= ceilRadius; z++) {
|
||||
double z2 = (z + 0.5D) * (z + 0.5D);
|
||||
double dSq = x2 + y2 + z2; // Distance from current position
|
||||
double dSq = Math.sqrt(x2 + y2 + z2); // Distance from current position
|
||||
// to center
|
||||
|
||||
// Skip too far blocks
|
||||
if (dSq > radiusSq)
|
||||
continue;
|
||||
// Hollow sphere condition
|
||||
if ((hollow)
|
||||
&& ((dSq < radius1Sq) || ((lengthSq(x + 1.5D, y + 0.5D, z + 0.5D) <= radiusSq)
|
||||
&& (lengthSq(x + 0.5D, y + 1.5D, z + 0.5D) <= radiusSq) && (lengthSq(x + 0.5D, y + 0.5D, z + 1.5D) <= radiusSq))))
|
||||
if (dSq > radius)
|
||||
continue;
|
||||
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
int rad = (int) Math.ceil(dSq);
|
||||
|
||||
// Add blocks to memory
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord + y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord + y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord - y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord + y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord - y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord - y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord + y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord - y, zCoord - z));
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord + y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord + y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord - y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord + y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord - y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord - y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord + y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord - y, zCoord - z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +192,7 @@ public final class EntitySphereGen extends Entity {
|
|||
if (blocks == null)
|
||||
return;
|
||||
// Replace water with random gas (ship in moon)
|
||||
if (worldObj.getBlock(jb.x, jb.y, jb.z).isAssociatedBlock(Blocks.leaves)) {
|
||||
if (worldObj.getBlock(jb.x, jb.y, jb.z).isAssociatedBlock(Blocks.water)) {
|
||||
if (worldObj.rand.nextInt(50) != 1) {
|
||||
jb.block = WarpDrive.gasBlock;
|
||||
jb.blockMeta = gasColor;
|
||||
|
@ -223,15 +201,11 @@ public final class EntitySphereGen extends Entity {
|
|||
return;
|
||||
}
|
||||
// Do not replace existing blocks if fillingSphere is true
|
||||
if (fillingSphere && !worldObj.isAirBlock(jb.x, jb.y, jb.z))
|
||||
if (!replace && !worldObj.isAirBlock(jb.x, jb.y, jb.z))
|
||||
return;
|
||||
blocks.add(jb);
|
||||
}
|
||||
|
||||
private static double lengthSq(double x, double y, double z) {
|
||||
return (x * x) + (y * y) + (z * z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound tag) {
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue