use of net.minecraft.world.chunk.ChunkSection in project LoliServer by Loli-Server.
the class CraftChunk method contains.
@Override
public boolean contains(BlockData block) {
Preconditions.checkArgument(block != null, "Block cannot be null");
Predicate<net.minecraft.block.BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
for (ChunkSection section : getHandle().getSections()) {
if (section != null && section.getStates().maybeHas(nms)) {
return true;
}
}
return false;
}
use of net.minecraft.world.chunk.ChunkSection 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.world.chunk.ChunkSection in project Valkyrien-Skies-2 by ValkyrienSkies.
the class MixinClientChunkManager method preLoadChunkFromPacket.
@Inject(method = "loadChunkFromPacket", at = @At("HEAD"), cancellable = true)
private void preLoadChunkFromPacket(final int x, final int z, final BiomeArray biomes, final PacketByteBuf buf, final CompoundTag tag, final int verticalStripBitmask, final boolean complete, final CallbackInfoReturnable<WorldChunk> cir) {
final ClientChunkManagerClientChunkMapAccessor clientChunkMapAccessor = ClientChunkManagerClientChunkMapAccessor.class.cast(chunks);
if (!clientChunkMapAccessor.callIsInRadius(x, z)) {
if (ChunkAllocator.isChunkInShipyard(x, z)) {
final long chunkPosLong = ChunkPos.toLong(x, z);
final WorldChunk worldChunk = new WorldChunk(this.world, new ChunkPos(x, z), biomes);
worldChunk.loadFromPacket(biomes, buf, tag, verticalStripBitmask);
shipChunks.put(chunkPosLong, worldChunk);
final ChunkSection[] chunkSections = worldChunk.getSectionArray();
final LightingProvider lightingProvider = this.getLightingProvider();
lightingProvider.setColumnEnabled(new ChunkPos(x, z), true);
for (int j = 0; j < chunkSections.length; ++j) {
final ChunkSection chunkSection = chunkSections[j];
lightingProvider.setSectionStatus(ChunkSectionPos.from(x, j, z), ChunkSection.isEmpty(chunkSection));
}
this.world.resetChunkColor(x, z);
cir.setReturnValue(worldChunk);
}
}
}
use of net.minecraft.world.chunk.ChunkSection in project Valkyrien-Skies-2 by ValkyrienSkies.
the class MixinServerWorld method postTick.
@Inject(method = "tick", at = @At("TAIL"))
private void postTick(final BooleanSupplier shouldKeepTicking, final CallbackInfo ci) {
// First update the IPlayer wrapper list
updateVSPlayerWrappers();
// Find newly loaded chunks
final List<ChunkHolder> loadedChunksList = Lists.newArrayList(((ThreadedAnvilChunkStorageAccessor) serverChunkManager.threadedAnvilChunkStorage).callEntryIterator());
// Create DenseVoxelShapeUpdate for new loaded chunks
final List<IVoxelShapeUpdate> newLoadedChunks = new ArrayList<>();
for (final ChunkHolder chunkHolder : loadedChunksList) {
final Optional<WorldChunk> worldChunkOptional = chunkHolder.getTickingFuture().getNow(ChunkHolder.UNLOADED_WORLD_CHUNK).left();
if (worldChunkOptional.isPresent()) {
final WorldChunk worldChunk = worldChunkOptional.get();
final int chunkX = worldChunk.getPos().x;
final int chunkZ = worldChunk.getPos().z;
final ChunkSection[] chunkSections = worldChunk.getSectionArray();
// For now just assume chunkY goes from 0 to 16
for (int chunkY = 0; chunkY < 16; chunkY++) {
final ChunkSection chunkSection = chunkSections[chunkY];
final Vector3ic chunkPos = new Vector3i(chunkX, chunkY, chunkZ);
if (!knownChunkRegions.contains(chunkPos)) {
if (chunkSection != null) {
// Add this chunk to the ground rigid body
final DenseVoxelShapeUpdate voxelShapeUpdate = VSGameUtilsKt.toDenseVoxelUpdate(chunkSection, chunkPos);
newLoadedChunks.add(voxelShapeUpdate);
} else {
final EmptyVoxelShapeUpdate emptyVoxelShapeUpdate = new EmptyVoxelShapeUpdate(chunkPos.x(), chunkPos.y(), chunkPos.z(), false, false);
newLoadedChunks.add(emptyVoxelShapeUpdate);
}
knownChunkRegions.add(chunkPos);
}
}
}
}
// Then tick the ship world
shipObjectWorld.tickShips(newLoadedChunks);
// Send ships to clients
final IVSPacket shipDataPacket = VSPacketShipDataList.Companion.create(shipObjectWorld.getQueryableShipData().iterator());
for (final ServerPlayerEntity playerEntity : players) {
VSNetworking.shipDataPacketToClientSender.sendToClient(shipDataPacket, playerEntity);
}
// Then determine the chunk watch/unwatch tasks, and then execute them
final ImmutableList<IPlayer> playersToTick = ImmutableList.copyOf(vsPlayerWrappers.values());
final Pair<Spliterator<ChunkWatchTask>, Spliterator<ChunkUnwatchTask>> chunkWatchAndUnwatchTasksPair = shipObjectWorld.tickShipChunkLoading(playersToTick);
// Use Spliterator instead of iterators so that we can multi thread the execution of these tasks
final Spliterator<ChunkWatchTask> chunkWatchTasks = chunkWatchAndUnwatchTasksPair.getFirst();
final Spliterator<ChunkUnwatchTask> chunkUnwatchTasks = chunkWatchAndUnwatchTasksPair.getSecond();
// But for now just do it single threaded
chunkWatchTasks.forEachRemaining(chunkWatchTask -> {
System.out.println("Watch task for " + chunkWatchTask.getChunkX() + " : " + chunkWatchTask.getChunkZ());
final Packet<?>[] chunkPacketBuffer = new Packet[2];
final ChunkPos chunkPos = new ChunkPos(chunkWatchTask.getChunkX(), chunkWatchTask.getChunkZ());
// TODO: Move this somewhere else
serverChunkManager.setChunkForced(chunkPos, true);
for (final IPlayer player : chunkWatchTask.getPlayersNeedWatching()) {
final MinecraftPlayer minecraftPlayer = (MinecraftPlayer) player;
final ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) minecraftPlayer.getPlayerEntityReference().get();
if (serverPlayerEntity != null) {
((ThreadedAnvilChunkStorageAccessor) serverChunkManager.threadedAnvilChunkStorage).callSendWatchPackets(serverPlayerEntity, chunkPos, chunkPacketBuffer, false, true);
}
}
chunkWatchTask.onExecuteChunkWatchTask();
});
chunkUnwatchTasks.forEachRemaining(chunkUnwatchTask -> {
System.out.println("Unwatch task for " + chunkUnwatchTask.getChunkX() + " : " + chunkUnwatchTask.getChunkZ());
chunkUnwatchTask.onExecuteChunkUnwatchTask();
});
}
use of net.minecraft.world.chunk.ChunkSection in project ChocolateQuestRepoured by TeamChocoQuest.
the class GeneratableDungeon method tryGeneratePart.
private void tryGeneratePart(World world) {
long t = System.nanoTime();
for (IDungeonPart part : this.parts) {
part.generate(world, this);
}
for (ChunkInfo chunkInfo : this.chunkInfoMap.values()) {
Chunk chunk = world.getChunk(chunkInfo.getChunkX(), chunkInfo.getChunkZ());
if (world.provider.hasSkyLight()) {
for (int chunkY = chunkInfo.topMarked(); chunkY >= 0; chunkY--) {
ChunkSection blockStorage = chunk.getSections()[chunkY];
if (blockStorage == Chunk.EMPTY_SECTION) {
blockStorage = new ChunkSection(chunkY << 4);
chunk.getSections()[chunkY] = blockStorage;
}
Arrays.fill(blockStorage.getSkyLight().getData(), (byte) 0);
}
}
chunkInfo.forEach(chunkY -> {
ChunkSection blockStorage = chunk.getSections()[chunkY];
if (blockStorage != Chunk.EMPTY_SECTION) {
Arrays.fill(blockStorage.getBlockLight().getData(), (byte) 0);
}
int r = 1;
for (int x = -r; x <= r; x++) {
for (int y = -r; y <= r; y++) {
for (int z = -r; z <= r; z++) {
this.chunkInfoMapExtended.mark(chunkInfo.getChunkX() + x, chunkY + y, chunkInfo.getChunkZ() + z);
}
}
}
});
}
this.generationTimes[1] += System.nanoTime() - t;
}
Aggregations