From 18f04bf8eae901629fee6ab461b0d58db2abf09d Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Sun, 24 Mar 2024 11:05:30 +0100 Subject: [PATCH] Add more functionality to ChunkUtil (#3755) --- .../viaversion/viaversion/util/ChunkUtil.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/util/ChunkUtil.java b/api/src/main/java/com/viaversion/viaversion/util/ChunkUtil.java index 1d21c2ea3..875b62472 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/ChunkUtil.java +++ b/api/src/main/java/com/viaversion/viaversion/util/ChunkUtil.java @@ -22,19 +22,50 @@ */ package com.viaversion.viaversion.util; -import com.viaversion.viaversion.api.minecraft.chunks.*; - +import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; +import com.viaversion.viaversion.api.minecraft.chunks.Chunk; +import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import java.util.ArrayList; +import java.util.Arrays; public class ChunkUtil { public static Chunk createEmptyChunk(final int chunkX, final int chunkZ) { - final ChunkSection[] airSections = new ChunkSection[16]; + return createEmptyChunk(chunkX, chunkZ, 16, 0xFFFF); + } + + public static Chunk createEmptyChunk(final int chunkX, final int chunkZ, final int sectionCount) { + int sectionBitmask = 0; + for (int i = 0; i < sectionCount; i++) sectionBitmask = (sectionBitmask << 1) | 1; + return createEmptyChunk(chunkX, chunkZ, sectionCount, sectionBitmask); + } + + public static Chunk createEmptyChunk(final int chunkX, final int chunkZ, final int sectionCount, final int bitmask) { + final ChunkSection[] airSections = new ChunkSection[sectionCount]; for (int i = 0; i < airSections.length; i++) { airSections[i] = new ChunkSectionImpl(true); airSections[i].palette(PaletteType.BLOCKS).addId(0); } - return new BaseChunk(chunkX, chunkZ, true, false, 0xFFFF, airSections, new int[256], new ArrayList<>()); + return new BaseChunk(chunkX, chunkZ, true, false, bitmask, airSections, new int[256], new ArrayList<>()); } -} + public static void setDummySkylight(final Chunk chunk) { + setDummySkylight(chunk, false); + } + + public static void setDummySkylight(final Chunk chunk, final boolean fullbright) { + for (final ChunkSection section : chunk.getSections()) { + if (section == null) continue; + if (section.hasLight()) { + final byte[] skyLight = new byte[2048]; + if (fullbright) { + Arrays.fill(skyLight, (byte) 255); + } + section.getLight().setSkyLight(skyLight); + } + } + } + +} \ No newline at end of file