Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ protected <T extends Future<T>> T internalCall(
new char[4096],
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(
Expand Down Expand Up @@ -484,6 +485,7 @@ protected <T extends Future<T>> T internalCall(
setArr,
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(
Expand Down Expand Up @@ -548,6 +550,7 @@ protected <T extends Future<T>> T internalCall(
setArr,
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData != null ? biomeData : (PalettedContainer<Holder<Biome>>) existingSection.getBiomes()
);
if (!PaperweightPlatformAdapter.setSectionAtomic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.minecraft.core.BlockPos;
Expand All @@ -33,13 +32,13 @@
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.util.ProblemReporter;
import net.minecraft.util.ThreadingDetector;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
Expand Down Expand Up @@ -402,9 +401,10 @@ public static LevelChunkSection newChunkSection(
final char[] blocks,
CachedBukkitAdapter adapter,
RegistryAccess registryAccess,
Strategy<net.minecraft.world.level.block.state.BlockState> strategy,
@Nullable PalettedContainer<Holder<Biome>> biomes
) {
return newChunkSection(layer, null, blocks, adapter, registryAccess, biomes);
return newChunkSection(layer, null, blocks, adapter, registryAccess, strategy, biomes);
}

public static LevelChunkSection newChunkSection(
Expand All @@ -413,6 +413,7 @@ public static LevelChunkSection newChunkSection(
char[] set,
CachedBukkitAdapter adapter,
RegistryAccess registryAccess,
Strategy<net.minecraft.world.level.block.state.BlockState> strategy,
@Nullable PalettedContainer<Holder<Biome>> biomes
) {
if (set == null) {
Expand All @@ -425,47 +426,36 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, true);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, true);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
if (bitsPerEntry > 0 && bitsPerEntry < 5) {
bitsPerEntry = 4;
} else if (bitsPerEntry > 8) {
bitsPerEntry = MathMan.log2nlz(Block.BLOCK_STATE_REGISTRY.size() - 1);
}

int bitsPerEntryNonZero = Math.max(bitsPerEntry, 1); // We do want to use zero sometimes
final int blockBitArrayEnd = MathMan.longArrayLength(bitsPerEntryNonZero, 4096);

if (num_palette == 1) {
for (int i = 0; i < blockBitArrayEnd; i++) {
blockStates[i] = 0;
}
boolean singleValue = num_palette == 1;
LongStream bits;
if (singleValue) {
bits = null;
} else {
final BitArrayUnstretched bitArray = new BitArrayUnstretched(bitsPerEntryNonZero, 4096, blockStates);
int bitsPerEntry = Mth.ceillog2(num_palette);
if (bitsPerEntry < 4) {
bitsPerEntry = 4;
}
final int blockBitArrayEnd = MathMan.longArrayLength(bitsPerEntry, 4096);
final BitArrayUnstretched bitArray = new BitArrayUnstretched(bitsPerEntry, 4096, blockStates);

bitArray.fromRaw(blocksCopy);
bits = Arrays.stream(blockStates, 0, blockBitArrayEnd);
}

final long[] bits = Arrays.copyOfRange(blockStates, 0, blockBitArrayEnd);
List<net.minecraft.world.level.block.state.BlockState> palette;
if (bitsPerEntry < 9) {
palette = new ArrayList<>();
for (int i = 0; i < num_palette; i++) {
int ordinal = paletteToBlock[i];
blockToPalette[ordinal] = Integer.MAX_VALUE;
final BlockState state = BlockTypesCache.states[ordinal];
palette.add(((PaperweightBlockMaterial) state.getMaterial()).getState());
}
} else {
palette = List.of();
List<net.minecraft.world.level.block.state.BlockState> palette = new ArrayList<>();
for (int i = 0; i < num_palette; i++) {
int ordinal = paletteToBlock[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) BlockTypesCache.states[ordinal].getMaterial();
palette.add(material.getState());
}

// Create palette with data
var strategy = Strategy.createForBlockStates(Block.BLOCK_STATE_REGISTRY);
var packedData = new PalettedContainerRO.PackedData<>(palette, Optional.of(LongStream.of(bits)), bitsPerEntry);
var packedData = new PalettedContainerRO.PackedData<>(palette, Optional.ofNullable(bits));
DataResult<PalettedContainer<net.minecraft.world.level.block.state.BlockState>> result;
if (PaperLib.isPaper()) {
result = PalettedContainer.unpack(strategy, packedData, Blocks.AIR.defaultBlockState(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ public static LevelChunkSection newChunkSection(
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, false);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, false);
}

int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ protected <T extends Future<T>> T internalCall(
new char[4096],
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(
Expand Down Expand Up @@ -488,6 +489,7 @@ protected <T extends Future<T>> T internalCall(
setArr,
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(
Expand Down Expand Up @@ -552,6 +554,7 @@ protected <T extends Future<T>> T internalCall(
setArr,
adapter,
serverLevel.registryAccess(),
serverLevel.palettedContainerFactory().blockStatesStrategy(),
biomeData != null ? biomeData : (PalettedContainer<Holder<Biome>>) existingSection.getBiomes()
);
if (!PaperweightPlatformAdapter.setSectionAtomic(
Expand Down
Loading
Loading