Minecraft uses the global block palette if there are more than 8 bits per entry in a chunk section

- Fixes #1228
Dieser Commit ist enthalten in:
dordsor21 2021-08-14 14:29:57 +01:00
Ursprung 98673b5743
Commit c287739be7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
4 geänderte Dateien mit 67 neuen und 53 gelöschten Zeilen

Datei anzeigen

@ -100,4 +100,8 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
}
}
protected abstract char[] getIbdToStateOrdinal();
protected abstract int[] getOrdinalToIbdID();
}

Datei anzeigen

@ -3,6 +3,7 @@ package com.fastasyncworldedit.bukkit.adapter;
import com.fastasyncworldedit.core.FAWEPlatformAdapterImpl;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
@ -16,10 +17,32 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
public static int createPalette(
int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy,
int[] num_palette_buffer, char[] set, Map<BlockVector3, Integer> ticking_blocks, boolean fastmode
int[] num_palette_buffer, char[] set, Map<BlockVector3, Integer> ticking_blocks, boolean fastmode,
CachedBukkitAdapter adapter
) {
int air = 0;
int num_palette = 0;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == BlockID.__RESERVED__) {
ordinal = BlockID.AIR;
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
// If bits per entry is over 8, the game uses the global palette.
if (bitsPerEntry > 8 && adapter != null) {
// Cannot System#array copy char[] -> int[];
for (int i = 0; i < adapter.getIbdToStateOrdinal().length; i++) {
paletteToBlock[i] = adapter.getIbdToStateOrdinal()[i];
}
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
}
char lastOrdinal = BlockID.__RESERVED__;
boolean lastticking = false;
boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED;
@ -55,11 +78,6 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
}
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[i] = palette;
}
num_palette_buffer[0] = num_palette;
@ -69,11 +87,39 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
public static int createPalette(
int layer, int[] blockToPalette, int[] paletteToBlock,
int[] blocksCopy, int[] num_palette_buffer, Function<Integer, char[]> get, char[] set,
Map<BlockVector3, Integer> ticking_blocks, boolean fastmode
Map<BlockVector3, Integer> ticking_blocks, boolean fastmode,
CachedBukkitAdapter adapter
) {
int air = 0;
int num_palette = 0;
char[] getArr = null;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == BlockID.__RESERVED__) {
if (getArr == null) {
getArr = get.apply(layer);
}
ordinal = getArr[i];
if (ordinal == BlockID.__RESERVED__) {
ordinal = BlockID.AIR;
}
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
// If bits per entry is over 8, the game uses the global palette.
if (bitsPerEntry > 8 && adapter != null) {
// Cannot System#array copy char[] -> int[];
for (int i = 0; i < adapter.getIbdToStateOrdinal().length; i++) {
paletteToBlock[i] = adapter.getIbdToStateOrdinal()[i];
}
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
}
char lastOrdinal = BlockID.__RESERVED__;
boolean lastticking = false;
boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED;
@ -143,54 +189,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
}
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[i] = palette;
}
//Keeping this here for reference.
//if (setblocks != 4096) {
// char[] getArr = get.apply(layer);
// for (i = setblocks; i < 4096; i++) {
// char ordinal = set[i];
// switch (ordinal) {
// case BlockID.__RESERVED__:
// ordinal = getArr[i];
// switch (ordinal) {
// case BlockID.__RESERVED__:
// ordinal = BlockID.AIR;
// case BlockID.AIR:
// case BlockID.CAVE_AIR:
// case BlockID.VOID_AIR:
// air++;
// break;
// default:
// BlockState state = BlockState.getFromOrdinal(ordinal);
// if (state.getMaterial().isTicksRandomly()) {
// ticking_blocks
// .put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15),
// WorldEditPlugin.getInstance().getBukkitImplAdapter()
// .getInternalBlockStateId(state).orElse(0));
// }
// set[i] = ordinal;
// }
// break;
// case BlockID.AIR:
// case BlockID.CAVE_AIR:
// case BlockID.VOID_AIR:
// air++;
// }
// int palette = blockToPalette[ordinal];
// if (palette == Integer.MAX_VALUE) {
// blockToPalette[ordinal] = palette = num_palette;
// paletteToBlock[num_palette] = ordinal;
// num_palette++;
// }
// blocksCopy[i] = palette;
// }
//}
num_palette_buffer[0] = num_palette;
return air;

Datei anzeigen

@ -22,6 +22,16 @@ public class SimpleBukkitAdapter extends CachedBukkitAdapter {
return true;
}
@Override
protected char[] getIbdToStateOrdinal() {
return new char[Character.MAX_VALUE + 1];
}
@Override
protected int[] getOrdinalToIbdID() {
return new int[Character.MAX_VALUE + 1];
}
/**
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder
*