3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Add more functionality to ChunkUtil (#3755)

Dieser Commit ist enthalten in:
RK_01 2024-03-24 11:05:30 +01:00 committet von GitHub
Ursprung feefe6f278
Commit 18f04bf8ea
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -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);
}
}
}
}