1
0
Fork 0

make light clientside

This commit is contained in:
Sen 2025-08-30 12:03:46 +02:00
parent e3e5fbd7fd
commit 16d20fb31d
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
54 changed files with 556 additions and 1316 deletions

View file

@ -35,7 +35,6 @@ import common.entity.npc.EntityCameraHolder;
import common.entity.npc.EntityCultivator;
import common.entity.npc.EntityElf;
import common.entity.npc.EntityFireDemon;
import common.entity.npc.EntityHaunter;
import common.entity.npc.EntityMage;
import common.entity.npc.EntityMerfolk;
import common.entity.npc.EntityMetalhead;
@ -547,9 +546,6 @@ public abstract class UniverseRegistry extends DimensionRegistry {
.addSpawn(EntityChicken.class, 10, 4, 4)
.addSpawn(EntityCow.class, 8, 4, 4)
.addSpawn(EntityArachnoid.class, 100, 4, 4)
.addSpawn(EntityZombie.class, 100, 4, 4)
.addSpawn(EntityUndead.class, 100, 4, 4)
.addSpawn(EntityHaunter.class, 100, 4, 4)
.addSpawn(EntitySlime.class, 100, 4, 4)
.addSpawn(EntityMage.class, 5, 1, 1)
.addSpawn(EntityBat.class, 10, 8, 8)
@ -723,10 +719,6 @@ public abstract class UniverseRegistry extends DimensionRegistry {
.addSpawn(EntityPig.class, 10, 4, 4)
.addSpawn(EntityChicken.class, 10, 4, 4)
.addSpawn(EntityCow.class, 8, 4, 4)
.addSpawn(EntityArachnoid.class, 100, 4, 4)
.addSpawn(EntityZombie.class, 100, 4, 4)
.addSpawn(EntityUndead.class, 100, 4, 4)
.addSpawn(EntitySlime.class, 100, 4, 4)
);
});
});

View file

