From 31dd9d6303fe1836a4666258ea758eab6b2ee209 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 20 May 2025 11:51:35 +0200 Subject: [PATCH] add dummy display chunks --- client/src/client/Client.java | 3 +- client/src/client/network/ClientPlayer.java | 1 + client/src/client/world/EmptyChunk.java | 101 ++++++++++++------ client/src/client/world/WorldClient.java | 52 +++++++-- common/src/common/block/BlockTorch.java | 2 +- common/src/common/dimension/Dimension.java | 46 ++++---- .../src/common/entity/types/EntityLiving.java | 2 +- common/src/common/world/Chunk.java | 6 +- common/src/common/world/World.java | 2 +- 9 files changed, 147 insertions(+), 68 deletions(-) diff --git a/client/src/client/Client.java b/client/src/client/Client.java index 7ceb7b6..0c669f3 100755 --- a/client/src/client/Client.java +++ b/client/src/client/Client.java @@ -1799,7 +1799,8 @@ public class Client implements IThreadListener { ) + "\n" + String.format("Letzte Zeitsynch.: + %d.%d s", ticked / 1000L, (ticked / 100L) % 10L - ) + + ) + "\n" + + "Startwert: " + this.world.dimension.getSeed() + (this.serverInfo != null ? "\n" + this.serverInfo : "") // IWorldServer world = this.server.getWorld(this.theWorld.dimension.getDimensionId()); // if(world != null) diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java index eb3c533..1500a4e 100755 --- a/client/src/client/network/ClientPlayer.java +++ b/client/src/client/network/ClientPlayer.java @@ -722,6 +722,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer this.gameController.player.prevY = this.gameController.player.posY; this.gameController.player.prevZ = this.gameController.player.posZ; this.doneLoadingTerrain = true; + this.clientWorldController.markReload(); // this.gameController.displayGuiScreen(null); // if(this.travelSound) { // this.gameController.getSoundManager().playSound(new PositionedSound(SoundEvent.TELEPORT)); diff --git a/client/src/client/world/EmptyChunk.java b/client/src/client/world/EmptyChunk.java index 3557561..ae10017 100755 --- a/client/src/client/world/EmptyChunk.java +++ b/client/src/client/world/EmptyChunk.java @@ -3,40 +3,40 @@ package client.world; import java.util.List; import java.util.function.Predicate; +import common.biome.Biome; import common.block.Block; import common.entity.Entity; import common.init.Blocks; +import common.log.Log; 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 { + private final int liquidY; + private final State liquid; + private final Block liquidBlock; + private final int liquidMeta; + public EmptyChunk(WorldClient world) { super(world, 0, 0); + this.liquidY = world.dimension.getSeaLevel() - 1; + this.liquid = world.dimension.getLiquid(); + this.liquidBlock = this.liquid.getBlock(); + this.liquidMeta = this.liquidBlock.getMetaFromState(this.liquid); + Log.SYSTEM.info("See: %d", this.liquidY); } public int getHeight(int x, int z) { - return 0; - } - - public void genHeights() { - } - - public void genSkyLight() { + return this.liquidY; } public Block getBlock(BlockPos pos) { - return Blocks.air; - } - - public int getOpacity(BlockPos pos) { - return 255; - } - - public int getMeta(BlockPos pos) { - return 0; + return pos.getY() < this.liquidY ? Blocks.bedrock : (pos.getY() == this.liquidY ? this.liquidBlock : Blocks.air); } public int getLight(LightType type, BlockPos pos) { @@ -57,28 +57,19 @@ public class EmptyChunk extends Chunk { } public boolean canSeeSky(BlockPos pos) { - return false; + return pos.getY() > this.liquidY; } public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { return null; } - public void addTileEntity(TileEntity tile) { - } - public void addTileEntity(BlockPos pos, TileEntity tile) { } public void removeTileEntity(BlockPos pos) { } - public void onChunkLoad() { - } - - public void onChunkUnload() { - } - public void setModified() { } @@ -88,15 +79,63 @@ public class EmptyChunk extends Chunk { public void getEntities(Class clazz, BoundingBox bb, List list, Predicate pred) { } - public boolean isDirty(long time) { - return false; - } - - public boolean isEmpty() { + public boolean isDummy() { return true; } public boolean isEmpty(int bottom, int top) { + return top < 0 || bottom > this.liquidY; + } + + public State getState(BlockPos pos) { + return pos.getY() < this.liquidY ? Blocks.bedrock.getState() : (pos.getY() == this.liquidY ? this.liquid : Blocks.air.getState()); + } + + public State setState(BlockPos pos, State state) { + return null; + } + + public BlockPos getPrecipitation(BlockPos pos) { + return new BlockPos(pos.getX(), this.liquidY + 1, pos.getZ()); + } + + public void update(boolean noGaps) { + } + + public void onChunkUnload() { + } + + public boolean isPopulated() { return true; } + + public void setData(byte[] data, int update, boolean biomes) { + } + + public Biome getBiome(BlockPos pos, BiomeGenerator gen) { + return Biome.DEF_BIOME; + } + + public void setBiomes(byte[] biomes) { + } + + public void resetRelight() { + } + + public void enqueueRelight() { + } + + public void checkLight() { + } + + public boolean isLoaded() { + return false; + } + + public void setLoaded(boolean loaded) { + } + + public int getLowest() { + return 0; + } } diff --git a/client/src/client/world/WorldClient.java b/client/src/client/world/WorldClient.java index 7e8f142..bd170bd 100755 --- a/client/src/client/world/WorldClient.java +++ b/client/src/client/world/WorldClient.java @@ -47,7 +47,9 @@ public class WorldClient extends AWorldClient private final Set previousActive = Sets.newHashSet(); private final LongHashMap chunkMapping = new LongHashMap(); private final List chunkListing = Lists.newArrayList(); - private final Chunk blankChunk = new EmptyChunk(this); + private final Set emptyChunkListing = Sets.newHashSet(); + private final Set nextEmptyChunkListing = Sets.newHashSet(); + private final Chunk emptyChunk = new EmptyChunk(this); // public final Profiler profiler; protected int lastLightning; protected Vec3 lightColor = new Vec3(0xffffff); @@ -63,8 +65,41 @@ public class WorldClient extends AWorldClient // this.setDifficulty(this.gm.difficulty); } + private void markReload(int cx, int cz, int range) { + this.nextEmptyChunkListing.clear(); + for(int x = cx - range; x <= cx + range; x++) { + for(int z = cz - range; z <= cz + range; z++) { + long id = LongHashMap.packInt(x, z); + ChunkPos pos = new ChunkPos(x, z); + if(this.chunkMapping.getValueByKey(id) != null) { + if(this.emptyChunkListing.contains(pos)) { + this.emptyChunkListing.remove(pos); + this.nextEmptyChunkListing.add(pos); + } + continue; + } + this.chunkMapping.add(id, this.emptyChunk); + this.emptyChunkListing.remove(pos); + this.nextEmptyChunkListing.add(pos); + this.markBlockRangeForRenderUpdate(x << 4, 0, z << 4, (x << 4) + 15, 512, (z << 4) + 15); + } + } + for(ChunkPos pos : this.emptyChunkListing) { + this.chunkMapping.remove(LongHashMap.packInt(pos.x, pos.z)); + this.markBlockRangeForRenderUpdate(pos.x << 4, 0, pos.z << 4, (pos.x << 4) + 15, 512, (pos.z << 4) + 15); + } + this.emptyChunkListing.clear(); + this.emptyChunkListing.addAll(this.nextEmptyChunkListing); + } + + public void markReload() { + if(this.gm.player != null && !this.gm.charEditor) + this.markReload((int)this.gm.player.posX >> 4, (int)this.gm.player.posZ >> 4, this.gm.renderDistance + 4); + } + public void tick() { + this.markReload(); // this.info.tick(); if (this.gm.dayCycle) @@ -127,24 +162,23 @@ public class WorldClient extends AWorldClient public void doPreChunk(int x, int z, boolean load) { + long id = LongHashMap.packInt(x, z); if (load) { - if(this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z)) != null) + if(this.chunkMapping.getValueByKey(id) != null) this.doPreChunk(x, z, false); Chunk chunk = new Chunk(this, x, z); - this.chunkMapping.add(LongHashMap.packInt(x, z), chunk); + this.chunkMapping.add(id, chunk); this.chunkListing.add(chunk); chunk.setLoaded(true); } else { Chunk chunk = this.getChunk(x, z); - if (!chunk.isEmpty()) - { - chunk.onChunkUnload(); - } - this.chunkMapping.remove(LongHashMap.packInt(x, z)); + chunk.onChunkUnload(); + this.chunkMapping.remove(id); this.chunkListing.remove(chunk); + this.emptyChunkListing.remove(new ChunkPos(x, z)); } if (!load) @@ -354,7 +388,7 @@ public class WorldClient extends AWorldClient public Chunk getChunk(int x, int z) { Chunk chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z)); - return chunk == null ? this.blankChunk : chunk; + return chunk == null ? this.emptyChunk : chunk; } public String getInfo() 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..39b7bb3 100755 --- a/common/src/common/dimension/Dimension.java +++ b/common/src/common/dimension/Dimension.java @@ -911,14 +911,14 @@ public abstract class Dimension extends Nameable implements Comparable= UniverseRegistry.MORE_DIM_ID) { + this.seaLevel = tag.getInteger("SeaLevel"); + this.liquid = BlockRegistry.getFromIdName(tag.getString("LiquidBlock"), Blocks.water.getState()); + } + } + if(generator) { if(all || this.id >= UniverseRegistry.MORE_DIM_ID) { this.noiseGen.coordinateScale = tag.getFloat("CoordScale"); this.noiseGen.heightScale = tag.getFloat("HeightScale"); @@ -1009,7 +1015,6 @@ public abstract class Dimension extends Nameable implements Comparable= UniverseRegistry.MORE_DIM_ID) ? this.toNbt() : new NBTTagCompound(); if(this == Space.INSTANCE) { - if(generator) + if(generator || partialGen) tag.setLong("Seed", this.seed); return tag; } - if(generator) { + if(generator || partialGen) { tag.setLong("Seed", this.seed); + if(partialGen || all || this.id >= UniverseRegistry.MORE_DIM_ID) { + tag.setInteger("SeaLevel", this.seaLevel); + tag.setString("LiquidBlock", BlockRegistry.toIdName(this.liquid)); + } + } + if(generator) { if(all || this.id >= UniverseRegistry.MORE_DIM_ID) { tag.setFloat("CoordScale", this.noiseGen.coordinateScale); tag.setFloat("HeightScale", this.noiseGen.heightScale); @@ -1245,7 +1255,6 @@ public abstract class Dimension extends Nameable implements Comparable 0.0D) { diff --git a/common/src/common/world/Chunk.java b/common/src/common/world/Chunk.java index 6a5fdf7..efbb742 100755 --- a/common/src/common/world/Chunk.java +++ b/common/src/common/world/Chunk.java @@ -395,10 +395,6 @@ public class Chunk { return block; } - public Block getBlock(int x, int y, int z) { - return this.getBlock0(x & 15, y, z & 15); - } - public Block getBlock(BlockPos pos) { return this.getBlock0(pos.getX() & 15, pos.getY(), pos.getZ() & 15); } @@ -799,7 +795,7 @@ public class Chunk { return this.modified; } - public boolean isEmpty() { + public boolean isDummy() { return false; } diff --git a/common/src/common/world/World.java b/common/src/common/world/World.java index 519dc36..b1529dc 100755 --- a/common/src/common/world/World.java +++ b/common/src/common/world/World.java @@ -192,7 +192,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) {