3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Simplify NMSAdapter#createPalette methods (#3036)

Dieser Commit ist enthalten in:
Hannes Greule 2024-12-23 21:28:42 +01:00 committet von GitHub
Ursprung 0cf981399e
Commit c8f19849cb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
16 geänderte Dateien mit 170 neuen und 219 gelöschten Zeilen

Datei anzeigen

@ -147,17 +147,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -365,18 +365,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -385,28 +385,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
protected int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -82,7 +82,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -420,7 +420,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -436,9 +436,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

@ -146,17 +146,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -364,18 +364,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -384,28 +384,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
public int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -82,7 +82,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -420,7 +420,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -436,9 +436,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

@ -156,17 +156,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -374,18 +374,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -394,28 +394,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
public int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -10,7 +10,6 @@ import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -77,12 +76,11 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -415,7 +413,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -431,9 +429,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

@ -156,17 +156,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -374,18 +374,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -394,28 +394,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
public int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -11,7 +11,6 @@ import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -76,12 +75,11 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -399,7 +397,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -415,9 +413,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

@ -175,17 +175,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -356,18 +356,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -376,28 +376,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
public int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -80,7 +80,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -404,7 +404,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -420,9 +420,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

@ -175,17 +175,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
}
private synchronized boolean init() {
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
return false;
}
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
for (int i = 0; i < ibdToOrdinal.length; i++) {
BlockState blockState = BlockTypesCache.states[i];
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
char ordinal = blockState.getOrdinalChar();
ibdToStateOrdinal[id] = ordinal;
ibdToOrdinal[id] = ordinal;
ordinalToIbdID[ordinal] = id;
}
Map<String, List<Property<?>>> properties = new HashMap<>();
@ -356,18 +356,18 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
try {
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
} catch (ArrayIndexOutOfBoundsException e1) {
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
);
return BlockTypesCache.ReservedIDs.AIR;
}
@ -376,28 +376,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public char ibdIDToOrdinal(int id) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
init();
return ibdToStateOrdinal[id];
return (char) ibdToOrdinal[id];
}
}
@Override
public char[] getIbdToStateOrdinal() {
public int[] getIbdToOrdinal() {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
synchronized (this) {
if (initialised) {
return ibdToStateOrdinal;
return ibdToOrdinal;
}
init();
return ibdToStateOrdinal;
return ibdToOrdinal;
}
}

Datei anzeigen

@ -24,7 +24,6 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.IdMap;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
@ -80,7 +79,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.IntFunction;
import static java.lang.invoke.MethodType.methodType;
import static net.minecraft.core.registries.Registries.BIOME;
@ -400,7 +399,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
public static LevelChunkSection newChunkSection(
final int layer,
final Function<Integer, char[]> get,
final IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
Registry<Biome> biomeRegistry,
@ -416,9 +415,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
try {
int num_palette;
if (get == null) {
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
} else {
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter, null);
num_palette = createPalette(layer, blockToPalette, paletteToBlock, blocksCopy, get, set, adapter);
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);

Datei anzeigen

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

Datei anzeigen

@ -25,7 +25,7 @@ import java.util.Map;
public abstract class FaweAdapter<TAG, SERVER_LEVEL> extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<TAG> {
protected final BukkitImplAdapter<TAG> parent;
protected char[] ibdToStateOrdinal = null;
protected int[] ibdToOrdinal = null;
protected int[] ordinalToIbdID = null;
protected boolean initialised = false;
protected Map<String, List<Property<?>>> allBlockProperties = null;

Datei anzeigen

@ -7,65 +7,34 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.ReflectionUtils;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Function;
import java.util.function.IntFunction;
public class NMSAdapter implements FAWEPlatformAdapterImpl {
private static final Logger LOGGER = LogManager.getLogger();
public static int createPalette(
int[] blockToPalette,
int[] paletteToBlock,
int[] blocksCopy,
char[] set,
CachedBukkitAdapter adapter,
short[] nonEmptyBlockCount
CachedBukkitAdapter adapter
) {
short nonAir = 4096;
int num_palette = 0;
int numPaletteEntries = 0;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
ordinal = BlockTypesCache.ReservedIDs.AIR;
nonAir--;
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
}
int ordinal = set[i];
ordinal = Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
blockToPalette[ordinal] = numPaletteEntries;
paletteToBlock[numPaletteEntries] = ordinal;
numPaletteEntries++;
}
}
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);
}
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
int palette = blockToPalette[ordinal];
blocksCopy[i] = palette;
}
mapPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, numPaletteEntries);
if (nonEmptyBlockCount != null) {
nonEmptyBlockCount[0] = nonAir;
}
return num_palette;
return numPaletteEntries;
}
public static int createPalette(
@ -73,68 +42,55 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
int[] blockToPalette,
int[] paletteToBlock,
int[] blocksCopy,
Function<Integer, char[]> get,
IntFunction<char[]> get,
char[] set,
CachedBukkitAdapter adapter,
short[] nonEmptyBlockCount
CachedBukkitAdapter adapter
) {
short nonAir = 4096;
int num_palette = 0;
int numPaletteEntries = 0;
char[] getArr = null;
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
switch (ordinal) {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
if (getArr == null) {
getArr = get.apply(layer);
}
// write to set array as this should be a copied array, and will be important when the changes are written
// to the GET chunk cached by FAWE. Future dords, actually read this comment please.
set[i] = switch (ordinal = getArr[i]) {
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
nonAir--;
yield (ordinal = BlockTypesCache.ReservedIDs.AIR);
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR,
BlockTypesCache.ReservedIDs.VOID_AIR -> {
nonAir--;
yield ordinal;
}
default -> ordinal;
};
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
if (getArr == null) {
getArr = get.apply(layer);
}
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
ordinal = getArr[i];
// write to set array as this should be a copied array, and will be important when the changes are written
// to the GET chunk cached by FAWE. Future dords, actually read this comment please.
set[i] = (char) Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
blockToPalette[ordinal] = numPaletteEntries;
paletteToBlock[numPaletteEntries] = ordinal;
numPaletteEntries++;
}
}
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
mapPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, numPaletteEntries);
return numPaletteEntries;
}
private static void mapPalette(
int[] blockToPalette,
int[] paletteToBlock,
int[] blocksCopy,
char[] set,
CachedBukkitAdapter adapter,
int numPaletteEntries
) {
int bitsPerEntry = MathMan.log2nlz(numPaletteEntries - 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.getIbdToOrdinal(), 0, paletteToBlock, 0, adapter.getIbdToOrdinal().length);
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
}
for (int i = 0; i < 4096; i++) {
char ordinal = set[i];
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air.");
ordinal = BlockTypesCache.ReservedIDs.AIR;
}
int ordinal = set[i];
ordinal = Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
int palette = blockToPalette[ordinal];
blocksCopy[i] = palette;
}
if (nonEmptyBlockCount != null) {
nonEmptyBlockCount[0] = nonAir;
}
return num_palette;
}
@Override

Datei anzeigen

@ -23,8 +23,8 @@ public class SimpleBukkitAdapter extends CachedBukkitAdapter {
}
@Override
protected char[] getIbdToStateOrdinal() {
return new char[Character.MAX_VALUE + 1];
protected int[] getIbdToOrdinal() {
return new int[Character.MAX_VALUE + 1];
}
@Override