diff --git a/client/src/client/Client.java b/client/src/client/Client.java index 733137d..e9ee306 100755 --- a/client/src/client/Client.java +++ b/client/src/client/Client.java @@ -157,7 +157,6 @@ import common.util.LazyLoadBase; import common.util.Util; import common.util.HitPosition.ObjectType; import common.world.Chunk; -import common.world.LightType; import common.world.State; import common.world.World; import io.netty.bootstrap.Bootstrap; @@ -1730,30 +1729,22 @@ public class Client implements IThreadListener { break; } - Biome biome = null; - String bline; - String lline; + String light; if(this.world.isBlockLoaded(blockpos)) { Chunk chunk = this.world.getChunk(blockpos); - biome = chunk.getBiome(blockpos, null); - bline = "Biom: " + biome.display + " (" + biome.id + ")" + /* (this.debugHideInfo ? "" : */ (", D: " + - TextColor.stripCodes(this.world.dimension.getFormattedName(false)) + - " (" + this.world.dimension.getDimensionId() + ")"); - lline = "Licht: " + chunk.getLightSub(blockpos, 0) + " (" + chunk.getLight(LightType.SKY, blockpos) + " Himmel, " - + chunk.getLight(LightType.BLOCK, blockpos) + " Blöcke, " + String.format( + light = "Licht: " + chunk.getLightSub(blockpos, 0) + " (" + + chunk.getLight(blockpos) + " Blöcke, " + String.format( "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " + String.format("%.3f", this.world.getCelestialAngle(1.0f)); } else { - bline = "Biom: , D: " + - TextColor.stripCodes(this.world.dimension.getFormattedName(false)) + - " (" + this.world.dimension.getDimensionId() + ")"; - lline = "Licht: " + String.format( + light = "Licht: " + String.format( "%.1f", this.world.getSunBrightness(1.0f) * 15.0f) + " Welt, A: " + String.format("%.3f", this.world.getCelestialAngle(1.0f)); } - float temp = this.world.getTempOffset() + (biome != null ? biome.getTemperature(blockpos) : 0.0f); + float temp = this.world.getTemperatureK(blockpos); + Biome biome = this.world.getBiomeGenForCoords(blockpos); long ticked = System.currentTimeMillis() - this.lastTicked; return @@ -1778,8 +1769,10 @@ public class Client implements IThreadListener { String.format(" (Zoom x%.1f)", this.zoomLevel) : "") + "\n" + String.format("Richtung: %s (%.1f / %.1f)", dirStr, ExtMath.wrapf(entity.rotYaw), ExtMath.wrapf(entity.rotPitch)) + "\n" + - bline + "\n" + - lline + "\n" + + "Biom: " + biome.display + " (" + biome.id + ")" + (", D: " + + TextColor.stripCodes(this.world.dimension.getFormattedName(false)) + + " (" + this.world.dimension.getDimensionId() + ")") + "\n" + + light + "\n" + String.format("Zeit: %d T, R %d / %d T, U %d / %d T", this.world.getDayTime(), this.world.getDayTime() % this.world.dimension.getRotationalPeriod(), diff --git a/client/src/client/renderer/EntityRenderer.java b/client/src/client/renderer/EntityRenderer.java index 9e5bf48..d8e7fb2 100755 --- a/client/src/client/renderer/EntityRenderer.java +++ b/client/src/client/renderer/EntityRenderer.java @@ -1143,7 +1143,7 @@ public class EntityRenderer { for (int l = 0; l < k; ++l) { - BlockPos blockpos1 = world.getPrecipitationHeight(blockpos.add(this.random.zrange(i) - this.random.zrange(i), 0, this.random.zrange(i) - this.random.zrange(i))); + BlockPos blockpos1 = world.getHeight(blockpos.add(this.random.zrange(i) - this.random.zrange(i), 0, this.random.zrange(i) - this.random.zrange(i))); Biome biomegenbase = world.getBiomeGenForCoords(blockpos1); BlockPos blockpos2 = blockpos1.down(); Block block = world.getState(blockpos2).getBlock(); @@ -1189,7 +1189,7 @@ public class EntityRenderer { { this.rainSoundCounter = 0; - if (d1 > (double)(blockpos.getY() + 1) && world.getPrecipitationHeight(blockpos).getY() > ExtMath.floorf((float)blockpos.getY())) + if (d1 > (double)(blockpos.getY() + 1) && world.getHeight(blockpos).getY() > ExtMath.floorf((float)blockpos.getY())) { this.gm.world.playSound(d0, d1, d2, n >= j ? this.pickMoltenSound() : SoundEvent.RAIN, n >= j ? 0.2f : 0.1F); } @@ -1257,7 +1257,7 @@ public class EntityRenderer { // if (biomegenbase.canRain() || biomegenbase.isSnowyBiome()) // { - int j2 = world.getPrecipitationHeight(blockpos$mutableblockpos).getY(); + int j2 = world.getHeight(blockpos$mutableblockpos).getY(); int k2 = j - i1; int l2 = j + i1; diff --git a/client/src/client/renderer/RegionRenderCache.java b/client/src/client/renderer/RegionRenderCache.java index 635a77a..3782fb5 100755 --- a/client/src/client/renderer/RegionRenderCache.java +++ b/client/src/client/renderer/RegionRenderCache.java @@ -11,7 +11,6 @@ import common.util.Vec3i; import common.world.Chunk; import common.world.ChunkCache; import common.world.IWorldAccess; -import common.world.LightType; import common.world.State; import common.world.World; @@ -32,14 +31,16 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess boolean empty = true; for (int i1 = posFromIn.getX() >> 4; i1 <= posToIn.getX() >> 4; ++i1) { - for (int j1 = posFromIn.getZ() >> 4; j1 <= posToIn.getZ() >> 4; ++j1) - { - Chunk chunk = this.chunkArray[i1 - this.chunkX][j1 - this.chunkZ]; - - if (chunk != null && !chunk.isEmpty(posFromIn.getY(), posToIn.getY())) - { - empty = false; - } + for (int n1 = posFromIn.getY() >> 4; n1 <= posToIn.getY() >> 4; ++n1) { + for (int j1 = posFromIn.getZ() >> 4; j1 <= posToIn.getZ() >> 4; ++j1) + { + Chunk chunk = this.chunkArray[i1 - this.chunkX][n1 - this.chunkY][j1 - this.chunkZ]; + + if (chunk != null && !chunk.isEmpty()) + { + empty = false; + } + } } } this.empty = empty; @@ -53,8 +54,9 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess public TileEntity getTileEntity(BlockPos pos) { int i = (pos.getX() >> 4) - this.chunkX; + int n = (pos.getY() >> 4) - this.chunkY; int j = (pos.getZ() >> 4) - this.chunkZ; - return this.chunkArray[i][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED); + return this.chunkArray[i][n][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED); } public int getCombinedLight(BlockPos pos, int lightValue) @@ -87,16 +89,10 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess private State getBlockStateRaw(BlockPos pos) { - if (pos.getY() >= 0 && pos.getY() < 512) - { - int i = (pos.getX() >> 4) - this.chunkX; - int j = (pos.getZ() >> 4) - this.chunkZ; - return this.chunkArray[i][j].getState(pos); - } - else - { - return DEFAULT_STATE; - } + int i = (pos.getX() >> 4) - this.chunkX; + int n = (pos.getY() >> 4) - this.chunkY; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][n][j].getState(pos); } private int getPositionIndex(BlockPos p_175630_1_) @@ -114,15 +110,14 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess public int getLight(BlockPos pos, int lightValue) { - int i = this.getLightForExt(LightType.SKY, pos); - int j = this.getLightForExt(LightType.BLOCK, pos); + int j = this.getLightForExt(pos); if (j < lightValue) { j = lightValue; } - return i << 20 | j << 4; + return 15 << 20 | j << 4; } public Biome getBiomeGenForCoords(BlockPos pos) @@ -130,74 +125,43 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess return this.worldObj.getBiomeGenForCoords(pos); } - private int getLightForExt(LightType p_175629_1_, BlockPos pos) + private int getLightForExt(BlockPos pos) { - if (p_175629_1_ == LightType.SKY && this.worldObj.dimension.hasNoLight()) + if (this.getState(pos).getBlock().getSumBrightness()) { - return 0; - } - else if (pos.getY() >= 0 && pos.getY() < 512) - { - if (this.getState(pos).getBlock().getSumBrightness()) + int l = 0; + + for (Facing enumfacing : Facing.values()) { - int l = 0; + int k = this.getLightFor(pos.offset(enumfacing)); - for (Facing enumfacing : Facing.values()) + if (k > l) { - int k = this.getLightFor(p_175629_1_, pos.offset(enumfacing)); - - if (k > l) - { - l = k; - } - - if (l >= 15) - { - return l; - } + l = k; } - return l; - } - else - { - int i = (pos.getX() >> 4) - this.chunkX; - int j = (pos.getZ() >> 4) - this.chunkZ; - return this.chunkArray[i][j].getLight(p_175629_1_, pos); + if (l >= 15) + { + return l; + } } + + return l; } else - { - return p_175629_1_.defValue; - } - } - -// /** -// * Checks to see if an air block exists at the provided location. Note that this only checks to see if the blocks -// * material is set to air, meaning it is possible for non-vanilla blocks to still pass this check. -// */ -// public boolean isAirBlock(BlockPos pos) -// { -// return this.getBlockState(pos).getBlock().getMaterial() == Material.air; -// } - - public int getLightFor(LightType p_175628_1_, BlockPos pos) - { - if (pos.getY() >= 0 && pos.getY() < 512) { int i = (pos.getX() >> 4) - this.chunkX; + int n = (pos.getX() >> 4) - this.chunkY; int j = (pos.getZ() >> 4) - this.chunkZ; - return this.chunkArray[i][j].getLight(p_175628_1_, pos); - } - else - { - return p_175628_1_.defValue; + return this.chunkArray[i][n][j].getLight(pos); } } - -// public int getStrongPower(BlockPos pos, EnumFacing direction) -// { -// IBlockState iblockstate = this.getBlockState(pos); -// return iblockstate.getBlock().getStrongPower(this, pos, iblockstate, direction); -// } + + public int getLightFor(BlockPos pos) + { + int i = (pos.getX() >> 4) - this.chunkX; + int n = (pos.getY() >> 4) - this.chunkY; + int j = (pos.getZ() >> 4) - this.chunkZ; + return this.chunkArray[i][n][j].getLight(pos); + } } diff --git a/client/src/client/world/EmptyChunk.java b/client/src/client/world/EmptyChunk.java index 190c2d7..38e1e39 100755 --- a/client/src/client/world/EmptyChunk.java +++ b/client/src/client/world/EmptyChunk.java @@ -10,21 +10,10 @@ import common.tileentity.TileEntity; import common.util.BlockPos; import common.util.BoundingBox; import common.world.Chunk; -import common.world.LightType; public class EmptyChunk extends Chunk { public EmptyChunk(WorldClient world) { - super(world, 0, 0); - } - - public int getHeight(int x, int z) { - return 0; - } - - public void genHeights() { - } - - public void genSkyLight() { + super(world, 0, 0, 0); } public Block getBlock(BlockPos pos) { @@ -39,11 +28,11 @@ public class EmptyChunk extends Chunk { return 0; } - public int getLight(LightType type, BlockPos pos) { - return type.defValue; + public int getLight(BlockPos pos) { + return 0; } - public void setLight(LightType type, BlockPos pos, int value) { + public void setLight(BlockPos pos, int value) { } public int getLightSub(BlockPos pos, int amount) { @@ -56,10 +45,6 @@ public class EmptyChunk extends Chunk { public void removeEntity(Entity entity) { } - public boolean canSeeSky(BlockPos pos) { - return false; - } - public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { return null; } @@ -88,15 +73,15 @@ public class EmptyChunk extends Chunk { public void getEntities(Class clazz, BoundingBox bb, List list, Predicate pred) { } - public boolean isDirty() { + public boolean isDirty(long time) { return false; } + public boolean isDummy() { + return true; + } + public boolean isEmpty() { return true; } - - public boolean isEmpty(int bottom, int top) { - return true; - } } diff --git a/client/src/client/world/WorldClient.java b/client/src/client/world/WorldClient.java index 7e8f142..726815f 100755 --- a/client/src/client/world/WorldClient.java +++ b/client/src/client/world/WorldClient.java @@ -139,7 +139,7 @@ public class WorldClient extends AWorldClient else { Chunk chunk = this.getChunk(x, z); - if (!chunk.isEmpty()) + if (!chunk.isDummy()) { chunk.onChunkUnload(); } diff --git a/common/src/common/ai/EntityAIFleeSun.java b/common/src/common/ai/EntityAIFleeSun.java deleted file mode 100755 index 85c8c7e..0000000 --- a/common/src/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/common/block/BlockCrops.java b/common/src/common/block/BlockCrops.java index fee8af4..fbf07d6 100755 --- a/common/src/common/block/BlockCrops.java +++ b/common/src/common/block/BlockCrops.java @@ -129,7 +129,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 getSeed() diff --git a/common/src/common/block/BlockDaylightDetector.java b/common/src/common/block/BlockDaylightDetector.java index f213c1f..735a4bb 100755 --- a/common/src/common/block/BlockDaylightDetector.java +++ b/common/src/common/block/BlockDaylightDetector.java @@ -21,7 +21,6 @@ import common.util.BlockPos; import common.util.ExtMath; import common.util.Facing; import common.world.IWorldAccess; -import common.world.LightType; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -58,7 +57,7 @@ public class BlockDaylightDetector extends BlockContainer if (!worldIn.dimension.hasNoLight()) { State iblockstate = worldIn.getState(pos); - int i = worldIn.getLightFor(LightType.SKY, pos) - worldIn.getSkylightSubtracted(); + int i = 15 - worldIn.getSkylightSubtracted(); float f = worldIn.getCelestialAngleRadians(1.0F); float f1 = f < (float)Math.PI ? 0.0F : ((float)Math.PI * 2F); f = f + (f1 - f) * 0.2F; diff --git a/common/src/common/block/BlockIce.java b/common/src/common/block/BlockIce.java index a1e5981..aa42cc3 100755 --- a/common/src/common/block/BlockIce.java +++ b/common/src/common/block/BlockIce.java @@ -11,7 +11,6 @@ import common.model.BlockLayer; import common.rng.Random; import common.tileentity.TileEntity; import common.util.BlockPos; -import common.world.LightType; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -73,7 +72,7 @@ public class BlockIce extends BlockBreakable public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (Config.iceMelt && ((worldIn.getLightFor(LightType.BLOCK, pos) > 11 - this.getLightOpacity()) || !worldIn.canFreezeAt(pos))) + if (Config.iceMelt && ((worldIn.getLightFor(pos) > 11 - this.getLightOpacity()) || !worldIn.canFreezeAt(pos))) { if (worldIn.doesWaterVaporize(pos)) { diff --git a/common/src/common/block/BlockSnow.java b/common/src/common/block/BlockSnow.java index 3647804..02c193a 100755 --- a/common/src/common/block/BlockSnow.java +++ b/common/src/common/block/BlockSnow.java @@ -20,7 +20,6 @@ import common.util.BoundingBox; import common.util.Facing; import common.world.IBlockAccess; import common.world.IWorldAccess; -import common.world.LightType; import common.world.State; import common.world.World; import common.world.AWorldServer; @@ -137,7 +136,7 @@ public class BlockSnow extends Block public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (Config.snowMelt && ((worldIn.getLightFor(LightType.BLOCK, pos) > 11) || !worldIn.canFreezeAt(pos))) + if (Config.snowMelt && ((worldIn.getLightFor(pos) > 11) || !worldIn.canFreezeAt(pos))) { this.dropBlockAsItem(worldIn, pos, worldIn.getState(pos), 0); worldIn.setBlockToAir(pos); diff --git a/common/src/common/block/BlockSnowBlock.java b/common/src/common/block/BlockSnowBlock.java index 0e4a60e..da6fd2f 100755 --- a/common/src/common/block/BlockSnowBlock.java +++ b/common/src/common/block/BlockSnowBlock.java @@ -7,7 +7,6 @@ import common.item.Item; import common.material.Material; import common.rng.Random; import common.util.BlockPos; -import common.world.LightType; import common.world.State; import common.world.AWorldServer; @@ -38,7 +37,7 @@ public class BlockSnowBlock extends Block public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand) { - if (Config.snowFullMelt && worldIn.getLightFor(LightType.BLOCK, pos) > 11) + if (Config.snowFullMelt && worldIn.getLightFor(pos) > 11) { this.dropBlockAsItem(worldIn, pos, worldIn.getState(pos), 0); worldIn.setBlockToAir(pos); diff --git a/common/src/common/block/BlockTorch.java b/common/src/common/block/BlockTorch.java index a249b7e..3012c52 100755 --- a/common/src/common/block/BlockTorch.java +++ b/common/src/common/block/BlockTorch.java @@ -42,7 +42,7 @@ public class BlockTorch extends Block else { Chunk chunk = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4); - if(chunk.isEmpty()) { + if(chunk.isDummy()) { return def; } else { diff --git a/common/src/common/dimension/Dimension.java b/common/src/common/dimension/Dimension.java index bcb9137..33defd7 100755 --- a/common/src/common/dimension/Dimension.java +++ b/common/src/common/dimension/Dimension.java @@ -279,8 +279,6 @@ public abstract class Dimension extends Nameable implements Comparable 0) { --this.ticksCatchable; diff --git a/common/src/common/pathfinding/PathCache.java b/common/src/common/pathfinding/PathCache.java index 3af36a8..22e1135 100755 --- a/common/src/common/pathfinding/PathCache.java +++ b/common/src/common/pathfinding/PathCache.java @@ -17,19 +17,17 @@ public class PathCache extends ChunkCache implements IBlockAccess public State getState(BlockPos pos) { - if (pos.getY() >= 0 && pos.getY() < 512) + int i = (pos.getX() >> 4) - this.chunkX; + int n = (pos.getY() >> 4) - this.chunkY; + int j = (pos.getZ() >> 4) - this.chunkZ; + + if (i >= 0 && i < this.chunkArray.length && n >= 0 && n < this.chunkArray[i].length && j >= 0 && j < this.chunkArray[i][n].length) { - int i = (pos.getX() >> 4) - this.chunkX; - int j = (pos.getZ() >> 4) - this.chunkZ; + Chunk chunk = this.chunkArray[i][n][j]; - if (i >= 0 && i < this.chunkArray.length && j >= 0 && j < this.chunkArray[i].length) + if (chunk != null) { - Chunk chunk = this.chunkArray[i][j]; - - if (chunk != null) - { - return chunk.getState(pos); - } + return chunk.getState(pos); } } diff --git a/common/src/common/pathfinding/PathNavigate.java b/common/src/common/pathfinding/PathNavigate.java index 0d8fb09..4843e45 100755 --- a/common/src/common/pathfinding/PathNavigate.java +++ b/common/src/common/pathfinding/PathNavigate.java @@ -322,13 +322,6 @@ 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() - { - } - /** * 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 diff --git a/common/src/common/pathfinding/PathNavigateGround.java b/common/src/common/pathfinding/PathNavigateGround.java index f12b1c8..27cfebd 100755 --- a/common/src/common/pathfinding/PathNavigateGround.java +++ b/common/src/common/pathfinding/PathNavigateGround.java @@ -13,7 +13,6 @@ import common.world.World; public class PathNavigateGround extends PathNavigate { protected WalkNodeProcessor nodeProcessor; - private boolean shouldAvoidSun; public PathNavigateGround(EntityLiving entitylivingIn, World worldIn) { @@ -70,34 +69,7 @@ public class PathNavigateGround extends PathNavigate return (int)(this.theEntity.getEntityBoundingBox().minY + 0.5D); } } - - /** - * 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 @@ -286,9 +258,4 @@ public class PathNavigateGround extends PathNavigate { return this.nodeProcessor.getCanSwim(); } - - public void setAvoidSun(boolean par1) - { - this.shouldAvoidSun = par1; - } } diff --git a/common/src/common/util/ChunkPos.java b/common/src/common/util/ChunkPos.java index 32a1c8e..1784896 100755 --- a/common/src/common/util/ChunkPos.java +++ b/common/src/common/util/ChunkPos.java @@ -2,17 +2,20 @@ package common.util; public class ChunkPos { public final int x; + public final int y; public final int z; - public ChunkPos(int x, int z) { + public ChunkPos(int x, int y, int z) { this.x = x; + this.y = y; this.z = z; } public int hashCode() { int i = 1664525 * this.x + 1013904223; int j = 1664525 * (this.z ^ -559038737) + 1013904223; - return i ^ j; + int k = 1664525 * (this.y ^ -753653634) + 453434; + return (i ^ j) + k; } public boolean equals(Object obj) { @@ -24,11 +27,7 @@ public class ChunkPos { } else { ChunkPos pos = (ChunkPos)obj; - return this.x == pos.x && this.z == pos.z; + return this.x == pos.x && this.y == pos.y && this.z == pos.z; } } - - public String toString() { - return "[" + this.x + ", " + this.z + "]"; - } } diff --git a/common/src/common/util/Util.java b/common/src/common/util/Util.java index 629ef96..fa4aa17 100644 --- a/common/src/common/util/Util.java +++ b/common/src/common/util/Util.java @@ -390,11 +390,11 @@ int utf_len(const char *str) { return ((double)rtime()) / 1000000.0; } - public static String getRegionFolder(int x, int z) { - return String.format("%c%03X%c%03X", x < 0 ? 'n' : 'p', ((x < 0) ? -x : x) >> 9, z < 0 ? 'n' : 'p', ((z < 0) ? -z : z) >> 9); + public static String getRegionFolder(int x, int y, int z) { + return String.format("%c%03X%c%03X%c%03X", x < 0 ? 'n' : 'p', ((x < 0) ? -x : x) >> 9, y < 0 ? 'n' : 'p', ((y < 0) ? -y : y) >> 9, z < 0 ? 'n' : 'p', ((z < 0) ? -z : z) >> 9); } - public static String getRegionName(int x, int z) { - return String.format("r.%c%X%c%X.rgn", x < 0 ? 'n' : 'p', ((x < 0) ? -x : x) >> 3, z < 0 ? 'n' : 'p', ((z < 0) ? -z : z) >> 3); + public static String getRegionName(int x, int y, int z) { + return String.format("r.%c%X%c%X%c%X.rgn", x < 0 ? 'n' : 'p', ((x < 0) ? -x : x) >> 3, y < 0 ? 'n' : 'p', ((y < 0) ? -y : y) >> 3, z < 0 ? 'n' : 'p', ((z < 0) ? -z : z) >> 3); } } diff --git a/common/src/common/world/BlockArray.java b/common/src/common/world/BlockArray.java index 44fba70..b32d2d7 100755 --- a/common/src/common/world/BlockArray.java +++ b/common/src/common/world/BlockArray.java @@ -6,19 +6,14 @@ import common.init.Blocks; import common.util.NibbleArray; public class BlockArray { - private int yBase; private int blocks; private int ticked; private char[] data; private NibbleArray blocklight; - private NibbleArray skylight; - public BlockArray(int y, boolean sky) { - this.yBase = y; + public BlockArray() { this.data = new char[4096]; this.blocklight = new NibbleArray(); - if(sky) - this.skylight = new NibbleArray(); } public State get(int x, int y, int z) { @@ -59,19 +54,7 @@ public class BlockArray { public boolean isTicked() { return this.ticked > 0; } - - public int getY() { - return this.yBase; - } - - public void setSky(int x, int y, int z, int value) { - this.skylight.set(x, y, z, value); - } - - public int getSky(int x, int y, int z) { - return this.skylight.get(x, y, z); - } - + public void setLight(int x, int y, int z, int value) { this.blocklight.set(x, y, z, value); } @@ -105,10 +88,6 @@ public class BlockArray { return this.blocklight; } - public NibbleArray getSkylight() { - return this.skylight; - } - public void setData(char[] data) { this.data = data; } @@ -116,8 +95,4 @@ public class BlockArray { public void setBlocklight(NibbleArray data) { this.blocklight = data; } - - public void setSkylight(NibbleArray data) { - this.skylight = data; - } } diff --git a/common/src/common/world/Chunk.java b/common/src/common/world/Chunk.java index 6a5fdf7..d1348e5 100755 --- a/common/src/common/world/Chunk.java +++ b/common/src/common/world/Chunk.java @@ -1,6 +1,5 @@ package common.world; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; @@ -29,350 +28,50 @@ import common.worldgen.DebugStates; public class Chunk { public final int xPos; + public final int yPos; public final int zPos; private final World world; - private final BlockArray[] blocks = new BlockArray[32]; - private final byte[] biomes = new byte[256]; - private final int[] precHeight = new int[256]; - private final boolean[] updateSky = new boolean[256]; - private final int[] height = new int[256]; + private BlockArray blocks = null; private final Map tiles = Maps.newHashMap(); - private final ClassInheritanceMultiMap[] entities = new ClassInheritanceMultiMap[32]; + private final ClassInheritanceMultiMap entities = new ClassInheritanceMultiMap(Entity.class); private final ConcurrentLinkedQueue tileQueue = new ConcurrentLinkedQueue(); private boolean loaded; - private boolean gapUpdate; private boolean populated; - private boolean lightInit; private boolean updated; private boolean modified; private boolean hasEntity; - private int minHeight; - private int lightChecks = 8192; + private int lightChecks = 256; private long lastSave; private long inhabited; - public Chunk(World world, int x, int z) { + public Chunk(World world, int x, int y, int z) { this.world = world; this.xPos = x; + this.yPos = y; this.zPos = z; - for(int y = 0; y < this.entities.length; ++y) { - this.entities[y] = new ClassInheritanceMultiMap(Entity.class); - } - Arrays.fill(this.precHeight, -999); - Arrays.fill(this.biomes, (byte)-1); } - public Chunk(World world, short[] data, int height, State base, State ceil, Random rand, Biome[] biomes, int x, int z) { - this(world, x, z); - boolean sky = !world.dimension.hasNoLight(); + public Chunk(World world, short[] data, int x, int y, int z) { + this(world, x, y, z); for(int bx = 0; bx < 16; ++bx) { for(int bz = 0; bz < 16; ++bz) { - for(int by = 0; by < height; ++by) { + for(int by = 0; by < 16; ++by) { State state = BlockRegistry.STATEMAP.getByValue(data[bx << 4 | bz | by << 8]); if(state != null && state.getBlock().getMaterial() != Material.air) { - int y = by >> 4; - if(this.blocks[y] == null) - this.blocks[y] = new BlockArray(y << 4, sky); - this.blocks[y].set(bx, by & 15, bz, state); + if(this.blocks == null) + this.blocks = new BlockArray(); + this.blocks.set(bx, by, bz, state); } } } } - if(base != null) { - if(this.blocks[0] == null) - this.blocks[0] = new BlockArray(0, sky); - for(int bx = 0; bx < 16; ++bx) { - for(int bz = 0; bz < 16; ++bz) { - for(int by = 0; by < 5; ++by) { - if(by <= rand.zrange(5)) - this.blocks[0].set(bx, by, bz, base); - } - } - } - } - if(ceil != null) { - int y = (height - 1) >> 4; - if(this.blocks[y] == null) - this.blocks[y] = new BlockArray(y << 4, sky); - y = (height - 5) >> 4; - if(this.blocks[y] == null) - this.blocks[y] = new BlockArray(y << 4, sky); - for(int bx = 0; bx < 16; ++bx) { - for(int bz = 0; bz < 16; ++bz) { - for(int by = height - 1; by >= height - 5; --by) { - if(by >= (height - 1) - rand.zrange(5)) - this.blocks[by >> 4].set(bx, by & 15, bz, ceil); - } - } - } - } - for(int n = 0; n < this.biomes.length; ++n) { - this.biomes[n] = (byte)biomes[n].id; - } - if(ceil == null) - this.genSkyLight(); - else - this.resetRelight(); } - - public int getHeight(BlockPos pos) { - return this.getHeight(pos.getX() & 15, pos.getZ() & 15); - } - - public int getHeight(int x, int z) { - return this.height[z << 4 | x]; - } - - public int getTopSegment() { - for(int y = this.blocks.length - 1; y >= 0; --y) { - if(this.blocks[y] != null) { - return this.blocks[y].getY(); - } - } - - return 0; - } - - public BlockArray[] getStorage() { + + public BlockArray getStorage() { return this.blocks; } - - protected void genHeights() { - int h = this.getTopSegment(); - this.minHeight = Integer.MAX_VALUE; - - for(int x = 0; x < 16; ++x) { - for(int z = 0; z < 16; ++z) { - this.precHeight[x + (z << 4)] = -999; - - for(int y = h + 16; y > 0; --y) { - Block block = this.getBlock0(x, y - 1, z); - - if(block.getLightOpacity() != 0) { - this.height[z << 4 | x] = y; - - if(y < this.minHeight) { - this.minHeight = y; - } - - break; - } - } - } - } - - this.modified = true; - } - - public void genSkyLight() { - int h = this.getTopSegment(); - this.minHeight = Integer.MAX_VALUE; - - for(int x = 0; x < 16; ++x) { - for(int z = 0; z < 16; ++z) { - this.precHeight[x + (z << 4)] = -999; - - for(int y = h + 16; y > 0; --y) { - if(this.getOpacity(x, y - 1, z) != 0) { - this.height[z << 4 | x] = y; - - if(y < this.minHeight) { - this.minHeight = y; - } - - break; - } - } - - if(!this.world.dimension.hasNoLight()) { - int l = 15; - int y = h + 16 - 1; - - while(true) { - int b = this.getOpacity(x, y, z); - - if(b == 0 && l != 15) { - b = 1; - } - - l -= b; - - if(l > 0) { - BlockArray stor = this.blocks[y >> 4]; - - if(stor != null) { - stor.setSky(x, y & 15, z, l); - this.world.notifyLightSet(new BlockPos((this.xPos << 4) + x, y, (this.zPos << 4) + z)); - } - } - - --y; - - if(y <= 0 || l <= 0) { - break; - } - } - } - } - } - - this.modified = true; - } - - private void propagateOcclusion(int x, int z) { - this.updateSky[x + z * 16] = true; - this.gapUpdate = true; - } - - private void recheckGaps(boolean single) { -// this.world.profiler.start("recheckGaps"); - - if(this.world.isAreaLoaded(new BlockPos(this.xPos * 16 + 8, 0, this.zPos * 16 + 8), 16)) { - for(int x = 0; x < 16; ++x) { - for(int z = 0; z < 16; ++z) { - if(this.updateSky[x + z * 16]) { - this.updateSky[x + z * 16] = false; - int h = this.getHeight(x, z); - int cx = this.xPos * 16 + x; - int cz = this.zPos * 16 + z; - int max = Integer.MAX_VALUE; - - for(Facing face : Facing.Plane.HORIZONTAL) { - max = Math.min(max, this.world.getChunksLowestHorizon(cx + face.getFrontOffsetX(), - cz + face.getFrontOffsetZ())); - } - - this.checkNeighbor(cx, cz, max); - - for(Facing face : Facing.Plane.HORIZONTAL) { - this.checkNeighbor(cx + face.getFrontOffsetX(), cz + face.getFrontOffsetZ(), h); - } - - if(single) { -// this.world.profiler.end(); - return; - } - } - } - } - - this.gapUpdate = false; - } - -// this.world.profiler.end(); - } - - private void checkNeighbor(int x, int z, int max) { - int h = this.world.getHeight(new BlockPos(x, 0, z)).getY(); - - if(h > max) { - this.updateNeighbor(x, z, max, h + 1); - } - else if(h < max) { - this.updateNeighbor(x, z, h, max + 1); - } - } - - private void updateNeighbor(int x, int z, int bottom, int top) { - if(top > bottom && this.world.isAreaLoaded(new BlockPos(x, 0, z), 16)) { - for(int y = bottom; y < top; ++y) { - this.world.checkLightFor(LightType.SKY, new BlockPos(x, y, z)); - } - - this.modified = true; - } - } - - private void relightBlock(int x, int y, int z) { - int h = this.height[z << 4 | x] & 511; - int cy = h; - - if(y > h) { - cy = y; - } - - while(cy > 0 && this.getOpacity(x, cy - 1, z) == 0) { - --cy; - } - - if(cy != h) { - this.world.markBlocksDirtyVertical(x + this.xPos * 16, z + this.zPos * 16, cy, h); - this.height[z << 4 | x] = cy; - int cx = this.xPos * 16 + x; - int cz = this.zPos * 16 + z; - - if(!this.world.dimension.hasNoLight()) { - if(cy < h) { - for(int n = cy; n < h; ++n) { - BlockArray stor = this.blocks[n >> 4]; - - if(stor != null) { - stor.setSky(x, n & 15, z, 15); - this.world.notifyLightSet(new BlockPos((this.xPos << 4) + x, n, (this.zPos << 4) + z)); - } - } - } - else { - for(int n = h; n < cy; ++n) { - BlockArray stor = this.blocks[n >> 4]; - - if(stor != null) { - stor.setSky(x, n & 15, z, 0); - this.world.notifyLightSet(new BlockPos((this.xPos << 4) + x, n, (this.zPos << 4) + z)); - } - } - } - - int l = 15; - - while(cy > 0 && l > 0) { - --cy; - int b = this.getOpacity(x, cy, z); - - if(b == 0) { - b = 1; - } - - l -= b; - - if(l < 0) { - l = 0; - } - - BlockArray stor = this.blocks[cy >> 4]; - - if(stor != null) { - stor.setSky(x, cy & 15, z, l); - } - } - } - - int sh = this.height[z << 4 | x]; - int sy = h; - int ey = sh; - - if(sh < h) { - sy = sh; - ey = h; - } - - if(sh < this.minHeight) { - this.minHeight = sh; - } - - if(!this.world.dimension.hasNoLight()) { - for(Facing face : Facing.Plane.HORIZONTAL) { - this.updateNeighbor(cx + face.getFrontOffsetX(), cz + face.getFrontOffsetZ(), sy, ey); - } - - this.updateNeighbor(cx, cz, sy, ey); - } - - this.modified = true; - } - } - + public int getOpacity(BlockPos pos) { return this.getBlock(pos).getLightOpacity(); } @@ -384,33 +83,25 @@ public class Chunk { private Block getBlock0(int x, int y, int z) { Block block = Blocks.air; - if(y >= 0 && y >> 4 < this.blocks.length) { - BlockArray stor = this.blocks[y >> 4]; - - if(stor != null) { - block = stor.getBlock(x, y & 15, z); - } + if(this.blocks != null) { + block = this.blocks.getBlock(x, y, z); } return block; } public Block getBlock(int x, int y, int z) { - return this.getBlock0(x & 15, y, z & 15); + return this.getBlock0(x & 15, y & 15, z & 15); } public Block getBlock(BlockPos pos) { - return this.getBlock0(pos.getX() & 15, pos.getY(), pos.getZ() & 15); + return this.getBlock0(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15); } public State getState(BlockPos pos) { if(this.world.debug) { State state = null; - -// if(pos.getY() == 60) { -// state = Blocks.glass.getDefaultState(); -// } - + if(pos.getY() == 1) { state = DebugStates.getState(pos.getX(), pos.getZ()); } @@ -418,15 +109,11 @@ public class Chunk { return state == null ? Blocks.air.getState() : state; } else { - if(pos.getY() >= 0 && pos.getY() >> 4 < this.blocks.length) { - BlockArray stor = this.blocks[pos.getY() >> 4]; - - if(stor != null) { - int x = pos.getX() & 15; - int y = pos.getY() & 15; - int z = pos.getZ() & 15; - return stor.get(x, y, z); - } + if(this.blocks != null) { + int x = pos.getX() & 15; + int y = pos.getY() & 15; + int z = pos.getZ() & 15; + return this.blocks.get(x, y, z); } return Blocks.air.getState(); @@ -434,30 +121,20 @@ public class Chunk { } private int getMeta(int x, int y, int z) { - if(y >> 4 >= this.blocks.length) { + if(this.blocks == null) return 0; - } - else { - BlockArray stor = this.blocks[y >> 4]; - return stor != null ? stor.getMeta(x, y & 15, z) : 0; - } + return this.blocks.getMeta(x, y, z); } public int getMeta(BlockPos pos) { - return this.getMeta(pos.getX() & 15, pos.getY(), pos.getZ() & 15); + return this.getMeta(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15); } public State setState(BlockPos pos, State state) { int x = pos.getX() & 15; - int y = pos.getY(); + int y = pos.getY() & 15; int z = pos.getZ() & 15; - int o = z << 4 | x; - if(y >= this.precHeight[o] - 1) { - this.precHeight[o] = -999; - } - - int h = this.height[o]; State old = this.getState(pos); if(old == state) { @@ -466,19 +143,16 @@ public class Chunk { else { Block block = state.getBlock(); Block oldb = old.getBlock(); - BlockArray stor = this.blocks[y >> 4]; - boolean up = false; - if(stor == null) { + if(this.blocks == null) { if(block == Blocks.air) { return null; } - stor = this.blocks[y >> 4] = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight()); - up = y >= h; + this.blocks = new BlockArray(); } - stor.set(x, y & 15, z, state); + this.blocks.set(x, y & 15, z, state); if(oldb != block) { if(!this.world.client) { @@ -489,31 +163,10 @@ public class Chunk { } } - if(stor.getBlock(x, y & 15, z) != block) { + if(this.blocks.getBlock(x, y, z) != block) { return null; } else { - if(up) { - this.genSkyLight(); - } - else { - int b = block.getLightOpacity(); - int ob = oldb.getLightOpacity(); - - if(b > 0) { - if(y >= h) { - this.relightBlock(x, y + 1, z); - } - } - else if(y == h - 1) { - this.relightBlock(x, y, z); - } - - if(b != ob && (b < ob || this.getLight(LightType.SKY, pos) > 0 || this.getLight(LightType.BLOCK, pos) > 0)) { - this.propagateOcclusion(x, z); - } - } - if(oldb instanceof ITileEntityProvider) { TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); @@ -545,53 +198,39 @@ public class Chunk { } } - public int getLight(LightType type, BlockPos pos) { + public int getLight(BlockPos pos) { int x = pos.getX() & 15; - int y = pos.getY(); + int y = pos.getY() & 15; int z = pos.getZ() & 15; - BlockArray stor = this.blocks[y >> 4]; - return stor == null ? (this.canSeeSky(pos) ? type.defValue : 0) - : (type == LightType.SKY ? (this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z)) - : (type == LightType.BLOCK ? stor.getLight(x, y & 15, z) : type.defValue)); + return this.blocks == null ? 0 : this.blocks.getLight(x, y, z); } - public void setLight(LightType type, BlockPos pos, int value) { + public void setLight(BlockPos pos, int value) { int x = pos.getX() & 15; - int y = pos.getY(); + int y = pos.getY() & 15; int z = pos.getZ() & 15; - BlockArray stor = this.blocks[y >> 4]; - - if(stor == null) { - stor = this.blocks[y >> 4] = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight()); - this.genSkyLight(); - } + if(this.blocks == null) + this.blocks = new BlockArray(); + this.modified = true; - if(type == LightType.SKY) { - if(!this.world.dimension.hasNoLight()) { - stor.setSky(x, y & 15, z, value); - } - } - else if(type == LightType.BLOCK) { - stor.setLight(x, y & 15, z, value); - } + this.blocks.setLight(x, y, z, value); } public int getLightSub(BlockPos pos, int amount) { int x = pos.getX() & 15; - int y = pos.getY(); + int y = pos.getY() & 15; int z = pos.getZ() & 15; - BlockArray stor = this.blocks[y >> 4]; - if(stor == null) { - return !this.world.dimension.hasNoLight() && amount < LightType.SKY.defValue - ? LightType.SKY.defValue - amount : 0; + if(this.blocks == null) { + return !this.world.dimension.hasNoLight() && amount < 15 + ? 15 - amount : 0; } else { - int l = this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z); + int l = this.world.dimension.hasNoLight() ? 0 : 15; l = l - amount; - int b = stor.getLight(x, y & 15, z); + int b = this.blocks.getLight(x, y, z); if(b > l) { l = b; @@ -604,51 +243,25 @@ public class Chunk { public void addEntity(Entity entity) { this.hasEntity = true; int x = ExtMath.floord(entity.posX / 16.0D); + int y = ExtMath.floord(entity.posY / 16.0D); int z = ExtMath.floord(entity.posZ / 16.0D); - if(x != this.xPos || z != this.zPos) { - Log.JNI.warn("Falsche Position! (" + x + ", " + z + ") sollte (" + this.xPos + ", " + this.zPos + ") sein, " + entity); + if(x != this.xPos || y != this.yPos || z != this.zPos) { + Log.JNI.warn("Falsche Position! (" + x + ", " + y + ", " + z + ") sollte (" + this.xPos + ", " + this.yPos + ", " + this.zPos + ") sein, " + entity); entity.setDead(); } - - int y = ExtMath.floord(entity.posY / 16.0D); - - if(y < 0) { - y = 0; - } - - if(y >= this.entities.length) { - y = this.entities.length - 1; - } - + entity.addedToChunk = true; entity.chunkCoordX = this.xPos; - entity.chunkCoordY = y; + entity.chunkCoordY = this.yPos; entity.chunkCoordZ = this.zPos; - this.entities[y].add(entity); + this.entities.add(entity); } public void removeEntity(Entity entity) { - int y = entity.chunkCoordY; - - if(y < 0) { - y = 0; - } - - if(y >= this.entities.length) { - y = this.entities.length - 1; - } - - this.entities[y].remove(entity); + this.entities.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) { Block block = this.getBlock(pos); return !block.hasTileEntity() ? null : ((ITileEntityProvider)block).createNewTileEntity(this.world, this.getMeta(pos)); @@ -712,13 +325,11 @@ public class Chunk { this.loaded = true; this.world.addTileEntities(this.tiles.values()); - for(int n = 0; n < this.entities.length; ++n) { - for(Entity entity : this.entities[n]) { - entity.onChunkLoad(); - } - - this.world.loadEntities(this.entities[n]); + for(Entity entity : this.entities) { + entity.onChunkLoad(); } + + this.world.loadEntities(this.entities); } public void onChunkUnload() { @@ -728,9 +339,7 @@ public class Chunk { this.world.markTileEntityForRemoval(tile); } - for(int n = 0; n < this.entities.length; ++n) { - this.world.unloadEntities(this.entities[n]); - } + this.world.unloadEntities(this.entities); } public void setModified() { @@ -738,29 +347,22 @@ public class Chunk { } public void getEntities(Entity exclude, BoundingBox bb, List list, Predicate pred) { - int sy = ExtMath.floord((bb.minY - 2.0D) / 16.0D); - int ey = ExtMath.floord((bb.maxY + 2.0D) / 16.0D); - sy = ExtMath.clampi(sy, 0, this.entities.length - 1); - ey = ExtMath.clampi(ey, 0, this.entities.length - 1); + if(!this.entities.isEmpty()) { + for(Entity entity : this.entities) { + if(entity.getEntityBoundingBox().intersectsWith(bb) && entity != exclude) { + if(pred == null || pred.test(entity)) { + list.add(entity); + } - for(int y = sy; y <= ey; ++y) { - if(!this.entities[y].isEmpty()) { - for(Entity entity : this.entities[y]) { - if(entity.getEntityBoundingBox().intersectsWith(bb) && entity != exclude) { - if(pred == null || pred.test(entity)) { - list.add(entity); - } + Entity[] parts = entity.getParts(); - Entity[] parts = entity.getParts(); + if(parts != null) { + for(int l = 0; l < parts.length; ++l) { + entity = parts[l]; - if(parts != null) { - for(int l = 0; l < parts.length; ++l) { - entity = parts[l]; - - if(entity != exclude && entity.getEntityBoundingBox().intersectsWith(bb) - && (pred == null || pred.test(entity))) { - list.add(entity); - } + if(entity != exclude && entity.getEntityBoundingBox().intersectsWith(bb) + && (pred == null || pred.test(entity))) { + list.add(entity); } } } @@ -770,81 +372,26 @@ public class Chunk { } public void getEntities(Class clazz, BoundingBox bb, List list, Predicate pred) { - int sy = ExtMath.floord((bb.minY - 2.0D) / 16.0D); - int ey = ExtMath.floord((bb.maxY + 2.0D) / 16.0D); - sy = ExtMath.clampi(sy, 0, this.entities.length - 1); - ey = ExtMath.clampi(ey, 0, this.entities.length - 1); - - for(int y = sy; y <= ey; ++y) { - for(T entity : this.entities[y].getByClass(clazz)) { - if(entity.getEntityBoundingBox().intersectsWith(bb) && (pred == null || pred.test(entity))) { - list.add(entity); - } + for(T entity : this.entities.getByClass(clazz)) { + if(entity.getEntityBoundingBox().intersectsWith(bb) && (pred == null || pred.test(entity))) { + list.add(entity); } } } public boolean isDirty(long time) { -// if (all) -// { - if(this.hasEntity && time /* this.world.getTime() */ != this.lastSave || this.modified) { + if(this.hasEntity && time != this.lastSave || this.modified) return true; - } -// } -// else if (this.hasEntity && this.world.getTime() >= this.lastSave + 600L) -// { -// return true; -// } - return this.modified; } - public boolean isEmpty() { + public boolean isDummy() { return false; } - - public BlockPos getPrecipitation(BlockPos pos) { - int x = pos.getX() & 15; - int z = pos.getZ() & 15; - int o = x | z << 4; - BlockPos loc = new BlockPos(pos.getX(), this.precHeight[o], pos.getZ()); - - if(loc.getY() == -999) { - int y = this.getTopSegment() + 15; - loc = new BlockPos(pos.getX(), y, pos.getZ()); - int h = -1; - - while(loc.getY() > 0 && h == -1) { - Block block = this.getBlock(loc); - Material mat = block.getMaterial(); - - if((!mat.blocksMovement() && !mat.isLiquid()) - || (mat == Material.leaves && ((mat = this.getBlock(loc.up()).getMaterial()) == Material.snow) - || mat == Material.leaves)) { - loc = loc.down(); - } - else { - h = loc.getY() + 1; - } - } - - this.precHeight[o] = h; - } - - return new BlockPos(pos.getX(), this.precHeight[o], pos.getZ()); - } - - public void update(boolean noGaps) { - if(this.gapUpdate && !this.world.dimension.hasNoLight() && !noGaps) { - this.recheckGaps(this.world.client); - } - + + public void update() { this.updated = true; - - if(!this.lightInit && this.populated) { - this.checkLight(); - } - + while(!this.tileQueue.isEmpty()) { BlockPos pos = (BlockPos)this.tileQueue.poll(); @@ -857,134 +404,57 @@ public class Chunk { } public boolean isPopulated() { - return this.updated && this.populated && this.lightInit; + return this.updated && this.populated; } public ChunkPos getPos() { - return new ChunkPos(this.xPos, this.zPos); + return new ChunkPos(this.xPos, this.yPos, this.zPos); } - public boolean isEmpty(int bottom, int top) { - if(bottom < 0) { - bottom = 0; - } - - if(top >= 512) { - top = 511; - } - - for(int y = bottom; y <= top; y += 16) { - BlockArray stor = this.blocks[y >> 4]; - - if(stor != null && !stor.isEmpty()) { - return false; - } - } - - return true; + public boolean isEmpty() { + return this.blocks == null || this.blocks.isEmpty(); } - public void setStorage(BlockArray[] arrays) { - if(this.blocks.length != arrays.length) { - Log.JNI.warn("Konnte Sektionen des Chunks nicht setzen, Länge des Arrays ist " + arrays.length + " statt " - + this.blocks.length); - } - else { - for(int n = 0; n < this.blocks.length; ++n) { - this.blocks[n] = arrays[n]; - } - } + public void setStorage(BlockArray array) { + this.blocks = array; } - public void setData(byte[] data, int update, boolean biomes) { + public void setData(byte[] data, boolean update, boolean clear) { int pos = 0; - boolean sky = !this.world.dimension.hasNoLight(); - - for(int n = 0; n < this.blocks.length; ++n) { - if((update & 1 << n) != 0) { - if(this.blocks[n] == null) { - this.blocks[n] = new BlockArray(n << 4, sky); - } - - char[] blocks = this.blocks[n].getData(); - - for(int k = 0; k < blocks.length; ++k) { - blocks[k] = (char)((data[pos + 1] & 255) << 8 | data[pos] & 255); - pos += 2; - } + + if(update) { + if(this.blocks == null) { + this.blocks = new BlockArray(); } - else if(biomes && this.blocks[n] != null) { - this.blocks[n] = null; + + char[] blocks = this.blocks.getData(); + + for(int k = 0; k < blocks.length; ++k) { + blocks[k] = (char)((data[pos + 1] & 255) << 8 | data[pos] & 255); + pos += 2; } } - - for(int n = 0; n < this.blocks.length; ++n) { - if((update & 1 << n) != 0 && this.blocks[n] != null) { - NibbleArray light = this.blocks[n].getBlocklight(); - System.arraycopy(data, pos, light.getData(), 0, light.getData().length); - pos += light.getData().length; - } + else if(clear && this.blocks != null) { + this.blocks = null; } - if(sky) { - for(int n = 0; n < this.blocks.length; ++n) { - if((update & 1 << n) != 0 && this.blocks[n] != null) { - NibbleArray slight = this.blocks[n].getSkylight(); - System.arraycopy(data, pos, slight.getData(), 0, slight.getData().length); - pos += slight.getData().length; - } - } + if(update && this.blocks != null) { + NibbleArray light = this.blocks.getBlocklight(); + System.arraycopy(data, pos, light.getData(), 0, light.getData().length); + pos += light.getData().length; + } + + if(this.blocks != null && update) { + this.blocks.update(); } - if(biomes) { - System.arraycopy(data, pos, this.biomes, 0, this.biomes.length); -// int unk = pos + this.biomes.length; - } - - for(int n = 0; n < this.blocks.length; ++n) { - if(this.blocks[n] != null && (update & 1 << n) != 0) { - this.blocks[n].update(); - } - } - - this.lightInit = true; this.populated = true; - this.genHeights(); for(TileEntity tile : this.tiles.values()) { tile.updateContainingBlockInfo(); } } - public Biome getBiome(BlockPos pos, BiomeGenerator gen) { - int x = pos.getX() & 15; - int z = pos.getZ() & 15; - int o = this.biomes[z << 4 | x] & 255; - - if(o == 255) { - Biome biome = gen == null ? Biome.DEF_BIOME : gen.getBiomeGenerator(pos, Biome.DEF_BIOME); - o = biome.id; - this.biomes[z << 4 | x] = (byte)(o & 255); - } - - return Biome.getBiomeDef(o); - } - - public byte[] getBiomes() { - return this.biomes; - } - - public void setBiomes(byte[] biomes) { - if(this.biomes.length != biomes.length) { - Log.JNI.warn("Konnte Biome des Chunks nicht setzen, Länge des Arrays ist " + biomes.length + " statt " + this.biomes.length); - } - else { - for(int n = 0; n < this.biomes.length; ++n) { - this.biomes[n] = biomes[n]; - } - } - } - public void resetRelight() { this.lightChecks = 0; } @@ -992,7 +462,7 @@ public class Chunk { /** * Called once-per-chunk-per-tick, and advances the round-robin relight check * index by up to 8 blocks at a time. In a worst-case scenario, can potentially - * take up to 51.2 seconds, calculated via (8192/8)/20, to re-check all blocks + * take up to 1.6 seconds, calculated via (256/8)/20, to re-check all blocks * in a chunk, which may explain lagging light updates on initial world * generation. */ @@ -1000,20 +470,19 @@ public class Chunk { BlockPos pos = new BlockPos(this.xPos << 4, 0, this.zPos << 4); for(int n = 0; n < 8; ++n) { - if(this.lightChecks >= 8192) + if(this.lightChecks >= 256) return; - int s = this.lightChecks % 31; - int x = this.lightChecks / 31 % 16; - int z = this.lightChecks / 512; + int x = this.lightChecks % 16; + int z = this.lightChecks / 16; ++this.lightChecks; for(int y = 0; y < 16; ++y) { - BlockPos block = pos.add(x, (s << 4) + y, z); + BlockPos block = pos.add(x, y, z); boolean edge = y == 0 || y == 15 || x == 0 || x == 15 || z == 0 || z == 15; - if(this.blocks[s] == null && edge || this.blocks[s] != null - && this.blocks[s].getBlock(x, y, z).getMaterial() == Material.air) { + if(this.blocks == null && edge || this.blocks != null + && this.blocks.getBlock(x, y, z).getMaterial() == Material.air) { for(Facing face : Facing.values()) { BlockPos side = block.offset(face); @@ -1027,106 +496,7 @@ public class Chunk { } } } - - public void checkLight() { - this.populated = true; - this.lightInit = true; - BlockPos pos = new BlockPos(this.xPos << 4, 0, this.zPos << 4); - - if(!this.world.dimension.hasNoLight()) { - if(this.world.isAreaLoaded(pos.add(-1, 0, -1), pos.add(16, this.world.getSeaLevel(), 16))) { - label92: - - for(int x = 0; x < 16; ++x) { - for(int z = 0; z < 16; ++z) { - if(!this.updateColumn(x, z)) { - this.lightInit = false; - break label92; - } - } - } - - if(this.lightInit) { - for(Facing face : Facing.Plane.HORIZONTAL) { - int d = face.getAxisDirection() == Facing.AxisDirection.POSITIVE ? 16 : 1; - this.world.getChunk(pos.offset(face, d)).updateColumns(face.getOpposite()); - } - - this.setSkyDirty(); - } - } - else { - this.lightInit = false; - } - } - } - - private void setSkyDirty() { - for(int n = 0; n < this.updateSky.length; ++n) { - this.updateSky[n] = true; - } - - this.recheckGaps(false); - } - - private void updateColumns(Facing facing) { - if(this.populated) { - if(facing == Facing.EAST) { - for(int z = 0; z < 16; ++z) { - this.updateColumn(15, z); - } - } - else if(facing == Facing.WEST) { - for(int z = 0; z < 16; ++z) { - this.updateColumn(0, z); - } - } - else if(facing == Facing.SOUTH) { - for(int x = 0; x < 16; ++x) { - this.updateColumn(x, 15); - } - } - else if(facing == Facing.NORTH) { - for(int x = 0; x < 16; ++x) { - this.updateColumn(x, 0); - } - } - } - } - - private boolean updateColumn(int x, int z) { - int top = this.getTopSegment(); - boolean opaque = false; - boolean below = false; - BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos((this.xPos << 4) + x, 0, (this.zPos << 4) + z); - - for(int y = top + 16 - 1; y > this.world.getSeaLevel() || y > 0 && !below; --y) { - pos.set(pos.getX(), y, pos.getZ()); - int o = this.getOpacity(pos); - - if(o == 255 && pos.getY() < this.world.getSeaLevel()) { - below = true; - } - - if(!opaque && o > 0) { - opaque = true; - } - else if(opaque && o == 0 && !this.world.checkLight(pos)) { - return false; - } - } - - for(int y = pos.getY(); y > 0; --y) { - pos.set(pos.getX(), y, pos.getZ()); - - if(this.getBlock(pos).getLightValue() > 0) { - this.world.checkLight(pos); - } - } - - return true; - } - + public boolean isLoaded() { return this.loaded; } @@ -1139,26 +509,11 @@ public class Chunk { return this.world; } - public int[] getHeights() { - return this.height; - } - - public void setHeights(int[] map) { - if(this.height.length != map.length) { - Log.JNI.warn("Konnte Höhen des Chunks nicht setzen, Länge des Arrays ist " + map.length + " statt " + this.height.length); - } - else { - for(int n = 0; n < this.height.length; ++n) { - this.height[n] = map[n]; - } - } - } - public Map getTiles() { return this.tiles; } - public ClassInheritanceMultiMap[] getEntities() { + public ClassInheritanceMultiMap getEntities() { return this.entities; } @@ -1170,14 +525,6 @@ public class Chunk { this.populated = populated; } - public boolean isLightPopulated() { - return this.lightInit; - } - - public void setLightPopulated(boolean populated) { - this.lightInit = populated; - } - public void setModified(boolean modified) { this.modified = modified; } @@ -1190,10 +537,6 @@ public class Chunk { this.lastSave = time; } - public int getLowest() { - return this.minHeight; - } - public long getInhabited() { return this.inhabited; } diff --git a/common/src/common/world/ChunkCache.java b/common/src/common/world/ChunkCache.java index d495ab1..748a164 100755 --- a/common/src/common/world/ChunkCache.java +++ b/common/src/common/world/ChunkCache.java @@ -5,22 +5,28 @@ import common.util.BlockPos; public class ChunkCache { protected final int chunkX; + protected final int chunkY; protected final int chunkZ; - protected final Chunk[][] chunkArray; + protected final Chunk[][][] chunkArray; public ChunkCache(World worldIn, BlockPos posFromIn, BlockPos posToIn, int subIn) { this.chunkX = posFromIn.getX() - subIn >> 4; + this.chunkY = posFromIn.getY() - subIn >> 4; this.chunkZ = posFromIn.getZ() - subIn >> 4; int i = posToIn.getX() + subIn >> 4; + int n = posToIn.getY() + subIn >> 4; int j = posToIn.getZ() + subIn >> 4; - this.chunkArray = new Chunk[i - this.chunkX + 1][j - this.chunkZ + 1]; + this.chunkArray = new Chunk[i - this.chunkX + 1][n - this.chunkY + 1][j - this.chunkZ + 1]; for (int k = this.chunkX; k <= i; ++k) { - for (int l = this.chunkZ; l <= j; ++l) + for (int m = this.chunkY; m <= n; ++m) { - this.chunkArray[k - this.chunkX][l - this.chunkZ] = worldIn.getChunk(k, l); + for (int l = this.chunkZ; l <= j; ++l) + { + this.chunkArray[k - this.chunkX][m - this.chunkY][l - this.chunkZ] = worldIn.getChunk(k, l); + } } } } diff --git a/common/src/common/world/LightType.java b/common/src/common/world/LightType.java deleted file mode 100755 index e1bfdbb..0000000 --- a/common/src/common/world/LightType.java +++ /dev/null @@ -1,11 +0,0 @@ -package common.world; - -public enum LightType { - SKY(15), BLOCK(0); - - public final int defValue; - - private LightType(int def) { - this.defValue = def; - } -} diff --git a/common/src/common/world/World.java b/common/src/common/world/World.java index 519dc36..307f592 100755 --- a/common/src/common/world/World.java +++ b/common/src/common/world/World.java @@ -134,10 +134,7 @@ public abstract class World implements IWorldAccess { } public Biome getBiomeGenForCoords(final BlockPos pos) { - if(this.isBlockLoaded(pos)) - return this.getChunk(pos).getBiome(pos, null); - else - return Biome.DEF_BIOME; + return Biome.DEF_BIOME; } public boolean isAirBlock(BlockPos pos) { @@ -192,7 +189,7 @@ public abstract class World implements IWorldAccess { } protected boolean isLoaded(int x, int z, boolean allowEmpty) { - return allowEmpty || !this.getChunk(x, z).isEmpty(); + return allowEmpty || !this.getChunk(x, z).isDummy(); } public Chunk getChunk(BlockPos pos) { @@ -282,13 +279,7 @@ public abstract class World implements IWorldAccess { z2 = x2; x2 = i; } - - if(!this.dimension.hasNoLight()) { - for(int j = x2; j <= z2; ++j) { - this.checkLightFor(LightType.SKY, new BlockPos(x1, j, z1)); - } - } - + this.markBlockRangeForRenderUpdate(x1, x2, z1, x1, z2, z1); } @@ -338,11 +329,7 @@ public abstract class World implements IWorldAccess { iblockstate.getBlock().onNeighborBlockChange(this, pos, iblockstate, blockIn); } } - - public boolean canSeeSky(BlockPos pos) { - return this.getChunk(pos).canSeeSky(pos); - } - + public int getLight(BlockPos pos) { if(pos.getY() < 0) { return 0; @@ -403,123 +390,84 @@ public abstract class World implements IWorldAccess { 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 getChunksLowestHorizon(int x, int z) { - if(x >= -MAX_SIZE && z >= -MAX_SIZE && x < MAX_SIZE && z < MAX_SIZE) { - if(!this.isLoaded(x >> 4, z >> 4, true)) { - return 0; - } - else { - Chunk chunk = this.getChunk(x >> 4, z >> 4); - return chunk.getLowest(); - } - } - else { - return this.getSeaLevel() + 1; - } - } - - public int getLightFromNeighborsFor(LightType type, BlockPos pos) { - if(this.dimension.hasNoLight() && type == LightType.SKY) { - return 0; - } - else { - if(pos.getY() < 0) { - pos = new BlockPos(pos.getX(), 0, pos.getZ()); - } - - if(!isValid(pos)) { - return type.defValue; - } - else if(!this.isBlockLoaded(pos)) { - return type.defValue; - } - else if(this.getState(pos).getBlock().getSumBrightness()) { - int i1 = this.getLightFor(type, pos.up()); - int i = this.getLightFor(type, pos.east()); - int j = this.getLightFor(type, pos.west()); - int k = this.getLightFor(type, pos.south()); - int l = this.getLightFor(type, 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(type, pos); - } - } - } - - public int getLightFor(LightType type, BlockPos pos) { + + public int getLightFromNeighborsFor(BlockPos pos) { if(pos.getY() < 0) { pos = new BlockPos(pos.getX(), 0, pos.getZ()); } if(!isValid(pos)) { - return type.defValue; + return 0; } else if(!this.isBlockLoaded(pos)) { - return type.defValue; + 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(type, pos); + return chunk.getLight(pos); } } - public void setLightFor(LightType type, BlockPos pos, int lightValue) { + public int getLightFor(BlockPos pos) { + if(pos.getY() < 0) { + pos = new BlockPos(pos.getX(), 0, 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 setLightFor(BlockPos pos, int lightValue) { if(isValid(pos)) { if(this.isBlockLoaded(pos)) { Chunk chunk = this.getChunk(pos); - chunk.setLight(type, pos, lightValue); + chunk.setLight(pos, lightValue); this.notifyLightSet(pos); } } } public int getCombinedLight(BlockPos pos, int lightValue) { - int i = this.getLightFromNeighborsFor(LightType.SKY, pos); - int j = this.getLightFromNeighborsFor(LightType.BLOCK, pos); + int j = this.getLightFromNeighborsFor(pos); if(j < lightValue) { j = lightValue; } - return i << 20 | j << 4; + return 15 << 20 | j << 4; } public float getLightBrightness(BlockPos pos) { @@ -935,8 +883,32 @@ public abstract class World implements IWorldAccess { return f * (float)Math.PI * 2.0F; } - public BlockPos getPrecipitationHeight(BlockPos pos) { - return this.getChunk(pos).getPrecipitation(pos); + public BlockPos getPrecipitationHeight(BlockPos pos, int y, int scan) { + scan = y - scan; + int x = pos.getX(); + int z = pos.getZ(); + BlockPos loc = new BlockPos(x, y, z); + y = -1; + + while(loc.getY() > 0 && loc.getY() >= scan && y == -1) { + Block block = this.getState(loc).getBlock(); + Material mat = block.getMaterial(); + + if((!mat.blocksMovement() && !mat.isLiquid()) + || (mat == Material.leaves && ((mat = this.getState(loc.up()).getBlock().getMaterial()) == Material.snow) + || mat == Material.leaves)) { + loc = loc.down(); + } + else { + y = loc.getY() + 1; + } + } + + return new BlockPos(x, y, z); + } + + public BlockPos getHeight(BlockPos pos) { + return this.getPrecipitationHeight(pos, 256, 256); } public void updateEntities() { @@ -1519,12 +1491,15 @@ public abstract class World implements IWorldAccess { 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 n = ExtMath.floord(entityplayer.posY / 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 n1 = -l; n1 <= l; ++n1) { + for(int j1 = -l; j1 <= l; ++j1) { + this.active.add(new ChunkPos(i1 + j, n1 + n, j1 + k)); + } } } } @@ -1593,7 +1568,7 @@ public abstract class World implements IWorldAccess { return true; } else { - if(pos.getY() >= 0 && pos.getY() < 512 && this.getLightFor(LightType.BLOCK, pos) < 10) { + if(pos.getY() >= 0 && pos.getY() < 512 && this.getLightFor(pos) < 10) { Block block = this.getState(pos).getBlock(); if((block.getMaterial() == Material.air || (allowLayers && block == Blocks.snow_layer)) @@ -1607,59 +1582,47 @@ public abstract class World implements IWorldAccess { } public boolean checkLight(BlockPos pos) { - boolean flag = false; - - if(!this.dimension.hasNoLight()) { - flag |= this.checkLightFor(LightType.SKY, pos); - } - - flag = flag | this.checkLightFor(LightType.BLOCK, pos); - return flag; + return this.checkLightFor(pos); } - private int getRawLight(BlockPos pos, LightType lightType) { - if(lightType == LightType.SKY && this.canSeeSky(pos)) { - return 15; + private int getRawLight(BlockPos pos) { + Block block = this.getState(pos).getBlock(); + int i = block.getLightValue(); + int j = block.getLightOpacity(); + + if(j >= 15 && block.getLightValue() > 0) { + j = 1; + } + + if(j < 1) { + j = 1; + } + + if(j >= 15) { + return 0; + } + else if(i >= 14) { + return i; } else { - Block block = this.getState(pos).getBlock(); - int i = lightType == LightType.SKY ? 0 : block.getLightValue(); - int j = block.getLightOpacity(); + for(Facing enumfacing : Facing.values()) { + BlockPos blockpos = pos.offset(enumfacing); + int k = this.getLightFor(blockpos) - j; - if(j >= 15 && block.getLightValue() > 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(lightType, blockpos) - j; - - if(k > i) { - i = k; - } - - if(i >= 14) { - return i; - } + if(k > i) { + i = k; } - return i; + if(i >= 14) { + return i; + } } + + return i; } } - public boolean checkLightFor(LightType lightType, BlockPos pos) { + public boolean checkLightFor(BlockPos pos) { if(!this.isAreaLoaded(pos, 17, false)) { return false; } @@ -1667,8 +1630,8 @@ public abstract class World implements IWorldAccess { int i = 0; int j = 0; // this.profiler.start("getBrightness"); - int k = this.getLightFor(lightType, pos); - int l = this.getRawLight(pos, lightType); + int k = this.getLightFor(pos); + int l = this.getRawLight(pos); int i1 = pos.getX(); int j1 = pos.getY(); int k1 = pos.getZ(); @@ -1686,10 +1649,10 @@ public abstract class World implements IWorldAccess { int k2 = (l1 >> 12 & 63) - 32 + k1; int l2 = l1 >> 18 & 15; BlockPos blockpos = new BlockPos(i2, j2, k2); - int i3 = this.getLightFor(lightType, blockpos); + int i3 = this.getLightFor(blockpos); if(i3 == l2) { - this.setLightFor(lightType, blockpos, 0); + this.setLightFor(blockpos, 0); if(l2 > 0) { int j3 = ExtMath.absi(i2 - i1); @@ -1705,7 +1668,7 @@ public abstract class World implements IWorldAccess { int k4 = k2 + enumfacing.getFrontOffsetZ(); blockpos$mutableblockpos.set(i4, j4, k4); int l4 = Math.max(1, this.getState(blockpos$mutableblockpos).getBlock().getLightOpacity()); - i3 = this.getLightFor(lightType, blockpos$mutableblockpos); + i3 = this.getLightFor(blockpos$mutableblockpos); if(i3 == l2 - l4 && j < this.lightUpdate.length) { this.lightUpdate[j++] = i4 - i1 + 32 | j4 - j1 + 32 << 6 | k4 - k1 + 32 << 12 | l2 - l4 << 18; @@ -1728,11 +1691,11 @@ public abstract class World implements IWorldAccess { int k5 = (i5 >> 6 & 63) - 32 + j1; int l5 = (i5 >> 12 & 63) - 32 + k1; BlockPos blockpos1 = new BlockPos(j5, k5, l5); - int i6 = this.getLightFor(lightType, blockpos1); - int j6 = this.getRawLight(blockpos1, lightType); + int i6 = this.getLightFor(blockpos1); + int j6 = this.getRawLight(blockpos1); if(j6 != i6) { - this.setLightFor(lightType, blockpos1, j6); + this.setLightFor(blockpos1, j6); if(j6 > i6) { int k6 = Math.abs(j5 - i1); @@ -1741,27 +1704,27 @@ public abstract class World implements IWorldAccess { boolean flag = j < this.lightUpdate.length - 6; if(k6 + l6 + i7 < 17 && flag) { - if(this.getLightFor(lightType, blockpos1.west()) < j6) { + if(this.getLightFor(blockpos1.west()) < j6) { this.lightUpdate[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12); } - if(this.getLightFor(lightType, blockpos1.east()) < j6) { + if(this.getLightFor(blockpos1.east()) < j6) { this.lightUpdate[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12); } - if(this.getLightFor(lightType, blockpos1.down()) < j6) { + if(this.getLightFor(blockpos1.down()) < j6) { this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12); } - if(this.getLightFor(lightType, blockpos1.up()) < j6) { + if(this.getLightFor(blockpos1.up()) < j6) { this.lightUpdate[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12); } - if(this.getLightFor(lightType, blockpos1.north()) < j6) { + if(this.getLightFor(blockpos1.north()) < j6) { this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - 1 - k1 + 32 << 12); } - if(this.getLightFor(lightType, blockpos1.south()) < j6) { + if(this.getLightFor(blockpos1.south()) < j6) { this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 + 1 - k1 + 32 << 12); } } @@ -2064,10 +2027,7 @@ 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()) { + else if(this.getHeight(strikePosition).getY() > strikePosition.getY()) { return false; } return !this.canSnowAt(strikePosition, false, false); diff --git a/server/src/server/village/VillageCollection.java b/server/src/server/village/VillageCollection.java index 53ad125..08163f0 100755 --- a/server/src/server/village/VillageCollection.java +++ b/server/src/server/village/VillageCollection.java @@ -215,15 +215,16 @@ public class VillageCollection for (int j = 1; j <= 5; ++j) { - if (world.canSeeSky(centerPos.offset(direction, j))) - { - ++i; - - if (i >= limitation) - { - return i; - } - } + BlockPos pos = centerPos.offset(direction, j); + for(int z = 0; z < 5; z++) { + if(!world.isAirBlock(pos.up(z))) + break; + if(z == 4) { + ++i; + if (i >= limitation) + return i; + } + } } return i; diff --git a/server/src/server/world/Region.java b/server/src/server/world/Region.java index fcf1367..f953313 100755 --- a/server/src/server/world/Region.java +++ b/server/src/server/world/Region.java @@ -66,12 +66,13 @@ public class Region { private static volatile boolean waiting; private static volatile boolean killed; - private final int[] timestamps = new int[64]; - private final int[] positions = new int[64]; - private final int[] sizes = new int[64]; + private final int[] timestamps = new int[512]; + private final int[] positions = new int[512]; + private final int[] sizes = new int[512]; private final File regFile; private final File folder; private final int xPos; + private final int yPos; private final int zPos; private RandomAccessFile file; @@ -79,26 +80,27 @@ public class Region { private int offset; private boolean modified; - public Region(File dir, int x, int z) { - File sdir = new File(dir, Util.getRegionFolder(x << 3, z << 3)); + public Region(File dir, int x, int y, int z) { + File sdir = new File(dir, Util.getRegionFolder(x << 3, y << 3, z << 3)); if(!sdir.exists()) sdir.mkdirs(); - this.regFile = new File(sdir, Util.getRegionName(x << 3, z << 3)); + this.regFile = new File(sdir, Util.getRegionName(x << 3, y << 3, z << 3)); this.folder = dir; this.xPos = x; + this.yPos = y; this.zPos = z; try { if(this.regFile.exists()) this.lastModified = this.regFile.lastModified(); this.file = new RandomAccessFile(this.regFile, "rw"); this.file.seek(0L); - if(this.file.length() < 512L) { - for(int i = 0; i < 64; i++) { + if(this.file.length() < 4096L) { + for(int i = 0; i < 512; i++) { this.file.writeLong(0L); } } else { - for(int i = 0; i < 64; i++) { + for(int i = 0; i < 512; i++) { int end = this.positions[i] = this.file.readUnsignedShort(); end += ((this.sizes[i] = this.file.readUnsignedShort()) + 255) >> 8; this.timestamps[i] = this.file.readInt(); @@ -117,7 +119,7 @@ public class Region { File tmp = new File(this.folder, this.regFile.getName() + ".tmp"); RandomAccessFile file = new RandomAccessFile(tmp, "rw"); int offset = 0; - for(int i = 0; i < 64; i++) { + for(int i = 0; i < 512; i++) { file.writeShort(this.sizes[i] == 0 ? 0 : offset); file.writeShort(this.sizes[i]); file.writeInt(this.timestamps[i]); @@ -125,18 +127,18 @@ public class Region { } this.offset = offset; offset = 0; - for(int i = 0; i < 64; i++) { + for(int i = 0; i < 512; i++) { int size = this.sizes[i]; if(size == 0) { this.positions[i] = 0; continue; } - this.file.seek(512L + (long)(this.positions[i] << 8)); + this.file.seek(4096L + (long)(this.positions[i] << 8)); this.file.read(buffer, 0, size); file.write(buffer, 0, size); this.positions[i] = offset; offset += (size + 255) >> 8; - file.seek(512L + (long)(offset << 8)); + file.seek(4096L + (long)(offset << 8)); } file.close(); this.file.close(); @@ -145,7 +147,7 @@ public class Region { this.modified = false; } - private synchronized byte[] read(int x, int z) { + private synchronized byte[] read(int x, int y, int z) { if(this.timestamps[x + z * 8] == 0) return null; FileInputStream in = null; @@ -153,12 +155,12 @@ public class Region { // this.file.seek((long)(512 + (x + z * 8) * 8192)); int size = this.sizes[x + z * 8]; // this.file.readShort(); if(size > 8192 /* - 2 */ || size < 0) { - Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Größe bei " + x + ", " + z + ", überspringe"); + Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Größe bei " + x + ", " + y + ", " + z + ", überspringe"); return null; } byte[] data; if(size == 0) { - File expand = getExpansionFile(this.folder, this.xPos * 8 + x, this.zPos * 8 + z); + File expand = getExpansionFile(this.folder, this.xPos * 8 + x, this.yPos * 8 + y, this.zPos * 8 + z); if(!expand.exists()) { Log.JNI.warn("Chunk-Erweiterungs-Datei " + expand + " ist nicht vorhanden oder nicht lesbar, überspringe"); return null; @@ -182,11 +184,11 @@ public class Region { } else { int pos = this.positions[x + z * 8] << 8; - if(pos + size > this.file.length() - 512L || pos < 0) { - Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Position bei " + x + ", " + z + ", überspringe"); + if(pos + size > this.file.length() - 4096L || pos < 0) { + Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Position bei " + x + ", " + y + ", " + z + ", überspringe"); return null; } - this.file.seek(512L + (long)pos); + this.file.seek(4096L + (long)pos); data = new byte[size]; // - 2]; this.file.read(data); } @@ -200,14 +202,14 @@ public class Region { } catch(IOException e1) { } - Log.JNI.error(e, "Fehler beim lesen von Chunk-Region-Datei " + this.regFile + " bei " + x + ", " + z + ", überspringe"); + Log.JNI.error(e, "Fehler beim lesen von Chunk-Region-Datei " + this.regFile + " bei " + x + ", " + y + ", " + z + ", überspringe"); return null; } } - private synchronized void write(int x, int z, byte[] data, int size) { + private synchronized void write(int x, int y, int z, byte[] data, int size) { try { - if(((int)this.file.length() - 512) >= 1048576) + if(((int)this.file.length() - 4096) >= 1048576) this.reorganize(true); this.modified = true; // if(size >= 8192) @@ -216,7 +218,7 @@ public class Region { if(size /* + 2 */ > 8192) { FileOutputStream out = null; try { - out = new FileOutputStream(getExpansionFile(this.folder, this.xPos * 8 + x, this.zPos * 8 + z)); + out = new FileOutputStream(getExpansionFile(this.folder, this.xPos * 8 + x, this.yPos * 8 + y, this.zPos * 8 + z)); int remain = size; while(remain > 0) { int n = Math.min(remain, 8192); @@ -240,7 +242,7 @@ public class Region { else { pos = this.offset; this.offset += (size + 255) >> 8; - this.file.seek(512L + (long)(pos << 8)); // (512 + (x + z * 8) * 8192)); + this.file.seek(4096L + (long)(pos << 8)); // (512 + (x + z * 8) * 8192)); // this.file.writeShort(size); this.file.write(data, 0, size); } @@ -268,38 +270,38 @@ public class Region { } } - public long getTimestamp(int x, int z) { + public long getTimestamp(int x, int y, int z) { return (long)this.timestamps[x + z * 8] * 10000L; } - public void writeTag(int x, int z, NBTTagCompound tag) throws IOException { + public void writeTag(int x, int y, int z, NBTTagCompound tag) throws IOException { ChunkBuffer buf = new ChunkBuffer(); DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf)); NBTLoader.write(tag, out); out.close(); - this.write(x, z, buf.getData(), buf.size()); + this.write(x, y, z, buf.getData(), buf.size()); } public File getFile() { return this.regFile; } - private static synchronized Region getRegionFile(File dir, int x, int z) { - Region reg = CACHE.get(dir + "." + x + "." + z); + private static synchronized Region getRegionFile(File dir, int x, int y, int z) { + Region reg = CACHE.get(dir + "." + x + "." + y + "." + z); if(reg != null) return reg; if(CACHE.size() >= 256) clearCache(false); - Region nreg = new Region(dir, x, z); - CACHE.put(dir + "." + x + "." + z, nreg); + Region nreg = new Region(dir, x, y, z); + CACHE.put(dir + "." + x + "." + y + "." + z, nreg); return nreg; } - private static File getExpansionFile(File dir, int x, int z) { - File sdir = new File(dir, Util.getRegionFolder(x, z)); + private static File getExpansionFile(File dir, int x, int y, int z) { + File sdir = new File(dir, Util.getRegionFolder(x, y, z)); if(!sdir.exists()) sdir.mkdirs(); - return new File(sdir, String.format("c.%c%X%c%X.chk", x < 0 ? 'n' : 'p', (x < 0) ? -x : x, z < 0 ? 'n' : 'p', (z < 0) ? -z : z)); + return new File(sdir, String.format("c.%c%X%c%X%c%X.chk", x < 0 ? 'n' : 'p', (x < 0) ? -x : x, y < 0 ? 'n' : 'p', (y < 0) ? -y : y, z < 0 ? 'n' : 'p', (z < 0) ? -z : z)); } private static synchronized void clearCache(boolean all) { @@ -342,52 +344,33 @@ public class Region { clearCache(true); } - public static /* synchronized */ NBTTagCompound readChunk(File dir, int x, int z) throws IOException { -// return getRegionFile(dir, x >> 3, z >> 3).readTag(x & 7, z & 7); - byte[] data = getRegionFile(dir, x >> 3, z >> 3).read(x & 7, z & 7); + public static /* synchronized */ NBTTagCompound readChunk(File dir, int x, int y, int z) throws IOException { + byte[] data = getRegionFile(dir, x >> 3, y >> 3, z >> 3).read(x & 7, y & 7, z & 7); if(data == null) return null; return NBTLoader.read(new DataInputStream(new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(data))))); } - public static /* synchronized */ void writeChunk(File dir, int x, int z, NBTTagCompound tag) throws IOException { + public static /* synchronized */ void writeChunk(File dir, int x, int y, int z, NBTTagCompound tag) throws IOException { ChunkBuffer buf = new ChunkBuffer(); DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf)); NBTLoader.write(tag, out); out.close(); - getRegionFile(dir, x >> 3, z >> 3).write(x & 7, z & 7, buf.getData(), buf.size()); -// getRegionFile(dir, x >> 3, z >> 3).writeTag(x & 7, z & 7, tag); + getRegionFile(dir, x >> 3, y >> 3, z >> 3).write(x & 7, y & 7, z & 7, buf.getData(), buf.size()); } - public static Chunk readNbt(WorldServer world, int x, int z, NBTTagCompound tag) { -// if(!tag.hasKey("Level", 10)) { -// Log.error("Chunk-Datei bei " + x + "," + z + " hat keine Level-Daten, überspringe"); -// return null; -// } -// tag = tag.getCompoundTag("Level"); - if(!tag.hasKey("Sections", 9)) { - Log.JNI.warn("Chunk-Datei bei " + x + "," + z + " hat keine Block-Daten, überspringe"); - return null; - } - Chunk chunk = new Chunk(world, x, z); - chunk.setHeights(tag.getIntArray("HeightMap")); + public static Chunk readNbt(WorldServer world, int x, int y, int z, NBTTagCompound tag) { + Chunk chunk = new Chunk(world, x, y, z); chunk.setTerrainPopulated(tag.getBoolean("TerrainPopulated")); - chunk.setLightPopulated(tag.getBoolean("LightPopulated")); chunk.setInhabited(tag.getLong("InhabitedTime")); - NBTTagList sects = tag.getTagList("Sections", 10); - int stor = 32; - BlockArray[] sections = new BlockArray[stor]; - boolean light = !world.dimension.hasNoLight(); - for(int n = 0; n < sects.tagCount(); ++n) { - NBTTagCompound sect = sects.getCompoundTagAt(n); - int y = sect.getByte("Y"); - BlockArray storage = new BlockArray(y << 4, light); - byte[] blocks = sect.getByteArray("Blocks"); - NibbleArray data = new NibbleArray(sect.getByteArray("Data")); - NibbleArray adddata = sect.hasKey("Add", 7) ? new NibbleArray(sect.getByteArray("Add")) : null; + if(tag.hasKey("Blocks", 7)) { + BlockArray storage = new BlockArray(); + byte[] blocks = tag.getByteArray("Blocks"); + NibbleArray data = new NibbleArray(tag.getByteArray("Data")); + NibbleArray adddata = tag.hasKey("Add", 7) ? new NibbleArray(tag.getByteArray("Add")) : null; char[] seg = new char[blocks.length]; - + for(int c = 0; c < seg.length; ++c) { int cx = c & 15; int cy = c >> 8 & 15; @@ -395,22 +378,13 @@ public class Region { int ca = adddata != null ? adddata.get(cx, cy, cz) : 0; seg[c] = (char)(ca << 12 | (blocks[c] & 255) << 4 | data.get(cx, cy, cz)); } - + storage.setData(seg); - storage.setBlocklight(new NibbleArray(sect.getByteArray("BlockLight"))); - - if(light) { - storage.setSkylight(new NibbleArray(sect.getByteArray("SkyLight"))); - } - + storage.setBlocklight(new NibbleArray(tag.getByteArray("BlockLight"))); + storage.update(); - sections[y] = storage; - } - - chunk.setStorage(sections); - - if(tag.hasKey("Biomes", 7)) { - chunk.setBiomes(tag.getByteArray("Biomes")); + + chunk.setStorage(storage); } NBTTagList entities = tag.getTagList("Entities", 10); @@ -490,73 +464,52 @@ public class Region { NBTTagCompound tag = new NBTTagCompound(); // tag.setShort("V", (short)Config.PROTOCOL); tag.setLong("LastUpdate", world.getTime()); - tag.setIntArray("HeightMap", chunk.getHeights()); tag.setBoolean("TerrainPopulated", chunk.isTerrainPopulated()); - tag.setBoolean("LightPopulated", chunk.isLightPopulated()); tag.setLong("InhabitedTime", chunk.getInhabited()); - BlockArray[] sections = chunk.getStorage(); - NBTTagList sects = new NBTTagList(); - boolean light = !world.dimension.hasNoLight(); - for(BlockArray storage : sections) { - if(storage != null) { - NBTTagCompound sect = new NBTTagCompound(); - sect.setByte("Y", (byte)(storage.getY() >> 4 & 511)); - byte[] blocks = new byte[storage.getData().length]; - NibbleArray data = new NibbleArray(); - NibbleArray adddata = null; + BlockArray storage = chunk.getStorage(); + if(storage != null) { + byte[] blocks = new byte[storage.getData().length]; + NibbleArray data = new NibbleArray(); + NibbleArray adddata = null; - for(int c = 0; c < storage.getData().length; ++c) { - char cd = storage.getData()[c]; - int cx = c & 15; - int cy = c >> 8 & 15; - int cz = c >> 4 & 15; + for(int c = 0; c < storage.getData().length; ++c) { + char cd = storage.getData()[c]; + int cx = c & 15; + int cy = c >> 8 & 15; + int cz = c >> 4 & 15; - if(cd >> 12 != 0) { - if(adddata == null) { - adddata = new NibbleArray(); - } - - adddata.set(cx, cy, cz, cd >> 12); + if(cd >> 12 != 0) { + if(adddata == null) { + adddata = new NibbleArray(); } - blocks[c] = (byte)(cd >> 4 & 255); - data.set(cx, cy, cz, cd & 15); + adddata.set(cx, cy, cz, cd >> 12); } - sect.setByteArray("Blocks", blocks); - sect.setByteArray("Data", data.getData()); - - if(adddata != null) { - sect.setByteArray("Add", adddata.getData()); - } - - sect.setByteArray("BlockLight", storage.getBlocklight().getData()); - - if(light) { - sect.setByteArray("SkyLight", storage.getSkylight().getData()); - } - else { - sect.setByteArray("SkyLight", new byte[storage.getBlocklight().getData().length]); - } - - sects.appendTag(sect); + blocks[c] = (byte)(cd >> 4 & 255); + data.set(cx, cy, cz, cd & 15); } + + tag.setByteArray("Blocks", blocks); + tag.setByteArray("Data", data.getData()); + + if(adddata != null) { + tag.setByteArray("Add", adddata.getData()); + } + + tag.setByteArray("BlockLight", storage.getBlocklight().getData()); } - tag.setTag("Sections", sects); - tag.setByteArray("Biomes", chunk.getBiomes()); chunk.setHasEntities(false); NBTTagList entities = new NBTTagList(); - for(int n = 0; n < chunk.getEntities().length; ++n) { - for(Entity entity : chunk.getEntities()[n]) { - NBTTagCompound ent = new NBTTagCompound(); + for(Entity entity : chunk.getEntities()) { + NBTTagCompound ent = new NBTTagCompound(); - if(entity.writeToNBTOptional(ent)) { - chunk.setHasEntities(true); - entities.appendTag(ent); - } + if(entity.writeToNBTOptional(ent)) { + chunk.setHasEntities(true); + entities.appendTag(ent); } } diff --git a/server/src/server/world/Spawner.java b/server/src/server/world/Spawner.java index 5133cf3..f454420 100755 --- a/server/src/server/world/Spawner.java +++ b/server/src/server/world/Spawner.java @@ -62,7 +62,7 @@ public abstract class Spawner { for(int cx = -range; cx <= range; ++cx) { for(int cz = -range; cz <= range; ++cz) { boolean flag = cx == -range || cx == range || cz == -range || cz == range; - ChunkPos coord = new ChunkPos(cx + x, cz + z); + ChunkPos coord = new ChunkPos(cx + x, 0, cz + z); if(!CHUNKS.contains(coord)) { ++locs; if(!flag && coord.x << 4 >= -World.MAX_SIZE + 64 && coord.z << 4 >= -World.MAX_SIZE + 64 @@ -87,15 +87,14 @@ public abstract class Spawner { if(cur <= max) { typeLabel: for(ChunkPos coord : CHUNKS) { - Chunk chunk = world.getChunk(coord.x, coord.z); int x = coord.x * 16 + world.rand.zrange(16); int z = coord.z * 16 + world.rand.zrange(16); - int h = chunk.getHeight(new BlockPos(x, 0, z)) + 1; + int h = world.getHeight(new BlockPos(x, 0, z)).getY() + 1; if(h > 0) { int m = h % 16; h = m == 0 ? h : h + 16 - m; } - h = h == 0 ? 16 : (h > 0 ? h : chunk.getTopSegment() + 16 - 1); + h = h <= 0 ? 16 : h; int y = world.rand.excl(h <= 8 ? 0 : 8, h); BlockPos pos = new BlockPos(x, y, z); Block block = world.getState(pos).getBlock(); diff --git a/server/src/server/world/WorldServer.java b/server/src/server/world/WorldServer.java index 84c1cf1..7894954 100755 --- a/server/src/server/world/WorldServer.java +++ b/server/src/server/world/WorldServer.java @@ -76,7 +76,6 @@ import common.world.BlockArray; import common.world.Chunk; import common.world.Explosion; import common.world.AWorldServer; -import common.world.LightType; import common.world.State; import common.world.Weather; import common.world.World; @@ -162,13 +161,10 @@ public final class WorldServer extends AWorldServer { private BlockReplacer replacer; private FeatureDungeons dungeons; private State liquid; - private State base; - private State ceil; private FeatureOres[] ores; private FeatureLakes[] lakes; private FeatureLiquids[] liquids; private long seed; - private int height; private int seaLevel; private boolean mobs; private boolean snow; @@ -341,8 +337,6 @@ public final class WorldServer extends AWorldServer { this.caveGen = null; this.bigCaveGen = null; this.ravineGen = null; - this.base = null; - this.ceil = null; this.mobs = false; this.snow = false; this.strongholdGen = null; @@ -422,8 +416,6 @@ public final class WorldServer extends AWorldServer { this.caveGen = this.createCaveGenerator(); this.bigCaveGen = this.createBigCaveGenerator(); this.ravineGen = this.createRavineGenerator(); - this.base = this.dimension.getWorldFloor(); - this.ceil = this.dimension.getWorldCeiling(); this.mobs = this.dimension.hasMobs(); this.snow = this.dimension.hasSnow(); this.strongholdGen = this.dimension.hasStrongholds() ? new MapGenStronghold() : null; @@ -437,7 +429,6 @@ public final class WorldServer extends AWorldServer { this.liquids = this.createLiquids(); this.dungeons = this.createDungeonGenerator(); } - this.height = this.generator.getMaximumHeight(); // this.teleporter = new Teleporter(this); this.calculateInitialSkylight(); this.calculateInitialWeather(); @@ -624,10 +615,7 @@ public final class WorldServer extends AWorldServer { } public Biome getBiomeGenForCoords(final BlockPos pos) { - if(this.isBlockLoaded(pos)) - return this.getChunk(pos).getBiome(pos, this.biomeGen); - else - return this.biomeGen.getBiomeGenerator(pos, Biome.DEF_BIOME); + return this.biomeGen.getBiomeGenerator(pos, Biome.DEF_BIOME); } public void setItemData(String dataID, WorldSavedData worldSavedDataIn) { @@ -644,15 +632,13 @@ public final class WorldServer extends AWorldServer { if(this.debug) { for(ChunkPos chunkcoordintpair1 : this.active) { - this.getChunk(chunkcoordintpair1.x, chunkcoordintpair1.z).update(false); + this.getChunk(chunkcoordintpair1.x, chunkcoordintpair1.z).update(); } } else { - int i = 0; - int j = 0; - for(ChunkPos chunkcoordintpair : this.active) { int k = chunkcoordintpair.x * 16; + int n = chunkcoordintpair.y * 16; int l = chunkcoordintpair.z * 16; // this.profiler.start("getChunk"); Chunk chunk = this.getChunk(chunkcoordintpair.x, chunkcoordintpair.z); @@ -661,7 +647,7 @@ public final class WorldServer extends AWorldServer { // this.profiler.next("checkLight"); chunk.enqueueRelight(); // this.profiler.next("tickChunk"); - chunk.update(false); + chunk.update(); // this.profiler.next("thunder"); int l2 = Config.boltChance; @@ -679,10 +665,10 @@ public final class WorldServer extends AWorldServer { l2 = Config.weatherTick; for(int z = 0; z < l2; z++) { - if(this.rand.zrange(16) == 0) { + if(this.rand.chance(16 * 32)) { this.updateLCG = this.updateLCG * 3 + 1013904223; int k2 = this.updateLCG >> 2; - BlockPos blockpos2 = this.getPrecipitationHeight(new BlockPos(k + (k2 & 15), 0, l + (k2 >> 8 & 15))); + BlockPos blockpos2 = this.getHeight(new BlockPos(k + (k2 & 15), 0, l + (k2 >> 8 & 15))); BlockPos blockpos1 = blockpos2.down(); if(this.canBlockFreeze(blockpos1, true)) { @@ -711,24 +697,21 @@ public final class WorldServer extends AWorldServer { // this.profiler.next("tickBlocks"); l2 = Config.randomTick; - if(l2 > 0) { - for(BlockArray extendedblockstorage : chunk.getStorage()) { - if(extendedblockstorage != null && extendedblockstorage.isTicked()) { - for(int j1 = 0; j1 < l2; ++j1) { - this.updateLCG = this.updateLCG * 3 + 1013904223; - int k1 = this.updateLCG >> 2; - int l1 = k1 & 15; - int i2 = k1 >> 8 & 15; - int j2 = k1 >> 16 & 15; - ++j; - State iblockstate = extendedblockstorage.get(l1, j2, i2); - Block block = iblockstate.getBlock(); + if(l2 > 0 && this.rand.chance(32)) { + BlockArray extendedblockstorage = chunk.getStorage(); + if(extendedblockstorage != null && extendedblockstorage.isTicked()) { + for(int j1 = 0; j1 < l2; ++j1) { + this.updateLCG = this.updateLCG * 3 + 1013904223; + int k1 = this.updateLCG >> 2; + int l1 = k1 & 15; + int i2 = k1 >> 8 & 15; + int j2 = k1 >> 16 & 15; + State iblockstate = extendedblockstorage.get(l1, j2, i2); + Block block = iblockstate.getBlock(); - if(block.getTickRandomly()) { - ++i; - block.randomTick(this, new BlockPos(l1 + k, j2 + extendedblockstorage.getY(), i2 + l), iblockstate, - this.rand); - } + if(block.getTickRandomly()) { + block.randomTick(this, new BlockPos(l1 + k, j2 + n, i2 + l), iblockstate, + this.rand); } } } @@ -740,12 +723,12 @@ public final class WorldServer extends AWorldServer { } private BlockPos adjustPosToNearbyEntity(BlockPos pos) { - BlockPos blockpos = this.getPrecipitationHeight(pos); + BlockPos blockpos = this.getHeight(pos); BoundingBox axisalignedbb = (new BoundingBox(blockpos, new BlockPos(blockpos.getX(), World.HEIGHT, blockpos.getZ()))).expand(3.0D, 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() && p_apply_1_.getPosition().getY() >= blockpos.getY(); } }); return !list.isEmpty() ? ((EntityLiving)list.get(this.rand.zrange(list.size()))).getPosition() : blockpos; @@ -1374,9 +1357,9 @@ public final class WorldServer extends AWorldServer { return chunk; } - private Chunk loadChunkFromFile(int x, int z) { + private Chunk loadChunkFromFile(int x, int y, int z) { try { - ChunkPos coord = new ChunkPos(x, z); + ChunkPos coord = new ChunkPos(x, y, z); NBTTagCompound tag = this.toRemove.get(coord); if(tag == null) { tag = Region.readChunk(this.chunkDir, x, z); @@ -1529,10 +1512,10 @@ public final class WorldServer extends AWorldServer { } } - private void populate(int x, int z) { - Chunk chunk = this.getChunk(x, z); + private void populate(int x, int y, int z) { + Chunk chunk = this.getChunk(x, y, z); if(!chunk.isTerrainPopulated()) { - chunk.checkLight(); + chunk.setTerrainPopulated(true); BlockFalling.fallInstantly = true; int bx = x * 16; int bz = z * 16; @@ -1543,7 +1526,7 @@ public final class WorldServer extends AWorldServer { long sz = this.grng.longv() / 2L * 2L + 1L; this.grng.setSeed((long)x * sx + (long)z * sz ^ this.seed); boolean lakes = true; - ChunkPos coord = new ChunkPos(x, z); + ChunkPos coord = new ChunkPos(x, y, z); if(this.bridgeGen != null) { this.bridgeGen.generateStructure(this, this.grng, coord); } @@ -1587,7 +1570,7 @@ public final class WorldServer extends AWorldServer { pos = pos.add(8, 0, 8); for(int fx = 0; fx < 16; ++fx) { for(int fz = 0; fz < 16; ++fz) { - BlockPos snow = this.getPrecipitationHeight(pos.add(fx, 0, fz)); + BlockPos snow = this.getHeight(pos.add(fx, 0, fz)); BlockPos ice = snow.down(); if(this.canBlockFreeze(ice, false)) { this.setState(ice, Blocks.ice.getState(), 2); @@ -1603,9 +1586,9 @@ public final class WorldServer extends AWorldServer { } } - private Chunk generate(int x, int z) { + private Chunk generate(int x, int y, int z) { this.grng.setSeed((long)x * 341873128712L + (long)z * 132897987541L); - ChunkPrimer primer = new ChunkPrimer(this.height); + ChunkPrimer primer = new ChunkPrimer(); this.generator.generateChunk(this, x, z, primer); this.biomeGen.getChunkBiomes(this.biomes, x * 16, z * 16, 16, 16); if(this.replacer != null) { @@ -1635,7 +1618,7 @@ public final class WorldServer extends AWorldServer { if(this.scatteredGen != null) { this.scatteredGen.generate(this, x, z, primer); } - return new Chunk(this, primer.getData(), primer.height, this.base, this.ceil, this.grng, this.biomes, x, z); + return new Chunk(this, primer.getData(), x, y, z); } public boolean isExterminated() { @@ -1685,15 +1668,15 @@ public final class WorldServer extends AWorldServer { long pos = LongHashMap.packInt(chunk.xPos, chunk.zPos); chunk.onChunkUnload(); this.chunks.remove(pos); - chunk = this.generate(chunk.xPos, chunk.zPos); + chunk = this.generate(chunk.xPos, chunk.yPos, chunk.zPos); this.chunks.add(pos, chunk); this.loaded.add(chunk); chunk.onChunkLoad(); - chunk.checkLight(); + chunk.setTerrainPopulated(true); chunk.setModified(); } for(Chunk chunk : this.loaded) { - chunk.update(false); + chunk.update(); } this.entities.removeAll(this.unloaded); for(int l = 0; l < this.unloaded.size(); ++l) { @@ -1745,9 +1728,6 @@ public final class WorldServer extends AWorldServer { this.replacer = null; this.populate = false; this.liquid = Blocks.air.getState(); - this.base = Blocks.air.getState(); - this.ceil = null; - this.height = this.generator.getMaximumHeight(); this.seaLevel = this.dimension.getSeaLevel(); this.ores = null; this.lakes = null; @@ -1869,17 +1849,6 @@ public final class WorldServer extends AWorldServer { return this.instances.getValueByKey(v) != null; } - public boolean updateBiomes(int chunkX, int chunkZ) { - long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32; - PlayerInstance ins = this.instances.getValueByKey(v); - if(ins == null) - return false; - Chunk chunk = this.getChunk(chunkX, chunkZ); - chunk.setModified(); - ins.sendToAllPlayersWatchingChunk(new SPacketBiomes(chunkX, chunkZ, chunk.getBiomes())); - return true; - } - private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) { long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32; PlayerInstance inst = this.instances.getValueByKey(v); @@ -2245,29 +2214,6 @@ public final class WorldServer extends AWorldServer { // return new LazyBlock(state, this, position); // } - public final boolean setBiome(BlockPos position, Biome biome) { - Chunk chunk = this.getChunk(position); - if((chunk != null) && (chunk.isLoaded())) { - chunk.getBiomes()[((position.getZ() & 0xF) << 4 | position.getX() & 0xF)] = (byte)biome.id; - return true; - } - return false; - } - - public final void setBiomes(BlockPos start, BlockPos end, Biome biome) { - Set chunks = Sets.newHashSet(); - for(int x = start.getX(); x <= end.getX(); x++) { - for(int z = start.getZ(); z <= end.getZ(); z++) { - if(this.setBiome(new BlockPos(x, 0, z), biome)) - chunks.add(new ChunkPos(x >> 4, z >> 4)); - } - } - for(ChunkPos pos : chunks) { - this.updateBiomes(pos.x, pos.z); - } - chunks.clear(); - } - // public final List getEntities(EditRegion region) { // List entities = Lists.newArrayList(); // for(Entity entity : this.entities) { @@ -2304,10 +2250,7 @@ public final class WorldServer extends AWorldServer { } public boolean canStrikeAt(BlockPos strikePosition) { - if(!this.canSeeSky(strikePosition)) { - return false; - } - else if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) { + if(this.getHeight(strikePosition).getY() > strikePosition.getY()) { return false; } return true; @@ -2380,7 +2323,7 @@ public final class WorldServer extends AWorldServer { return false; } else { - if(pos.getY() >= 0 && pos.getY() < 512 && this.getLightFor(LightType.BLOCK, pos) < 10) { + if(pos.getY() >= 0 && pos.getY() < 512 && this.getLightFor(pos) < 10) { State iblockstate = this.getState(pos); Block block = iblockstate.getBlock(); diff --git a/server/src/server/worldgen/ChunkPrimer.java b/server/src/server/worldgen/ChunkPrimer.java index 7372177..8405359 100755 --- a/server/src/server/worldgen/ChunkPrimer.java +++ b/server/src/server/worldgen/ChunkPrimer.java @@ -5,12 +5,10 @@ import common.init.Blocks; import common.world.State; public class ChunkPrimer { - public final int height; private final short[] data; - public ChunkPrimer(int height) { - this.data = new short[Math.max(height, 256) * 256]; - this.height = height; + public ChunkPrimer() { + this.data = new short[4096]; } public short[] getData() { diff --git a/server/src/server/worldgen/FeatureLakes.java b/server/src/server/worldgen/FeatureLakes.java index 98fe8bd..1f4e2c1 100755 --- a/server/src/server/worldgen/FeatureLakes.java +++ b/server/src/server/worldgen/FeatureLakes.java @@ -5,7 +5,6 @@ import common.init.Blocks; import common.material.Material; import common.rng.Random; import common.util.BlockPos; -import common.world.LightType; import common.world.State; import server.biome.GenBiome; import server.world.WorldServer; @@ -161,7 +160,7 @@ public class FeatureLakes { BlockPos blockpos = position.add(i2, j4 - 1, j3); - if (worldIn.getState(blockpos).getBlock() == replace && worldIn.getLightFor(LightType.SKY, position.add(i2, j4, j3)) > 0) + if (worldIn.getState(blockpos).getBlock() == replace && worldIn.isAirBlock(position.add(i2, j4, j3))) { GenBiome biomegenbase = GenBiome.BIOMES[worldIn.getBiomeGenForCoords(blockpos).id];