use of net.minecraft.util.palette.PalettedContainer in project LoliServer by Loli-Server.
the class CraftChunk method getChunkSnapshot.
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
net.minecraft.world.chunk.Chunk chunk = getHandle();
ChunkSection[] cs = chunk.getSections();
PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
byte[][] sectionSkyLights = new byte[cs.length][];
byte[][] sectionEmitLights = new byte[cs.length][];
boolean[] sectionEmpty = new boolean[cs.length];
for (int i = 0; i < cs.length; i++) {
if (cs[i] == null) {
// Section is empty?
sectionBlockIDs[i] = emptyBlockIDs;
sectionSkyLights[i] = emptyLight;
sectionEmitLights[i] = emptyLight;
sectionEmpty[i] = true;
} else {
// Not empty
CompoundNBT data = new CompoundNBT();
cs[i].getStates().write(data, "Palette", "BlockStates");
// TODO: snapshot whole ChunkSection
PalettedContainer blockids = new PalettedContainer<net.minecraft.block.BlockState>(ChunkSection.GLOBAL_BLOCKSTATE_PALETTE, net.minecraft.block.Block.BLOCK_STATE_REGISTRY, NBTUtil::readBlockState, NBTUtil::writeBlockState, Blocks.AIR.defaultBlockState());
blockids.read(data.getList("Palette", CraftMagicNumbers.NBT.TAG_COMPOUND), data.getLongArray("BlockStates"));
sectionBlockIDs[i] = blockids;
WorldLightManager lightengine = chunk.level.getChunkSource().getLightEngine();
NibbleArray skyLightArray = lightengine.getLayerListener(LightType.SKY).getDataLayerData(SectionPos.of(x, i, z));
if (skyLightArray == null) {
sectionSkyLights[i] = emptyLight;
} else {
sectionSkyLights[i] = new byte[2048];
System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
}
NibbleArray emitLightArray = lightengine.getLayerListener(LightType.BLOCK).getDataLayerData(SectionPos.of(x, i, z));
if (emitLightArray == null) {
sectionEmitLights[i] = emptyLight;
} else {
sectionEmitLights[i] = new byte[2048];
System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
}
}
}
Heightmap hmap = null;
if (includeMaxBlockY) {
hmap = new Heightmap(null, Heightmap.Type.MOTION_BLOCKING);
hmap.setRawData(chunk.heightmaps.get(Heightmap.Type.MOTION_BLOCKING).getRawData());
}
BiomeContainer biome = null;
if (includeBiome || includeBiomeTempRain) {
biome = chunk.getBiomes();
}
World world = getWorld();
return new CraftChunkSnapshot(getX(), getZ(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, biome);
}
use of net.minecraft.util.palette.PalettedContainer in project Magma-1.16.x by magmafoundation.
the class CraftChunk method getChunkSnapshot.
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
net.minecraft.world.chunk.Chunk chunk = getHandle();
ChunkSection[] cs = chunk.getSections();
PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
byte[][] sectionSkyLights = new byte[cs.length][];
byte[][] sectionEmitLights = new byte[cs.length][];
boolean[] sectionEmpty = new boolean[cs.length];
for (int i = 0; i < cs.length; i++) {
if (cs[i] == null) {
// Section is empty?
sectionBlockIDs[i] = emptyBlockIDs;
sectionSkyLights[i] = emptyLight;
sectionEmitLights[i] = emptyLight;
sectionEmpty[i] = true;
} else {
// Not empty
CompoundNBT data = new CompoundNBT();
cs[i].getStates().write(data, "Palette", "BlockStates");
// TODO: snapshot whole ChunkSection
PalettedContainer blockids = new PalettedContainer<net.minecraft.block.BlockState>(ChunkSection.GLOBAL_BLOCKSTATE_PALETTE, net.minecraft.block.Block.BLOCK_STATE_REGISTRY, NBTUtil::readBlockState, NBTUtil::writeBlockState, Blocks.AIR.defaultBlockState());
blockids.read(data.getList("Palette", CraftMagicNumbers.NBT.TAG_COMPOUND), data.getLongArray("BlockStates"));
sectionBlockIDs[i] = blockids;
WorldLightManager lightengine = chunk.level.getChunkSource().getLightEngine();
NibbleArray skyLightArray = lightengine.getLayerListener(LightType.SKY).getDataLayerData(SectionPos.of(x, i, z));
if (skyLightArray == null) {
sectionSkyLights[i] = emptyLight;
} else {
sectionSkyLights[i] = new byte[2048];
System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
}
NibbleArray emitLightArray = lightengine.getLayerListener(LightType.BLOCK).getDataLayerData(SectionPos.of(x, i, z));
if (emitLightArray == null) {
sectionEmitLights[i] = emptyLight;
} else {
sectionEmitLights[i] = new byte[2048];
System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
}
}
}
Heightmap hmap = null;
if (includeMaxBlockY) {
hmap = new Heightmap(null, Heightmap.Type.MOTION_BLOCKING);
hmap.setRawData(chunk.heightmaps.get(Heightmap.Type.MOTION_BLOCKING).getRawData());
}
BiomeContainer biome = null;
if (includeBiome || includeBiomeTempRain) {
biome = chunk.getBiomes();
}
World world = getWorld();
return new CraftChunkSnapshot(getX(), getZ(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, biome);
}
use of net.minecraft.util.palette.PalettedContainer in project Magma-1.16.x by magmafoundation.
the class CraftChunk method getEmptyChunkSnapshot.
public static ChunkSnapshot getEmptyChunkSnapshot(int x, int z, CraftWorld world, boolean includeBiome, boolean includeBiomeTempRain) {
BiomeContainer biome = null;
if (includeBiome || includeBiomeTempRain) {
BiomeProvider wcm = world.getHandle().getChunkSource().getGenerator().getBiomeSource();
biome = new BiomeContainer(world.getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), new ChunkPos(x, z), wcm);
}
/* Fill with empty data */
int hSection = world.getMaxHeight() >> 4;
PalettedContainer[] blockIDs = new PalettedContainer[hSection];
byte[][] skyLight = new byte[hSection][];
byte[][] emitLight = new byte[hSection][];
boolean[] empty = new boolean[hSection];
for (int i = 0; i < hSection; i++) {
blockIDs[i] = emptyBlockIDs;
skyLight[i] = emptyLight;
emitLight[i] = emptyLight;
empty[i] = true;
}
return new CraftChunkSnapshot(x, z, world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(null, Heightmap.Type.MOTION_BLOCKING), biome);
}
use of net.minecraft.util.palette.PalettedContainer in project LoliServer by Loli-Server.
the class CraftChunk method getEmptyChunkSnapshot.
public static ChunkSnapshot getEmptyChunkSnapshot(int x, int z, CraftWorld world, boolean includeBiome, boolean includeBiomeTempRain) {
BiomeContainer biome = null;
if (includeBiome || includeBiomeTempRain) {
BiomeProvider wcm = world.getHandle().getChunkSource().getGenerator().getBiomeSource();
biome = new BiomeContainer(world.getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), new ChunkPos(x, z), wcm);
}
/* Fill with empty data */
int hSection = world.getMaxHeight() >> 4;
PalettedContainer[] blockIDs = new PalettedContainer[hSection];
byte[][] skyLight = new byte[hSection][];
byte[][] emitLight = new byte[hSection][];
boolean[] empty = new boolean[hSection];
for (int i = 0; i < hSection; i++) {
blockIDs[i] = emptyBlockIDs;
skyLight[i] = emptyLight;
emitLight[i] = emptyLight;
empty[i] = true;
}
return new CraftChunkSnapshot(x, z, world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(null, Heightmap.Type.MOTION_BLOCKING), biome);
}
Aggregations