@ -897,11 +897,6 @@ public class Player extends User implements Executor, IPlayer
}
}
for (BlockArray extendedblockstorage2 : list)
{
j = copyTo(extendedblockstorage2.getBlocklight().getData(), dataset.data, j);
}
if (biomes)
{
BiomeGenerator gen = world.getBiomeGenerator();
@ -1005,7 +1000,7 @@ public class Player extends User implements Executor, IPlayer
{
ChunkServer chunk = world.getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
if (chunk.isPopulated())
if (chunk.isTerrainPopulated())
{
list.add(chunk);
list1.addAll(world.getTileEntitiesIn(chunkcoordintpair.x * 16, -World.MAX_SIZE_Y, chunkcoordintpair.z * 16, chunkcoordintpair.x * 16 + 16, World.MAX_SIZE_Y, chunkcoordintpair.z * 16 + 16));

View file

@ -214,7 +214,7 @@ public class VillageCollection
for (int j = 1; j <= 5; ++j)
{
if (world.canSeeSky(centerPos.offset(direction, j)))
if (world.getPrecipitationHeight(centerPos.offset(direction, j)).getY() - 1 <= centerPos.getY())
{
++i;

View file

@ -17,10 +17,10 @@ import common.world.State;
public class ChunkServer extends Chunk {
private long lastSave;
private long inhabited;
private boolean populated;
public ChunkServer(WorldServer world, int x, int z) {
super(world, x, z);
this.updated = true;
}
public ChunkServer(WorldServer world, char[] data, int height, boolean base, boolean ceil, Random rand, int x, int z) {
@ -82,8 +82,7 @@ public class ChunkServer extends Chunk {
}
}
if(!ceil)
this.genSky();
this.updated = true;
this.genHeightMap();
}
public int getTopSegment() {

View file

@ -1434,66 +1434,12 @@ public abstract class Converter {
return state;
}
private static TagObject convertChunkData(NbtTag tag, boolean legacy) {
private static TagObject convertChunkData(NbtTag tag) {
TagObject ntag = new TagObject();
tag = tag.getTag("Level");
if(legacy) {
byte[] oldheight = tag.getByteArray("HeightMap");
int[] height = new int[oldheight.length];
for(int i = 0; i < oldheight.length; ++i) {
height[i] = oldheight[i];
}
ntag.setIntArray("H", height);
byte[] oldblks = tag.getByteArray("Blocks");
byte[] olddata = tag.getByteArray("Data");
byte[] oldlight = tag.getByteArray("BlockLight");
List<TagObject> sections = Lists.newArrayList();
for(int n = 0; n < 8; ++n) {
boolean empty = true;
for(int x = 0; x < 16 && empty; ++x) {
for(int y = 0; y < 16 && empty; ++y) {
for(int z = 0; z < 16; ++z) {
int pos = x << 11 | z << 7 | y + (n << 4);
int blk = oldblks[pos];
if(blk != 0) {
empty = false;
break;
}
}
}
}
if(!empty) {
byte[] blocks = new byte[4096];
NibbleArray data = new NibbleArray();
NibbleArray sky = new NibbleArray();
NibbleArray light = new NibbleArray();
for(int x = 0; x < 16; ++x) {
for(int y = 0; y < 16; ++y) {
for(int z = 0; z < 16; ++z) {
int pos = x << 11 | z << 7 | y + (n << 4);
int blk = oldblks[pos];
blocks[y << 8 | z << 4 | x] = (byte)(blk & 255);
data.set(x, y, z, getNibble(olddata, x, y + (n << 4), z));
light.set(x, y, z, getNibble(oldlight, x, y + (n << 4), z));
}
}
}
TagObject section = new TagObject();
section.setByte("Y", (byte)(n & 255));
section.setByteArray("Blocks", blocks);
section.setByteArray("Data", data.getData());
section.setByteArray("BlockLight", light.getData());
sections.add(section);
}
}
ntag.setList("S", sections);
}
else {
ntag.setIntArray("H", tag.getIntArray("HeightMap"));
}
ntag.setIntArray("H", tag.getIntArray("HeightMap"));
ntag.setBool("P", true);
ntag.setList("E", Lists.newArrayList());
NbtTag[] tes = tag.getTagList("TileEntities");
@ -1563,7 +1509,6 @@ public abstract class Converter {
TagObject nsect = new TagObject();
nsect.setInt("Y", y);
nsect.setByteArray("D", newblks);
nsect.setByteArray("B", sect.getByteArray("BlockLight"));
list.add(nsect);
}
@ -1577,7 +1522,6 @@ public abstract class Converter {
private static long convertChunks(File dir, File file, long start, int progress, int total) {
String name = file.getName();
boolean legacy = name.endsWith(".mcr");
int rx, rz;
String[] reg = name.split("\\.");
if(reg.length != 4) {
@ -1620,7 +1564,7 @@ public abstract class Converter {
}
NbtTag tag = readTag(in);
in.close();
TagObject ntag = convertChunkData(tag, legacy);
TagObject ntag = convertChunkData(tag);
newreg.writeTag(nx, nz, ntag);
}
}
@ -1685,17 +1629,17 @@ public abstract class Converter {
return null;
}
File chunkDir = new File(new File("chunk"), dest);
Log.IO.info("Durchsuche Ordner region/ nach .mca- und .mcr-Dateien ...");
Log.IO.info("Durchsuche Ordner region/ nach .mca-Dateien ...");
File[] files = regionDir.listFiles(new FilenameFilter() {
public boolean accept(File file, String name) {
return name.endsWith(".mca") || name.endsWith(".mcr");
return name.endsWith(".mca");
}
});
if(files.length == 0) {
Log.IO.info("Keine .mca- oder .mcr-Dateien gefunden");
Log.IO.info("Keine .mca-Dateien gefunden");
return null;
}
Log.IO.info("Konvertiere %d .mca- und .mcr-Datei%s (%s) von region/*.mca,*.mcr nach %s ...", files.length, files.length == 1 ? "" : "en", ver, chunkDir);
Log.IO.info("Konvertiere %d .mca-Datei%s (%s) von region/*.mca nach %s ...", files.length, files.length == 1 ? "" : "en", ver, chunkDir);
if(ver == SaveVersion.RELEASE_1_9)
Log.IO.warn("Konvertiere von neuerer Version, dies wird Blöcke entfernen ...");
chunkDir.mkdirs();

View file

@ -30,7 +30,6 @@ import common.log.Log;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.NibbleArray;
import common.util.Util;
import common.world.BlockArray;
import common.world.State;
@ -502,7 +501,6 @@ public class Region {
}
storage.setData(seg);
storage.setBlocklight(new NibbleArray(sect.getByteArray("B")));
storage.update();
sections[n] = storage;
@ -605,8 +603,6 @@ public class Region {
sect.setByteArray("D", blocks);
sect.setByteArray("B", storage.getBlocklight().getData());
sects.add(sect);
}
}

View file

@ -297,7 +297,6 @@ public final class WorldServer extends AWorldServer {
this.grng = new Random(this.seed ^ 836430928262265276L);
this.tempGen = new PerlinGen(this.grng, 1);
this.initGenerator(this.dimension.isExterminated());
this.calculateInitialSkylight();
this.calculateInitialWeather();
this.updatePhysics();
this.loadLoaderList();
@ -346,9 +345,6 @@ public final class WorldServer extends AWorldServer {
this.dropped.remove(v);
}
}
int light = this.calcSkylightSubtracted(true);
if(light != this.getSkylightSubtracted())
this.setSkylightSubtracted(light);
// if(this.primary)
// this.info.tick();
this.dimension.setTimeExisted(this.time += 1L);
@ -451,7 +447,7 @@ public final class WorldServer extends AWorldServer {
}
protected void updateBlocks() {
this.setActivePlayerChunksAndCheckLight(SVars.updateDistance);
this.setActiveChunks(SVars.updateDistance);
int dtics = 0;
int rtics = 0;
@ -465,7 +461,6 @@ public final class WorldServer extends AWorldServer {
// this.playMoodSound(k, l, chunk);
// this.profiler.next("checkLight");
// this.profiler.next("tickChunk");
chunk.update(false);
// this.profiler.next("thunder");
int tics = SVars.boltChance;
@ -561,7 +556,7 @@ public final class WorldServer extends AWorldServer {
3.0D, 3.0D);
List<EntityLiving> list = this.getEntitiesWithinAABB(EntityLiving.class, axisalignedbb, new Predicate<EntityLiving>() {
public boolean test(EntityLiving p_apply_1_) {
return p_apply_1_ != null && p_apply_1_.isEntityAlive() && WorldServer.this.canSeeSky(p_apply_1_.getPosition());
return p_apply_1_ != null && p_apply_1_.isEntityAlive();
}
});
return !list.isEmpty() ? ((EntityLiving)list.get(this.rand.zrange(list.size()))).getPosition() : blockpos;
@ -1397,8 +1392,8 @@ public final class WorldServer extends AWorldServer {
private void populate(int x, int z) {
ChunkServer chunk = this.getChunk(x, z);
if(!chunk.isTerrainPopulated()) {
chunk.setTerrainPopulated(true);
if(x < -this.size || z < -this.size || x >= this.size || z >= this.size) {
chunk.setTerrainPopulated(true);
chunk.setModified(true);
return;
}
@ -1463,6 +1458,7 @@ public final class WorldServer extends AWorldServer {
}
// }
BlockFalling.fallInstantly = false;
chunk.setTerrainPopulated(true);
chunk.setModified(true);
}
}
@ -1470,7 +1466,7 @@ public final class WorldServer extends AWorldServer {
private ChunkServer generate(int x, int z) {
if(x < -this.size || z < -this.size || x >= this.size || z >= this.size) {
ChunkServer chunk = new ChunkServer(this, x, z);
chunk.genSky();
chunk.genHeightMap();
return chunk;
}
this.grng.setSeed((long)x * 341873128712L + (long)z * 132897987541L);
@ -1602,7 +1598,6 @@ public final class WorldServer extends AWorldServer {
if(!this.chunkExists(x + 1, z - 1))
this.insertChunk(x + 1, z - 1);
this.popChunk(x, z);
chunk.update(false);
}
this.entities.removeAll(this.unloaded);
for(int l = 0; l < this.unloaded.size(); ++l) {
@ -2015,15 +2010,13 @@ public final class WorldServer extends AWorldServer {
public boolean setState(BlockPos pos, State newState, int flags) {
if(!isValid(pos))
return false;
Chunk chunk = this.getChunk(pos);
ChunkServer chunk = this.getChunk(pos);
Block block = newState.getBlock();
State iblockstate = chunk.setState(pos, newState, (flags & 8) == 0);
if(iblockstate == null)
return false;
Block block1 = iblockstate.getBlock();
if((flags & 8) == 0 && (block.getLightOpacity() != block1.getLightOpacity() || block.getLight() != block1.getLight()))
this.checkBlockLight(pos);
if((flags & 2) != 0 && chunk.isPopulated())
if((flags & 2) != 0 && chunk.isTerrainPopulated())
this.markBlockForUpdate(pos);
if((flags & 1) != 0)
this.notifyNeighborsOfStateChange(pos, iblockstate.getBlock());
@ -2059,9 +2052,7 @@ public final class WorldServer extends AWorldServer {
// if(update) {
// if(!successful)
// newState = old;
this.checkBlockLight(pos);
if(chunk.isPopulated())
this.markBlockForUpdate(pos);
this.markBlockForUpdate(pos);
// this.notifyNeighborsRespectDebug(pos, old.getBlock());
// if(newState.getBlock().hasComparatorInputOverride())
// this.updateComparatorOutputLevel(pos, newState.getBlock());
@ -2092,23 +2083,8 @@ public final class WorldServer extends AWorldServer {
return entities;
}
public boolean isDaytime() {
return this.subtract < 4;
}
public int getSkylightSubtracted() {
return this.subtract;
}
public void setSkylightSubtracted(int newSkylightSubtracted) {
this.subtract = newSkylightSubtracted;
}
public boolean canStrikeAt(BlockPos strikePosition) {
if(!this.canSeeSky(strikePosition)) {
return false;
}
else if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) {
if(this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY()) {
return false;
}
return true;
@ -2181,7 +2157,7 @@ public final class WorldServer extends AWorldServer {
return false;
}
else {
if(pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y && this.getLightFor(pos) < 10) {
if(pos.getY() >= -World.MAX_SIZE_Y && pos.getY() < World.MAX_SIZE_Y) {
State iblockstate = this.getState(pos);
Block block = iblockstate.getBlock();
@ -2349,29 +2325,14 @@ public final class WorldServer extends AWorldServer {
this.dimension.getOrbitalPeriod()) * 4L / this.dimension.getOrbitalPeriod())]);
}
// public boolean canBlockSeeSky(BlockPos pos) {
// if(pos.getY() >= this.getSeaLevel()) {
// return this.canSeeSky(pos);
// }
// else {
// BlockPos blockpos = new BlockPos(pos.getX(), this.getSeaLevel(), pos.getZ());
//
// if(!this.canSeeSky(blockpos)) {
// return false;
// }
// else {
// for(blockpos = blockpos.down(); blockpos.getY() > pos.getY(); blockpos = blockpos.down()) {
// Block block = this.getBlockState(blockpos).getBlock();
//
// if(block.getLightOpacity() > 0 && !block.getMaterial().isLiquid()) {
// return false;
// }
// }
//
// return true;
// }
// }
// }
public BlockPos getHeight(BlockPos pos) {
int y;
if(pos.getX() >= -MAX_SIZE && pos.getZ() >= -MAX_SIZE && pos.getX() < MAX_SIZE && pos.getZ() < MAX_SIZE)
y = this.isLoaded(pos.getX() >> 4, pos.getZ() >> 4, true) ? this.getChunk(pos.getX() >> 4, pos.getZ() >> 4).getHeight(pos.getX() & 15, pos.getZ() & 15) : 0;
else
y = this.getSeaLevel() + 1;
return new BlockPos(pos.getX(), y, pos.getZ());
}
public boolean makePortal(BlockPos pos, int maxHeight, PortalType type) // TODO: Portals
{
@ -2892,7 +2853,7 @@ public final class WorldServer extends AWorldServer {
if(this.watching.contains(player)) {
ChunkServer chunk = WorldServer.this.getChunk(this.position.x, this.position.z);
if(chunk.isPopulated()) {
if(chunk.isTerrainPopulated()) {
player.connection.sendPacket(Player.getPacket(WorldServer.this, chunk, true, new int[0]));
}