change biome packet
This commit is contained in:
parent
88c43d0824
commit
ffca1f62e5
7 changed files with 50 additions and 80 deletions
|
@ -780,7 +780,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
|
||||||
{
|
{
|
||||||
NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController);
|
NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController);
|
||||||
ChunkClient chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,10 @@ public class ChunkClient extends Chunk {
|
||||||
return Biome.getBiomeDef(this.biomes[z << 4 | x] & 255);
|
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() {
|
public boolean isDummy() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class ChunkEmpty extends ChunkClient {
|
||||||
return Biome.DEF_BIOME;
|
return Biome.DEF_BIOME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiomes(byte[] biomes) {
|
public void setBiome(BlockPos pos, Biome biome) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetRelight() {
|
public void resetRelight() {
|
||||||
|
|
|
@ -2,34 +2,36 @@ package common.packet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import common.biome.Biome;
|
||||||
import common.network.IClientPlayer;
|
import common.network.IClientPlayer;
|
||||||
import common.network.Packet;
|
import common.network.Packet;
|
||||||
import common.network.PacketBuffer;
|
import common.network.PacketBuffer;
|
||||||
|
import common.util.BlockPos;
|
||||||
|
|
||||||
public class SPacketBiomes implements Packet<IClientPlayer> {
|
public class SPacketBiomes implements Packet<IClientPlayer> {
|
||||||
private int chunkX;
|
private int posX;
|
||||||
private int chunkZ;
|
private int posZ;
|
||||||
private byte[] biomes;
|
private Biome biome;
|
||||||
|
|
||||||
public SPacketBiomes() {
|
public SPacketBiomes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPacketBiomes(int chunkX, int chunkZ, byte[] biomes) {
|
public SPacketBiomes(BlockPos pos, Biome biome) {
|
||||||
this.chunkX = chunkX;
|
this.posX = pos.getX();
|
||||||
this.chunkZ = chunkZ;
|
this.posZ = pos.getZ();
|
||||||
this.biomes = biomes;
|
this.biome = biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||||
this.chunkX = buf.readInt();
|
this.posX = buf.readInt();
|
||||||
this.chunkZ = buf.readInt();
|
this.posZ = buf.readInt();
|
||||||
buf.readBytes(this.biomes = new byte[256]);
|
this.biome = buf.readEnumValue(Biome.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||||
buf.writeInt(this.chunkX);
|
buf.writeInt(this.posX);
|
||||||
buf.writeInt(this.chunkZ);
|
buf.writeInt(this.posZ);
|
||||||
buf.writeBytes(this.biomes);
|
buf.writeEnumValue(this.biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPacket(IClientPlayer handler) {
|
public void processPacket(IClientPlayer handler) {
|
||||||
|
@ -37,14 +39,18 @@ public class SPacketBiomes implements Packet<IClientPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChunkX() {
|
public int getChunkX() {
|
||||||
return this.chunkX;
|
return this.posX >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChunkZ() {
|
public int getChunkZ() {
|
||||||
return this.chunkZ;
|
return this.posZ >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBiomes() {
|
public BlockPos getPos() {
|
||||||
return this.biomes;
|
return new BlockPos(this.posX, 0, this.posZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Biome getBiome() {
|
||||||
|
return this.biome;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -686,17 +686,6 @@ public abstract class Chunk {
|
||||||
return this.updated && this.populated && this.lightInit;
|
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() {
|
public void resetRelight() {
|
||||||
this.lightChecks = 0;
|
this.lightChecks = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,17 @@ public class ChunkServer extends Chunk {
|
||||||
return this.biomes;
|
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() {
|
public int[] getHeights() {
|
||||||
return this.height;
|
return this.height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1874,15 +1874,18 @@ public final class WorldServer extends AWorldServer {
|
||||||
return this.instances.getValueByKey(v) != null;
|
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;
|
long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32;
|
||||||
PlayerInstance ins = this.instances.getValueByKey(v);
|
PlayerInstance ins = this.instances.getValueByKey(v);
|
||||||
if(ins == null)
|
if(ins != null)
|
||||||
return false;
|
ins.sendToAllPlayersWatchingChunk(new SPacketBiomes(pos, biome));
|
||||||
ChunkServer chunk = this.getChunk(chunkX, chunkZ);
|
|
||||||
chunk.setModified(true);
|
|
||||||
ins.sendToAllPlayersWatchingChunk(new SPacketBiomes(chunkX, chunkZ, chunk.getBiomes()));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) {
|
private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) {
|
||||||
|
@ -2245,49 +2248,6 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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<ChunkPos> 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<? extends Entity> getEntities(EditRegion region) {
|
|
||||||
// List<Entity> 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<? extends Entity> getEntities() {
|
public final List<? extends Entity> getEntities() {
|
||||||
List<Entity> entities = Lists.newArrayList();
|
List<Entity> entities = Lists.newArrayList();
|
||||||
for(Entity entity : this.entities) {
|
for(Entity entity : this.entities) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue