split chunk class into server and client

This commit is contained in:
Sen 2025-05-24 18:18:04 +02:00
parent 7126ca5a9f
commit 71e50743fd
35 changed files with 734 additions and 715 deletions

View file

@ -94,6 +94,7 @@ import client.window.Keysym;
import client.window.Wheel;
import client.window.Window;
import client.window.WindowEvent;
import client.world.ChunkClient;
import client.world.WorldClient;
import common.biome.Biome;
import common.block.Block;
@ -156,7 +157,6 @@ import common.util.HitPosition;
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;
@ -1735,8 +1735,8 @@ public class Client implements IThreadListener {
String bline;
String lline;
if(this.world.isBlockLoaded(blockpos)) {
Chunk chunk = this.world.getChunk(blockpos);
biome = chunk.getBiome(blockpos, null);
ChunkClient chunk = this.world.getChunk(blockpos);
biome = chunk.getBiome(blockpos);
bline = "Biom: " + biome.display + " (" + biome.id + ")" + /* (this.debugHideInfo ? "" : */ (", D: " +
TextColor.stripCodes(this.world.dimension.getFormattedName(false)) +
" (" + this.world.dimension.getDimensionId() + ")");

View file

@ -28,6 +28,7 @@ import client.gui.ingame.GuiSign;
import client.gui.ingame.GuiForm;
import client.renderer.particle.EntityPickupFX;
import client.renderer.texture.EntityTexManager;
import client.world.ChunkClient;
import client.world.WorldClient;
import common.attributes.Attribute;
import common.attributes.AttributeInstance;
@ -137,7 +138,6 @@ import common.tileentity.TileEntityMachine;
import common.tileentity.TileEntitySign;
import common.util.BlockPos;
import common.village.MerchantRecipeList;
import common.world.Chunk;
import common.world.Explosion;
import common.world.Weather;
import common.world.World;
@ -741,9 +741,9 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
{
NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController);
for (SPacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : packetIn.getChangedBlocks())
for (SPacketMultiBlockChange.BlockUpdateData update : packetIn.getChangedBlocks())
{
this.clientWorldController.invalidateRegionAndSetBlock(s22packetmultiblockchange$blockupdatedata.getPos(), s22packetmultiblockchange$blockupdatedata.getBlockState());
this.clientWorldController.invalidateRegionAndSetBlock(SPacketMultiBlockChange.getPos(packetIn.getChunkPos(), update.getRawPos()), update.getBlockState());
}
}
@ -766,7 +766,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
}
// this.clientWorldController.invalidateBlockReceiveRegion(packetIn.getChunkX() << 4, 0, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, 512, (packetIn.getChunkZ() << 4) + 15);
Chunk chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
ChunkClient chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
chunk.setData(packetIn.getExtractedDataBytes(), packetIn.getExtractedExtend(), packetIn.hasBiomes());
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);
@ -779,7 +779,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
public void handleBiomes(SPacketBiomes packetIn)
{
NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController);
Chunk chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
ChunkClient chunk = this.clientWorldController.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
chunk.setBiomes(packetIn.getBiomes());
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);
}
@ -1412,7 +1412,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer
int k = packetIn.getChunkZ(i);
this.clientWorldController.doPreChunk(j, k, true);
// this.clientWorldController.invalidateBlockReceiveRegion(j << 4, 0, k << 4, (j << 4) + 15, 512, (k << 4) + 15);
Chunk chunk = this.clientWorldController.getChunk(j, k);
ChunkClient chunk = this.clientWorldController.getChunk(j, k);
chunk.setData(packetIn.getChunkBytes(i), packetIn.getChunkExtend(i), true);
this.clientWorldController.markBlockRangeForRenderUpdate(j << 4, -World.MAX_SIZE_Y, k << 4, (j << 4) + 15, World.MAX_SIZE_Y, (k << 4) + 15);

View file

