change biome packet

This commit is contained in:
Sen 2025-05-24 18:49:24 +02:00
parent 88c43d0824
commit ffca1f62e5
7 changed files with 50 additions and 80 deletions

View file

@ -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);
}

View file

@ -134,6 +134,10 @@ public class ChunkClient extends Chunk {
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;
}

View file

@ -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() {

View file

@ -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<IClientPlayer> {
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<IClientPlayer> {
}
public int getChunkX() {
return this.chunkX;
return this.posX >> 4;
}
public int getChunkZ() {
return this.chunkZ;
return this.posZ >> 4;
}
public byte[] getBiomes() {
return this.biomes;
public BlockPos getPos() {
return new BlockPos(this.posX, 0, this.posZ);
}
public Biome getBiome() {
return this.biome;
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {
@ -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() {
List<Entity> entities = Lists.newArrayList();
for(Entity entity : this.entities) {