Skip to content

Commit aadd6ac

Browse files
JayemCeekaySirYwell
authored andcommitted
Apply DataArray Patch and update bukkit adapters.
1 parent c0edab6 commit aadd6ac

File tree

53 files changed

+824
-811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+824
-811
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.common.util.concurrent.Futures;
2929
import com.mojang.datafixers.util.Either;
3030
import com.mojang.serialization.Lifecycle;
31+
import com.sk89q.jnbt.CompoundTag;
3132
import com.sk89q.jnbt.NBTConstants;
3233
import com.sk89q.worldedit.WorldEditException;
3334
import com.sk89q.worldedit.blocks.BaseItem;
@@ -145,7 +146,6 @@
145146
import org.spigotmc.SpigotConfig;
146147
import org.spigotmc.WatchdogThread;
147148

148-
import javax.annotation.Nullable;
149149
import java.lang.ref.WeakReference;
150150
import java.lang.reflect.Field;
151151
import java.lang.reflect.InvocationTargetException;
@@ -168,6 +168,7 @@
168168
import java.util.logging.Level;
169169
import java.util.logging.Logger;
170170
import java.util.stream.Collectors;
171+
import javax.annotation.Nullable;
171172

172173
import static com.google.common.base.Preconditions.checkNotNull;
173174
import static com.google.common.base.Preconditions.checkState;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.apache.logging.log4j.Logger;
5050
import org.enginehub.linbus.tree.LinCompoundTag;
5151

52-
import javax.annotation.Nullable;
5352
import java.lang.reflect.Type;
5453
import java.util.ArrayList;
5554
import java.util.EnumMap;
@@ -63,6 +62,7 @@
6362
import java.util.UUID;
6463
import java.util.concurrent.Executor;
6564
import java.util.stream.Collectors;
65+
import javax.annotation.Nullable;
6666

