Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Simplify NMSAdapter#createPalette methods (#3036)
Dieser Commit ist enthalten in:
Ursprung
0cf981399e
Commit
c8f19849cb
@ -147,17 +147,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -385,28 +385,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
protected int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -420,7 +420,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -436,9 +436,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -146,17 +146,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -384,28 +384,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
public int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -420,7 +420,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -436,9 +436,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -156,17 +156,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -394,28 +394,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
public int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import com.fastasyncworldedit.core.math.BitArrayUnstretched;
|
|||||||
import com.fastasyncworldedit.core.math.IntPair;
|
import com.fastasyncworldedit.core.math.IntPair;
|
||||||
import com.fastasyncworldedit.core.util.MathMan;
|
import com.fastasyncworldedit.core.util.MathMan;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.mojang.datafixers.util.Either;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.Refraction;
|
import com.sk89q.worldedit.bukkit.adapter.Refraction;
|
||||||
@ -77,12 +76,11 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -415,7 +413,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -431,9 +429,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -156,17 +156,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -394,28 +394,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
public int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import com.fastasyncworldedit.core.math.BitArrayUnstretched;
|
|||||||
import com.fastasyncworldedit.core.math.IntPair;
|
import com.fastasyncworldedit.core.math.IntPair;
|
||||||
import com.fastasyncworldedit.core.util.MathMan;
|
import com.fastasyncworldedit.core.util.MathMan;
|
||||||
import com.fastasyncworldedit.core.util.TaskManager;
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.mojang.datafixers.util.Either;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.Refraction;
|
import com.sk89q.worldedit.bukkit.adapter.Refraction;
|
||||||
@ -76,12 +75,11 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -399,7 +397,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -415,9 +413,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -175,17 +175,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -376,28 +376,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
public int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -404,7 +404,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -420,9 +420,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -175,17 +175,17 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean init() {
|
private synchronized boolean init() {
|
||||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) {
|
if (ibdToOrdinal != null && ibdToOrdinal[1] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ibdToStateOrdinal = new char[BlockTypesCache.states.length]; // size
|
ibdToOrdinal = new int[BlockTypesCache.states.length]; // size
|
||||||
ordinalToIbdID = new int[ibdToStateOrdinal.length]; // size
|
ordinalToIbdID = new int[ibdToOrdinal.length]; // size
|
||||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
for (int i = 0; i < ibdToOrdinal.length; i++) {
|
||||||
BlockState blockState = BlockTypesCache.states[i];
|
BlockState blockState = BlockTypesCache.states[i];
|
||||||
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
PaperweightBlockMaterial material = (PaperweightBlockMaterial) blockState.getMaterial();
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
int id = Block.BLOCK_STATE_REGISTRY.getId(material.getState());
|
||||||
char ordinal = blockState.getOrdinalChar();
|
char ordinal = blockState.getOrdinalChar();
|
||||||
ibdToStateOrdinal[id] = ordinal;
|
ibdToOrdinal[id] = ordinal;
|
||||||
ordinalToIbdID[ordinal] = id;
|
ordinalToIbdID[ordinal] = id;
|
||||||
}
|
}
|
||||||
Map<String, List<Property<?>>> properties = new HashMap<>();
|
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) {
|
public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
int id = Block.BLOCK_STATE_REGISTRY.getId(blockState);
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||||
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToStateOrdinal length: {}. Defaulting to air!",
|
LOGGER.error("Attempted to convert {} with ID {} to char. ibdToOrdinal length: {}. Defaulting to air!",
|
||||||
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToStateOrdinal.length, e1
|
blockState.getBlock(), Block.BLOCK_STATE_REGISTRY.getId(blockState), ibdToOrdinal.length, e1
|
||||||
);
|
);
|
||||||
return BlockTypesCache.ReservedIDs.AIR;
|
return BlockTypesCache.ReservedIDs.AIR;
|
||||||
}
|
}
|
||||||
@ -376,28 +376,28 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
|||||||
|
|
||||||
public char ibdIDToOrdinal(int id) {
|
public char ibdIDToOrdinal(int id) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal[id];
|
return (char) ibdToOrdinal[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getIbdToStateOrdinal() {
|
public int[] getIbdToOrdinal() {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (initialised) {
|
if (initialised) {
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
return ibdToStateOrdinal;
|
return ibdToOrdinal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.IdMap;
|
import net.minecraft.core.IdMap;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
@ -80,7 +79,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
import static net.minecraft.core.registries.Registries.BIOME;
|
import static net.minecraft.core.registries.Registries.BIOME;
|
||||||
@ -400,7 +399,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
|
|
||||||
public static LevelChunkSection newChunkSection(
|
public static LevelChunkSection newChunkSection(
|
||||||
final int layer,
|
final int layer,
|
||||||
final Function<Integer, char[]> get,
|
final IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter,
|
||||||
Registry<Biome> biomeRegistry,
|
Registry<Biome> biomeRegistry,
|
||||||
@ -416,9 +415,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
|||||||
try {
|
try {
|
||||||
int num_palette;
|
int num_palette;
|
||||||
if (get == null) {
|
if (get == null) {
|
||||||
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, null);
|
num_palette = createPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter);
|
||||||
} else {
|
} 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);
|
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
||||||
|
@ -100,7 +100,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract char[] getIbdToStateOrdinal();
|
protected abstract int[] getIbdToOrdinal();
|
||||||
|
|
||||||
protected abstract int[] getOrdinalToIbdID();
|
protected abstract int[] getOrdinalToIbdID();
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import java.util.Map;
|
|||||||
public abstract class FaweAdapter<TAG, SERVER_LEVEL> extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<TAG> {
|
public abstract class FaweAdapter<TAG, SERVER_LEVEL> extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<TAG> {
|
||||||
|
|
||||||
protected final BukkitImplAdapter<TAG> parent;
|
protected final BukkitImplAdapter<TAG> parent;
|
||||||
protected char[] ibdToStateOrdinal = null;
|
protected int[] ibdToOrdinal = null;
|
||||||
protected int[] ordinalToIbdID = null;
|
protected int[] ordinalToIbdID = null;
|
||||||
protected boolean initialised = false;
|
protected boolean initialised = false;
|
||||||
protected Map<String, List<Property<?>>> allBlockProperties = null;
|
protected Map<String, List<Property<?>>> allBlockProperties = null;
|
||||||
|
@ -7,65 +7,34 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
|
|||||||
import com.fastasyncworldedit.core.util.MathMan;
|
import com.fastasyncworldedit.core.util.MathMan;
|
||||||
import com.fastasyncworldedit.core.util.ReflectionUtils;
|
import com.fastasyncworldedit.core.util.ReflectionUtils;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
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.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.StampedLock;
|
import java.util.concurrent.locks.StampedLock;
|
||||||
import java.util.function.Function;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
public class NMSAdapter implements FAWEPlatformAdapterImpl {
|
public class NMSAdapter implements FAWEPlatformAdapterImpl {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
|
||||||
|
|
||||||
public static int createPalette(
|
public static int createPalette(
|
||||||
int[] blockToPalette,
|
int[] blockToPalette,
|
||||||
int[] paletteToBlock,
|
int[] paletteToBlock,
|
||||||
int[] blocksCopy,
|
int[] blocksCopy,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter
|
||||||
short[] nonEmptyBlockCount
|
|
||||||
) {
|
) {
|
||||||
short nonAir = 4096;
|
int numPaletteEntries = 0;
|
||||||
int num_palette = 0;
|
|
||||||
for (int i = 0; i < 4096; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
char ordinal = set[i];
|
int ordinal = set[i];
|
||||||
switch (ordinal) {
|
ordinal = Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
|
||||||
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
|
|
||||||
ordinal = BlockTypesCache.ReservedIDs.AIR;
|
|
||||||
nonAir--;
|
|
||||||
}
|
|
||||||
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
|
|
||||||
}
|
|
||||||
int palette = blockToPalette[ordinal];
|
int palette = blockToPalette[ordinal];
|
||||||
if (palette == Integer.MAX_VALUE) {
|
if (palette == Integer.MAX_VALUE) {
|
||||||
blockToPalette[ordinal] = num_palette;
|
blockToPalette[ordinal] = numPaletteEntries;
|
||||||
paletteToBlock[num_palette] = ordinal;
|
paletteToBlock[numPaletteEntries] = ordinal;
|
||||||
num_palette++;
|
numPaletteEntries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
|
mapPalette(blockToPalette, paletteToBlock, blocksCopy, set, adapter, numPaletteEntries);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nonEmptyBlockCount != null) {
|
return numPaletteEntries;
|
||||||
nonEmptyBlockCount[0] = nonAir;
|
|
||||||
}
|
|
||||||
return num_palette;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int createPalette(
|
public static int createPalette(
|
||||||
@ -73,68 +42,55 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
|
|||||||
int[] blockToPalette,
|
int[] blockToPalette,
|
||||||
int[] paletteToBlock,
|
int[] paletteToBlock,
|
||||||
int[] blocksCopy,
|
int[] blocksCopy,
|
||||||
Function<Integer, char[]> get,
|
IntFunction<char[]> get,
|
||||||
char[] set,
|
char[] set,
|
||||||
CachedBukkitAdapter adapter,
|
CachedBukkitAdapter adapter
|
||||||
short[] nonEmptyBlockCount
|
|
||||||
) {
|
) {
|
||||||
short nonAir = 4096;
|
int numPaletteEntries = 0;
|
||||||
int num_palette = 0;
|
|
||||||
char[] getArr = null;
|
char[] getArr = null;
|
||||||
for (int i = 0; i < 4096; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
char ordinal = set[i];
|
char ordinal = set[i];
|
||||||
switch (ordinal) {
|
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
|
||||||
case BlockTypesCache.ReservedIDs.__RESERVED__ -> {
|
|
||||||
if (getArr == null) {
|
if (getArr == null) {
|
||||||
getArr = get.apply(layer);
|
getArr = get.apply(layer);
|
||||||
}
|
}
|
||||||
|
ordinal = getArr[i];
|
||||||
// write to set array as this should be a copied array, and will be important when the changes are written
|
// 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.
|
// to the GET chunk cached by FAWE. Future dords, actually read this comment please.
|
||||||
set[i] = switch (ordinal = getArr[i]) {
|
set[i] = (char) Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--;
|
|
||||||
}
|
}
|
||||||
int palette = blockToPalette[ordinal];
|
int palette = blockToPalette[ordinal];
|
||||||
if (palette == Integer.MAX_VALUE) {
|
if (palette == Integer.MAX_VALUE) {
|
||||||
blockToPalette[ordinal] = num_palette;
|
blockToPalette[ordinal] = numPaletteEntries;
|
||||||
paletteToBlock[num_palette] = ordinal;
|
paletteToBlock[numPaletteEntries] = ordinal;
|
||||||
num_palette++;
|
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 bits per entry is over 8, the game uses the global palette.
|
||||||
if (bitsPerEntry > 8 && adapter != null) {
|
if (bitsPerEntry > 8 && adapter != null) {
|
||||||
// Cannot System#array copy char[] -> int[];
|
System.arraycopy(adapter.getIbdToOrdinal(), 0, paletteToBlock, 0, adapter.getIbdToOrdinal().length);
|
||||||
for (int i = 0; i < adapter.getIbdToStateOrdinal().length; i++) {
|
|
||||||
paletteToBlock[i] = adapter.getIbdToStateOrdinal()[i];
|
|
||||||
}
|
|
||||||
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
|
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 4096; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
char ordinal = set[i];
|
int ordinal = set[i];
|
||||||
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
|
ordinal = Math.max(ordinal, BlockTypesCache.ReservedIDs.AIR);
|
||||||
LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air.");
|
|
||||||
ordinal = BlockTypesCache.ReservedIDs.AIR;
|
|
||||||
}
|
|
||||||
int palette = blockToPalette[ordinal];
|
int palette = blockToPalette[ordinal];
|
||||||
blocksCopy[i] = palette;
|
blocksCopy[i] = palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonEmptyBlockCount != null) {
|
|
||||||
nonEmptyBlockCount[0] = nonAir;
|
|
||||||
}
|
|
||||||
return num_palette;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +23,8 @@ public class SimpleBukkitAdapter extends CachedBukkitAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected char[] getIbdToStateOrdinal() {
|
protected int[] getIbdToOrdinal() {
|
||||||
return new char[Character.MAX_VALUE + 1];
|
return new int[Character.MAX_VALUE + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren