From a5691c0ee09ce3ff42077381bc8fc31500c2c1af Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sat, 15 Jul 2017 15:47:07 +0200 Subject: [PATCH] Fixed moon lighting during world generation --- .../cr0s/warpdrive/world/EntitySphereGen.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java index 0e77db07..1ccece6f 100644 --- a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java +++ b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java @@ -63,6 +63,7 @@ public final class EntitySphereGen extends Entity { private int pregenSize = 0; private ArrayList blocks; + private ArrayList isSurfaces; private OrbInstance orbInstance; private boolean replace; @@ -85,6 +86,7 @@ public final class EntitySphereGen extends Entity { this.state = STATE_SAVING; this.pregenSize = (int) Math.ceil(Math.PI * 4.0F / 3.0F * Math.pow(radius + 1, 3)); blocks = new ArrayList<>(this.pregenSize); + isSurfaces = new ArrayList<>(this.pregenSize); this.ticksDelay = world.rand.nextInt(60); this.replace = replace; } @@ -149,10 +151,13 @@ public final class EntitySphereGen extends Entity { for (int index = 0; index < blocksToMove; index++) { if (currentIndex >= blocks.size()) break; - notifyFlag = (currentIndex % 1000 == 0 ? 2 : 2); - JumpBlock jb = blocks.get(currentIndex); - JumpBlock.setBlockNoLight(worldObj, jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag); - // worldObj.setBlock(jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag); + notifyFlag = (currentIndex % 1024 == 0 ? 2 : 2); + final JumpBlock jumpBlock = blocks.get(currentIndex); + if (isSurfaces.get(currentIndex)) { + worldObj.setBlock(jumpBlock.x, jumpBlock.y, jumpBlock.z, jumpBlock.block, jumpBlock.blockMeta, notifyFlag); + } else { + JumpBlock.setBlockNoLight(worldObj, jumpBlock.x, jumpBlock.y, jumpBlock.z, jumpBlock.block, jumpBlock.blockMeta, notifyFlag); + } currentIndex++; } @@ -163,7 +168,8 @@ public final class EntitySphereGen extends Entity { LocalProfiler.start("[EntitySphereGen] Saving blocks, radius " + radius); // square radius from center of block - double sqRadius = (radius + 0.5D) * (radius + 0.5D); + double sqRadiusHigh = (radius + 0.5D) * (radius + 0.5D); + double sqRadiusLow = (radius - 0.5D) * (radius - 0.5D); // sphere int ceilRadius = radius + 1; @@ -177,21 +183,22 @@ public final class EntitySphereGen extends Entity { double sqRange = x2y2 + (z + 0.5D) * (z + 0.5D); // Square distance from current position to center // Skip too far blocks - if (sqRange > sqRadius) { + if (sqRange > sqRadiusHigh) { continue; } + final boolean isSurface = sqRange > sqRadiusLow; // Add blocks to memory OrbShell orbShell = orbInstance.getShellForSqRadius(sqRange); // WarpDrive.logger.info("sqRange " + sqRange + " sqRadius " + sqRadius); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord + y, zCoord + z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord + y, zCoord + z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord - y, zCoord + z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord + y, zCoord - z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord - y, zCoord + z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord - y, zCoord - z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord + y, zCoord - z)); - addBlock(new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord - y, zCoord - z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord + y, zCoord + z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord + y, zCoord + z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord - y, zCoord + z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord + y, zCoord - z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord - y, zCoord + z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord + x, yCoord - y, zCoord - z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord + y, zCoord - z)); + addBlock(isSurface, new JumpBlock(orbShell.getRandomUnit(rand), xCoord - x, yCoord - y, zCoord - z)); } } } @@ -201,24 +208,26 @@ public final class EntitySphereGen extends Entity { LocalProfiler.stop(); } - private void addBlock(JumpBlock jb) { + private void addBlock(final boolean isSurface, final JumpBlock jumpBlock) { if (blocks == null) { return; } // Replace water with random gas (ship in moon) - if (worldObj.getBlock(jb.x, jb.y, jb.z).isAssociatedBlock(Blocks.water)) { + if (worldObj.getBlock(jumpBlock.x, jumpBlock.y, jumpBlock.z).isAssociatedBlock(Blocks.water)) { if (worldObj.rand.nextInt(50) != 1) { - jb.block = WarpDrive.blockGas; - jb.blockMeta = gasColor; + jumpBlock.block = WarpDrive.blockGas; + jumpBlock.blockMeta = gasColor; } - blocks.add(jb); + blocks.add(jumpBlock); + isSurfaces.add(isSurface); return; } // Do not replace existing blocks if fillingSphere is true - if (!replace && !worldObj.isAirBlock(jb.x, jb.y, jb.z)) { + if (!replace && !worldObj.isAirBlock(jumpBlock.x, jumpBlock.y, jumpBlock.z)) { return; } - blocks.add(jb); + blocks.add(jumpBlock); + isSurfaces.add(isSurface); } @Override