6767
/**
6868
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
import org.bukkit.event.block.BlockPhysicsEvent;
3838
import org.enginehub.linbus.tree.LinCompoundTag;
3939

40-
import javax.annotation.Nullable;
4140
import java.lang.ref.WeakReference;
4241
import java.util.Objects;
42+
import javax.annotation.Nullable;
4343

4444
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
4545
private static final int UPDATE = 1;

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

Lines changed: 21 additions & 34 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;
@@ -86,7 +87,7 @@
8687

8788
import static net.minecraft.core.registries.Registries.BIOME;
8889

89-
public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBlocks {
90+
public class PaperweightGetBlocks extends DataArrayGetBlocks implements BukkitGetBlocks {
9091

9192
private static final Logger LOGGER = LogManagerCompat.getLogger();
9293

@@ -495,7 +496,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
495496
);
496497
LevelChunkSection newSection = PaperweightPlatformAdapter.newChunkSection(
497498
layerNo,
498-
new char[4096],
499+
DataArray.createEmpty(),
499500
adapter,
500501
biomeRegistry,
501502
biomeData
@@ -506,7 +507,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
506507
newSection,
507508
getSectionIndex
508509
)) {
509-
updateGet(nmsChunk, levelChunkSections, newSection, new char[4096], getSectionIndex);
510+
updateGet(nmsChunk, levelChunkSections, newSection, DataArray.createEmpty(), getSectionIndex);
510511
continue;
511512
} else {
512513
existingSection = levelChunkSections[getSectionIndex];
@@ -536,9 +537,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
536537

537538
// setArr is modified by PaperweightPlatformAdapter#newChunkSection. This is in order to write changes to
538539
// this chunk GET when #updateGet is called. Future dords, please listen this time.
539-
char[] tmp = set.load(layerNo);
540-
char[] setArr = new char[tmp.length];
541-
System.arraycopy(tmp, 0, setArr, 0, tmp.length);
540+
DataArray setArr = DataArray.createCopy(set.load(layerNo));
542541

543542
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
544543
// submitted to keep loaded internal chunks to queue target size.
@@ -555,10 +554,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
555554
}
556555

557556
if (createCopy) {
558-
char[] tmpLoad = loadPrivately(layerNo);
559-
char[] copyArr = new char[4096];
560-
System.arraycopy(tmpLoad, 0, copyArr, 0, 4096);
561-
copy.storeSection(getSectionIndex, copyArr);
557+
copy.storeSection(getSectionIndex, DataArray.createCopy(loadPrivately(layerNo)));
562558
if (biomes != null && existingSection != null) {
563559
copy.storeBiomes(getSectionIndex, existingSection.getBiomes());
564560
}
@@ -616,10 +612,8 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
616612
} else if (existingSection != getSections(false)[getSectionIndex]) {
617613
this.sections[getSectionIndex] = existingSection;
618614
this.reset();
619-
} else if (!Arrays.equals(
620-
update(getSectionIndex, new char[4096], true),
621-
loadPrivately(layerNo)
622-
)) {
615+
} else if (!update(getSectionIndex, DataArray.createEmpty(), true)
616+
.equals(loadPrivately(layerNo))) {
623617
this.reset(layerNo);
624618
/*} else if (lock.isModified()) {
625619
this.reset(layerNo);*/
@@ -889,7 +883,7 @@ private void updateGet(
889883
LevelChunk nmsChunk,
890884
LevelChunkSection[] chunkSections,
891885
LevelChunkSection section,
892-
char[] arr,
886+
DataArray arr,
893887
int layer
894888
) {
895889
try {
@@ -914,7 +908,7 @@ private void updateGet(
914908
this.blocks[layer] = arr;
915909
}
916910

917-
private char[] loadPrivately(int layer) {
911+
private DataArray loadPrivately(int layer) {
918912
layer -= getMinSectionPosition();
919913
if (super.sections[layer] != null) {
920914
synchronized (super.sectionLocks[layer]) {
@@ -945,21 +939,14 @@ public void send() {
945939
*/
946940
@Override
947941
@SuppressWarnings("unchecked")
948-
public char[] update(int layer, char[] data, boolean aggressive) {
942+
public DataArray update(int layer, DataArray data, boolean aggressive) {
949943
LevelChunkSection section = getSections(aggressive)[layer];
950944
// Section is null, return empty array
951945
if (section == null) {
952-
data = new char[4096];
953-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
954-
return data;
946+
return DataArray.createFilled(BlockTypesCache.ReservedIDs.AIR);
955947
}
956-
if (data != null && data.length != 4096) {
957-
data = new char[4096];
958-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
959-
}
960-
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
961-
data = new char[4096];
962-
Arrays.fill(data, (char) BlockTypesCache.ReservedIDs.AIR);
948+
if (data == null || data == FaweCache.INSTANCE.EMPTY_DATA) {
949+
data = DataArray.createFilled(BlockTypesCache.ReservedIDs.AIR);
963950
}
964951
Semaphore lock = PaperweightPlatformAdapter.applyLock(section);
965952
synchronized (lock) {
@@ -972,7 +959,7 @@ public char[] update(int layer, char[] data, boolean aggressive) {
972959
final BitStorage bits = (BitStorage) PaperweightPlatformAdapter.fieldStorage.get(dataObject);
973960

974961
if (bits instanceof ZeroBitStorage) {
975-
Arrays.fill(data, adapter.adaptToChar(blocks.get(0, 0, 0))); // get(int) is only public on paper
962+
data.setAll(adapter.adaptToChar(blocks.get(0, 0, 0))); // get(int) is only public on paper
976963
return data;
977964
}
978965

@@ -989,9 +976,9 @@ public char[] update(int layer, char[] data, boolean aggressive) {
989976
} else {
990977
// The section's palette is the global block palette.
991978
for (int i = 0; i < 4096; i++) {
992-
char paletteVal = data[i];
979+
char paletteVal = (char) data.getAt(i);
993980
char ordinal = adapter.ibdIDToOrdinal(paletteVal);
994-
data[i] = ordinal;
981+
data.setAt(i, ordinal);
995982
}
996983
return data;
997984
}
@@ -1004,17 +991,17 @@ public char[] update(int layer, char[] data, boolean aggressive) {
1004991
paletteToOrdinal[i] = ordinal;
1005992
}
1006993
for (int i = 0; i < 4096; i++) {
1007-
char paletteVal = data[i];
994+
char paletteVal = (char) data.getAt(i);
1008995
char val = paletteToOrdinal[paletteVal];
1009996
if (val == Character.MAX_VALUE) {
1010997
val = ordinal(palette.valueFor(i), adapter);
1011998
paletteToOrdinal[i] = val;
1012999
}
1013-
data[i] = val;
1000+
data.setAt(i, val);
10141001
}
10151002
} else {
10161003
char ordinal = ordinal(palette.valueFor(0), adapter);
1017-
Arrays.fill(data, ordinal);
1004+
data.setAll(ordinal);
10181005
}
10191006
} finally {
10201007
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: 8 additions & 8 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;
@@ -40,7 +41,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
4041

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

5859
protected void storeTile(BlockEntity blockEntity) {
@@ -167,7 +168,7 @@ public int getSectionCount() {
167168
return serverLevel.getSectionsCount();
168169
}
169170

170-
protected void storeSection(int layer, char[] data) {
171+
protected void storeSection(int layer, DataArray data) {
171172
blocks[layer] = data;
172173
}
173174

@@ -204,17 +205,16 @@ public boolean hasSection(int layer) {
204205
}
205206

206207
@Override
207-
public char[] load(int layer) {
208+
public DataArray load(int layer) {
208209
layer -= getMinSectionPosition();
209210
if (blocks[layer] == null) {
210-
blocks[layer] = new char[4096];
211-
Arrays.fill(blocks[layer], (char) BlockTypesCache.ReservedIDs.AIR);
211+
blocks[layer] = DataArray.createFilled(BlockTypesCache.ReservedIDs.AIR);
212212
}
213213
return blocks[layer];
214214
}
215215

216216
@Override
217-
public char[] loadIfPresent(int layer) {
217+
public DataArray loadIfPresent(int layer) {
218218
layer -= getMinSectionPosition();
219219
return blocks[layer];
220220
}
@@ -247,7 +247,7 @@ public <T extends Future<T>> T call(IChunkSet set, Runnable finalize) {
247247
public char get(int x, int y, int z) {
248248
final int layer = (y >> 4) - getMinSectionPosition();
249249
final int index = (y & 15) << 8 | z << 4 | x;
250-
return blocks[layer][index];
250+
return (char) blocks[layer].getAt(index);
251251
}
252252

253253

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;
@@ -393,7 +394,7 @@ private static List<ServerPlayer> nearbyPlayers(ServerLevel serverLevel, ChunkPo
393394
*/
394395
public static LevelChunkSection newChunkSection(
395396
final int layer,
396-
final char[] blocks,
397+
final DataArray blocks,
397398
CachedBukkitAdapter adapter,
398399
Registry<Biome> biomeRegistry,
399400
@Nullable PalettedContainer<Holder<Biome>> biomes
@@ -403,8 +404,8 @@ public static LevelChunkSection newChunkSection(
403404

404405
public static LevelChunkSection newChunkSection(
405406
final int layer,
406-
final Function<Integer, char[]> get,
407-
char[] set,
407+
final Function<Integer, DataArray> get,
408+
DataArray set,
408409
CachedBukkitAdapter adapter,
409410
Registry<Biome> biomeRegistry,
410411
@Nullable PalettedContainer<Holder<Biome>> biomes

0 commit comments

Comments
 (0)