use of net.minecraft.world.chunk.ChunkSection in project LoliServer by Loli-Server.
the class CraftChunkData method setRegion.
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, net.minecraft.block.BlockState type) {
// Clamp to sane values.
if (xMin > 0xf || yMin >= maxHeight || zMin > 0xf) {
return;
}
if (xMin < 0) {
xMin = 0;
}
if (yMin < 0) {
yMin = 0;
}
if (zMin < 0) {
zMin = 0;
}
if (xMax > 0x10) {
xMax = 0x10;
}
if (yMax > maxHeight) {
yMax = maxHeight;
}
if (zMax > 0x10) {
zMax = 0x10;
}
if (xMin >= xMax || yMin >= yMax || zMin >= zMax) {
return;
}
for (int y = yMin; y < yMax; y++) {
ChunkSection section = getChunkSection(y, true);
int offsetBase = y & 0xf;
for (int x = xMin; x < xMax; x++) {
for (int z = zMin; z < zMax; z++) {
section.setBlockState(x, offsetBase, z, type);
}
}
}
}
use of net.minecraft.world.chunk.ChunkSection in project LoliServer by Loli-Server.
the class CustomChunkGenerator method buildSurfaceAndBedrock.
@Override
public void buildSurfaceAndBedrock(WorldGenRegion p_225551_1_, IChunk p_225551_2_) {
// Call the bukkit ChunkGenerator before structure generation so correct biome information is available.
int x = p_225551_2_.getPos().x;
int z = p_225551_2_.getPos().z;
random.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
// Get default biome data for chunk
CustomBiomeGrid biomegrid = new CustomBiomeGrid(new BiomeContainer(world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), p_225551_2_.getPos(), this.getBiomeSource()));
ChunkData data;
if (generator.isParallelCapable()) {
data = generator.generateChunkData(this.world.getWorld(), random, x, z, biomegrid);
} else {
synchronized (this) {
data = generator.generateChunkData(this.world.getWorld(), random, x, z, biomegrid);
}
}
Preconditions.checkArgument(data instanceof CraftChunkData, "Plugins must use createChunkData(World) rather than implementing ChunkData: %s", data);
CraftChunkData craftData = (CraftChunkData) data;
ChunkSection[] sections = craftData.getRawChunkData();
ChunkSection[] csect = p_225551_2_.getSections();
int scnt = Math.min(csect.length, sections.length);
// Loop through returned sections
for (int sec = 0; sec < scnt; sec++) {
if (sections[sec] == null) {
continue;
}
ChunkSection section = sections[sec];
csect[sec] = section;
}
// Set biome grid
((ChunkPrimer) p_225551_2_).setBiomes(biomegrid.biome);
if (craftData.getTiles() != null) {
for (BlockPos pos : craftData.getTiles()) {
int tx = pos.getX();
int ty = pos.getY();
int tz = pos.getZ();
Block block = craftData.getTypeId(tx, ty, tz).getBlock();
if (block.isEntityBlock()) {
TileEntity tile = ((ITileEntityProvider) block).newBlockEntity(world);
p_225551_2_.setBlockEntity(new BlockPos((x << 4) + tx, ty, (z << 4) + tz), tile);
}
}
}
}
use of net.minecraft.world.chunk.ChunkSection in project Magma-1.16.x by magmafoundation.
the class CraftChunkData method setBlock.
private void setBlock(int x, int y, int z, net.minecraft.block.BlockState type) {
if (x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) {
return;
}
ChunkSection section = getChunkSection(y, true);
section.setBlockState(x, y & 0xf, z, type);
if (type.getBlock().hasTileEntity(type.getBlock().defaultBlockState())) {
if (tiles == null) {
tiles = new HashSet<>();
}
tiles.add(new BlockPos(x, y, z));
}
}
use of net.minecraft.world.chunk.ChunkSection in project Magma-1.16.x by magmafoundation.
the class CraftChunkData method setRegion.
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, net.minecraft.block.BlockState type) {
// Clamp to sane values.
if (xMin > 0xf || yMin >= maxHeight || zMin > 0xf) {
return;
}
if (xMin < 0) {
xMin = 0;
}
if (yMin < 0) {
yMin = 0;
}
if (zMin < 0) {
zMin = 0;
}
if (xMax > 0x10) {
xMax = 0x10;
}
if (yMax > maxHeight) {
yMax = maxHeight;
}
if (zMax > 0x10) {
zMax = 0x10;
}
if (xMin >= xMax || yMin >= yMax || zMin >= zMax) {
return;
}
for (int y = yMin; y < yMax; y++) {
ChunkSection section = getChunkSection(y, true);
int offsetBase = y & 0xf;
for (int x = xMin; x < xMax; x++) {
for (int z = zMin; z < zMax; z++) {
section.setBlockState(x, offsetBase, z, type);
}
}
}
}
use of net.minecraft.world.chunk.ChunkSection 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);
}
Aggregations