Skip to content

Commit 6ce7f42

Browse files
committed
update 1.20.2 adapters to use DataArrays
1 parent 6fbd229 commit 6ce7f42

File tree

4 files changed

+52
-64
lines changed

4 files changed

+52
-64
lines changed

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import com.fastasyncworldedit.core.queue.IChunkGet;
1111
import com.fastasyncworldedit.core.queue.IChunkSet;
1212
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
13-
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
13+
import com.fastasyncworldedit.core.queue.implementation.blocks.DataArray;
14+
import com.fastasyncworldedit.core.queue.implementation.blocks.DataArrayGetBlocks;
1415
import com.fastasyncworldedit.core.util.MathMan;
1516
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
1617
import com.google.common.base.Suppliers;
@@ -63,7 +64,7 @@
6364

6465
import static net.minecraft.core.registries.Registries.BIOME;
6566

66-
public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBlocks {
67+
public class PaperweightGetBlocks extends DataArrayGetBlocks implements BukkitGetBlocks {
6768

6869
private static final Logger LOGGER = LogManagerCompat.getLogger();
6970

@@ -445,7 +446,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
445446
);
446447
LevelChunkSection newSection = PaperweightPlatformAdapter.newChunkSection(
447448
layerNo,
448-
new char[4096],
449+
DataArray.createEmpty(),
449450
adapter,
450451
biomeRegistry,
451452
biomeData
@@ -456,7 +457,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
456457
newSection,
457458
getSectionIndex
458459
)) {
459-
updateGet(nmsChunk, levelChunkSections, newSection, new char[4096], getSectionIndex);
460+
updateGet(nmsChunk, levelChunkSections, newSection, DataArray.createEmpty(), getSectionIndex);
460461
continue;
461462
} else {
462463
existingSection = levelChunkSections[getSectionIndex];
@@ -479,9 +480,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
479480

480481
// setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
481482
// this chunk GET when #updateGet is called. Future dords, please listen this time.
482-
char[] tmp = set.load(layerNo);
483-
char[] setArr = new char[tmp.length];
484-
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
483+
DataArray setArr = DataArray.createCopy(set.load(layerNo));
485484

486485
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
487486
// submitted to keep loaded internal chunks to queue target size.
@@ -498,10 +497,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
498497
}
499498

