diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java index 4a4fdce..42de3ce 100755 --- a/client/src/client/network/ClientPlayer.java +++ b/client/src/client/network/ClientPlayer.java @@ -780,7 +780,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); ChunkClient chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ()); - chunk.setBiomes(packetIn.getBiomes()); + chunk.setBiome(packetIn.getPos(), packetIn.getBiome()); this.clientWorldController.markBlockRangeForRenderUpdate(packetIn.getChunkX() << 4, -World.MAX_SIZE_Y, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, World.MAX_SIZE_Y, (packetIn.getChunkZ() << 4) + 15); } diff --git a/client/src/client/world/ChunkClient.java b/client/src/client/world/ChunkClient.java index a016246..8f59b89 100644 --- a/client/src/client/world/ChunkClient.java +++ b/client/src/client/world/ChunkClient.java @@ -133,6 +133,10 @@ public class ChunkClient extends Chunk { int z = pos.getZ() & 15; return Biome.getBiomeDef(this.biomes[z << 4 | x] & 255); } + + public void setBiome(BlockPos pos, Biome biome) { + this.biomes[((pos.getZ() & 15) << 4 | pos.getX() & 15)] = (byte)biome.id; + } public boolean isDummy() { return false; diff --git a/client/src/client/world/ChunkEmpty.java b/client/src/client/world/ChunkEmpty.java index 31a78d2..1b03600 100755 --- a/client/src/client/world/ChunkEmpty.java +++ b/client/src/client/world/ChunkEmpty.java @@ -107,7 +107,7 @@ public class ChunkEmpty extends ChunkClient { return Biome.DEF_BIOME; } - public void setBiomes(byte[] biomes) { + public void setBiome(BlockPos pos, Biome biome) { } public void resetRelight() { diff --git a/common/src/common/packet/SPacketBiomes.java b/common/src/common/packet/SPacketBiomes.java index 3d83aed..9cb7ef3 100755 --- a/common/src/common/packet/SPacketBiomes.java +++ b/common/src/common/packet/SPacketBiomes.java @@ -2,34 +2,36 @@ package common.packet; import java.io.IOException; +import common.biome.Biome; import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; +import common.util.BlockPos; public class SPacketBiomes implements Packet { - private int chunkX; - private int chunkZ; - private byte[] biomes; + private int posX; + private int posZ; + private Biome biome; public SPacketBiomes() { } - public SPacketBiomes(int chunkX, int chunkZ, byte[] biomes) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.biomes = biomes; + public SPacketBiomes(BlockPos pos, Biome biome) { + this.posX = pos.getX(); + this.posZ = pos.getZ(); + this.biome = biome; } public void readPacketData(PacketBuffer buf) throws IOException { - this.chunkX = buf.readInt(); - this.chunkZ = buf.readInt(); - buf.readBytes(this.biomes = new byte[256]); + this.posX = buf.readInt(); + this.posZ = buf.readInt(); + this.biome = buf.readEnumValue(Biome.class); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeInt(this.chunkX); - buf.writeInt(this.chunkZ); - buf.writeBytes(this.biomes); + buf.writeInt(this.posX); + buf.writeInt(this.posZ); + buf.writeEnumValue(this.biome); } public void processPacket(IClientPlayer handler) { @@ -37,14 +39,18 @@ public class SPacketBiomes implements Packet { } public int getChunkX() { - return this.chunkX; + return this.posX >> 4; } public int getChunkZ() { - return this.chunkZ; + return this.posZ >> 4; + } + + public BlockPos getPos() { + return new BlockPos(this.posX, 0, this.posZ); } - public byte[] getBiomes() { - return this.biomes; + public Biome getBiome() { + return this.biome; } } diff --git a/common/src/common/world/Chunk.java b/common/src/common/world/Chunk.java index 841292b..3210d9f 100755 --- a/common/src/common/world/Chunk.java +++ b/common/src/common/world/Chunk.java @@ -686,17 +686,6 @@ public abstract class Chunk { return this.updated && this.populated && this.lightInit; } - 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; } diff --git a/server/src/server/world/ChunkServer.java b/server/src/server/world/ChunkServer.java index 15ee816..675ec10 100644 --- a/server/src/server/world/ChunkServer.java +++ b/server/src/server/world/ChunkServer.java @@ -159,6 +159,17 @@ public class ChunkServer extends Chunk { 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 int[] getHeights() { return this.height; } diff --git a/server/src/server/world/WorldServer.java b/server/src/server/world/WorldServer.java index 46f8957..037b7cd 100755 --- a/server/src/server/world/WorldServer.java +++ b/server/src/server/world/WorldServer.java @@ -1874,15 +1874,18 @@ public final class WorldServer extends AWorldServer { return this.instances.getValueByKey(v) != null; } - public boolean updateBiomes(int chunkX, int chunkZ) { + public void setBiome(BlockPos pos, Biome biome) { + ChunkServer chunk = this.getChunk(pos); + if(chunk == null || !chunk.isLoaded()) + return; + chunk.getBiomes()[((pos.getZ() & 0xF) << 4 | pos.getX() & 0xF)] = (byte)biome.id; + chunk.setModified(true); + int chunkX = pos.getX() >> 4; + int chunkZ = pos.getZ() >> 4; long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32; PlayerInstance ins = this.instances.getValueByKey(v); - if(ins == null) - return false; - ChunkServer chunk = this.getChunk(chunkX, chunkZ); - chunk.setModified(true); - ins.sendToAllPlayersWatchingChunk(new SPacketBiomes(chunkX, chunkZ, chunk.getBiomes())); - return true; + if(ins != null) + ins.sendToAllPlayersWatchingChunk(new SPacketBiomes(pos, biome)); } private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) { @@ -2244,50 +2247,7 @@ public final class WorldServer extends AWorldServer { return new ClipboardBlock(state); } } - -// public final EditBlock getLazyBlock(Vector position) { -// State state = this.getState(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ())); -// return new LazyBlock(state, this, position); -// } - - private final boolean setChunkBiome(BlockPos position, Biome biome) { - ChunkServer 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.setChunkBiome(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 void setBiome(BlockPos pos, Biome biome) { - if(this.setChunkBiome(pos, biome)) - this.updateBiomes(pos.getX() >> 4, pos.getZ() >> 4); - } - -// public final List getEntities(EditRegion region) { -// List entities = Lists.newArrayList(); -// for(Entity entity : this.entities) { -// if(region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) { -// entities.add(entity); -// } -// } -// return entities; -// } - public final List getEntities() { List entities = Lists.newArrayList(); for(Entity entity : this.entities) {