From 16d20fb31dd694e13dea14ce5d8bccc31a68d66a Mon Sep 17 00:00:00 2001 From: Sen Date: Sat, 30 Aug 2025 12:03:46 +0200 Subject: [PATCH] make light clientside --- client/src/main/java/client/Client.java | 36 +- .../java/client/gui/options/GuiDisplay.java | 4 + .../client/renderer/RegionRenderCache.java | 2 +- .../main/java/client/renderer/Renderer.java | 341 +++++++++++++- .../src/main/java/client/renderer/Shader.java | 2 +- .../java/client/renderer/entity/Render.java | 6 - .../renderer/entity/RenderBlockEntity.java | 3 +- .../renderer/entity/RenderFallingBlock.java | 2 +- .../renderer/entity/RenderMinecart.java | 3 +- .../renderer/entity/RenderTntMinecart.java | 2 +- .../renderer/entity/RenderTntPrimed.java | 5 +- .../main/java/client/world/ChunkClient.java | 83 +++- .../main/java/client/world/ChunkEmpty.java | 10 +- .../main/java/common/ai/EntityAIFleeSun.java | 95 ---- .../java/common/ai/EntityAIMoveIndoors.java | 104 ----- .../common/ai/EntityAIMoveThroughVillage.java | 174 -------- .../common/ai/EntityAIRestrictOpenDoor.java | 85 ---- .../java/common/ai/EntityAIRestrictSun.java | 39 -- .../block/foliage/BlockBlackenedSoil.java | 6 +- .../common/block/foliage/BlockBlueShroom.java | 2 +- .../java/common/block/foliage/BlockCrops.java | 4 +- .../java/common/block/foliage/BlockGrass.java | 6 +- .../common/block/foliage/BlockMushroom.java | 2 +- .../common/block/foliage/BlockMycelium.java | 27 +- .../common/block/foliage/BlockSapling.java | 2 +- .../java/common/block/foliage/BlockStem.java | 2 +- .../java/common/block/foliage/BlockSwamp.java | 2 +- .../block/natural/BlockBlackenedDirt.java | 2 +- .../java/common/block/natural/BlockIce.java | 2 +- .../java/common/block/natural/BlockSnow.java | 2 +- .../common/block/natural/BlockSnowBlock.java | 2 +- .../java/common/entity/animal/EntityBat.java | 15 +- .../common/entity/animal/EntityMouse.java | 16 +- .../common/entity/npc/EntityArachnoid.java | 2 +- .../java/common/entity/npc/EntityHaunter.java | 5 - .../java/common/entity/npc/EntitySlime.java | 2 +- .../java/common/entity/npc/EntityUndead.java | 4 - .../java/common/entity/npc/EntityZombie.java | 8 +- .../common/entity/projectile/EntityHook.java | 5 - .../common/entity/types/EntityAnimal.java | 6 +- .../java/common/packet/SPacketChunkData.java | 3 +- .../java/common/pathfinding/PathNavigate.java | 7 +- .../pathfinding/PathNavigateGround.java | 33 -- .../main/java/common/world/AWorldServer.java | 2 - .../main/java/common/world/BlockArray.java | 31 +- common/src/main/java/common/world/Chunk.java | 86 +--- common/src/main/java/common/world/World.java | 417 +----------------- .../java/server/init/UniverseRegistry.java | 8 - .../src/main/java/server/network/Player.java | 7 +- .../server/village/VillageCollection.java | 2 +- .../main/java/server/world/ChunkServer.java | 5 +- .../src/main/java/server/world/Converter.java | 70 +-- server/src/main/java/server/world/Region.java | 4 - .../main/java/server/world/WorldServer.java | 77 +--- 54 files changed, 556 insertions(+), 1316 deletions(-) delete mode 100755 common/src/main/java/common/ai/EntityAIFleeSun.java delete mode 100755 common/src/main/java/common/ai/EntityAIMoveIndoors.java delete mode 100755 common/src/main/java/common/ai/EntityAIMoveThroughVillage.java delete mode 100755 common/src/main/java/common/ai/EntityAIRestrictOpenDoor.java delete mode 100755 common/src/main/java/common/ai/EntityAIRestrictSun.java diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index fa6a3022..94589156 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -348,7 +348,6 @@ public class Client implements IThreadListener { super(dim, true); this.orbit = dim.getOrbit(); this.rotation = dim.getRotation(); - this.calculateInitialSkylight(); this.calculateInitialWeather(); this.updatePhysics(); } @@ -424,6 +423,14 @@ public class Client implements IThreadListener { public void setLastLightning(int last, int color) { Client.this.renderer.setLastLightning(last, color); } + + public void checkBlockLight(BlockPos pos) { + Client.this.renderer.checkBlockLight(pos); + } + + public int getCombinedLight(BlockPos pos, int lightValue) { + return Client.this.renderer.getCombinedLight(pos, lightValue); + } } public static final String VERSION = Version.NAME + " Client " + Util.VERSION; @@ -590,6 +597,10 @@ public class Client implements IThreadListener { public int renderDistance = 8; @Variable(name = "chunk_build_time", category = CVarCategory.RENDER, min = 1, max = 100, display = "Zeit für Chunk-Bau", unit = "ms") public int maxBuildTime = 8; + @Variable(name = "chunk_light_updates", category = CVarCategory.RENDER, min = 100, max = 10000, display = "Licht-Updates / Tick") + private int lightUpdates = 2048; + @Variable(name = "chunk_light_range", category = CVarCategory.RENDER, min = 5, max = 1024, display = "Radius Licht-Updates") + private int lightRange = 32; @Variable(name = "gl_fov", category = CVarCategory.RENDER, min = 1.0f, max = 179.0f, display = "Sichtfeld (FOV)", unit = "°", precision = 1) public float fov = 70.0f; @Variable(name = "gl_wireframe", category = CVarCategory.RENDER, display = "Gitter-Render-Modus") @@ -2042,11 +2053,11 @@ public class Client implements IThreadListener { String.format("Biom: %.2f K, N: %.2f K, D: %s (%s)", chunk.getTemperature(pos), chunk.getOffset(pos), Color.stripCodes(this.world.dimension.getDisplay()), this.dimensionName) + "\n" + - "Licht: " + chunk.getLightSub(pos, 0) + " (" + (this.world.dimension.hasSkyLight() ? + World.getSkyLightFor(pos.getY()) + " Himmel, " : "") + "Licht: " + chunk.getLightSub(pos, 0) + " (" + (this.world.dimension.hasSkyLight() ? + Renderer.getSkyLightFor(pos.getY()) + " Himmel, " : "") + chunk.getLight(pos) + " Blöcke, " + String.format( "%.1f", this.renderer.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " - + String.format("%.1f ° (%.1f, %.1f)", this.world.getCelestialAngle(1.0f), !this.world.dimension.hasDaylight() ? 0.0f : ExtMath.cos((-90.0f + this.world.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI), - !this.world.dimension.hasDaylight() ? -1.0f : ExtMath.sin((-90.0f + this.world.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI)) + "\n" + + + String.format("%.1f ° (%.1f, %.1f)", this.renderer.getCelestialAngle(1.0f), !this.world.dimension.hasDaylight() ? 0.0f : ExtMath.cos((-90.0f + this.renderer.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI), + !this.world.dimension.hasDaylight() ? -1.0f : ExtMath.sin((-90.0f + this.renderer.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI)) + "\n" + String.format("Zeit: %s" + (this.world.dimension.hasRotation() ? ", R %d / %d T" : "") + (this.world.dimension.hasOrbit() ? ", U %d / %d T" : ""), this.world.formatEpochSimple(), this.world.getRotation(), @@ -3666,16 +3677,25 @@ public class Client implements IThreadListener { long time = System.currentTimeMillis(); for (ChunkClient chunk : this.chunkListing) { - chunk.update(System.currentTimeMillis() - time > 5L); + chunk.spawnTiles(); } if (System.currentTimeMillis() - time > 100L) { Log.TICK.warn("Render-Chunk-Tick dauerte " + (System.currentTimeMillis() - time) + " ms"); } - - Set active = this.world.setActivePlayerChunksAndCheckLight(this.renderDistance); - this.previousActive.retainAll(active); + if(this.player != null) { + int radius = Math.min(this.renderDistance * 16, this.lightRange); + for(int n = 0; n < this.lightUpdates; n++) { + int x = ExtMath.floord(this.player.posX) + this.world.rand.range(-radius, radius); + int y = ExtMath.floord(this.player.posY) + this.world.rand.range(-radius, radius); + int z = ExtMath.floord(this.player.posZ) + this.world.rand.range(-radius, radius); + this.world.checkBlockLight(new BlockPos(x, y, z)); + } + } + + Set active = this.world.setActiveChunks(this.renderDistance); + this.previousActive.retainAll(active); if (this.previousActive.size() == active.size()) { this.previousActive.clear(); diff --git a/client/src/main/java/client/gui/options/GuiDisplay.java b/client/src/main/java/client/gui/options/GuiDisplay.java index d0b04443..41c8e3da 100644 --- a/client/src/main/java/client/gui/options/GuiDisplay.java +++ b/client/src/main/java/client/gui/options/GuiDisplay.java @@ -92,6 +92,10 @@ public class GuiDisplay extends GuiOptions { this.distanceSlider = this.addSelector("chunk_view_distance", 0, 160, 240, 0); this.addSelector("chunk_build_time", 242, 160, 240, 0); + + this.addSelector("chunk_light_updates", 0, 180, 240, 0); + this.addSelector("chunk_light_range", 242, 180, 240, 0); + super.init(width, height); } diff --git a/client/src/main/java/client/renderer/RegionRenderCache.java b/client/src/main/java/client/renderer/RegionRenderCache.java index 5e59ef1d..7d01a6eb 100755 --- a/client/src/main/java/client/renderer/RegionRenderCache.java +++ b/client/src/main/java/client/renderer/RegionRenderCache.java @@ -126,7 +126,7 @@ public class RegionRenderCache implements IWorldAccess public int getLight(BlockPos pos, int lightValue) { - int i = this.sky ? World.getSkyLightFor(pos.getY()) : 0; + int i = this.sky ? Renderer.getSkyLightFor(pos.getY()) : 0; int j = this.getBlockLightExt(pos); if (j < lightValue) diff --git a/client/src/main/java/client/renderer/Renderer.java b/client/src/main/java/client/renderer/Renderer.java index e5139cb4..1c9b2d95 100755 --- a/client/src/main/java/client/renderer/Renderer.java +++ b/client/src/main/java/client/renderer/Renderer.java @@ -61,16 +61,19 @@ import common.sound.Sound; import common.tileentity.TileEntity; import common.util.BlockPos; import common.util.BoundingBox; +import common.util.Clientside; import common.util.ExtMath; import common.util.Facing; import common.util.HitPosition; import common.util.InheritanceMultiMap; import common.util.Pair; import common.util.HitPosition.ObjectType; +import common.vars.Vars; import common.util.ParticleType; import common.util.Vec3; import common.util.Vec3i; import common.util.Vector3f; +import common.world.Chunk; import common.world.IBlockAccess; import common.world.IWorldAccess; import common.world.State; @@ -104,6 +107,7 @@ public class Renderer { private static final float FOG_DISTANCE = 0.4f; private static final float SQRT_2 = ExtMath.sqrtf(2.0F); private static final float[] SUN_COLOR = new float[4]; + private static final float[] BRIGHTNESS = new float[] {0.0f, 0.02f, 0.04f, 0.06f, 0.08f, 0.11f, 0.14f, 0.18f, 0.22f, 0.27f, 0.33f, 0.41f, 0.5f, 0.62f, 0.78f, 1.0f}; private final Client gm; private final Random rng = new Random(); @@ -188,6 +192,8 @@ public class Renderer { private float blockColorRed; private float blockColorGreen; private float blockColorBlue; + private int subtract; + private final int[] lightUpdate = new int[32768]; public Renderer(Client gm, ModelManager manager) { @@ -268,7 +274,7 @@ public class Renderer { this.gm.setRenderViewEntity(this.gm.player); } - float light = this.gm.world.getLightBrightness(new BlockPos(this.gm.getRenderViewEntity())); + float light = this.getLightBrightness(new BlockPos(this.gm.getRenderViewEntity())); float dist = (float)this.gm.renderDistance / 32.0F; float shift = light * (1.0F - dist) + dist; this.fogMult += (shift - this.fogMult) * 0.1F; @@ -853,7 +859,7 @@ public class Renderer { } public float getSunBrightness(float partial) { - float f = this.gm.world.getDayPhase(partial); + float f = this.getDayPhase(partial); float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.2F); f1 = ExtMath.clampf(f1, 0.0F, 1.0F); f1 = 1.0F - f1; @@ -871,7 +877,7 @@ public class Renderer { else vec = new Vec3(this.gm.world.dimension.getSkyColor()); if(this.gm.world.dimension.hasDaylight()) { - float mult = ExtMath.clampf(ExtMath.cos(this.gm.world.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); + float mult = ExtMath.clampf(ExtMath.cos(this.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); vec = new Vec3(vec.xCoord * mult, vec.yCoord * mult, vec.zCoord * mult); } float r = (float)vec.xCoord; @@ -934,7 +940,7 @@ public class Renderer { } if(this.gm.world.dimension.hasDaylight()) { - float sun = ExtMath.clampf(ExtMath.cos(this.gm.world.getDayPhase(partialTicks)) * 2.0F + 0.5F, + float sun = ExtMath.clampf(ExtMath.cos(this.getDayPhase(partialTicks)) * 2.0F + 0.5F, 0.0F, 1.0F); r = r * (sun * 0.9F + 0.1F); g = g * (sun * 0.9F + 0.1F); @@ -961,14 +967,14 @@ public class Renderer { } private float getStarBrightness(float partialTicks) { - float f = this.gm.world.getDayPhase(partialTicks); + float f = this.getDayPhase(partialTicks); float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); f1 = ExtMath.clampf(f1, 0.0F, 1.0F); return Math.max(f1 * f1 * this.gm.world.dimension.getStarBrightness(), this.getSpaceFactor()); } private float getDeepStarBrightness(float partialTicks) { - float f = this.gm.world.getDayPhase(partialTicks); + float f = this.getDayPhase(partialTicks); float f1 = 1.0F - (ExtMath.cos(f) * 2.0F + 0.25F); f1 = ExtMath.clampf(f1, 0.0F, 1.0F); return Math.max(f1 * f1 * this.gm.world.dimension.getDeepStarBrightness(), this.getSpaceFactor()); @@ -994,8 +1000,8 @@ public class Renderer { for (int n = 0; n < 256; ++n) { - float rsky = World.BRIGHTNESS[n / 16]; - float rblock = World.BRIGHTNESS[n % 16]; + float rsky = BRIGHTNESS[n / 16]; + float rblock = BRIGHTNESS[n % 16]; float sky = rsky * msun; float block = rblock * (this.torchFlickerX * 0.1F + 1.5F); @@ -1550,7 +1556,7 @@ public class Renderer { } if(world.dimension.hasDaylight()) { - float sun = ExtMath.clampf(ExtMath.cos(world.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); + float sun = ExtMath.clampf(ExtMath.cos(this.getDayPhase(partial)) * 2.0F + 0.5F, 0.0F, 1.0F); this.fogColorRed = this.fogColorRed * (sun * 0.94F + 0.06F); this.fogColorGreen = this.fogColorGreen * (sun * 0.94F + 0.06F); this.fogColorBlue = this.fogColorBlue * (sun * 0.91F + 0.09F); @@ -1566,11 +1572,11 @@ public class Renderer { if (this.gm.renderDistance >= 4 && world.dimension.hasDaylight() && !world.dimension.isBaseDestroyed()) { double neg = -1.0D; - Vec3 pos = ExtMath.sin(world.getDayPhase(partial)) > 0.0F ? new Vec3(neg, 0.0D, 0.0D) : new Vec3(1.0D, 0.0D, 0.0D); + Vec3 pos = ExtMath.sin(this.getDayPhase(partial)) > 0.0F ? new Vec3(neg, 0.0D, 0.0D) : new Vec3(1.0D, 0.0D, 0.0D); float shift = (float)entity.getLook(partial).dotProduct(pos); if (shift > 0.0F) { - float[] sun = calcSunriseSunsetColors(world.getDayPhase(partial), partial); + float[] sun = calcSunriseSunsetColors(this.getDayPhase(partial), partial); if (sun != null) { shift = shift * sun[3]; @@ -2035,6 +2041,7 @@ public class Renderer { if (worldClientIn != null) { + this.calculateInitialSkylight(); // worldClientIn.setWorldAccess(this); this.loadRenderers(); } @@ -2733,14 +2740,14 @@ public class Renderer { ItemRenderer.disableStandardItemLighting(); float[] afloat = this.theWorld.dimension.hasDaylight() && !this.theWorld.dimension.isBaseDestroyed() ? - calcSunriseSunsetColors(this.theWorld.getDayPhase(partialTicks), partialTicks) : null; + calcSunriseSunsetColors(this.getDayPhase(partialTicks), partialTicks) : null; if (afloat != null) { GlState.disableTexture2D(); GlState.shadeModel(GL46.GL_SMOOTH); GL46.glPushMatrix(); GL46.glRotatef(90.0F, 1.0F, 0.0F, 0.0F); - GL46.glRotatef(ExtMath.sin(this.theWorld.getDayPhase(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F); + GL46.glRotatef(ExtMath.sin(this.getDayPhase(partialTicks)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F); GL46.glRotatef(90.0F, 0.0F, 0.0F, 1.0F); float f6 = afloat[0]; float f7 = afloat[1]; @@ -2778,7 +2785,7 @@ public class Renderer { GL46.glPushMatrix(); float f16 = 1.0F - Math.max(this.theWorld.getRainStrength(), this.theWorld.getFogStrength()); GL46.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); - GL46.glRotatef(this.theWorld.getCelestialAngle(partialTicks), 1.0F, 0.0F, 0.0F); + GL46.glRotatef(this.getCelestialAngle(partialTicks), 1.0F, 0.0F, 0.0F); if(this.gm.world.dimension.getType() == DimType.PLANET || this.gm.world.dimension.getType() == DimType.MOON) { float size = 30.0F; int color = this.gm.world.dimension.getSunColor(); @@ -3242,10 +3249,11 @@ public class Renderer { } } - public void renderBlockEntity(State state, float brightness) + public void renderBlockEntity(State state, BlockPos brightPos) { if (state.getBlock() != Blocks.air && !state.getBlock().getMaterial().isLiquid()) { + float brightness = brightPos == null ? 1.0f : this.getLightBrightness(brightPos); IBakedModel model = this.manager.getModelForState(state); Block block = state.getBlock(); GL46.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); @@ -3915,4 +3923,307 @@ public class Renderer { return n == 4 ? 1.0f : (s + a == 4 && a > 1 ? 0.0f : 1.0F - f / (float)i); } + + private int getLightFor(BlockPos pos) { + if(pos.getY() < -World.MAX_SIZE_Y) { + pos = new BlockPos(pos.getX(), -World.MAX_SIZE_Y, pos.getZ()); + } + + if(!World.isValid(pos)) { + return 0; + } + else { + ChunkClient chunk = this.gm.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + return chunk.getLight(pos); + } + } + + private int getBlockLightSum(BlockPos pos) { + if(pos.getY() < -World.MAX_SIZE_Y) { + pos = new BlockPos(pos.getX(), -World.MAX_SIZE_Y, pos.getZ()); + } + + if(!World.isValid(pos)) { + return 0; + } + else if(this.gm.world.getState(pos).getBlock().getSumBrightness()) { + int i1 = this.getLightFor(pos.up()); + int i = this.getLightFor(pos.east()); + int j = this.getLightFor(pos.west()); + int k = this.getLightFor(pos.south()); + int l = this.getLightFor(pos.north()); + + if(i > i1) { + i1 = i; + } + + if(j > i1) { + i1 = j; + } + + if(k > i1) { + i1 = k; + } + + if(l > i1) { + i1 = l; + } + + return i1; + } + else { + ChunkClient chunk = this.gm.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + return chunk.getLight(pos); + } + } + + public int getCombinedLight(BlockPos pos, int lightValue) { + int i = this.gm.world.dimension.hasSkyLight() ? getSkyLightFor(pos.getY()) : 0; + int j = this.getBlockLightSum(pos); + + if(j < lightValue) { + j = lightValue; + } + + return i << 20 | j << 4; + } + + private int getLight(BlockPos pos, boolean checkNeighbors) { + if(pos.getX() >= -World.MAX_SIZE && pos.getZ() >= -World.MAX_SIZE && pos.getX() < World.MAX_SIZE && pos.getZ() < World.MAX_SIZE) { + if(checkNeighbors && this.gm.world.getState(pos).getBlock().getSumBrightness()) { + int i1 = this.getLight(pos.up(), false); + int i = this.getLight(pos.east(), false); + int j = this.getLight(pos.west(), false); + int k = this.getLight(pos.south(), false); + int l = this.getLight(pos.north(), false); + + if(i > i1) { + i1 = i; + } + + if(j > i1) { + i1 = j; + } + + if(k > i1) { + i1 = k; + } + + if(l > i1) { + i1 = l; + } + + return i1; + } + else if(pos.getY() < -World.MAX_SIZE_Y) { + return 0; + } + else { + if(pos.getY() >= World.MAX_SIZE_Y) { + pos = new BlockPos(pos.getX(), World.MAX_SIZE_Y - 1, pos.getZ()); + } + + ChunkClient chunk = this.gm.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + return chunk.getLightSub(pos, this.subtract); + } + } + else { + return 15; + } + } + + public float getLightBrightness(BlockPos pos) { + return Math.max(BRIGHTNESS[this.getLight(pos, true)], (float)this.gm.world.dimension.getBrightness() / 15.0f); + } + + private int getRawBlockLight(BlockPos pos) { + Block block = this.gm.world.getState(pos).getBlock(); + int light = block.getLight(); + int opacity = block.getLightOpacity(); + + if(opacity >= 15 && block.getLight() > 0) { + opacity = 1; + } + + if(opacity < 1) { + opacity = 1; + } + + if(opacity >= 15) { + return 0; + } + else if(light >= 14) { + return light; + } + else { + for(Facing side : Facing.values()) { + BlockPos bpos = pos.offset(side); + int blight = this.getLightFor(bpos) - opacity; + + if(blight > light) { + light = blight; + } + + if(light >= 14) { + return light; + } + } + + return light; + } + } + + private void setBlockLight(BlockPos pos, int lightValue) { + if(World.isValid(pos)) { + ChunkClient chunk = this.gm.getChunk(pos.getX() >> 4, pos.getZ() >> 4); + chunk.setLight(pos, lightValue); + this.markUpdate(pos.getX() - 1, pos.getY() - 1, pos.getZ() - 1, pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + } + } + + public boolean checkBlockLight(BlockPos pos) { + if(!this.gm.world.isAreaLoaded(pos, 17, false)) + return false; + int done = 0; + int cnt = 0; + int light = this.getLightFor(pos); + int raw = this.getRawBlockLight(pos); + int bx = pos.getX(); + int by = pos.getY(); + int bz = pos.getZ(); + + if(raw > light) { + this.lightUpdate[cnt++] = 133152; + } + else if(raw < light) { + this.lightUpdate[cnt++] = 133152 | light << 18; + + while(done < cnt) { + int p = this.lightUpdate[done++]; + int x = (p & 63) - 32 + bx; + int y = (p >> 6 & 63) - 32 + by; + int z = (p >> 12 & 63) - 32 + bz; + int s = p >> 18 & 15; + BlockPos blk = new BlockPos(x, y, z); + int l = this.getLightFor(blk); + + if(l == s) { + this.setBlockLight(blk, 0); + + if(s > 0) { + int dx = ExtMath.absi(x - bx); + int dy = ExtMath.absi(y - by); + int dz = ExtMath.absi(z - bz); + + if(dx + dy + dz < 17) { + BlockPos.MutableBlockPos bpos = new BlockPos.MutableBlockPos(); + + for(Facing dir : Facing.values()) { + int ox = x + dir.getFrontOffsetX(); + int oy = y + dir.getFrontOffsetY(); + int oz = z + dir.getFrontOffsetZ(); + bpos.set(ox, oy, oz); + int op = Math.max(1, this.theWorld.getState(bpos).getBlock().getLightOpacity()); + l = this.getLightFor(bpos); + + if(l == s - op && cnt < this.lightUpdate.length) { + this.lightUpdate[cnt++] = ox - bx + 32 | oy - by + 32 << 6 | oz - bz + 32 << 12 | s - op << 18; + } + } + } + } + } + } + + done = 0; + } + + while(done < cnt) { + int p = this.lightUpdate[done++]; + int x = (p & 63) - 32 + bx; + int y = (p >> 6 & 63) - 32 + by; + int z = (p >> 12 & 63) - 32 + bz; + BlockPos blk = new BlockPos(x, y, z); + int l = this.getLightFor(blk); + int r = this.getRawBlockLight(blk); + + if(r != l) { + this.setBlockLight(blk, r); + + if(r > l) { + int k6 = Math.abs(x - bx); + int l6 = Math.abs(y - by); + int i7 = Math.abs(z - bz); + boolean flag = cnt < this.lightUpdate.length - 6; + + if(k6 + l6 + i7 < 17 && flag) { + if(this.getLightFor(blk.west()) < r) { + this.lightUpdate[cnt++] = x - 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12); + } + + if(this.getLightFor(blk.east()) < r) { + this.lightUpdate[cnt++] = x + 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12); + } + + if(this.getLightFor(blk.down()) < r) { + this.lightUpdate[cnt++] = x - bx + 32 + (y - 1 - by + 32 << 6) + (z - bz + 32 << 12); + } + + if(this.getLightFor(blk.up()) < r) { + this.lightUpdate[cnt++] = x - bx + 32 + (y + 1 - by + 32 << 6) + (z - bz + 32 << 12); + } + + if(this.getLightFor(blk.north()) < r) { + this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z - 1 - bz + 32 << 12); + } + + if(this.getLightFor(blk.south()) < r) { + this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z + 1 - bz + 32 << 12); + } + } + } + } + } + return true; + } + + private void calculateInitialSkylight() { + float f = !this.gm.world.dimension.hasDaylight() ? 0.5f : this.calcRotationPhase(this.gm.world.dimension.getRotationalPeriod() / 4L, 1.0f); + float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F); + f1 = ExtMath.clampf(f1, 0.0F, 1.0F); +// f1 = 1.0F - f1; +// f1 = (float)((double)f1 * (1.0D - (double)(this.gm.world.getRainStrength() * 5.0F) / 16.0D)); +// f1 = (float)((double)f1 * (1.0D - (double)(this.gm.world.getDarkness() * 5.0F) / 16.0D)); +// f1 = 1.0F - f1; + this.subtract = (int)(f1 * 11.0F); + } + + public static int getSkyLightFor(int y) { + return y < 0 ? 0 : (y < 64 ? y / 4 : 15); + } + + private float calcRotationPhase(long worldTime, float partial) { + int i = (int)(worldTime % this.gm.world.dimension.getRotationalPeriod()); + float f = ((float)i + partial) / (float)this.gm.world.dimension.getRotationalPeriod() - 0.5F; + + if(f < 0.0F) { + ++f; + } + + if(f > 1.0F) { + --f; + } + + f = 1.0F - (float)((Math.cos((double)f * Math.PI) + 1.0D) / 2.0D); + f = f + (f - f) / 3.0F; + return f; + } + + public float getCelestialAngle(float partial) { + return !this.gm.world.dimension.hasRotation() ? 180.0f : (this.calcRotationPhase(this.gm.world.getRotation(), Vars.timeFlow > 0 ? partial : 0.0f) * 360.0F); + } + + private float getDayPhase(float partial) { + return !this.gm.world.dimension.hasDaylight() || this.gm.world.dimension.isBaseDestroyed() ? (float)Math.PI : (this.calcRotationPhase(this.gm.world.getRotation(), Vars.timeFlow > 0 ? partial : 0.0f) * (float)Math.PI * 2.0F); + } } diff --git a/client/src/main/java/client/renderer/Shader.java b/client/src/main/java/client/renderer/Shader.java index 8e69db3a..cc33eaca 100644 --- a/client/src/main/java/client/renderer/Shader.java +++ b/client/src/main/java/client/renderer/Shader.java @@ -31,7 +31,7 @@ public enum Shader { context.matrix("projection", MatrixState.getProjection()); context.vec("time", (float)Util.ftime()); - float angle = -90.0f + Client.CLIENT.world.getCelestialAngle(Client.CLIENT.getTickFraction()); + float angle = -90.0f + Client.CLIENT.renderer.getCelestialAngle(Client.CLIENT.getTickFraction()); float sunX = !Client.CLIENT.world.dimension.hasDaylight() ? 0.0f : ExtMath.cos(angle / 180.0f * (float)Math.PI); float sunY = !Client.CLIENT.world.dimension.hasDaylight() ? -1.0f : ExtMath.sin(angle / 180.0f * (float)Math.PI); diff --git a/client/src/main/java/client/renderer/entity/Render.java b/client/src/main/java/client/renderer/entity/Render.java index 53f51390..652d4bbc 100755 --- a/client/src/main/java/client/renderer/entity/Render.java +++ b/client/src/main/java/client/renderer/entity/Render.java @@ -2,7 +2,6 @@ package client.renderer.entity; import client.renderer.Frustum; import common.entity.Entity; -import common.util.BlockPos; import common.util.BoundingBox; public abstract class Render @@ -54,9 +53,4 @@ public abstract class Render { return this.manager; } - - protected static float getBrightness(Entity entity) { - BlockPos pos = new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ); - return entity.worldObj.isBlockLoaded(pos) ? entity.worldObj.getLightBrightness(pos) : 0.0F; - } } diff --git a/client/src/main/java/client/renderer/entity/RenderBlockEntity.java b/client/src/main/java/client/renderer/entity/RenderBlockEntity.java index 11497241..926935c5 100755 --- a/client/src/main/java/client/renderer/entity/RenderBlockEntity.java +++ b/client/src/main/java/client/renderer/entity/RenderBlockEntity.java @@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL46; import client.Client; import client.renderer.texture.TextureMap; import common.entity.Entity; +import common.util.BlockPos; import common.world.State; @@ -24,7 +25,7 @@ public class RenderBlockEntity extends Render GL46.glTranslatef((float)x, (float)y + 0.5F, (float)z); this.bindEntityTexture(entity); GL46.glTranslatef(-0.5F, -0.5F, 0.5F); - Client.CLIENT.renderer.renderBlockEntity(this.state, getBrightness(entity)); + Client.CLIENT.renderer.renderBlockEntity(this.state, new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ)); GL46.glTranslatef(0.0F, 0.0F, 1.0F); GL46.glPopMatrix(); super.doRender(entity, x, y, z, partialTicks); diff --git a/client/src/main/java/client/renderer/entity/RenderFallingBlock.java b/client/src/main/java/client/renderer/entity/RenderFallingBlock.java index cdad3012..c5d44d7a 100755 --- a/client/src/main/java/client/renderer/entity/RenderFallingBlock.java +++ b/client/src/main/java/client/renderer/entity/RenderFallingBlock.java @@ -29,7 +29,7 @@ public class RenderFallingBlock extends Render { GL46.glTranslatef((float)x, (float)y + 0.5F, (float)z); this.bindEntityTexture(entity); GL46.glTranslatef(-0.5F, -0.5F, 0.5F); - Client.CLIENT.renderer.renderBlockEntity(state, getBrightness(entity)); + Client.CLIENT.renderer.renderBlockEntity(state, new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ)); GL46.glTranslatef(0.0F, 0.0F, 1.0F); GL46.glPopMatrix(); super.doRender(entity, x, y, z, partialTicks); diff --git a/client/src/main/java/client/renderer/entity/RenderMinecart.java b/client/src/main/java/client/renderer/entity/RenderMinecart.java index 7cea28f1..1625e348 100755 --- a/client/src/main/java/client/renderer/entity/RenderMinecart.java +++ b/client/src/main/java/client/renderer/entity/RenderMinecart.java @@ -9,6 +9,7 @@ import client.renderer.model.ModelMinecart; import client.renderer.texture.TextureMap; import common.entity.item.EntityCart; import common.init.Blocks; +import common.util.BlockPos; import common.util.ExtMath; import common.util.Vec3; import common.world.State; @@ -124,7 +125,7 @@ public class RenderMinecart extends Render protected void func_180560_a(T minecart, float partialTicks, State state) { GL46.glPushMatrix(); - Client.CLIENT.renderer.renderBlockEntity(state, getBrightness(minecart)); + Client.CLIENT.renderer.renderBlockEntity(state, new BlockPos(minecart.posX, minecart.posY + (double)minecart.getEyeHeight(), minecart.posZ)); GL46.glPopMatrix(); } } diff --git a/client/src/main/java/client/renderer/entity/RenderTntMinecart.java b/client/src/main/java/client/renderer/entity/RenderTntMinecart.java index 36eb3c3c..e7bdbe3d 100755 --- a/client/src/main/java/client/renderer/entity/RenderTntMinecart.java +++ b/client/src/main/java/client/renderer/entity/RenderTntMinecart.java @@ -40,7 +40,7 @@ public class RenderTntMinecart extends RenderMinecart GlState.blendFunc(GL46.GL_SRC_ALPHA, GL46.GL_DST_ALPHA); GlState.color(1.0F, 1.0F, 1.0F, (1.0F - ((float)i - partialTicks + 1.0F) / 100.0F) * 0.8F); GL46.glPushMatrix(); - Client.CLIENT.renderer.renderBlockEntity(Blocks.tnt.getState(), 1.0F); + Client.CLIENT.renderer.renderBlockEntity(Blocks.tnt.getState(), null); GL46.glPopMatrix(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); GlState.disableBlend(); diff --git a/client/src/main/java/client/renderer/entity/RenderTntPrimed.java b/client/src/main/java/client/renderer/entity/RenderTntPrimed.java index cf81a985..ab22173b 100755 --- a/client/src/main/java/client/renderer/entity/RenderTntPrimed.java +++ b/client/src/main/java/client/renderer/entity/RenderTntPrimed.java @@ -9,6 +9,7 @@ import client.renderer.texture.TextureMap; import common.block.Block; import common.entity.item.EntityTnt; import common.init.BlockRegistry; +import common.util.BlockPos; import common.util.ExtMath; @@ -39,7 +40,7 @@ public class RenderTntPrimed extends Render this.bindEntityTexture(entity); GL46.glTranslatef(-0.5F, -0.5F, 0.5F); Block tnt = BlockRegistry.byName("tnt" + (entity.explosionSize <= 0 || entity.explosionSize >= 8 ? "" : "_" + entity.explosionSize)); - renderer.renderBlockEntity(tnt.getState(), getBrightness(entity)); + renderer.renderBlockEntity(tnt.getState(), new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ)); GL46.glTranslatef(0.0F, 0.0F, 1.0F); if (entity.fuse / 5 % 2 == 0) @@ -51,7 +52,7 @@ public class RenderTntPrimed extends Render GlState.color(1.0F, 1.0F, 1.0F, f2); GlState.doPolygonOffset(-3.0F, -3.0F); GlState.enablePolygonOffset(); - renderer.renderBlockEntity(tnt.getState(), 1.0F); + renderer.renderBlockEntity(tnt.getState(), null); GlState.doPolygonOffset(0.0F, 0.0F); GlState.disablePolygonOffset(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/client/src/main/java/client/world/ChunkClient.java b/client/src/main/java/client/world/ChunkClient.java index 0c87001c..63c62719 100644 --- a/client/src/main/java/client/world/ChunkClient.java +++ b/client/src/main/java/client/world/ChunkClient.java @@ -1,15 +1,19 @@ package client.world; +import java.util.concurrent.ConcurrentLinkedQueue; + +import client.renderer.Renderer; import common.block.Block; +import common.block.ITileEntityProvider; import common.init.Blocks; import common.tileentity.TileEntity; import common.util.BlockPos; -import common.util.NibbleArray; import common.world.BlockArray; import common.world.Chunk; import common.world.World; public class ChunkClient extends Chunk { + private final ConcurrentLinkedQueue tileQueue = new ConcurrentLinkedQueue(); private final float[] temperatures = new float[256]; private final float[] offsets = new float[256]; @@ -48,8 +52,6 @@ public class ChunkClient extends Chunk { } } } - - this.modified = true; } public boolean isEmpty(int bottom, int top) { @@ -87,11 +89,8 @@ public class ChunkClient extends Chunk { for(int cy : extend) { BlockArray arr = this.getArray(cy); - if(arr != null) { - NibbleArray light = arr.getBlocklight(); - System.arraycopy(data, pos, light.getData(), 0, light.getData().length); - pos += light.getData().length; - } + if(arr != null) + arr.clearLight(); } if(biomes) { @@ -110,7 +109,6 @@ public class ChunkClient extends Chunk { } } - this.populated = true; this.genHeights(); for(TileEntity tile : this.tiles.values()) { @@ -137,4 +135,71 @@ public class ChunkClient extends Chunk { int z = pos.getZ() & 15; return this.offsets[z << 4 | x]; } + + public void spawnTiles() { + while(!this.tileQueue.isEmpty()) { + BlockPos pos = this.tileQueue.poll(); + if(this.getTileEntity(pos, TileEntity.CreateMode.CHECK) == null && this.getBlock(pos) instanceof ITileEntityProvider) { + TileEntity tile = this.createNewTileEntity(pos); + this.world.setTileEntity(pos, tile); + this.world.markBlockRangeForRenderUpdate(pos, pos); + } + } + } + + public TileEntity getTileEntity(BlockPos pos, TileEntity.CreateMode type) { + TileEntity tile = this.tiles.get(pos); + + if(tile == null) { + if(type == TileEntity.CreateMode.IMMEDIATE) { + tile = this.createNewTileEntity(pos); + this.world.setTileEntity(pos, tile); + } + else if(type == TileEntity.CreateMode.QUEUED) { + this.tileQueue.add(pos); + } + } + else if(tile.isInvalid()) { + this.tiles.remove(pos); + return null; + } + + return tile; + } + + public int getLight(BlockPos pos) { + int x = pos.getX() & 15; + int y = pos.getY(); + int z = pos.getZ() & 15; + BlockArray stor = this.getArray(y >> 4); + return stor == null ? 0 : stor.getLight(x, y & 15, z); + } + + public void setLight(BlockPos pos, int value) { + int x = pos.getX() & 15; + int y = pos.getY(); + int z = pos.getZ() & 15; + BlockArray stor = this.getArray(y >> 4); + + if(stor == null) { + stor = new BlockArray(y >> 4 << 4, y < 0 ? this.filler : null); + this.setArray(stor); + this.genHeightMap(); + } + + stor.setLight(x, y & 15, z, value); + } + + public int getLightSub(BlockPos pos, int amount) { + int x = pos.getX() & 15; + int y = pos.getY(); + int z = pos.getZ() & 15; + BlockArray stor = this.getArray(y >> 4); + int l = this.world.dimension.hasSkyLight() ? Renderer.getSkyLightFor(pos.getY()) : 0; + if(stor == null) + return this.world.dimension.hasSkyLight() && amount < l ? l - amount : 0; + l = l - amount; + int b = stor.getLight(x, y & 15, z); + return b > l ? b : l; + } } diff --git a/client/src/main/java/client/world/ChunkEmpty.java b/client/src/main/java/client/world/ChunkEmpty.java index e6f41a0b..750c93c4 100755 --- a/client/src/main/java/client/world/ChunkEmpty.java +++ b/client/src/main/java/client/world/ChunkEmpty.java @@ -89,10 +89,6 @@ public class ChunkEmpty extends ChunkClient { public void removeEntity(Entity entity) { } - public boolean canSeeSky(BlockPos pos) { - return pos.getY() > this.liquidY; - } - public TileEntity getTileEntity(BlockPos pos, TileEntity.CreateMode type) { return null; } @@ -133,16 +129,12 @@ public class ChunkEmpty extends ChunkClient { return new BlockPos(pos.getX(), this.liquidY + 1, pos.getZ()); } - public void update(boolean noGaps) { + public void spawnTiles() { } public void onChunkUnload() { } - public boolean isPopulated() { - return true; - } - public void setData(byte[] data, int[] extend, boolean biomes) { } diff --git a/common/src/main/java/common/ai/EntityAIFleeSun.java b/common/src/main/java/common/ai/EntityAIFleeSun.java deleted file mode 100755 index 85c8c7eb..00000000 --- a/common/src/main/java/common/ai/EntityAIFleeSun.java +++ /dev/null @@ -1,95 +0,0 @@ -package common.ai; - -import common.entity.types.EntityLiving; -import common.rng.Random; -import common.util.BlockPos; -import common.util.Vec3; -import common.world.World; -import common.world.AWorldServer; - -public class EntityAIFleeSun extends EntityAIBase -{ - private EntityLiving theCreature; - private double shelterX; - private double shelterY; - private double shelterZ; - private double movementSpeed; - private World theWorld; - - public EntityAIFleeSun(EntityLiving theCreatureIn, double movementSpeedIn) - { - this.theCreature = theCreatureIn; - this.movementSpeed = movementSpeedIn; - this.theWorld = theCreatureIn.worldObj; - this.setMutexBits(1); - } - - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - if (!((AWorldServer)this.theWorld).isDaytime()) - { - return false; - } - else if (!this.theCreature.isBurning()) - { - return false; - } - else if (!this.theWorld.canSeeSky(new BlockPos(this.theCreature.posX, this.theCreature.getEntityBoundingBox().minY, this.theCreature.posZ))) - { - return false; - } - else - { - Vec3 vec3 = this.findPossibleShelter(); - - if (vec3 == null) - { - return false; - } - else - { - this.shelterX = vec3.xCoord; - this.shelterY = vec3.yCoord; - this.shelterZ = vec3.zCoord; - return true; - } - } - } - - /** - * Returns whether an in-progress EntityAIBase should continue executing - */ - public boolean continueExecuting() - { - return !this.theCreature.getNavigator().noPath(); - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - this.theCreature.getNavigator().tryMoveToXYZ(this.shelterX, this.shelterY, this.shelterZ, this.movementSpeed); - } - - private Vec3 findPossibleShelter() - { - Random random = this.theCreature.getRNG(); - BlockPos blockpos = new BlockPos(this.theCreature.posX, this.theCreature.getEntityBoundingBox().minY, this.theCreature.posZ); - - for (int i = 0; i < 10; ++i) - { - BlockPos blockpos1 = blockpos.add(random.zrange(20) - 10, random.zrange(6) - 3, random.zrange(20) - 10); - - if (!this.theWorld.canSeeSky(blockpos1) && this.theCreature.getBlockPathWeight(blockpos1) < 0.0F) - { - return new Vec3((double)blockpos1.getX(), (double)blockpos1.getY(), (double)blockpos1.getZ()); - } - } - - return null; - } -} diff --git a/common/src/main/java/common/ai/EntityAIMoveIndoors.java b/common/src/main/java/common/ai/EntityAIMoveIndoors.java deleted file mode 100755 index 600af34f..00000000 --- a/common/src/main/java/common/ai/EntityAIMoveIndoors.java +++ /dev/null @@ -1,104 +0,0 @@ -package common.ai; - -import common.entity.types.EntityLiving; -import common.util.BlockPos; -import common.util.Vec3; -import common.village.Village; -import common.village.VillageDoorInfo; -import common.world.AWorldServer; - -public class EntityAIMoveIndoors extends EntityAIBase -{ - private EntityLiving entityObj; - private VillageDoorInfo doorInfo; - private int insidePosX = -1; - private int insidePosZ = -1; - - public EntityAIMoveIndoors(EntityLiving entityObjIn) - { - this.entityObj = entityObjIn; - this.setMutexBits(1); - } - - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - BlockPos blockpos = new BlockPos(this.entityObj); - - if ((!((AWorldServer)this.entityObj.worldObj).isDaytime() /* || this.entityObj.worldObj.isRaining() && !this.entityObj.worldObj.getBiomeGenForCoords(blockpos).canRain() */) && this.entityObj.worldObj.dimension.hasSkyLight()) - { - if (this.entityObj.getRNG().zrange(50) != 0) - { - return false; - } - else if (this.insidePosX != -1 && this.entityObj.getDistanceSq((double)this.insidePosX, this.entityObj.posY, (double)this.insidePosZ) < 4.0D) - { - return false; - } - else - { - Village village = ((AWorldServer)this.entityObj.worldObj).getNearestVillage(blockpos, 14); - - if (village == null) - { - return false; - } - else - { - this.doorInfo = village.getDoorInfo(blockpos); - return this.doorInfo != null; - } - } - } - else - { - return false; - } - } - - /** - * Returns whether an in-progress EntityAIBase should continue executing - */ - public boolean continueExecuting() - { - return !this.entityObj.getNavigator().noPath(); - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - this.insidePosX = -1; - BlockPos blockpos = this.doorInfo.getInsideBlockPos(); - int i = blockpos.getX(); - int j = blockpos.getY(); - int k = blockpos.getZ(); - - if (this.entityObj.getDistanceSq(blockpos) > 256.0D) - { - Vec3 vec3 = RandomPositionGenerator.findRandomTargetBlockTowards(this.entityObj, 14, 3, new Vec3((double)i + 0.5D, (double)j, (double)k + 0.5D)); - - if (vec3 != null) - { - this.entityObj.getNavigator().tryMoveToXYZ(vec3.xCoord, vec3.yCoord, vec3.zCoord, 1.0D); - } - } - else - { - this.entityObj.getNavigator().tryMoveToXYZ((double)i + 0.5D, (double)j, (double)k + 0.5D, 1.0D); - } - } - - /** - * Resets the task - */ - public void resetTask() - { - this.insidePosX = this.doorInfo.getInsideBlockPos().getX(); - this.insidePosZ = this.doorInfo.getInsideBlockPos().getZ(); - this.doorInfo = null; - } -} diff --git a/common/src/main/java/common/ai/EntityAIMoveThroughVillage.java b/common/src/main/java/common/ai/EntityAIMoveThroughVillage.java deleted file mode 100755 index 2ebfcb64..00000000 --- a/common/src/main/java/common/ai/EntityAIMoveThroughVillage.java +++ /dev/null @@ -1,174 +0,0 @@ -package common.ai; - -import java.util.List; - -import common.collect.Lists; -import common.entity.types.EntityLiving; -import common.pathfinding.PathEntity; -import common.pathfinding.PathNavigateGround; -import common.util.BlockPos; -import common.util.ExtMath; -import common.util.Vec3; -import common.village.Village; -import common.village.VillageDoorInfo; -import common.world.AWorldServer; - -public class EntityAIMoveThroughVillage extends EntityAIBase -{ - private EntityLiving theEntity; - private double movementSpeed; - - /** The PathNavigate of our entity. */ - private PathEntity entityPathNavigate; - private VillageDoorInfo doorInfo; - private boolean isNocturnal; - private List doorList = Lists.newArrayList(); - - public EntityAIMoveThroughVillage(EntityLiving theEntityIn, double movementSpeedIn, boolean isNocturnalIn) - { - this.theEntity = theEntityIn; - this.movementSpeed = movementSpeedIn; - this.isNocturnal = isNocturnalIn; - this.setMutexBits(1); - - if (!(theEntityIn.getNavigator() instanceof PathNavigateGround)) - { - throw new IllegalArgumentException("Unsupported mob for MoveThroughVillageGoal"); - } - } - - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - this.resizeDoorList(); - - if (this.isNocturnal && ((AWorldServer)this.theEntity.worldObj).isDaytime()) - { - return false; - } - else - { - Village village = ((AWorldServer)this.theEntity.worldObj).getNearestVillage(new BlockPos(this.theEntity), 0); - - if (village == null) - { - return false; - } - else - { - this.doorInfo = this.findNearestDoor(village); - - if (this.doorInfo == null) - { - return false; - } - else - { - PathNavigateGround pathnavigateground = (PathNavigateGround)this.theEntity.getNavigator(); - boolean flag = pathnavigateground.getEnterDoors(); - pathnavigateground.setBreakDoors(false); - this.entityPathNavigate = pathnavigateground.getPathToPos(this.doorInfo.getDoorBlockPos()); - pathnavigateground.setBreakDoors(flag); - - if (this.entityPathNavigate != null) - { - return true; - } - else - { - Vec3 vec3 = RandomPositionGenerator.findRandomTargetBlockTowards(this.theEntity, 10, 7, new Vec3((double)this.doorInfo.getDoorBlockPos().getX(), (double)this.doorInfo.getDoorBlockPos().getY(), (double)this.doorInfo.getDoorBlockPos().getZ())); - - if (vec3 == null) - { - return false; - } - else - { - pathnavigateground.setBreakDoors(false); - this.entityPathNavigate = this.theEntity.getNavigator().getPathToXYZ(vec3.xCoord, vec3.yCoord, vec3.zCoord); - pathnavigateground.setBreakDoors(flag); - return this.entityPathNavigate != null; - } - } - } - } - } - } - - /** - * Returns whether an in-progress EntityAIBase should continue executing - */ - public boolean continueExecuting() - { - if (this.theEntity.getNavigator().noPath()) - { - return false; - } - else - { - float f = this.theEntity.width + 4.0F; - return this.theEntity.getDistanceSq(this.doorInfo.getDoorBlockPos()) > (double)(f * f); - } - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - this.theEntity.getNavigator().setPath(this.entityPathNavigate, this.movementSpeed); - } - - /** - * Resets the task - */ - public void resetTask() - { - if (this.theEntity.getNavigator().noPath() || this.theEntity.getDistanceSq(this.doorInfo.getDoorBlockPos()) < 16.0D) - { - this.doorList.add(this.doorInfo); - } - } - - private VillageDoorInfo findNearestDoor(Village villageIn) - { - VillageDoorInfo villagedoorinfo = null; - int i = Integer.MAX_VALUE; - - for (VillageDoorInfo villagedoorinfo1 : villageIn.getDoorList()) - { - int j = villagedoorinfo1.getDistanceSquared(ExtMath.floord(this.theEntity.posX), ExtMath.floord(this.theEntity.posY), ExtMath.floord(this.theEntity.posZ)); - - if (j < i && !this.doesDoorListContain(villagedoorinfo1)) - { - villagedoorinfo = villagedoorinfo1; - i = j; - } - } - - return villagedoorinfo; - } - - private boolean doesDoorListContain(VillageDoorInfo doorInfoIn) - { - for (VillageDoorInfo villagedoorinfo : this.doorList) - { - if (doorInfoIn.getDoorBlockPos().equals(villagedoorinfo.getDoorBlockPos())) - { - return true; - } - } - - return false; - } - - private void resizeDoorList() - { - if (this.doorList.size() > 15) - { - this.doorList.remove(0); - } - } -} diff --git a/common/src/main/java/common/ai/EntityAIRestrictOpenDoor.java b/common/src/main/java/common/ai/EntityAIRestrictOpenDoor.java deleted file mode 100755 index 15235cbc..00000000 --- a/common/src/main/java/common/ai/EntityAIRestrictOpenDoor.java +++ /dev/null @@ -1,85 +0,0 @@ -package common.ai; - -import common.entity.types.EntityLiving; -import common.pathfinding.PathNavigateGround; -import common.util.BlockPos; -import common.village.Village; -import common.village.VillageDoorInfo; -import common.world.AWorldServer; - -public class EntityAIRestrictOpenDoor extends EntityAIBase -{ - private EntityLiving entityObj; - private VillageDoorInfo frontDoor; - - public EntityAIRestrictOpenDoor(EntityLiving creatureIn) - { - this.entityObj = creatureIn; - - if (!(creatureIn.getNavigator() instanceof PathNavigateGround)) - { - throw new IllegalArgumentException("Unsupported mob type for RestrictOpenDoorGoal"); - } - } - - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - if (((AWorldServer)this.entityObj.worldObj).isDaytime()) - { - return false; - } - else - { - BlockPos blockpos = new BlockPos(this.entityObj); - Village village = ((AWorldServer)this.entityObj.worldObj).getNearestVillage(blockpos, 16); - - if (village == null) - { - return false; - } - else - { - this.frontDoor = village.getNearestDoor(blockpos); - return this.frontDoor == null ? false : (double)this.frontDoor.getDistanceToInsideBlockSq(blockpos) < 2.25D; - } - } - } - - /** - * Returns whether an in-progress EntityAIBase should continue executing - */ - public boolean continueExecuting() - { - return ((AWorldServer)this.entityObj.worldObj).isDaytime() ? false : !this.frontDoor.getIsDetachedFromVillageFlag() && this.frontDoor.isIndoorSide(new BlockPos(this.entityObj)); - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - ((PathNavigateGround)this.entityObj.getNavigator()).setBreakDoors(false); - ((PathNavigateGround)this.entityObj.getNavigator()).setEnterDoors(false); - } - - /** - * Resets the task - */ - public void resetTask() - { - ((PathNavigateGround)this.entityObj.getNavigator()).setBreakDoors(true); - ((PathNavigateGround)this.entityObj.getNavigator()).setEnterDoors(true); - this.frontDoor = null; - } - - /** - * Updates the task - */ - public void updateTask() - { - this.frontDoor.incrementDoorOpeningRestrictionCounter(); - } -} diff --git a/common/src/main/java/common/ai/EntityAIRestrictSun.java b/common/src/main/java/common/ai/EntityAIRestrictSun.java deleted file mode 100755 index 50e29012..00000000 --- a/common/src/main/java/common/ai/EntityAIRestrictSun.java +++ /dev/null @@ -1,39 +0,0 @@ -package common.ai; - -import common.entity.types.EntityLiving; -import common.pathfinding.PathNavigateGround; -import common.world.AWorldServer; - -public class EntityAIRestrictSun extends EntityAIBase -{ - private EntityLiving theEntity; - - public EntityAIRestrictSun(EntityLiving creature) - { - this.theEntity = creature; - } - - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - return ((AWorldServer)this.theEntity.worldObj).isDaytime(); - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - ((PathNavigateGround)this.theEntity.getNavigator()).setAvoidSun(true); - } - - /** - * Resets the task - */ - public void resetTask() - { - ((PathNavigateGround)this.theEntity.getNavigator()).setAvoidSun(false); - } -} diff --git a/common/src/main/java/common/block/foliage/BlockBlackenedSoil.java b/common/src/main/java/common/block/foliage/BlockBlackenedSoil.java index 7b261c06..c82587a4 100644 --- a/common/src/main/java/common/block/foliage/BlockBlackenedSoil.java +++ b/common/src/main/java/common/block/foliage/BlockBlackenedSoil.java @@ -21,13 +21,13 @@ public class BlockBlackenedSoil extends BlockSnowable public void tick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (worldIn.getLightFromNeighbors(pos.up()) < 2 && worldIn.getState(pos.up()).getBlock().getLightOpacity() > 6) + if (worldIn.getState(pos.up()).getBlock().getLightOpacity() > 6) { if(Vars.darkSoilDecay) worldIn.setState(pos, Blocks.blackened_dirt.getState()); } else { - if (Vars.darkSoilSpread && worldIn.getLightFromNeighbors(pos.up()) >= 1) + if (Vars.darkSoilSpread) { for (int i = 0; i < 4; i++) { @@ -35,7 +35,7 @@ public class BlockBlackenedSoil extends BlockSnowable Block block = worldIn.getState(blockpos.up()).getBlock(); State iblockstate = worldIn.getState(blockpos); - if ((iblockstate.getBlock() == Blocks.dirt || iblockstate.getBlock() == Blocks.grass || iblockstate.getBlock() == Blocks.swamp || iblockstate.getBlock() == Blocks.blackened_dirt) && worldIn.getLightFromNeighbors(blockpos.up()) >= 2 && block.getLightOpacity() <= 6) + if ((iblockstate.getBlock() == Blocks.dirt || iblockstate.getBlock() == Blocks.grass || iblockstate.getBlock() == Blocks.swamp || iblockstate.getBlock() == Blocks.blackened_dirt) && block.getLightOpacity() <= 6) { worldIn.setState(blockpos, Blocks.blackened_soil.getState()); } diff --git a/common/src/main/java/common/block/foliage/BlockBlueShroom.java b/common/src/main/java/common/block/foliage/BlockBlueShroom.java index 488b5943..cc7b249d 100755 --- a/common/src/main/java/common/block/foliage/BlockBlueShroom.java +++ b/common/src/main/java/common/block/foliage/BlockBlueShroom.java @@ -75,7 +75,7 @@ public class BlockBlueShroom extends BlockBush if (pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y) { State iblockstate = worldIn.getState(pos.down()); - return (iblockstate.getBlock() == Blocks.tian_soil || iblockstate.getBlock() == Blocks.obsidian) ? true : (worldIn.getLight(pos) < 13 && this.canPlaceBlockOn(iblockstate.getBlock())); + return (iblockstate.getBlock() == Blocks.tian_soil || iblockstate.getBlock() == Blocks.obsidian) ? true : this.canPlaceBlockOn(iblockstate.getBlock()); } else { diff --git a/common/src/main/java/common/block/foliage/BlockCrops.java b/common/src/main/java/common/block/foliage/BlockCrops.java index 4bf25742..e8d1cfbf 100755 --- a/common/src/main/java/common/block/foliage/BlockCrops.java +++ b/common/src/main/java/common/block/foliage/BlockCrops.java @@ -46,7 +46,7 @@ public class BlockCrops extends BlockBush implements IGrowable { super.tick(worldIn, pos, state, rand); - if (Vars.cropGrowth > 0 && worldIn.getLightFromNeighbors(pos.up()) >= 9) + if (Vars.cropGrowth > 0) { int i = ((Integer)state.getValue(AGE)).intValue(); @@ -131,7 +131,7 @@ public class BlockCrops extends BlockBush implements IGrowable public boolean canBlockStay(World worldIn, BlockPos pos, State state) { - return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && this.canPlaceBlockOn(worldIn.getState(pos.down()).getBlock()); + return this.canPlaceBlockOn(worldIn.getState(pos.down()).getBlock()); } protected Item getCrop() diff --git a/common/src/main/java/common/block/foliage/BlockGrass.java b/common/src/main/java/common/block/foliage/BlockGrass.java index a2899fab..f57fbe6b 100755 --- a/common/src/main/java/common/block/foliage/BlockGrass.java +++ b/common/src/main/java/common/block/foliage/BlockGrass.java @@ -22,7 +22,7 @@ public class BlockGrass extends BlockSnowable implements IGrowable public void tick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) + if (worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) { if(Vars.grassDecay) worldIn.setState(pos, Blocks.dirt.getState()); @@ -34,7 +34,7 @@ public class BlockGrass extends BlockSnowable implements IGrowable } else { - if (Vars.grassSpread && worldIn.getLightFromNeighbors(pos.up()) >= 9) + if (Vars.grassSpread) { for (int i = 0; i < 4; ++i) { @@ -42,7 +42,7 @@ public class BlockGrass extends BlockSnowable implements IGrowable Block block = worldIn.getState(blockpos.up()).getBlock(); State iblockstate = worldIn.getState(blockpos); - if (iblockstate.getBlock() == Blocks.dirt && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2) + if (iblockstate.getBlock() == Blocks.dirt && block.getLightOpacity() <= 2) { worldIn.setState(blockpos, Blocks.grass.getState()); } diff --git a/common/src/main/java/common/block/foliage/BlockMushroom.java b/common/src/main/java/common/block/foliage/BlockMushroom.java index bb545574..5940671f 100755 --- a/common/src/main/java/common/block/foliage/BlockMushroom.java +++ b/common/src/main/java/common/block/foliage/BlockMushroom.java @@ -78,7 +78,7 @@ public class BlockMushroom extends BlockBush implements IGrowable if (pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y) { State iblockstate = worldIn.getState(pos.down()); - return iblockstate.getBlock() == Blocks.mycelium ? true : (iblockstate.getBlock() == Blocks.podzol ? true : worldIn.getLight(pos) < 13 && this.canPlaceBlockOn(iblockstate.getBlock())); + return iblockstate.getBlock() == Blocks.mycelium ? true : (iblockstate.getBlock() == Blocks.podzol ? true : this.canPlaceBlockOn(iblockstate.getBlock())); } else { diff --git a/common/src/main/java/common/block/foliage/BlockMycelium.java b/common/src/main/java/common/block/foliage/BlockMycelium.java index c2854447..d87fc7ad 100755 --- a/common/src/main/java/common/block/foliage/BlockMycelium.java +++ b/common/src/main/java/common/block/foliage/BlockMycelium.java @@ -25,7 +25,7 @@ public class BlockMycelium extends BlockSnowable { // if (!worldIn.client) // { - if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) + if (worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) { if(Vars.mycelDecay) worldIn.setState(pos, Blocks.dirt.getState()); @@ -33,20 +33,17 @@ public class BlockMycelium extends BlockSnowable else { if(Vars.mycelSpread) { - if (worldIn.getLightFromNeighbors(pos.up()) >= 9) - { - for (int i = 0; i < 4; ++i) - { - BlockPos blockpos = pos.add(rand.zrange(3) - 1, rand.zrange(5) - 3, rand.zrange(3) - 1); - State iblockstate = worldIn.getState(blockpos); - Block block = worldIn.getState(blockpos.up()).getBlock(); - - if (iblockstate.getBlock() == Blocks.dirt && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2) - { - worldIn.setState(blockpos, this.getState()); - } - } - } + for (int i = 0; i < 4; ++i) + { + BlockPos blockpos = pos.add(rand.zrange(3) - 1, rand.zrange(5) - 3, rand.zrange(3) - 1); + State iblockstate = worldIn.getState(blockpos); + Block block = worldIn.getState(blockpos.up()).getBlock(); + + if (iblockstate.getBlock() == Blocks.dirt && block.getLightOpacity() <= 2) + { + worldIn.setState(blockpos, this.getState()); + } + } } super.tick(worldIn, pos, state, rand); } diff --git a/common/src/main/java/common/block/foliage/BlockSapling.java b/common/src/main/java/common/block/foliage/BlockSapling.java index a3fb54e7..4b52e9f0 100755 --- a/common/src/main/java/common/block/foliage/BlockSapling.java +++ b/common/src/main/java/common/block/foliage/BlockSapling.java @@ -63,7 +63,7 @@ public class BlockSapling extends BlockBush implements IGrowable // { super.tick(worldIn, pos, state, rand); - if (Vars.treeGrowth > 0 && worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.chance(Vars.treeGrowth)) + if (Vars.treeGrowth > 0 && rand.chance(Vars.treeGrowth)) { this.grow(worldIn, pos, state, rand); } diff --git a/common/src/main/java/common/block/foliage/BlockStem.java b/common/src/main/java/common/block/foliage/BlockStem.java index b13e3e3c..af828bd5 100755 --- a/common/src/main/java/common/block/foliage/BlockStem.java +++ b/common/src/main/java/common/block/foliage/BlockStem.java @@ -46,7 +46,7 @@ public class BlockStem extends BlockBush implements IGrowable { super.tick(worldIn, pos, state, rand); - if (Vars.stemGrowth > 0 && worldIn.getLightFromNeighbors(pos.up()) >= 9) + if (Vars.stemGrowth > 0) { float f = BlockCrops.getGrowthChance(this, worldIn, pos); diff --git a/common/src/main/java/common/block/foliage/BlockSwamp.java b/common/src/main/java/common/block/foliage/BlockSwamp.java index 5c3be5b7..c57e3c07 100644 --- a/common/src/main/java/common/block/foliage/BlockSwamp.java +++ b/common/src/main/java/common/block/foliage/BlockSwamp.java @@ -40,7 +40,7 @@ public class BlockSwamp extends BlockSnowable public void tick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) + if (worldIn.getState(pos.up()).getBlock().getLightOpacity() > 2) { if(Vars.swampDecay) worldIn.setState(pos, Blocks.dirt.getState()); diff --git a/common/src/main/java/common/block/natural/BlockBlackenedDirt.java b/common/src/main/java/common/block/natural/BlockBlackenedDirt.java index ab929da9..3503bf39 100644 --- a/common/src/main/java/common/block/natural/BlockBlackenedDirt.java +++ b/common/src/main/java/common/block/natural/BlockBlackenedDirt.java @@ -33,7 +33,7 @@ public class BlockBlackenedDirt extends BlockNonBlock { worldIn.setState(blockpos, Blocks.blackened_dirt.getState()); } - else if ((iblockstate.getBlock() == Blocks.grass || iblockstate.getBlock() == Blocks.swamp) && worldIn.getLightFromNeighbors(blockpos.up()) >= 2 && block.getLightOpacity() <= 6) + else if ((iblockstate.getBlock() == Blocks.grass || iblockstate.getBlock() == Blocks.swamp) && block.getLightOpacity() <= 6) { worldIn.setState(blockpos, Blocks.blackened_soil.getState()); } diff --git a/common/src/main/java/common/block/natural/BlockIce.java b/common/src/main/java/common/block/natural/BlockIce.java index 31fdc279..fcc4e013 100755 --- a/common/src/main/java/common/block/natural/BlockIce.java +++ b/common/src/main/java/common/block/natural/BlockIce.java @@ -51,7 +51,7 @@ public class BlockIce extends BlockNonBlock { } public void tick(AWorldServer world, BlockPos pos, State state, Random rand) { - if(Vars.iceMelt && (world.getLightFor(pos) > 11 - this.getLightOpacity() || !world.canFreezeAt(pos))) { + if(Vars.iceMelt && !world.canFreezeAt(pos)) { if(world.doesWaterVaporize(pos)) { world.setBlockToAir(pos); } diff --git a/common/src/main/java/common/block/natural/BlockSnow.java b/common/src/main/java/common/block/natural/BlockSnow.java index 45e3009f..06293416 100755 --- a/common/src/main/java/common/block/natural/BlockSnow.java +++ b/common/src/main/java/common/block/natural/BlockSnow.java @@ -130,7 +130,7 @@ public class BlockSnow extends Block public void tick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (Vars.snowMelt && (worldIn.getLightFor(pos) > 11 || !worldIn.canFreezeAt(pos))) + if (Vars.snowMelt && !worldIn.canFreezeAt(pos)) { this.drop(worldIn, pos, worldIn.getState(pos), 0); worldIn.setBlockToAir(pos); diff --git a/common/src/main/java/common/block/natural/BlockSnowBlock.java b/common/src/main/java/common/block/natural/BlockSnowBlock.java index 0f8c8fe6..1e59ce08 100755 --- a/common/src/main/java/common/block/natural/BlockSnowBlock.java +++ b/common/src/main/java/common/block/natural/BlockSnowBlock.java @@ -27,7 +27,7 @@ public class BlockSnowBlock extends BlockNonBlock { } public void tick(AWorldServer world, BlockPos pos, State state, Random rand) { - if(Vars.snowFullMelt && (world.getLightFor(pos) > 11 || !world.canFreezeAt(pos))) { + if(Vars.snowFullMelt && !world.canFreezeAt(pos)) { this.drop(world, pos, world.getState(pos), 0); world.setBlockToAir(pos); } diff --git a/common/src/main/java/common/entity/animal/EntityBat.java b/common/src/main/java/common/entity/animal/EntityBat.java index b061a5b9..cb9ed0c5 100755 --- a/common/src/main/java/common/entity/animal/EntityBat.java +++ b/common/src/main/java/common/entity/animal/EntityBat.java @@ -270,20 +270,7 @@ public class EntityBat extends EntityLiving } else { - int i = this.worldObj.getLightFromNeighbors(blockpos); - int j = 4; - -// if (Config.useHalloween && isDateAroundHalloween(World.getCurrentDate())) -// { -// j = 7; -// } -// else - if (this.rand.chance()) - { - return false; - } - - return i <= this.rand.zrange(j); // ? false : super.getCanSpawnHere(); + return this.rand.chance(); } } diff --git a/common/src/main/java/common/entity/animal/EntityMouse.java b/common/src/main/java/common/entity/animal/EntityMouse.java index 6ca426d7..a0747625 100755 --- a/common/src/main/java/common/entity/animal/EntityMouse.java +++ b/common/src/main/java/common/entity/animal/EntityMouse.java @@ -91,22 +91,10 @@ public class EntityMouse extends EntityAnimal { protected int getExperiencePoints(EntityNPC player) { return this.worldObj.rand.range(0, 1); } - - public boolean getCanSpawnHere() - { - if (((int)this.getEntityBoundingBox().minY) >= this.worldObj.getSeaLevel()) - { - return false; - } - else - { - return super.getCanSpawnHere(); - } - } - protected boolean isValidLightLevel(int level) + protected boolean isValidSpawnHeight(int y) { - return level < 6; + return y < this.worldObj.getSeaLevel(); } public float getBlockPathWeight(BlockPos pos) diff --git a/common/src/main/java/common/entity/npc/EntityArachnoid.java b/common/src/main/java/common/entity/npc/EntityArachnoid.java index 9e60df97..2774acf7 100755 --- a/common/src/main/java/common/entity/npc/EntityArachnoid.java +++ b/common/src/main/java/common/entity/npc/EntityArachnoid.java @@ -147,7 +147,7 @@ public class EntityArachnoid extends EntityNPC { } public boolean getCanSpawnHere() { - return this.worldObj.getLightFromNeighbors(new BlockPos(this)) <= this.rand.zrange(8); + return (int)this.posY < this.worldObj.getSeaLevel() || this.rand.chance(6); } public boolean canAmbush(EntityLiving entity) { diff --git a/common/src/main/java/common/entity/npc/EntityHaunter.java b/common/src/main/java/common/entity/npc/EntityHaunter.java index 46b45402..5a9d83e8 100755 --- a/common/src/main/java/common/entity/npc/EntityHaunter.java +++ b/common/src/main/java/common/entity/npc/EntityHaunter.java @@ -11,7 +11,6 @@ import common.rng.Random; import common.tags.TagObject; import common.vars.Vars; import common.world.World; -import common.world.AWorldServer; public class EntityHaunter extends EntityNPC { // private int lastActiveTime; @@ -334,10 +333,6 @@ public class EntityHaunter extends EntityNPC { public boolean isGhost() { return true; } - - public boolean getCanSpawnHere() { - return !((AWorldServer)this.worldObj).isDaytime(); - } // public boolean canAmbush(EntityLiving entity) { // return true; diff --git a/common/src/main/java/common/entity/npc/EntitySlime.java b/common/src/main/java/common/entity/npc/EntitySlime.java index 3a2f6134..d82952d5 100755 --- a/common/src/main/java/common/entity/npc/EntitySlime.java +++ b/common/src/main/java/common/entity/npc/EntitySlime.java @@ -392,7 +392,7 @@ public class EntitySlime extends EntityNPC // { // if (this.worldObj.getDifficulty() != Difficulty.PEACEFUL) // { - if (this.worldObj.getState(new BlockPos(this.posX, this.getEntityBoundingBox().minY - 1.0, this.posZ)).getBlock() == Blocks.swamp && this.posY > 50.0D && this.posY < 70.0D && this.rand.floatv() < 0.5F && this.rand.floatv() < this.worldObj.getMoonPhase() && this.worldObj.getLightFromNeighbors(new BlockPos(this)) <= this.rand.zrange(8)) + if (this.worldObj.getState(new BlockPos(this.posX, this.getEntityBoundingBox().minY - 1.0, this.posZ)).getBlock() == Blocks.swamp && this.posY > 50.0D && this.posY < 70.0D && this.rand.floatv() < 0.5F && this.rand.floatv() < this.worldObj.getMoonPhase()) { return super.getCanSpawnHere(); } diff --git a/common/src/main/java/common/entity/npc/EntityUndead.java b/common/src/main/java/common/entity/npc/EntityUndead.java index b16db288..82ed28fb 100755 --- a/common/src/main/java/common/entity/npc/EntityUndead.java +++ b/common/src/main/java/common/entity/npc/EntityUndead.java @@ -104,10 +104,6 @@ public class EntityUndead extends EntityNPC public Alignment getNaturalAlign() { return Alignment.EVIL; } - - public boolean getCanSpawnHere() { - return !((AWorldServer)this.worldObj).isDaytime(); - } // public boolean canAmbush(EntityLiving entity) { // return true; diff --git a/common/src/main/java/common/entity/npc/EntityZombie.java b/common/src/main/java/common/entity/npc/EntityZombie.java index 896a5012..4f664cbc 100755 --- a/common/src/main/java/common/entity/npc/EntityZombie.java +++ b/common/src/main/java/common/entity/npc/EntityZombie.java @@ -3,7 +3,6 @@ package common.entity.npc; import java.util.List; import java.util.function.Predicate; -import common.ai.EntityAIMoveThroughVillage; import common.entity.DamageSource; import common.entity.animal.EntityChicken; import common.entity.types.EntityLiving; @@ -19,7 +18,6 @@ public class EntityZombie extends EntityNPC public EntityZombie(World worldIn) { super(worldIn); - this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); } protected void applyEntityAttributes() @@ -66,7 +64,7 @@ public class EntityZombie extends EntityNPC int j1 = j + this.rand.range(7, 40) * this.rand.range(-1, 1); int k1 = k + this.rand.range(7, 40) * this.rand.range(-1, 1); - if (this.worldObj.isBlockSolid(new BlockPos(i1, j1 - 1, k1)) && this.worldObj.getLightFromNeighbors(new BlockPos(i1, j1, k1)) < 10) + if (this.worldObj.isBlockSolid(new BlockPos(i1, j1 - 1, k1))) { entityzombie.setPosition((double)i1, (double)j1, (double)k1); @@ -312,10 +310,6 @@ public class EntityZombie extends EntityNPC public Alignment getNaturalAlign() { return rand.pick(Alignment.CHAOTIC_EVIL, Alignment.EVIL); } - - public boolean getCanSpawnHere() { - return !((AWorldServer)this.worldObj).isDaytime(); - } // public boolean canAmbush(EntityLiving entity) { // return true; diff --git a/common/src/main/java/common/entity/projectile/EntityHook.java b/common/src/main/java/common/entity/projectile/EntityHook.java index 8d3297b3..1eec7f8e 100755 --- a/common/src/main/java/common/entity/projectile/EntityHook.java +++ b/common/src/main/java/common/entity/projectile/EntityHook.java @@ -393,11 +393,6 @@ public class EntityHook extends Entity implements IObjectData l = 2; } - if (this.rand.floatv() < 0.5F && !this.worldObj.canSeeSky(blockpos)) - { - --l; - } - if (this.ticksCatchable > 0) { --this.ticksCatchable; diff --git a/common/src/main/java/common/entity/types/EntityAnimal.java b/common/src/main/java/common/entity/types/EntityAnimal.java index 84aa88ce..068e2253 100755 --- a/common/src/main/java/common/entity/types/EntityAnimal.java +++ b/common/src/main/java/common/entity/types/EntityAnimal.java @@ -117,12 +117,12 @@ public abstract class EntityAnimal extends EntityLiving int j = ExtMath.floord(this.getEntityBoundingBox().minY); int k = ExtMath.floord(this.posZ); BlockPos blockpos = new BlockPos(i, j, k); - return this.spawnableBlocks.contains(this.worldObj.getState(blockpos.down()).getBlock()) && this.isValidLightLevel(this.worldObj.getLight(blockpos)) && super.getCanSpawnHere(); + return this.spawnableBlocks.contains(this.worldObj.getState(blockpos.down()).getBlock()) && this.isValidSpawnHeight(blockpos.getY()) && super.getCanSpawnHere(); } - protected boolean isValidLightLevel(int level) + protected boolean isValidSpawnHeight(int y) { - return level > 8; + return y >= this.worldObj.getSeaLevel(); } /** diff --git a/common/src/main/java/common/packet/SPacketChunkData.java b/common/src/main/java/common/packet/SPacketChunkData.java index 381b6f84..c125a37b 100755 --- a/common/src/main/java/common/packet/SPacketChunkData.java +++ b/common/src/main/java/common/packet/SPacketChunkData.java @@ -71,9 +71,8 @@ public class SPacketChunkData implements Packet public static int getSize(int segments, boolean biomes) { int i = segments * 2 * 16 * 16 * 16; - int j = segments * 16 * 16 * 16 / 2; int l = biomes ? 256 * 8 : 0; - return i + j + l; + return i + l; } public int getChunkX() diff --git a/common/src/main/java/common/pathfinding/PathNavigate.java b/common/src/main/java/common/pathfinding/PathNavigate.java index 605a176f..7b0993ac 100755 --- a/common/src/main/java/common/pathfinding/PathNavigate.java +++ b/common/src/main/java/common/pathfinding/PathNavigate.java @@ -155,7 +155,7 @@ public abstract class PathNavigate this.currentPath = pathentityIn; } - this.removeSunnyPath(); + this.removeInvalidPath(); if (this.currentPath.getCurrentPathLength() == 0) { @@ -314,10 +314,7 @@ public abstract class PathNavigate return this.theEntity.isInLiquid() || this.theEntity.isInMolten(); } - /** - * Trims path data from the end to the first sun covered block - */ - protected void removeSunnyPath() + protected void removeInvalidPath() { } diff --git a/common/src/main/java/common/pathfinding/PathNavigateGround.java b/common/src/main/java/common/pathfinding/PathNavigateGround.java index 7a6c5de1..de0767c3 100755 --- a/common/src/main/java/common/pathfinding/PathNavigateGround.java +++ b/common/src/main/java/common/pathfinding/PathNavigateGround.java @@ -14,7 +14,6 @@ import common.world.World; public class PathNavigateGround extends PathNavigate { protected WalkNodeProcessor nodeProcessor; - private boolean shouldAvoidSun; public PathNavigateGround(EntityLiving entitylivingIn, World worldIn) { @@ -72,33 +71,6 @@ public class PathNavigateGround extends PathNavigate } } - /** - * Trims path data from the end to the first sun covered block - */ - protected void removeSunnyPath() - { - super.removeSunnyPath(); - - if (this.shouldAvoidSun) - { - if (this.worldObj.canSeeSky(new BlockPos(ExtMath.floord(this.theEntity.posX), (int)(this.theEntity.getEntityBoundingBox().minY + 0.5D), ExtMath.floord(this.theEntity.posZ)))) - { - return; - } - - for (int i = 0; i < this.currentPath.getCurrentPathLength(); ++i) - { - PathPoint pathpoint = this.currentPath.getPathPointFromIndex(i); - - if (this.worldObj.canSeeSky(new BlockPos(pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord))) - { - this.currentPath.setCurrentPathLength(i - 1); - return; - } - } - } - } - /** * Returns true when an entity of specified size could safely walk in a straight line between the two points. Args: * pos1, pos2, entityXSize, entityYSize, entityZSize @@ -287,9 +259,4 @@ public class PathNavigateGround extends PathNavigate { return this.nodeProcessor.getCanSwim(); } - - public void setAvoidSun(boolean par1) - { - this.shouldAvoidSun = par1; - } } diff --git a/common/src/main/java/common/world/AWorldServer.java b/common/src/main/java/common/world/AWorldServer.java index f1b74e04..c145c3ff 100644 --- a/common/src/main/java/common/world/AWorldServer.java +++ b/common/src/main/java/common/world/AWorldServer.java @@ -44,8 +44,6 @@ public abstract class AWorldServer extends World { public abstract void addToVillagerPositionList(BlockPos blockpos); public abstract boolean isPlayerWatchingChunk(EntityNPC player, int chunkX, int chunkZ); public abstract void sendToAllTrackingEntity(Entity entityIn, Packet packet); - public abstract boolean isDaytime(); - public abstract int getSkylightSubtracted(); public abstract T findNearestEntityWithinAABB(Class entityType, BoundingBox aabb, T closestTo); public abstract void markChunkDirty(BlockPos pos); public abstract void growGrass(BlockPos pos, State state, Random rand); diff --git a/common/src/main/java/common/world/BlockArray.java b/common/src/main/java/common/world/BlockArray.java index abff814b..4cbf8f67 100755 --- a/common/src/main/java/common/world/BlockArray.java +++ b/common/src/main/java/common/world/BlockArray.java @@ -21,7 +21,6 @@ public class BlockArray { this.yBase = y; this.filler = filler; this.data = new char[4096]; - this.blocklight = new NibbleArray(); if(filler != null && filler.getBlock() != Blocks.air) { Arrays.fill(this.data, (char)BlockRegistry.getId(filler)); this.blocks = this.data.length; @@ -75,14 +74,6 @@ public class BlockArray { return this.yBase; } - public void setLight(int x, int y, int z, int value) { - this.blocklight.set(x, y, z, value); - } - - public int getLight(int x, int y, int z) { - return this.blocklight.get(x, y, z); - } - public void update() { this.blocks = 0; this.ticked = 0; @@ -108,17 +99,9 @@ public class BlockArray { return this.data; } - public NibbleArray getBlocklight() { - return this.blocklight; - } - public void setData(char[] data) { this.data = data; } - - public void setBlocklight(NibbleArray data) { - this.blocklight = data; - } public int hashCode() { return this.yBase >> 4; @@ -127,4 +110,18 @@ public class BlockArray { public boolean equals(Object other) { return other instanceof BlockArray && ((BlockArray)other).yBase == this.yBase; } + + public void setLight(int x, int y, int z, int value) { + if(this.blocklight == null) + this.blocklight = new NibbleArray(); + this.blocklight.set(x, y, z, value); + } + + public int getLight(int x, int y, int z) { + return this.blocklight == null ? 0 : this.blocklight.get(x, y, z); + } + + public void clearLight() { + this.blocklight = null; + } } diff --git a/common/src/main/java/common/world/Chunk.java b/common/src/main/java/common/world/Chunk.java index f3035c7f..351f23fa 100755 --- a/common/src/main/java/common/world/Chunk.java +++ b/common/src/main/java/common/world/Chunk.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Predicate; import common.block.Block; @@ -34,11 +33,8 @@ public abstract class Chunk { protected final int[] height = new int[256]; protected final Map tiles = Maps.newHashMap(); protected final InheritanceMultiMap[] entities = new InheritanceMultiMap[32]; - protected final ConcurrentLinkedQueue tileQueue = new ConcurrentLinkedQueue(); protected boolean loaded; - protected boolean populated; - protected boolean updated; protected boolean modified; protected boolean hasEntity; protected int minHeight; @@ -75,7 +71,7 @@ public abstract class Chunk { this.top = y > this.top ? y : this.top; } - public void genSky() { + public void genHeightMap() { int top = this.top; int bottom = this.bottom < -64 ? -64 : this.bottom; this.minHeight = Integer.MAX_VALUE; @@ -101,7 +97,7 @@ public abstract class Chunk { this.modified = true; } - private void relightBlock(int x, int y, int z) { + private void updateHeight(int x, int y, int z) { int h = this.height[z << 4 | x]; int min = this.bottom < -64 ? -64 : this.bottom; int cy = h; @@ -159,7 +155,7 @@ public abstract class Chunk { return this.getBlock0(pos.getX() & 15, pos.getY(), pos.getZ() & 15); } - public State setState(BlockPos pos, State state, boolean updateLight) { + public State setState(BlockPos pos, State state, boolean updateHeight) { int x = pos.getX() & 15; int y = pos.getY(); int z = pos.getZ() & 15; @@ -206,9 +202,9 @@ public abstract class Chunk { return null; } else { - if(updateLight) { + if(updateHeight) { if(up) { - this.genSky(); + this.genHeightMap(); } else { int b = block.getLightOpacity(); @@ -216,11 +212,11 @@ public abstract class Chunk { if(b > 0) { if(y >= h) { - this.relightBlock(x, y + 1, z); + this.updateHeight(x, y + 1, z); } } else if(y == h - 1) { - this.relightBlock(x, y, z); + this.updateHeight(x, y, z); } } } @@ -256,44 +252,6 @@ public abstract class Chunk { } } - public int getLight(BlockPos pos) { - int x = pos.getX() & 15; - int y = pos.getY(); - int z = pos.getZ() & 15; - BlockArray stor = this.getArray(y >> 4); - return stor == null ? 0 : stor.getLight(x, y & 15, z); - } - - public void setLight(BlockPos pos, int value) { - int x = pos.getX() & 15; - int y = pos.getY(); - int z = pos.getZ() & 15; - BlockArray stor = this.getArray(y >> 4); - - if(stor == null) { - stor = new BlockArray(y >> 4 << 4, y < 0 ? this.filler : null); - this.setArray(stor); - this.genSky(); - } - - this.modified = true; - - stor.setLight(x, y & 15, z, value); - } - - public int getLightSub(BlockPos pos, int amount) { - int x = pos.getX() & 15; - int y = pos.getY(); - int z = pos.getZ() & 15; - BlockArray stor = this.getArray(y >> 4); - int l = this.world.dimension.hasSkyLight() ? World.getSkyLightFor(pos.getY()) : 0; - if(stor == null) - return this.world.dimension.hasSkyLight() && amount < l ? l - amount : 0; - l = l - amount; - int b = stor.getLight(x, y & 15, z); - return b > l ? b : l; - } - public void addEntity(Entity entity) { this.hasEntity = true; int x = ExtMath.floord(entity.posX / 16.0D); @@ -336,14 +294,7 @@ public abstract class Chunk { this.entities[y].remove(entity); } - public boolean canSeeSky(BlockPos pos) { - int x = pos.getX() & 15; - int y = pos.getY(); - int z = pos.getZ() & 15; - return y >= this.height[z << 4 | x]; - } - - private TileEntity createNewTileEntity(BlockPos pos) { + protected TileEntity createNewTileEntity(BlockPos pos) { Block block = this.getBlock(pos); return !(block instanceof ITileEntityProvider provider) ? null : provider.createNewTileEntity(); } @@ -356,9 +307,6 @@ public abstract class Chunk { tile = this.createNewTileEntity(pos); this.world.setTileEntity(pos, tile); } - else if(type == TileEntity.CreateMode.QUEUED) { - this.tileQueue.add(pos); - } } else if(tile.isInvalid()) { this.tiles.remove(pos); @@ -470,24 +418,6 @@ public abstract class Chunk { return new BlockPos(pos.getX(), this.precHeight[o], pos.getZ()); } - public void update(boolean noGaps) { - this.updated = true; - - while(!this.tileQueue.isEmpty()) { - BlockPos pos = (BlockPos)this.tileQueue.poll(); - - if(this.getTileEntity(pos, TileEntity.CreateMode.CHECK) == null && this.getBlock(pos) instanceof ITileEntityProvider) { - TileEntity tile = this.createNewTileEntity(pos); - this.world.setTileEntity(pos, tile); - this.world.markBlockRangeForRenderUpdate(pos, pos); - } - } - } - - public boolean isPopulated() { - return this.updated && this.populated; - } - public boolean isLoaded() { return this.loaded; } diff --git a/common/src/main/java/common/world/World.java b/common/src/main/java/common/world/World.java index f8ea5d43..abaab740 100755 --- a/common/src/main/java/common/world/World.java +++ b/common/src/main/java/common/world/World.java @@ -32,7 +32,6 @@ import common.tileentity.TileEntity; import common.util.BlockPos; import common.util.BoundingBox; import common.util.ChunkPos; -import common.util.Clientside; import common.util.ExtMath; import common.util.Facing; import common.util.HitPosition; @@ -42,7 +41,6 @@ import common.util.Vec3; import common.vars.Vars; public abstract class World implements IWorldAccess { - public static final float[] BRIGHTNESS = new float[] {0.0f, 0.02f, 0.04f, 0.06f, 0.08f, 0.11f, 0.14f, 0.18f, 0.22f, 0.27f, 0.33f, 0.41f, 0.5f, 0.62f, 0.78f, 1.0f}; public static final float[] MOON_PHASES = new float[] {1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F}; public static final int MAX_SIZE = 67108864; public static final int MAX_SIZE_Y = 4096; @@ -60,12 +58,10 @@ public abstract class World implements IWorldAccess { public final List effects = Lists.newArrayList(); public final IntHashMap entityIds = new IntHashMap(); protected final Set active = Sets.newHashSet(); - protected final int[] lightUpdate = new int[32768]; public final Dimension dimension; protected double gravity = 1.0; protected boolean loadTiles; - protected int subtract; protected float rain; protected float darkness; protected float fog; @@ -183,11 +179,18 @@ public abstract class World implements IWorldAccess { Block block1 = iblockstate.getBlock(); if(block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight()) this.checkBlockLight(pos); - if((flags & 2) != 0 && (flags & 4) == 0 && chunk.isPopulated()) + if((flags & 2) != 0 && (flags & 4) == 0) this.markBlockForUpdate(pos); return true; } + public void checkBlockLight(BlockPos pos) { + } + + public int getCombinedLight(BlockPos pos, int lightValue) { + return 0; + } + public boolean setState(BlockPos pos, State state) { return this.setState(pos, state, 3); } @@ -228,174 +231,6 @@ public abstract class World implements IWorldAccess { this.clientRenderUpdate(rangeMin.getX(), rangeMin.getY(), rangeMin.getZ(), rangeMax.getX(), rangeMax.getY(), rangeMax.getZ()); } - public boolean canSeeSky(BlockPos pos) { - return this.getChunk(pos).canSeeSky(pos); - } - - public int getLight(BlockPos pos) { - if(pos.getY() < -MAX_SIZE_Y) { - return 0; - } - else { - if(pos.getY() >= MAX_SIZE_Y) { - pos = new BlockPos(pos.getX(), MAX_SIZE_Y - 1, pos.getZ()); - } - - return this.getChunk(pos).getLightSub(pos, 0); - } - } - - public int getLightFromNeighbors(BlockPos pos) { - return this.getLight(pos, true); - } - - private int getLight(BlockPos pos, boolean checkNeighbors) { - if(pos.getX() >= -MAX_SIZE && pos.getZ() >= -MAX_SIZE && pos.getX() < MAX_SIZE && pos.getZ() < MAX_SIZE) { - if(checkNeighbors && this.getState(pos).getBlock().getSumBrightness()) { - int i1 = this.getLight(pos.up(), false); - int i = this.getLight(pos.east(), false); - int j = this.getLight(pos.west(), false); - int k = this.getLight(pos.south(), false); - int l = this.getLight(pos.north(), false); - - if(i > i1) { - i1 = i; - } - - if(j > i1) { - i1 = j; - } - - if(k > i1) { - i1 = k; - } - - if(l > i1) { - i1 = l; - } - - return i1; - } - else if(pos.getY() < -MAX_SIZE_Y) { - return 0; - } - else { - if(pos.getY() >= MAX_SIZE_Y) { - pos = new BlockPos(pos.getX(), MAX_SIZE_Y - 1, pos.getZ()); - } - - Chunk chunk = this.getChunk(pos); - return chunk.getLightSub(pos, this.subtract); - } - } - else { - return 15; - } - } - - public BlockPos getHeight(BlockPos pos) { - int i; - - if(pos.getX() >= -MAX_SIZE && pos.getZ() >= -MAX_SIZE && pos.getX() < MAX_SIZE && pos.getZ() < MAX_SIZE) { - if(this.isLoaded(pos.getX() >> 4, pos.getZ() >> 4, true)) { - i = this.getChunk(pos.getX() >> 4, pos.getZ() >> 4).getHeight(pos.getX() & 15, pos.getZ() & 15); - } - else { - i = 0; - } - } - else { - i = this.getSeaLevel() + 1; - } - - return new BlockPos(pos.getX(), i, pos.getZ()); - } - - public int getBlockLightSum(BlockPos pos) { - if(pos.getY() < -MAX_SIZE_Y) { - pos = new BlockPos(pos.getX(), -MAX_SIZE_Y, pos.getZ()); - } - - if(!isValid(pos)) { - return 0; - } - else if(!this.isBlockLoaded(pos)) { - return 0; - } - else if(this.getState(pos).getBlock().getSumBrightness()) { - int i1 = this.getLightFor(pos.up()); - int i = this.getLightFor(pos.east()); - int j = this.getLightFor(pos.west()); - int k = this.getLightFor(pos.south()); - int l = this.getLightFor(pos.north()); - - if(i > i1) { - i1 = i; - } - - if(j > i1) { - i1 = j; - } - - if(k > i1) { - i1 = k; - } - - if(l > i1) { - i1 = l; - } - - return i1; - } - else { - Chunk chunk = this.getChunk(pos); - return chunk.getLight(pos); - } - } - - public int getLightFor(BlockPos pos) { - if(pos.getY() < -MAX_SIZE_Y) { - pos = new BlockPos(pos.getX(), -MAX_SIZE_Y, pos.getZ()); - } - - if(!isValid(pos)) { - return 0; - } - else if(!this.isBlockLoaded(pos)) { - return 0; - } - else { - Chunk chunk = this.getChunk(pos); - return chunk.getLight(pos); - } - } - - public void setBlockLight(BlockPos pos, int lightValue) { - if(isValid(pos)) { - if(this.isBlockLoaded(pos)) { - Chunk chunk = this.getChunk(pos); - chunk.setLight(pos, lightValue); - this.clientNotifyLight(pos); - } - } - } - - @Clientside - public int getCombinedLight(BlockPos pos, int lightValue) { - int i = this.dimension.hasSkyLight() ? getSkyLightFor(pos.getY()) : 0; - int j = this.getBlockLightSum(pos); - - if(j < lightValue) { - j = lightValue; - } - - return i << 20 | j << 4; - } - - public float getLightBrightness(BlockPos pos) { - return Math.max(BRIGHTNESS[this.getLightFromNeighbors(pos)], (float)this.dimension.getBrightness() / 15.0f); - } - public State getState(BlockPos pos) { if(!isValid(pos)) { return Blocks.air.getState(); @@ -759,39 +594,6 @@ public abstract class World implements IWorldAccess { return list; } - private float calcRotationPhase(long worldTime, float partial) { - int i = (int)(worldTime % this.dimension.getRotationalPeriod()); - float f = ((float)i + partial) / (float)this.dimension.getRotationalPeriod() - 0.5F; - - if(f < 0.0F) { - ++f; - } - - if(f > 1.0F) { - --f; - } - - f = 1.0F - (float)((Math.cos((double)f * Math.PI) + 1.0D) / 2.0D); - f = f + (f - f) / 3.0F; - return f; - } - - public int calcSkylightSubtracted(boolean current) { - float f = !this.dimension.hasDaylight() || (current && this.dimension.isBaseDestroyed()) ? 0.5f : this.calcRotationPhase(current ? this.rotation : - (this.dimension.getRotationalPeriod() / 4L), 1.0f); - float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F); - f1 = ExtMath.clampf(f1, 0.0F, 1.0F); - f1 = 1.0F - f1; - f1 = (float)((double)f1 * (1.0D - (double)(this.getRainStrength() * 5.0F) / 16.0D)); - f1 = (float)((double)f1 * (1.0D - (double)(this.getDarkness() * 5.0F) / 16.0D)); - f1 = 1.0F - f1; - return (int)(f1 * 11.0F); - } - - public float getCelestialAngle(float partial) { - return !this.dimension.hasRotation() ? 180.0f : (this.calcRotationPhase(this.rotation, Vars.timeFlow > 0 ? partial : 0.0f) * 360.0F); - } - public int getMoonPhase(int moon) { this.rand.setSeed((this.dimension.getSeed() + moon) ^ (moon << 12)); return (int)(this.rotation / this.dimension.getRotationalPeriod() % 8L + 8L + this.rand.zrange(8)) % 8; @@ -801,10 +603,6 @@ public abstract class World implements IWorldAccess { return MOON_PHASES[this.getMoonPhase(0)]; } - public float getDayPhase(float partial) { - return !this.dimension.hasDaylight() || this.dimension.isBaseDestroyed() ? (float)Math.PI : (this.calcRotationPhase(this.rotation, Vars.timeFlow > 0 ? partial : 0.0f) * (float)Math.PI * 2.0F); - } - public BlockPos getPrecipitationHeight(BlockPos pos) { return this.getChunk(pos).getPrecipitation(pos); } @@ -1348,12 +1146,6 @@ public abstract class World implements IWorldAccess { this.removeTiles.add(tileEntityIn); } - protected void calculateInitialSkylight() { - int light = this.calcSkylightSubtracted(false); - if(light != this.subtract) - this.subtract = light; - } - protected void calculateInitialWeather() { this.rain = this.weather.hasDownfall() ? 1.0f : 0.0f; this.darkness = this.weather.isDark() ? 1.0f : 0.0f; @@ -1361,39 +1153,19 @@ public abstract class World implements IWorldAccess { this.temp = this.getBaseTemperature() + this.weather.getTemperature(); } - public Set setActivePlayerChunksAndCheckLight(int l) { + public Set setActiveChunks(int radius) { this.active.clear(); -// this.profiler.start("buildList"); - - for(int i = 0; i < this.players.size(); ++i) { - EntityNPC entityplayer = (EntityNPC)this.players.get(i); - int j = ExtMath.floord(entityplayer.posX / 16.0D); - int k = ExtMath.floord(entityplayer.posZ / 16.0D); -// int l = this.getRenderDistanceChunks(); - - for(int i1 = -l; i1 <= l; ++i1) { - for(int j1 = -l; j1 <= l; ++j1) { - this.active.add(new ChunkPos(i1 + j, j1 + k)); + for(int n = 0; n < this.players.size(); ++n) { + EntityNPC player = (EntityNPC)this.players.get(n); + int x = ExtMath.floord(player.posX / 16.0D); + int z = ExtMath.floord(player.posZ / 16.0D); + for(int cx = -radius; cx <= radius; cx++) { + for(int cz = -radius; cz <= radius; cz++) { + this.active.add(new ChunkPos(cx + x, cz + z)); } } } - -// this.profiler.end(); -// -// this.profiler.start("playerCheckLight"); - - if(!this.players.isEmpty()) { - int k1 = this.rand.zrange(this.players.size()); - EntityNPC entityplayer1 = (EntityNPC)this.players.get(k1); - int l1 = ExtMath.floord(entityplayer1.posX) + this.rand.zrange(11) - 5; - int i2 = ExtMath.floord(entityplayer1.posY) + this.rand.zrange(11) - 5; - int j2 = ExtMath.floord(entityplayer1.posZ) + this.rand.zrange(11) - 5; - this.checkBlockLight(new BlockPos(l1, i2, j2)); - } - return this.active; - -// this.profiler.end(); } public float getTempOffset() { @@ -1435,15 +1207,15 @@ public abstract class World implements IWorldAccess { return this.getTemperatureC(pos) >= 314.0f; } - public boolean canSnowAt(BlockPos pos, boolean checkLight, boolean allowLayers) { + public boolean canSnowAt(BlockPos pos, boolean checkPlace, boolean allowLayers) { if(!this.canFreezeAt(pos)) { return false; } - else if(!checkLight) { + else if(!checkPlace) { return true; } else { - if(pos.getY() >= -MAX_SIZE_Y && pos.getY() < MAX_SIZE_Y && this.getLightFor(pos) < 10) { + if(pos.getY() >= -MAX_SIZE_Y && pos.getY() < MAX_SIZE_Y) { Block block = this.getState(pos).getBlock(); if((block == Blocks.air || (allowLayers && block == Blocks.snow_layer)) @@ -1456,149 +1228,6 @@ public abstract class World implements IWorldAccess { } } - private int getRawBlockLight(BlockPos pos) { - Block block = this.getState(pos).getBlock(); - int i = block.getLight(); - int j = block.getLightOpacity(); - - if(j >= 15 && block.getLight() > 0) { - j = 1; - } - - if(j < 1) { - j = 1; - } - - if(j >= 15) { - return 0; - } - else if(i >= 14) { - return i; - } - else { - for(Facing enumfacing : Facing.values()) { - BlockPos blockpos = pos.offset(enumfacing); - int k = this.getLightFor(blockpos) - j; - - if(k > i) { - i = k; - } - - if(i >= 14) { - return i; - } - } - - return i; - } - } - - public boolean checkBlockLight(BlockPos pos) { - if(!this.isAreaLoaded(pos, 17, false)) - return false; - int done = 0; - int cnt = 0; - int light = this.getLightFor(pos); - int raw = this.getRawBlockLight(pos); - int bx = pos.getX(); - int by = pos.getY(); - int bz = pos.getZ(); - - if(raw > light) { - this.lightUpdate[cnt++] = 133152; - } - else if(raw < light) { - this.lightUpdate[cnt++] = 133152 | light << 18; - - while(done < cnt) { - int p = this.lightUpdate[done++]; - int x = (p & 63) - 32 + bx; - int y = (p >> 6 & 63) - 32 + by; - int z = (p >> 12 & 63) - 32 + bz; - int s = p >> 18 & 15; - BlockPos blk = new BlockPos(x, y, z); - int l = this.getLightFor(blk); - - if(l == s) { - this.setBlockLight(blk, 0); - - if(s > 0) { - int dx = ExtMath.absi(x - bx); - int dy = ExtMath.absi(y - by); - int dz = ExtMath.absi(z - bz); - - if(dx + dy + dz < 17) { - BlockPos.MutableBlockPos bpos = new BlockPos.MutableBlockPos(); - - for(Facing dir : Facing.values()) { - int ox = x + dir.getFrontOffsetX(); - int oy = y + dir.getFrontOffsetY(); - int oz = z + dir.getFrontOffsetZ(); - bpos.set(ox, oy, oz); - int op = Math.max(1, this.getState(bpos).getBlock().getLightOpacity()); - l = this.getLightFor(bpos); - - if(l == s - op && cnt < this.lightUpdate.length) { - this.lightUpdate[cnt++] = ox - bx + 32 | oy - by + 32 << 6 | oz - bz + 32 << 12 | s - op << 18; - } - } - } - } - } - } - - done = 0; - } - - while(done < cnt) { - int p = this.lightUpdate[done++]; - int x = (p & 63) - 32 + bx; - int y = (p >> 6 & 63) - 32 + by; - int z = (p >> 12 & 63) - 32 + bz; - BlockPos blk = new BlockPos(x, y, z); - int l = this.getLightFor(blk); - int r = this.getRawBlockLight(blk); - - if(r != l) { - this.setBlockLight(blk, r); - - if(r > l) { - int k6 = Math.abs(x - bx); - int l6 = Math.abs(y - by); - int i7 = Math.abs(z - bz); - boolean flag = cnt < this.lightUpdate.length - 6; - - if(k6 + l6 + i7 < 17 && flag) { - if(this.getLightFor(blk.west()) < r) { - this.lightUpdate[cnt++] = x - 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12); - } - - if(this.getLightFor(blk.east()) < r) { - this.lightUpdate[cnt++] = x + 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12); - } - - if(this.getLightFor(blk.down()) < r) { - this.lightUpdate[cnt++] = x - bx + 32 + (y - 1 - by + 32 << 6) + (z - bz + 32 << 12); - } - - if(this.getLightFor(blk.up()) < r) { - this.lightUpdate[cnt++] = x - bx + 32 + (y + 1 - by + 32 << 6) + (z - bz + 32 << 12); - } - - if(this.getLightFor(blk.north()) < r) { - this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z - 1 - bz + 32 << 12); - } - - if(this.getLightFor(blk.south()) < r) { - this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z + 1 - bz + 32 << 12); - } - } - } - } - } - return true; - } - public List getEntitiesWithinAABBExcludingEntity(Entity entityIn, BoundingBox bb) { return this.getEntitiesInAABBexcluding(entityIn, bb, null); } @@ -1798,9 +1427,6 @@ public abstract class World implements IWorldAccess { if(wet ? !this.isRaining() : !this.hasDownfall()) { return false; } - else if(!this.canSeeSky(strikePosition)) { - return false; - } else if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) { return false; } @@ -1822,11 +1448,6 @@ public abstract class World implements IWorldAccess { double zm = (Math.abs(z) - r) / 16384.0; return ExtMath.clampd(Math.max(Math.max(xm, zm), ym), 0.0, 1.0); } - - @Clientside - public static int getSkyLightFor(int y) { - return y < 0 ? 0 : (y < 64 ? y / 4 : 15); - } public double getGravity(double x, double y, double z) { double gravity = this.gravity * (1.0 - this.getSpaceFactor(x, y, z)); diff --git a/server/src/main/java/server/init/UniverseRegistry.java b/server/src/main/java/server/init/UniverseRegistry.java index 0d8583a1..fda7a5c3 100755 --- a/server/src/main/java/server/init/UniverseRegistry.java +++ b/server/src/main/java/server/init/UniverseRegistry.java @@ -35,7 +35,6 @@ import common.entity.npc.EntityCameraHolder; import common.entity.npc.EntityCultivator; import common.entity.npc.EntityElf; import common.entity.npc.EntityFireDemon; -import common.entity.npc.EntityHaunter; import common.entity.npc.EntityMage; import common.entity.npc.EntityMerfolk; import common.entity.npc.EntityMetalhead; @@ -547,9 +546,6 @@ public abstract class UniverseRegistry extends DimensionRegistry { .addSpawn(EntityChicken.class, 10, 4, 4) .addSpawn(EntityCow.class, 8, 4, 4) .addSpawn(EntityArachnoid.class, 100, 4, 4) - .addSpawn(EntityZombie.class, 100, 4, 4) - .addSpawn(EntityUndead.class, 100, 4, 4) - .addSpawn(EntityHaunter.class, 100, 4, 4) .addSpawn(EntitySlime.class, 100, 4, 4) .addSpawn(EntityMage.class, 5, 1, 1) .addSpawn(EntityBat.class, 10, 8, 8) @@ -723,10 +719,6 @@ public abstract class UniverseRegistry extends DimensionRegistry { .addSpawn(EntityPig.class, 10, 4, 4) .addSpawn(EntityChicken.class, 10, 4, 4) .addSpawn(EntityCow.class, 8, 4, 4) - .addSpawn(EntityArachnoid.class, 100, 4, 4) - .addSpawn(EntityZombie.class, 100, 4, 4) - .addSpawn(EntityUndead.class, 100, 4, 4) - .addSpawn(EntitySlime.class, 100, 4, 4) ); }); }); diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index dbd5ff00..6cd7aa49 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -897,11 +897,6 @@ public class Player extends User implements Executor, IPlayer } } - for (BlockArray extendedblockstorage2 : list) - { - j = copyTo(extendedblockstorage2.getBlocklight().getData(), dataset.data, j); - } - if (biomes) { BiomeGenerator gen = world.getBiomeGenerator(); @@ -1005,7 +1000,7 @@ public class Player extends User implements Executor, IPlayer { ChunkServer chunk = world.getChunk(chunkcoordintpair.x, chunkcoordintpair.z); - if (chunk.isPopulated()) + if (chunk.isTerrainPopulated()) { list.add(chunk); list1.addAll(world.getTileEntitiesIn(chunkcoordintpair.x * 16, -World.MAX_SIZE_Y, chunkcoordintpair.z * 16, chunkcoordintpair.x * 16 + 16, World.MAX_SIZE_Y, chunkcoordintpair.z * 16 + 16)); diff --git a/server/src/main/java/server/village/VillageCollection.java b/server/src/main/java/server/village/VillageCollection.java index be459abd..498f1925 100755 --- a/server/src/main/java/server/village/VillageCollection.java +++ b/server/src/main/java/server/village/VillageCollection.java @@ -214,7 +214,7 @@ public class VillageCollection for (int j = 1; j <= 5; ++j) { - if (world.canSeeSky(centerPos.offset(direction, j))) + if (world.getPrecipitationHeight(centerPos.offset(direction, j)).getY() - 1 <= centerPos.getY()) { ++i; diff --git a/server/src/main/java/server/world/ChunkServer.java b/server/src/main/java/server/world/ChunkServer.java index 1c874c0e..ab75a29d 100644 --- a/server/src/main/java/server/world/ChunkServer.java +++ b/server/src/main/java/server/world/ChunkServer.java @@ -17,10 +17,10 @@ import common.world.State; public class ChunkServer extends Chunk { private long lastSave; private long inhabited; + private boolean populated; public ChunkServer(WorldServer world, int x, int z) { super(world, x, z); - this.updated = true; } public ChunkServer(WorldServer world, char[] data, int height, boolean base, boolean ceil, Random rand, int x, int z) { @@ -82,8 +82,7 @@ public class ChunkServer extends Chunk { } } if(!ceil) - this.genSky(); - this.updated = true; + this.genHeightMap(); } public int getTopSegment() { diff --git a/server/src/main/java/server/world/Converter.java b/server/src/main/java/server/world/Converter.java index 704981c5..90bc3bae 100644 --- a/server/src/main/java/server/world/Converter.java +++ b/server/src/main/java/server/world/Converter.java @@ -1434,66 +1434,12 @@ public abstract class Converter { return state; } - private static TagObject convertChunkData(NbtTag tag, boolean legacy) { + private static TagObject convertChunkData(NbtTag tag) { TagObject ntag = new TagObject(); tag = tag.getTag("Level"); - if(legacy) { - byte[] oldheight = tag.getByteArray("HeightMap"); - int[] height = new int[oldheight.length]; - for(int i = 0; i < oldheight.length; ++i) { - height[i] = oldheight[i]; - } - ntag.setIntArray("H", height); - byte[] oldblks = tag.getByteArray("Blocks"); - byte[] olddata = tag.getByteArray("Data"); - byte[] oldlight = tag.getByteArray("BlockLight"); - List sections = Lists.newArrayList(); - for(int n = 0; n < 8; ++n) { - boolean empty = true; - for(int x = 0; x < 16 && empty; ++x) { - for(int y = 0; y < 16 && empty; ++y) { - for(int z = 0; z < 16; ++z) { - int pos = x << 11 | z << 7 | y + (n << 4); - int blk = oldblks[pos]; - if(blk != 0) { - empty = false; - break; - } - } - } - } - if(!empty) { - byte[] blocks = new byte[4096]; - NibbleArray data = new NibbleArray(); - NibbleArray sky = new NibbleArray(); - NibbleArray light = new NibbleArray(); - for(int x = 0; x < 16; ++x) { - for(int y = 0; y < 16; ++y) { - for(int z = 0; z < 16; ++z) { - int pos = x << 11 | z << 7 | y + (n << 4); - int blk = oldblks[pos]; - blocks[y << 8 | z << 4 | x] = (byte)(blk & 255); - data.set(x, y, z, getNibble(olddata, x, y + (n << 4), z)); - light.set(x, y, z, getNibble(oldlight, x, y + (n << 4), z)); - } - } - } - TagObject section = new TagObject(); - section.setByte("Y", (byte)(n & 255)); - section.setByteArray("Blocks", blocks); - section.setByteArray("Data", data.getData()); - section.setByteArray("BlockLight", light.getData()); - sections.add(section); - } - } - ntag.setList("S", sections); - } - else { - ntag.setIntArray("H", tag.getIntArray("HeightMap")); - } + ntag.setIntArray("H", tag.getIntArray("HeightMap")); ntag.setBool("P", true); - ntag.setList("E", Lists.newArrayList()); NbtTag[] tes = tag.getTagList("TileEntities"); @@ -1563,7 +1509,6 @@ public abstract class Converter { TagObject nsect = new TagObject(); nsect.setInt("Y", y); nsect.setByteArray("D", newblks); - nsect.setByteArray("B", sect.getByteArray("BlockLight")); list.add(nsect); } @@ -1577,7 +1522,6 @@ public abstract class Converter { private static long convertChunks(File dir, File file, long start, int progress, int total) { String name = file.getName(); - boolean legacy = name.endsWith(".mcr"); int rx, rz; String[] reg = name.split("\\."); if(reg.length != 4) { @@ -1620,7 +1564,7 @@ public abstract class Converter { } NbtTag tag = readTag(in); in.close(); - TagObject ntag = convertChunkData(tag, legacy); + TagObject ntag = convertChunkData(tag); newreg.writeTag(nx, nz, ntag); } } @@ -1685,17 +1629,17 @@ public abstract class Converter { return null; } File chunkDir = new File(new File("chunk"), dest); - Log.IO.info("Durchsuche Ordner region/ nach .mca- und .mcr-Dateien ..."); + Log.IO.info("Durchsuche Ordner region/ nach .mca-Dateien ..."); File[] files = regionDir.listFiles(new FilenameFilter() { public boolean accept(File file, String name) { - return name.endsWith(".mca") || name.endsWith(".mcr"); + return name.endsWith(".mca"); } }); if(files.length == 0) { - Log.IO.info("Keine .mca- oder .mcr-Dateien gefunden"); + Log.IO.info("Keine .mca-Dateien gefunden"); return null; } - Log.IO.info("Konvertiere %d .mca- und .mcr-Datei%s (%s) von region/*.mca,*.mcr nach %s ...", files.length, files.length == 1 ? "" : "en", ver, chunkDir); + Log.IO.info("Konvertiere %d .mca-Datei%s (%s) von region/*.mca nach %s ...", files.length, files.length == 1 ? "" : "en", ver, chunkDir); if(ver == SaveVersion.RELEASE_1_9) Log.IO.warn("Konvertiere von neuerer Version, dies wird Blöcke entfernen ..."); chunkDir.mkdirs(); diff --git a/server/src/main/java/server/world/Region.java b/server/src/main/java/server/world/Region.java index 700991c1..9829486c 100755 --- a/server/src/main/java/server/world/Region.java +++ b/server/src/main/java/server/world/Region.java @@ -30,7 +30,6 @@ import common.log.Log; import common.tags.TagObject; import common.tileentity.TileEntity; import common.util.BlockPos; -import common.util.NibbleArray; import common.util.Util; import common.world.BlockArray; import common.world.State; @@ -502,7 +501,6 @@ public class Region { } storage.setData(seg); - storage.setBlocklight(new NibbleArray(sect.getByteArray("B"))); storage.update(); sections[n] = storage; @@ -605,8 +603,6 @@ public class Region { sect.setByteArray("D", blocks); - sect.setByteArray("B", storage.getBlocklight().getData()); - sects.add(sect); } } diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index 2489fb50..d2a7c23b 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -297,7 +297,6 @@ public final class WorldServer extends AWorldServer { this.grng = new Random(this.seed ^ 836430928262265276L); this.tempGen = new PerlinGen(this.grng, 1); this.initGenerator(this.dimension.isExterminated()); - this.calculateInitialSkylight(); this.calculateInitialWeather(); this.updatePhysics(); this.loadLoaderList(); @@ -346,9 +345,6 @@ public final class WorldServer extends AWorldServer { this.dropped.remove(v); } } - int light = this.calcSkylightSubtracted(true); - if(light != this.getSkylightSubtracted()) - this.setSkylightSubtracted(light); // if(this.primary) // this.info.tick(); this.dimension.setTimeExisted(this.time += 1L); @@ -451,7 +447,7 @@ public final class WorldServer extends AWorldServer { } protected void updateBlocks() { - this.setActivePlayerChunksAndCheckLight(SVars.updateDistance); + this.setActiveChunks(SVars.updateDistance); int dtics = 0; int rtics = 0; @@ -465,7 +461,6 @@ public final class WorldServer extends AWorldServer { // this.playMoodSound(k, l, chunk); // this.profiler.next("checkLight"); // this.profiler.next("tickChunk"); - chunk.update(false); // this.profiler.next("thunder"); int tics = SVars.boltChance; @@ -561,7 +556,7 @@ public final class WorldServer extends AWorldServer { 3.0D, 3.0D); List list = this.getEntitiesWithinAABB(EntityLiving.class, axisalignedbb, new Predicate() { public boolean test(EntityLiving p_apply_1_) { - return p_apply_1_ != null && p_apply_1_.isEntityAlive() && WorldServer.this.canSeeSky(p_apply_1_.getPosition()); + return p_apply_1_ != null && p_apply_1_.isEntityAlive(); } }); return !list.isEmpty() ? ((EntityLiving)list.get(this.rand.zrange(list.size()))).getPosition() : blockpos; @@ -1397,8 +1392,8 @@ public final class WorldServer extends AWorldServer { private void populate(int x, int z) { ChunkServer chunk = this.getChunk(x, z); if(!chunk.isTerrainPopulated()) { - chunk.setTerrainPopulated(true); if(x < -this.size || z < -this.size || x >= this.size || z >= this.size) { + chunk.setTerrainPopulated(true); chunk.setModified(true); return; } @@ -1463,6 +1458,7 @@ public final class WorldServer extends AWorldServer { } // } BlockFalling.fallInstantly = false; + chunk.setTerrainPopulated(true); chunk.setModified(true); } } @@ -1470,7 +1466,7 @@ public final class WorldServer extends AWorldServer { private ChunkServer generate(int x, int z) { if(x < -this.size || z < -this.size || x >= this.size || z >= this.size) { ChunkServer chunk = new ChunkServer(this, x, z); - chunk.genSky(); + chunk.genHeightMap(); return chunk; } this.grng.setSeed((long)x * 341873128712L + (long)z * 132897987541L); @@ -1602,7 +1598,6 @@ public final class WorldServer extends AWorldServer { if(!this.chunkExists(x + 1, z - 1)) this.insertChunk(x + 1, z - 1); this.popChunk(x, z); - chunk.update(false); } this.entities.removeAll(this.unloaded); for(int l = 0; l < this.unloaded.size(); ++l) { @@ -2015,15 +2010,13 @@ public final class WorldServer extends AWorldServer { public boolean setState(BlockPos pos, State newState, int flags) { if(!isValid(pos)) return false; - Chunk chunk = this.getChunk(pos); + ChunkServer chunk = this.getChunk(pos); Block block = newState.getBlock(); State iblockstate = chunk.setState(pos, newState, (flags & 8) == 0); if(iblockstate == null) return false; Block block1 = iblockstate.getBlock(); - if((flags & 8) == 0 && (block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight())) - this.checkBlockLight(pos); - if((flags & 2) != 0 && chunk.isPopulated()) + if((flags & 2) != 0 && chunk.isTerrainPopulated()) this.markBlockForUpdate(pos); if((flags & 1) != 0) this.notifyNeighborsOfStateChange(pos, iblockstate.getBlock()); @@ -2059,9 +2052,7 @@ public final class WorldServer extends AWorldServer { // if(update) { // if(!successful) // newState = old; - this.checkBlockLight(pos); - if(chunk.isPopulated()) - this.markBlockForUpdate(pos); + this.markBlockForUpdate(pos); // this.notifyNeighborsRespectDebug(pos, old.getBlock()); // if(newState.getBlock().hasComparatorInputOverride()) // this.updateComparatorOutputLevel(pos, newState.getBlock()); @@ -2092,23 +2083,8 @@ public final class WorldServer extends AWorldServer { return entities; } - public boolean isDaytime() { - return this.subtract < 4; - } - - public int getSkylightSubtracted() { - return this.subtract; - } - - public void setSkylightSubtracted(int newSkylightSubtracted) { - this.subtract = newSkylightSubtracted; - } - public boolean canStrikeAt(BlockPos strikePosition) { - if(!this.canSeeSky(strikePosition)) { - return false; - } - else if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) { + if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) { return false; } return true; @@ -2181,7 +2157,7 @@ public final class WorldServer extends AWorldServer { return false; } else { - if(pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y && this.getLightFor(pos) < 10) { + if(pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y) { State iblockstate = this.getState(pos); Block block = iblockstate.getBlock(); @@ -2349,29 +2325,14 @@ public final class WorldServer extends AWorldServer { this.dimension.getOrbitalPeriod()) * 4L / this.dimension.getOrbitalPeriod())]); } -// public boolean canBlockSeeSky(BlockPos pos) { -// if(pos.getY() >= this.getSeaLevel()) { -// return this.canSeeSky(pos); -// } -// else { -// BlockPos blockpos = new BlockPos(pos.getX(), this.getSeaLevel(), pos.getZ()); -// -// if(!this.canSeeSky(blockpos)) { -// return false; -// } -// else { -// for(blockpos = blockpos.down(); blockpos.getY() > pos.getY(); blockpos = blockpos.down()) { -// Block block = this.getBlockState(blockpos).getBlock(); -// -// if(block.getLightOpacity() > 0 && !block.getMaterial().isLiquid()) { -// return false; -// } -// } -// -// return true; -// } -// } -// } + public BlockPos getHeight(BlockPos pos) { + int y; + if(pos.getX() >= -MAX_SIZE && pos.getZ() >= -MAX_SIZE && pos.getX() < MAX_SIZE && pos.getZ() < MAX_SIZE) + y = this.isLoaded(pos.getX() >> 4, pos.getZ() >> 4, true) ? this.getChunk(pos.getX() >> 4, pos.getZ() >> 4).getHeight(pos.getX() & 15, pos.getZ() & 15) : 0; + else + y = this.getSeaLevel() + 1; + return new BlockPos(pos.getX(), y, pos.getZ()); + } public boolean makePortal(BlockPos pos, int maxHeight, PortalType type) // TODO: Portals { @@ -2892,7 +2853,7 @@ public final class WorldServer extends AWorldServer { if(this.watching.contains(player)) { ChunkServer chunk = WorldServer.this.getChunk(this.position.x, this.position.z); - if(chunk.isPopulated()) { + if(chunk.isTerrainPopulated()) { player.connection.sendPacket(Player.getPacket(WorldServer.this, chunk, true, new int[0])); }