add dummy display chunks

This commit is contained in:
Sen 2025-05-20 11:51:35 +02:00
parent e145675525
commit 31dd9d6303
9 changed files with 147 additions and 68 deletions

View file

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

View file

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

View file

@ -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 <T extends Entity> void getEntities(Class<? extends T> clazz, BoundingBox bb, List<T> list, Predicate<? super T> 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;
}
}

View file

@ -47,7 +47,9 @@ public class WorldClient extends AWorldClient
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 Chunk blankChunk = new EmptyChunk(this);
private final Set<ChunkPos> emptyChunkListing = Sets.<ChunkPos>newHashSet();
private final Set<ChunkPos> nextEmptyChunkListing = Sets.<ChunkPos>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()

View file

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

View file

@ -911,14 +911,14 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
}
public static Dimension getByNbt(NBTTagCompound tag) {
return getByNbt(tag, true, false, false);
return getByNbt(tag, true, false, false, false);
}
public static Dimension getByNbt(NBTTagCompound tag, boolean generator) {
return getByNbt(tag, false, generator, false);
return getByNbt(tag, false, generator, !generator, false);
}
private static Dimension getByNbt(NBTTagCompound tag, boolean mapOnly, boolean generator, boolean all) {
private static Dimension getByNbt(NBTTagCompound tag, boolean mapOnly, boolean generator, boolean partialGen, boolean all) {
Dimension dim;
DimType type = DimType.getByName(tag.getString("Type"));
int id = tag.getInteger("ID");
@ -944,35 +944,41 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
dim = Space.INSTANCE;
}
if(!mapOnly)
dim.fromNbt(tag, generator, all);
dim.fromNbt(tag, generator, partialGen, all);
return dim;
}
public final Dimension copy() {
Dimension dim = getByNbt(this.toNbt(true, true), false, true, true);
Dimension dim = getByNbt(this.toNbt(true, false, true), false, true, false, true);
dim.setCustomName(this.getCustomName());
return dim;
}
public final Dimension copy(int id, String name) {
NBTTagCompound tag = this.toNbt(true, true);
NBTTagCompound tag = this.toNbt(true, false, true);
tag.setInteger("ID", id);
tag.setString("Name", name);
return getByNbt(tag, false, true, true);
return getByNbt(tag, false, true, false, true);
}
public final void fromNbt(NBTTagCompound tag) {
this.fromNbt(tag, true, false);
this.fromNbt(tag, true, false, false);
}
private final void fromNbt(NBTTagCompound tag, boolean generator, boolean all) {
private final void fromNbt(NBTTagCompound tag, boolean generator, boolean partialGen, boolean all) {
if(this == Space.INSTANCE) {
if(generator)
if(generator || partialGen)
this.seed = tag.getLong("Seed");
return;
}
if(generator) {
if(generator || partialGen) {
this.seed = tag.getLong("Seed");
if(partialGen || all || this.id >= 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<Dimension
this.seaRarity = tag.getInteger("SeaRarity");
this.addRarity = tag.getInteger("AddRarity");
// this.biomeRarity = tag.getInteger("BiomeRarity");
this.seaLevel = tag.getInteger("SeaLevel");
this.defaultBiome = Biome.findByName(tag.getString("DefaultBiome"));
this.semiFixed = tag.getBoolean("SemiFixed");
this.defaultWeather = Weather.getByName(tag.getString("DefaultWeather"));
@ -1021,7 +1026,6 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
this.surface = BlockRegistry.getFromIdName(tag.getString("SurfaceBlock"), Blocks.grass.getState());
this.alt1 = BlockRegistry.getFromIdName(tag.getString("AltBlock1"), Blocks.gravel.getState());
this.alt2 = BlockRegistry.getFromIdName(tag.getString("AltBlock2"), Blocks.sand.getState());
this.liquid = BlockRegistry.getFromIdName(tag.getString("LiquidBlock"), Blocks.water.getState());
this.floor = tag.hasKey("FloorBlock", 8) ?
BlockRegistry.getFromIdName(tag.getString("FloorBlock"), Blocks.bedrock.getState()) : null;
this.ceiling = tag.hasKey("CeilingBlock", 8) ?
@ -1197,18 +1201,24 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
}
public final NBTTagCompound toNbt(boolean generator) {
return this.toNbt(generator, false);
return this.toNbt(generator, !generator, false);
}
private final NBTTagCompound toNbt(boolean generator, boolean all) {
private final NBTTagCompound toNbt(boolean generator, boolean partialGen, boolean all) {
NBTTagCompound tag = (all || !generator || this.id >= 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<Dimension
tag.setInteger("SeaRarity", this.seaRarity);
tag.setInteger("AddRarity", this.addRarity);
// tag.setInteger("BiomeRarity", this.biomeRarity);
tag.setInteger("SeaLevel", this.seaLevel);
// if(this.defaultBiome != null)
tag.setString("DefaultBiome", this.defaultBiome.name.toLowerCase());
// if(this.mainBiome != null)
@ -1257,7 +1266,6 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
tag.setString("SurfaceBlock", BlockRegistry.toIdName(this.surface));
tag.setString("AltBlock1", BlockRegistry.toIdName(this.alt1));
tag.setString("AltBlock2", BlockRegistry.toIdName(this.alt2));
tag.setString("LiquidBlock", BlockRegistry.toIdName(this.liquid));
if(this.floor != null)
tag.setString("FloorBlock", BlockRegistry.toIdName(this.floor));
if(this.ceiling != null)

View file

@ -1746,7 +1746,7 @@ public abstract class EntityLiving extends Entity
this.motionY = 0.2D;
}
if (this.worldObj.client && (!this.worldObj.isBlockLoaded(new BlockPos((int)this.posX, 0, (int)this.posZ)) || !this.worldObj.getChunk(new BlockPos((int)this.posX, 0, (int)this.posZ)).isLoaded()))
if (this.worldObj.client && (!this.worldObj.isBlockLoaded(new BlockPos((int)this.posX, 0, (int)this.posZ)) || !this.worldObj.getChunk(new BlockPos((int)this.posX, 0, (int)this.posZ)).isLoaded()) && !this.isPlayer())
{
if (this.posY > 0.0D)
{

View file

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

View file

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