In custom `IBatchProcessor` using `setBlock` on negative layer results in ArrayIndexOutOfBoundsException
EpicPlayerA10 opened this issue ยท 2 comments
Server Implementation
Paper
Server Version
1.20.5/6
Describe the bug
I wrote my own IBatchProcessor
to replace every set block to coal block. Example:
public class FaweCustomBatchProcessor implements IBatchProcessor {
@Override
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
int bx = chunk.getX() << 4;
int bz = chunk.getZ() << 4;
for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
if (!set.hasSection(layer)) {
continue;
}
// loadIfPresent shouldn't be null if set.hasSection(layer) is true
char[] blocksSet = set.loadIfPresent(layer);
int by = layer << 4;
for (int y = 0, index = 0; y < 16; y++) {
int yy = y + by;
for (int z = 0; z < 16; z++) {
int zz = z + bz;
for (int x = 0; x < 16; x++, index++) {
final int rawStateSet = blocksSet[index];
if (rawStateSet == BlockTypesCache.ReservedIDs.__RESERVED__) continue;
set.setBlock(x, yy, z, BlockTypes.COAL_BLOCK.getDefaultState());
}
}
}
}
return set;
}
@Nullable
@Override
public Extent construct(Extent child) {
return null;
}
@Override
public ProcessorScope getScope() {
return ProcessorScope.CHANGING_BLOCKS;
}
}
When I try to copy an area from top to bottom (//expand vert
) and paste it, then blocks are not replaced and it will throw this error:
[19:20:26] [FAWE QueueHandler Blocking Executor - 8/ERROR]: [com.fastasyncworldedit.core.queue.implementation.blocks.ThreadUnsafeCharBlocks] Tried setting block at coordinates (12,-5,12)
[19:20:26] [FAWE QueueHandler Blocking Executor - 8/ERROR]: [com.fastasyncworldedit.core.queue.implementation.blocks.ThreadUnsafeCharBlocks] Layer variable was = -1
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 20
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.queue.implementation.blocks.ThreadUnsafeCharBlocks.set(ThreadUnsafeCharBlocks.java:228) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.queue.implementation.blocks.ThreadUnsafeCharBlocks.setBlock(ThreadUnsafeCharBlocks.java:239) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at TestPlugin.jar/com.epicplayera10.testplugin.FaweCustomBatchProcessor.processSet(FaweCustomBatchProcessor.java:56) ~[TestPlugin.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor.processSet(MultiBatchProcessor.java:113) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor.processSet(MultiBatchProcessor.java:93) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder.processSet(BatchProcessorHolder.java:27) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder.processSet(BatchProcessorHolder.java:27) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:1028) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:1009) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar/com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:34) ~[FastAsyncWorldEdit-Bukkit-2.10.1-SNAPSHOT-785.jar:?]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[?:?]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
To Reproduce
- Use the custom
IBatchProcessor
above. - Copy section from top to bottom
//expand vert
- Paste it
- See error in console
Expected behaviour
It should replace every block with coal block and it should not show errors in the console
Screenshots / Videos
No response
Error log (if applicable)
No response
Fawe Debugpaste
https://athion.net/ISPaster/paste/view/04ebdfe459a14ab48576efefc64dbd15
Fawe Version
FastAsyncWorldEdit version 2.10.1-SNAPSHOT-790;a7e4d19
Checklist
- I have included a Fawe debugpaste.
- I am using the newest build from https://ci.athion.net/job/FastAsyncWorldEdit/ and the issue still persists.
Anything else?
No response
It's worth noting it's far more efficient to just write directly to the blocksSet array using the charcoal ordinal ID, and there's no need to loop over the get chunk sections if you're not reading anything from it, you can just do the set chunk