diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java index af676c0fd1..fef07001be 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java @@ -147,17 +147,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -365,18 +365,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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 char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java index d7fab2dd64..99f52e4feb 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java @@ -82,7 +82,7 @@ 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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -436,9 +436,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java index 34a2d6ee00..9489ced914 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java @@ -146,17 +146,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -364,18 +364,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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 char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlatformAdapter.java index 2c05d74662..1ff6819638 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlatformAdapter.java @@ -82,7 +82,7 @@ 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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -436,9 +436,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java index 6351210dff..3a08095ef8 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java @@ -156,17 +156,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -374,18 +374,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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 char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlatformAdapter.java index e7672ce81d..3ddfbc6fbf 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlatformAdapter.java @@ -10,7 +10,6 @@ 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.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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -431,9 +429,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java index b75a6529e6..bdb4b67d76 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java @@ -156,17 +156,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -374,18 +374,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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 char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlatformAdapter.java index 662140955e..6881ea4e24 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlatformAdapter.java @@ -11,7 +11,6 @@ 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.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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -415,9 +413,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java index 69ba10a71c..c19759d109 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java @@ -175,17 +175,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -356,18 +356,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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 char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightPlatformAdapter.java index e7fb1b3959..3bd0f5fb5a 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightPlatformAdapter.java @@ -80,7 +80,7 @@ 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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -420,9 +420,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java index ae3b591beb..77dd0715ef 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java @@ -176,17 +176,17 @@ public BukkitImplAdapter getParent() { } 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>> properties = new HashMap<>(); @@ -357,18 +357,18 @@ public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockSt 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; } @@ -377,28 +377,28 @@ public char adaptToChar(net.minecraft.world.level.block.state.BlockState blockSt 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; } } diff --git a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightPlatformAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightPlatformAdapter.java index 99062a2b79..c5f896da0c 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightPlatformAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightPlatformAdapter.java @@ -24,7 +24,6 @@ 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.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 static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection( final int layer, - final Function get, + final IntFunction get, char[] set, CachedBukkitAdapter adapter, Registry biomeRegistry, @@ -416,9 +415,9 @@ public static LevelChunkSection newChunkSection( 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); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/CachedBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/CachedBukkitAdapter.java index 666b13e251..57dfe680ac 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/CachedBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/CachedBukkitAdapter.java @@ -100,7 +100,7 @@ public BlockState adapt(BlockData blockData) { } } - protected abstract char[] getIbdToStateOrdinal(); + protected abstract int[] getIbdToOrdinal(); protected abstract int[] getOrdinalToIbdID(); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java index 441cd1d87f..14f4bd7942 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java @@ -25,7 +25,7 @@ public abstract class FaweAdapter extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter { protected final BukkitImplAdapter parent; - protected char[] ibdToStateOrdinal = null; + protected int[] ibdToOrdinal = null; protected int[] ordinalToIbdID = null; protected boolean initialised = false; protected Map>> allBlockProperties = null; diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java index f8b240bb99..52035aa697 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java @@ -7,65 +7,34 @@ 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++; - } - } - 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]; + blockToPalette[ordinal] = numPaletteEntries; + paletteToBlock[numPaletteEntries] = ordinal; + numPaletteEntries++; } - 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 static int createPalette( int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy, - Function get, + IntFunction 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 diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/SimpleBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/SimpleBukkitAdapter.java index 6dc63f1794..34bc9d7c98 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/SimpleBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/SimpleBukkitAdapter.java @@ -23,8 +23,8 @@ private boolean init() { } @Override - protected char[] getIbdToStateOrdinal() { - return new char[Character.MAX_VALUE + 1]; + protected int[] getIbdToOrdinal() { + return new int[Character.MAX_VALUE + 1]; } @Override