500499
if (createCopy) {
501-
char[] tmpLoad = loadPrivately(layerNo);
502-
char[] copyArr = new char[4096];
503-
System.arraycopy(tmpLoad, 0, copyArr, 0, 4096);
504-
copy.storeSection(getSectionIndex, copyArr);
500+
copy.storeSection(getSectionIndex, DataArray.createCopy(loadPrivately(layerNo)));
505501
if (biomes != null && existingSection != null) {
506502
copy.storeBiomes(getSectionIndex, existingSection.getBiomes());
507503
}
@@ -563,10 +559,8 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
563559
} else if (existingSection != getSections(false)[getSectionIndex]) {
564560
this.sections[getSectionIndex] = existingSection;
565561
this.reset();
566-
} else if (!Arrays.equals(
567-
update(getSectionIndex, new char[4096], true),
568-
loadPrivately(layerNo)
569-
)) {
562+
} else if (!update(getSectionIndex, DataArray.createEmpty(), true)
563+
.equals(loadPrivately(layerNo))) {
570564
this.reset(layerNo);
571565
/*} else if (lock.isModified()) {
572566
this.reset(layerNo);*/
@@ -837,7 +831,7 @@ private void updateGet(
837831
LevelChunk nmsChunk,
838832
LevelChunkSection[] chunkSections,
839833
LevelChunkSection section,
840-
char[] arr,
834+
DataArray arr,
841835
int layer
842836
) {
843837
try {
@@ -862,14 +856,12 @@ private void updateGet(
862856
this.blocks[layer] = arr;
863857
}
864858

865-
private char[] loadPrivately(int layer) {
859+
private DataArray loadPrivately(int layer) {
866860
layer -= getMinSectionPosition();
867861
if (super.sections[layer] != null) {
868862
synchronized (super.sectionLocks[layer]) {
869863
if (super.sections[layer].isFull() && super.blocks[layer] != null) {
870-
char[] blocks = new char[4096];
871-
System.arraycopy(super.blocks[layer], 0, blocks, 0, 4096);
872-
return blocks;
864+
return DataArray.createCopy(super.blocks[layer]);
873865
}
874866
}
875867
}
@@ -893,21 +885,14 @@ public synchronized void send(int mask, boolean lighting) {
893885
*/
894886
@Override
895887
@SuppressWarnings("unchecked")
896-
public char[] update(int layer, char[] data, boolean aggressive) {
888+
public DataArray update(int layer, DataArray data, boolean aggressive) {
897889
LevelChunkSection section = getSections(aggressive)[layer];
898890
// Section is null, return empty array
899891
if (section == null) {
900-
data = new char[4096];
901-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
902-
return data;
892+
return DataArray.createFilled(BlockTypesCache.ReservedIDs.AIR);
903893
}
904-
if (data != null && data.length != 4096) {
905-
data = new char[4096];
906-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
907-
}
908-
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
909-
data = new char[4096];
910-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
894+
if (data == null || data == FaweCache.INSTANCE.EMPTY_DATA) {
895+
data = DataArray.createFilled(BlockTypesCache.ReservedIDs.AIR);
911896
}
912897
Semaphore lock = PaperweightPlatformAdapter.applyLock(section);
913898
synchronized (lock) {
@@ -920,7 +905,7 @@ public char[] update(int layer, char[] data, boolean aggressive) {
920905
final BitStorage bits = (BitStorage) PaperweightPlatformAdapter.fieldStorage.get(dataObject);
921906

922907
if (bits instanceof ZeroBitStorage) {
923-
Arrays.fill(data, adapter.adaptToChar(blocks.get(0, 0, 0))); // get(int) is only public on paper
908+
data.setAll(adapter.adaptToChar(blocks.get(0, 0, 0))); // get(int) is only public on paper
924909
return data;
925910
}
926911

@@ -937,9 +922,9 @@ public char[] update(int layer, char[] data, boolean aggressive) {
937922
} else {
938923
// The section's palette is the global block palette.
939924
for (int i = 0; i < 4096; i++) {
940-
char paletteVal = data[i];
925+
char paletteVal = (char) data.getAt(i);
941926
char ordinal = adapter.ibdIDToOrdinal(paletteVal);
942-
data[i] = ordinal;
927+
data.setAt(i, ordinal);
943928
}
944929
return data;
945930
}
@@ -952,17 +937,17 @@ public char[] update(int layer, char[] data, boolean aggressive) {
952937
paletteToOrdinal[i] = ordinal;
953938
}
954939
for (int i = 0; i < 4096; i++) {
955-
char paletteVal = data[i];
940+
char paletteVal = (char) data.getAt(i);
956941
char val = paletteToOrdinal[paletteVal];
957942
if (val == Character.MAX_VALUE) {
958943
val = ordinal(palette.valueFor(i), adapter);
959944
paletteToOrdinal[i] = val;
960945
}
961-
data[i] = val;
946+
data.setAt(i, val);
962947
}
963948
} else {
964949
char ordinal = ordinal(palette.valueFor(0), adapter);
965-
Arrays.fill(data, ordinal);
950+
data.setAll(ordinal);
966951
}
967952
} finally {
968953
for (int i = 0; i < num_palette; i++) {

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks_Copy.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fastasyncworldedit.core.queue.IBlocks;
55
import com.fastasyncworldedit.core.queue.IChunkGet;
66
import com.fastasyncworldedit.core.queue.IChunkSet;
7+
import com.fastasyncworldedit.core.queue.implementation.blocks.DataArray;
78
import com.google.common.base.Suppliers;
89
import com.sk89q.jnbt.CompoundTag;
910
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
@@ -39,7 +40,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
3940

4041
private final Map<BlockVector3, CompoundTag> tiles = new HashMap<>();
4142
private final Set<CompoundTag> entities = new HashSet<>();
42-
private final char[][] blocks;
43+
private final DataArray[] blocks;
4344
private final int minHeight;
4445
private final int maxHeight;
4546
final ServerLevel serverLevel;
@@ -51,7 +52,7 @@ protected PaperweightGetBlocks_Copy(LevelChunk levelChunk) {
5152
this.serverLevel = levelChunk.level;
5253
this.minHeight = serverLevel.getMinBuildHeight();
5354
this.maxHeight = serverLevel.getMaxBuildHeight() - 1; // Minecraft max limit is exclusive.
54-
this.blocks = new char[getSectionCount()][];
55+
this.blocks = new DataArray[getSectionCount()];
5556
}
5657

5758
protected void storeTile(BlockEntity blockEntity) {
@@ -165,7 +166,7 @@ public int getSectionCount() {
165166
return serverLevel.getSectionsCount();
166167
}
167168

168-
protected void storeSection(int layer, char[] data) {
169+
protected void storeSection(int layer, DataArray data) {
169170
blocks[layer] = data;
170171
}
171172

@@ -197,13 +198,13 @@ public boolean hasSection(int layer) {
197198
}
198199

199200
@Override
200-
public char[] load(int layer) {
201+
public DataArray load(int layer) {
201202
layer -= getMinSectionPosition();
202203
return blocks[layer];
203204
}
204205

205206
@Override
206-
public char[] loadIfPresent(int layer) {
207+
public DataArray loadIfPresent(int layer) {
207208
layer -= getMinSectionPosition();
208209
return blocks[layer];
209210
}
@@ -236,7 +237,7 @@ public <T extends Future<T>> T call(IChunkSet set, Runnable finalize) {
236237
public char get(int x, int y, int z) {
237238
final int layer = (y >> 4) - getMinSectionPosition();
238239
final int index = (y & 15) << 8 | z << 4 | x;
239-
return blocks[layer][index];
240+
return (char) blocks[layer].getAt(index);
240241
}
241242

242243

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlatformAdapter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fastasyncworldedit.core.Fawe;
88
import com.fastasyncworldedit.core.FaweCache;
99
import com.fastasyncworldedit.core.math.BitArrayUnstretched;
10+
import com.fastasyncworldedit.core.queue.implementation.blocks.DataArray;
1011
import com.fastasyncworldedit.core.util.MathMan;
1112
import com.fastasyncworldedit.core.util.ReflectionUtils;
1213
import com.fastasyncworldedit.core.util.TaskManager;
@@ -386,7 +387,7 @@ private static List<ServerPlayer> nearbyPlayers(ServerLevel serverLevel, ChunkPo
386387
*/
387388
public static LevelChunkSection newChunkSection(
388389
final int layer,
389-
final char[] blocks,
390+
final DataArray blocks,
390391
CachedBukkitAdapter adapter,
391392
Registry<Biome> biomeRegistry,
392393
@Nullable PalettedContainer<Holder<Biome>> biomes
@@ -396,8 +397,8 @@ public static LevelChunkSection newChunkSection(
396397

397398
public static LevelChunkSection newChunkSection(
398399
final int layer,
399-
final Function<Integer, char[]> get,
400-
char[] set,
400+
final Function<Integer, DataArray> get,
401+
DataArray set,
401402
CachedBukkitAdapter adapter,
402403
Registry<Biome> biomeRegistry,
403404
@Nullable PalettedContainer<Holder<Biome>> biomes

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPostProcessor.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fastasyncworldedit.core.queue.IChunk;
77
import com.fastasyncworldedit.core.queue.IChunkGet;
88
import com.fastasyncworldedit.core.queue.IChunkSet;
9+
import com.fastasyncworldedit.core.queue.implementation.blocks.DataArray;
910
import com.fastasyncworldedit.core.registry.state.PropertyKey;
1011
import com.sk89q.worldedit.extent.Extent;
1112
import com.sk89q.worldedit.world.block.BlockState;
@@ -36,14 +37,14 @@ public void postProcess(final IChunk chunk, final IChunkGet iChunkGet, final ICh
3637
PaperweightGetBlocks_Copy getBlocks = (PaperweightGetBlocks_Copy) iChunkGet;
3738
layer:
3839
for (int layer = iChunkSet.getMinSectionPosition(); layer <= iChunkSet.getMaxSectionPosition(); layer++) {
39-
char[] set = iChunkSet.loadIfPresent(layer);
40+
DataArray set = iChunkSet.loadIfPresent(layer);
4041
if (set == null) {
4142
// No edit means no need to process
4243
continue;
4344
}
44-
char[] get = null;
45+
DataArray get = null;
4546
for (int i = 0; i < 4096; i++) {
46-
char ordinal = set[i];
47+
char ordinal = (char) set.getAt(i);
4748
char replacedOrdinal = BlockTypesCache.ReservedIDs.__RESERVED__;
4849
boolean fromGet = false; // Used for liquids
4950
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
@@ -56,15 +57,15 @@ public void postProcess(final IChunk chunk, final IChunkGet iChunkGet, final ICh
5657
continue layer;
5758
}
5859
fromGet = true;
59-
ordinal = replacedOrdinal = get[i];
60+
ordinal = replacedOrdinal = (char) get.getAt(i);
6061
}
6162
if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) {
6263
continue;
6364
} else if (!fromGet) { // if fromGet, don't do the same again
6465
if (get == null) {
6566
get = getBlocks.load(layer);
6667
}
67-
replacedOrdinal = get[i];
68+
replacedOrdinal = (char) get.getAt(i);
6869
}
6970
boolean ticking = BlockTypesCache.ticking[ordinal];
7071
boolean replacedWasTicking = BlockTypesCache.ticking[replacedOrdinal];
@@ -115,39 +116,39 @@ public ProcessorScope getScope() {
115116
return ProcessorScope.READING_SET_BLOCKS;
116117
}
117118

118-
private boolean wasAdjacentToWater(char[] get, char[] set, int i, int x, int y, int z) {
119+
private boolean wasAdjacentToWater(DataArray get, DataArray set, int i, int x, int y, int z) {
119120
if (set == null || get == null) {
120121
return false;
121122
}
122123
char ordinal;
123124
char reserved = BlockTypesCache.ReservedIDs.__RESERVED__;
124-
if (x > 0 && set[i - 1] != reserved) {
125-
if (BlockTypesCache.ticking[(ordinal = get[i - 1])] && isFluid(ordinal)) {
125+
if (x > 0 && set.getAt(i - 1) != reserved) {
126+
if (BlockTypesCache.ticking[(ordinal = (char) get.getAt(i - 1))] && isFluid(ordinal)) {
126127
return true;
127128
}
128129
}
129-
if (x < 15 && set[i + 1] != reserved) {
130-
if (BlockTypesCache.ticking[(ordinal = get[i + 1])] && isFluid(ordinal)) {
130+
if (x < 15 && set.getAt(i + 1) != reserved) {
131+
if (BlockTypesCache.ticking[(ordinal = (char) get.getAt(i + 1))] && isFluid(ordinal)) {
131132
return true;
132133
}
133134
}
134-
if (z > 0 && set[i - 16] != reserved) {
135-
if (BlockTypesCache.ticking[(ordinal = get[i - 16])] && isFluid(ordinal)) {
135+
if (z > 0 && set.getAt(i - 16) != reserved) {
136+
if (BlockTypesCache.ticking[(ordinal = (char) get.getAt(i - 16))] && isFluid(ordinal)) {
136137
return true;
137138
}
138139
}
139-
if (z < 15 && set[i + 16] != reserved) {
140-
if (BlockTypesCache.ticking[(ordinal = get[i + 16])] && isFluid(ordinal)) {
140+
if (z < 15 && set.getAt(i + 16) != reserved) {
141+
if (BlockTypesCache.ticking[(ordinal = (char) get.getAt(i + 16))] && isFluid(ordinal)) {
141142
return true;
142143
}
143144
}
144-
if (y > 0 && set[i - 256] != reserved) {
145-
if (BlockTypesCache.ticking[(ordinal = get[i - 256])] && isFluid(ordinal)) {
145+
if (y > 0 && set.getAt(i - 256) != reserved) {
146+
if (BlockTypesCache.ticking[(ordinal = (char) get.getAt(i - 256))] && isFluid(ordinal)) {
146147
return true;
147148
}
148149
}
149-
if (y < 15 && set[i + 256] != reserved) {
150-
return BlockTypesCache.ticking[(ordinal = get[i + 256])] && isFluid(ordinal);
150+
if (y < 15 && set.getAt(i + 256) != reserved) {
151+
return BlockTypesCache.ticking[(ordinal = (char) get.getAt(i + 256))] && isFluid(ordinal);
151152
}
152153
return false;
153154
}

0 commit comments

Comments
 (0)