ItemsAdder / ItemsAdderBlocksInjector

https://www.spigotmc.org/resources/itemsadderblocksinjector.102078/
5 stars 2 forks source link

FAWE compatibility #1

Open LoneDev6 opened 2 years ago

LoneDev6 commented 2 years ago

Here is the cause of the bug: https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/a240b002de435326aa5d0805709c5cd19ab126fe/worldedit-bukkit/adapters/adapter-1_18_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R2/PaperweightFaweAdapter.java#L410

Basically ibdToStateOrdinal is a cache array which doesn't contain my custom blocks. FAWE seems to populate it by iterating the Bukkit Material enum instead of the Block registry. The Material enum can't be edited even with reflection, so I cannot inject my custom blocks into that.

Here is where I think FAWE it populates its cache: https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/268d8cff49df810c5d8093aa7172606079f3114c/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java#L155

A solution would be to edit FAWE code to use the NMS Block registry instead of the Bukkit Material enum.

LoneDev6 commented 2 years ago

Here is the error I analyzed in order to come up with that conclusion

[17:21:08] [ForkJoinPool-8-worker-1/INFO]: Using com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.PaperweightStarlightRelighterFactory as relighter factory.
[17:21:08] [pool-34-thread-1/ERROR]: [com.fastasyncworldedit.core.FaweCache] Catching
java.lang.ArrayIndexOutOfBoundsException: Index 20375 out of bounds for length 20343
    at com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.PaperweightFaweAdapter.adaptToChar(PaperweightFaweAdapter.java:410) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.PaperweightGetBlocks.ordinal(PaperweightGetBlocks.java:991) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.PaperweightGetBlocks.update(PaperweightGetBlocks.java:956) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.blocks.CharBlocks$2.get(CharBlocks.java:46) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.blocks.CharBlocks$2.get(CharBlocks.java:38) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.blocks.CharBlocks.load(CharBlocks.java:153) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.extent.processor.heightmap.HeightmapProcessor.processSet(HeightmapProcessor.java:87) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor.processSet(MultiBatchProcessor.java:126) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor.processSet(MultiBatchProcessor.java:106) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder.processSet(BatchProcessorHolder.java:27) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder.processSet(BatchProcessorHolder.java:27) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:1008) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:997) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder.call(ChunkHolder.java:32) ~[FastAsyncWorldEdit-Bukkit-2.1.3-SNAPSHOT-179.jar:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]

FAWE is iterating their cache value assuming that the id obtained from Block.BLOCK_STATE_REGISTRY.getId is in their cache. It can't be in their cache because they populated it by using the Bukkit Material enum which doesn't contain injected blocks (enums can't be edited at runtime even with reflection so I can't fix it on my end).