@ -2,48 +2,62 @@ package client.renderer;
import java.util.Arrays;
import client.world.ChunkClient;
import client.world.WorldClient;
import common.biome.Biome;
import common.init.Blocks;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.Facing;
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;
public class RegionRenderCache extends ChunkCache implements IWorldAccess
public class RegionRenderCache implements IWorldAccess
{
private static final State DEFAULT_STATE = Blocks.air.getState();
private final World worldObj;
private final int xPos;
private final int zPos;
private final ChunkClient[][] chunks;
private final World world;
private final BlockPos position;
private final boolean empty;
private int[] combinedLights;
private State[] blockStates;
public RegionRenderCache(World worldIn, BlockPos posFromIn, BlockPos posToIn, int subIn)
public RegionRenderCache(WorldClient world, BlockPos from, BlockPos to, int sub)
{
super(worldIn, posFromIn, posToIn, subIn);
this.worldObj = worldIn;
boolean empty = true;
for (int i1 = posFromIn.getX() >> 4; i1 <= posToIn.getX() >> 4; ++i1)
this.world = world;
this.xPos = from.getX() - sub >> 4;
this.zPos = from.getZ() - sub >> 4;
int x2 = to.getX() + sub >> 4;
int z2 = to.getZ() + sub >> 4;
this.chunks = new ChunkClient[x2 - this.xPos + 1][z2 - this.zPos + 1];
for (int x = this.xPos; x <= x2; ++x)
{
for (int j1 = posFromIn.getZ() >> 4; j1 <= posToIn.getZ() >> 4; ++j1)
for (int z = this.zPos; z <= z2; ++z)
{
Chunk chunk = this.chunkArray[i1 - this.chunkX][j1 - this.chunkZ];
this.chunks[x - this.xPos][z - this.zPos] = world.getChunk(x, z);
}
}
boolean empty = true;
for (int x = from.getX() >> 4; x <= to.getX() >> 4; ++x)
{
for (int z = from.getZ() >> 4; z <= to.getZ() >> 4; ++z)
{
ChunkClient chunk = this.chunks[x - this.xPos][z - this.zPos];
if (chunk != null && !chunk.isEmpty(posFromIn.getY(), posToIn.getY()))
if (chunk != null && !chunk.isEmpty(from.getY(), to.getY()))
{
empty = false;
}
}
}
this.empty = empty;
this.position = posFromIn.subtract(new Vec3i(subIn, subIn, subIn));
this.position = from.subtract(new Vec3i(sub, sub, sub));
int i = 16000;
this.combinedLights = new int[16000];
Arrays.fill((int[])this.combinedLights, (int) - 1);
@ -52,9 +66,9 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess
public TileEntity getTileEntity(BlockPos pos)
{
int i = (pos.getX() >> 4) - this.chunkX;
int j = (pos.getZ() >> 4) - this.chunkZ;
return this.chunkArray[i][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED);
int i = (pos.getX() >> 4) - this.xPos;
int j = (pos.getZ() >> 4) - this.zPos;
return this.chunks[i][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED);
}
public int getCombinedLight(BlockPos pos, int lightValue)
@ -89,9 +103,9 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess
{
if (pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y)
{
int i = (pos.getX() >> 4) - this.chunkX;
int j = (pos.getZ() >> 4) - this.chunkZ;
return this.chunkArray[i][j].getState(pos);
int i = (pos.getX() >> 4) - this.xPos;
int j = (pos.getZ() >> 4) - this.zPos;
return this.chunks[i][j].getState(pos);
}
else
{
@ -127,12 +141,12 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess
public Biome getBiomeGenForCoords(BlockPos pos)
{
return this.worldObj.getBiomeGenForCoords(pos);
return this.world.getBiomeGenForCoords(pos);
}
private int getLightForExt(LightType p_175629_1_, BlockPos pos)
{
if (p_175629_1_ == LightType.SKY && this.worldObj.dimension.hasNoLight())
if (p_175629_1_ == LightType.SKY && this.world.dimension.hasNoLight())
{
return 0;
}
@ -161,9 +175,9 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess
}
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);
int i = (pos.getX() >> 4) - this.xPos;
int j = (pos.getZ() >> 4) - this.zPos;
return this.chunks[i][j].getLight(p_175629_1_, pos);
}
}
else
@ -185,9 +199,9 @@ public class RegionRenderCache extends ChunkCache implements IWorldAccess
{
if (pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y)
{
int i = (pos.getX() >> 4) - this.chunkX;
int j = (pos.getZ() >> 4) - this.chunkZ;
return this.chunkArray[i][j].getLight(p_175628_1_, pos);
int i = (pos.getX() >> 4) - this.xPos;
int j = (pos.getZ() >> 4) - this.zPos;
return this.chunks[i][j].getLight(p_175628_1_, pos);
}
else
{

View file

@ -25,6 +25,7 @@ import client.renderer.texture.TextureAtlasSprite;
import client.renderer.texture.TextureManager;
import client.renderer.texture.TextureMap;
import client.renderer.tileentity.TileEntityRendererDispatcher;
import client.world.ChunkClient;
import client.world.WorldClient;
import common.block.Block;
import common.block.BlockChest;
@ -51,7 +52,6 @@ import common.util.Facing;
import common.util.HitPosition;
import common.util.Vec3;
import common.util.Vector3f;
import common.world.Chunk;
import common.world.State;
import common.world.World;
@ -604,7 +604,7 @@ public class RenderGlobal
for (RenderGlobal.ContainerLocalRenderInformation renderglobal$containerlocalrenderinformation : this.renderInfos)
{
Chunk chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition());
ChunkClient chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition());
ClassInheritanceMultiMap<Entity> classinheritancemultimap = chunk.getEntities()[ExtMath.clampi(renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16, 0, 31)];
if (!classinheritancemultimap.isEmpty())
@ -935,7 +935,7 @@ public class RenderGlobal
{
VisGraph visgraph = new VisGraph();
BlockPos blockpos = new BlockPos(pos.getX() >> 4 << 4, pos.getY() >> 4 << 4, pos.getZ() >> 4 << 4);
Chunk chunk = this.theWorld.getChunk(blockpos);
ChunkClient chunk = this.theWorld.getChunk(blockpos);
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos.add(15, 15, 15)))
{

View file

@ -1,14 +1,14 @@
package client.renderer;
import client.renderer.chunk.RenderChunk;
import client.world.WorldClient;
import common.util.BlockPos;
import common.util.ExtMath;
import common.world.World;
public class ViewFrustum
{
protected final RenderGlobal renderGlobal;
protected final World world;
protected final WorldClient world;
protected int countChunksY;
protected int countChunksX;
protected int countChunksZ;
@ -18,7 +18,7 @@ public class ViewFrustum
return i < 0 ? -((-i - 1) / 16) - 1 : i / 16;
}
public ViewFrustum(World worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_)
public ViewFrustum(WorldClient worldIn, int renderDistanceChunks, RenderGlobal p_i46246_3_)
{
this.renderGlobal = p_i46246_3_;
this.world = worldIn;

View file

@ -19,6 +19,7 @@ import client.renderer.RenderGlobal;
import client.renderer.VertexBuffer;
import client.renderer.tileentity.TileEntityRendererDispatcher;
import client.renderer.tileentity.TileEntitySpecialRenderer;
import client.world.WorldClient;
import common.block.Block;
import common.collect.Maps;
import common.collect.Sets;
@ -28,11 +29,10 @@ import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Facing;
import common.world.State;
import common.world.World;
public class RenderChunk
{
private World world;
private WorldClient world;
private final RenderGlobal renderGlobal;
public static int renderChunksUpdated;
private BlockPos position;
@ -49,7 +49,7 @@ public class RenderChunk
private boolean needsUpdate = true;
private EnumMap<Facing, BlockPos> mapEnumFacing = Maps.newEnumMap(Facing.class);
public RenderChunk(World worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn)
public RenderChunk(WorldClient worldIn, RenderGlobal renderGlobalIn, BlockPos blockPosIn, int indexIn)
{
this.world = worldIn;
this.renderGlobal = renderGlobalIn;

View file

@ -0,0 +1,140 @@
package client.world;
import common.biome.Biome;
import common.block.Block;
import common.init.Blocks;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.NibbleArray;
import common.world.BlockArray;
import common.world.Chunk;
import common.world.World;
public class ChunkClient extends Chunk {
public ChunkClient(World world, int x, int z) {
super(world, x, z);
}
private void clearArrays() {
this.blocks.clearMap();
this.blockList.clear();
this.bottom = Integer.MAX_VALUE;
this.top = Integer.MIN_VALUE;
}
private void genHeights() {
int top = this.top;
int bottom = this.bottom;
this.minHeight = Integer.MAX_VALUE;
for(int x = 0; x < 16; ++x) {
for(int z = 0; z < 16; ++z) {
this.precHeight[x + (z << 4)] = -99999999;
for(int y = top + 16; y > bottom; --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 boolean isEmpty(int bottom, int top) {
for(int y = bottom; y <= top; y += 16) {
BlockArray stor = this.getArray(y >> 4);
if(stor != null ? !stor.isEmpty() : (y < 0 && this.fillerBlock != Blocks.air)) {
return false;
}
}
return true;
}
public void setData(byte[] data, int[] extend, boolean biomes) {
int pos = 0;
boolean sky = !this.world.dimension.hasNoLight();
if(biomes) {
this.clearArrays();
}
for(int cy : extend) {
BlockArray arr = this.getArray(cy);
if(arr == null) {
arr = new BlockArray(cy << 4, sky, null);
this.setArray(arr);
}
char[] blocks = arr.getData();
for(int k = 0; k < blocks.length; ++k) {
blocks[k] = (char)((data[pos + 1] & 255) << 8 | data[pos] & 255);
pos += 2;
}
}
for(int cy : extend) {
BlockArray arr = this.getArray(cy);
if(arr != null) {
NibbleArray light = arr.getBlocklight();
System.arraycopy(data, pos, light.getData(), 0, light.getData().length);
pos += light.getData().length;
}
}
if(sky) {
for(int cy : extend) {
BlockArray arr = this.getArray(cy);
if(arr != null) {
NibbleArray slight = arr.getSkylight();
System.arraycopy(data, pos, slight.getData(), 0, slight.getData().length);
pos += slight.getData().length;
}
}
}
if(biomes) {
System.arraycopy(data, pos, this.biomes, 0, this.biomes.length);
}
for(int cy : extend) {
BlockArray arr = this.getArray(cy);
if(arr != null) {
arr.update();
}
}
this.lightInit = true;
this.populated = true;
this.genHeights();
for(TileEntity tile : this.tiles.values()) {
tile.updateContainingBlockInfo();
}
}
public void setLoaded() {
this.loaded = true;
}
public Biome getBiome(BlockPos pos) {
int x = pos.getX() & 15;
int z = pos.getZ() & 15;
return Biome.getBiomeDef(this.biomes[z << 4 | x] & 255);
}
public boolean isDummy() {
return false;
}
}

View file

@ -10,17 +10,15 @@ import common.init.Blocks;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.world.Chunk;
import common.world.LightType;
import common.world.State;
import common.worldgen.BiomeGenerator;
public class EmptyChunk extends Chunk {
public class ChunkEmpty extends ChunkClient {
private final int liquidY;
private final State liquid;
private final Block liquidBlock;
public EmptyChunk(WorldClient world) {
public ChunkEmpty(WorldClient world) {
super(world, 0, 0);
this.liquidY = world.dimension.getSeaLevel() - 1;
this.liquid = world.dimension.getLiquid();
@ -65,10 +63,7 @@ public class EmptyChunk extends Chunk {
public void removeTileEntity(BlockPos pos) {
}
public void setModified() {
}
public void getEntities(Entity exclude, BoundingBox bb, List<Entity> list, Predicate<? super Entity> pred) {
}
@ -108,7 +103,7 @@ public class EmptyChunk extends Chunk {
public void setData(byte[] data, int[] extend, boolean biomes) {
}
public Biome getBiome(BlockPos pos, BiomeGenerator gen) {
public Biome getBiome(BlockPos pos) {
return Biome.DEF_BIOME;
}
@ -128,7 +123,7 @@ public class EmptyChunk extends Chunk {
return false;
}
public void setLoaded(boolean loaded) {
public void setLoaded() {
}
public int getLowest() {

View file

@ -33,7 +33,6 @@ import common.util.ExtMath;
import common.util.LongHashMap;
import common.util.Vec3;
import common.util.BlockPos.MutableBlockPos;
import common.world.Chunk;
import common.world.AWorldClient;
import common.world.State;
import common.world.World;
@ -46,11 +45,11 @@ public class WorldClient extends AWorldClient
private final Set<Entity> entityList = Sets.<Entity>newHashSet();
private final Set<Entity> spawnQueue = Sets.<Entity>newHashSet();
private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet();
private final LongHashMap<Chunk> chunkMapping = new LongHashMap();
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
private final LongHashMap<ChunkClient> chunkMapping = new LongHashMap();
private final List<ChunkClient> chunkListing = Lists.<ChunkClient>newArrayList();
private final Set<Long> emptyChunkListing = Sets.<Long>newHashSet();
private final Set<Long> nextEmptyChunkListing = Sets.<Long>newHashSet();
private final Chunk emptyChunk = new EmptyChunk(this);
private final ChunkClient emptyChunk = new ChunkEmpty(this);
// public final Profiler profiler;
protected int lastLightning;
protected Vec3 lightColor = new Vec3(0xffffff);
@ -120,7 +119,7 @@ public class WorldClient extends AWorldClient
}
}
long time = System.currentTimeMillis();
for (Chunk chunk : this.chunkListing)
for (ChunkClient chunk : this.chunkListing)
{
chunk.update(System.currentTimeMillis() - time > 5L);
}
@ -149,7 +148,7 @@ public class WorldClient extends AWorldClient
{
int j = chunkcoordintpair.x * 16;
int k = chunkcoordintpair.z * 16;
Chunk chunk = this.getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
ChunkClient chunk = this.getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
chunk.enqueueRelight();
this.previousActive.add(chunkcoordintpair);
++i;
@ -169,14 +168,14 @@ public class WorldClient extends AWorldClient
{
if(this.chunkMapping.getValueByKey(id) != null)
this.doPreChunk(x, z, false);
Chunk chunk = new Chunk(this, x, z);
ChunkClient chunk = new ChunkClient(this, x, z);
this.chunkMapping.add(id, chunk);
this.chunkListing.add(chunk);
chunk.setLoaded(true);
chunk.setLoaded();
}
else
{
Chunk chunk = this.getChunk(x, z);
ChunkClient chunk = this.getChunk(x, z);
chunk.onChunkUnload();
this.chunkMapping.remove(id);
this.chunkListing.remove(chunk);
@ -387,11 +386,26 @@ public class WorldClient extends AWorldClient
this.gm.effectRenderer.addEffect(new EntityFirework.StarterFX(this.gm.world, x, y, z, motionX, motionY, motionZ, this.gm.effectRenderer, compund));
}
public Chunk getChunk(int x, int z)
public ChunkClient getChunk(int x, int z)
{
Chunk chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z));
ChunkClient chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z));
return chunk == null ? this.emptyChunk : chunk;
}
public ChunkClient getChunk(BlockPos pos) {
return this.getChunk(pos.getX() >> 4, pos.getZ() >> 4);
}
public Biome getBiomeGenForCoords(BlockPos pos) {
if(this.isBlockLoaded(pos))
return this.getChunk(pos).getBiome(pos);
else
return Biome.DEF_BIOME;
}
protected boolean isLoaded(int x, int z, boolean allowEmpty) {
return allowEmpty || !this.getChunk(x, z).isDummy();
}
public String getInfo()
{