Skip to content

Commit

Permalink
Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Macagno committed Aug 26, 2015
1 parent 612e5a3 commit 3e62955
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions src/main/java/cr0s/warpdrive/world/EntitySphereGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,30 @@ public final class EntitySphereGen extends Entity {
public int xCoord;
public int yCoord;
public int zCoord;

private int radius;
private int gasColor;

private final int BLOCKS_PER_TICK = 5000;

private final int STATE_SAVING = 0;
private final int STATE_SETUP = 1;
private final int STATE_DELETE = 2;
private final int STATE_STOP = 3;
private int state = STATE_DELETE;
private int ticksDelay = 0;

private int currentIndex = 0;
private int pregenSize = 0;

private ArrayList<JumpBlock> blocks;
private Orb orb;
private boolean replace;

public EntitySphereGen(World world) {
super(world);
}

public EntitySphereGen(World world, int x, int y, int z, int radius, Orb orb, boolean replace) {
super(world);
this.xCoord = x;
Expand All @@ -87,23 +87,24 @@ public EntitySphereGen(World world, int x, int y, int z, int radius, Orb orb, bo
this.orb = orb;
this.replace = replace;
}

public void killEntity() {
this.state = STATE_STOP;
worldObj.markBlockRangeForRenderUpdate(xCoord - radius, yCoord - radius, zCoord - radius, xCoord + radius, yCoord + radius, zCoord + radius);
worldObj.removeEntity(this);
}

@Override
public void onUpdate() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return;
}

if (ticksDelay > 0) {
ticksDelay--;
return;
}

switch (this.state) {
case STATE_SAVING:
tickScheduleBlocks();
Expand All @@ -121,13 +122,13 @@ public void onUpdate() {
break;
}
}

private void tickPlaceBlocks() {
int blocksToMove = Math.min(BLOCKS_PER_TICK, blocks.size() - currentIndex);
// LocalProfiler.start("[EntitySphereGen] Placing blocks: " +
// currentIndex + "/" + blocks.size());
int notifyFlag;

for (int index = 0; index < blocksToMove; index++) {
if (currentIndex >= blocks.size())
break;
Expand All @@ -136,16 +137,16 @@ private void tickPlaceBlocks() {
JumpBlock.setBlockNoLight(worldObj, jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag);
currentIndex++;
}

// LocalProfiler.stop();
}

private void tickScheduleBlocks() {
radius += 0.5D; // Radius from center of block

// sphere
int ceilRadius = (int) Math.ceil(radius);

// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 = r^2
for (int x = 0; x <= ceilRadius; x++) {
double x2 = (x + 0.5D) * (x + 0.5D);
Expand All @@ -155,36 +156,36 @@ private void tickScheduleBlocks() {
double z2 = (z + 0.5D) * (z + 0.5D);
double dSq = Math.sqrt(x2 + y2 + z2); // Distance from current position
// to center

// Skip too far blocks
if (dSq > radius)
continue;

int rad = (int) Math.ceil(dSq);

// Add blocks to memory
OrbShell orbShell = orb.getShellForRadius(rad);
MetaBlock metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord + y, zCoord + z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord + y, zCoord + z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord - y, zCoord + z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord + y, zCoord - z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord - y, zCoord + z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord - y, zCoord - z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord + y, zCoord - z));

metablock = orbShell.getRandomBlock(rand);
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord - y, zCoord - z));
}
Expand All @@ -195,7 +196,7 @@ private void tickScheduleBlocks() {
}
// LocalProfiler.stop();
}

private void addBlock(JumpBlock jb) {
if (blocks == null)
return;
Expand All @@ -213,19 +214,19 @@ private void addBlock(JumpBlock jb) {
return;
blocks.add(jb);
}

@Override
protected void readEntityFromNBT(NBTTagCompound tag) {
}

@Override
protected void entityInit() {
}

@Override
protected void writeEntityToNBT(NBTTagCompound tag) {
}

@Override
public boolean shouldRenderInPass(int pass) {
return false;
Expand Down

0 comments on commit 3e62955

Please sign in to comment.