Sponge: Placing a custom block causes an ArrayIndexOutOfBoundsException in MixinBlock_BlockCapturing on initializeBlockCapturingState
I am currently running
- SpongeForge version: spongeforge-1.12.2-2611-7.1.0-BETA-2970.jar
- Forge version: Forge Mod Loader version 14.23.2.2635
- SpongeVanilla version: NO
- Java version: 8_186
- Operating System: DEBIAN
- Plugins/Mods: SpongeForge and DynmapForge, rest are private
Issue Description
I add custom blocks with Forge. Then I go ingame on forge server and place custom block. It works. Then I add SpongeForge and place custom block I get evil exception (see below). Doesnt make sense tbh because the same method that is used to get the id I use from forge and it is “gss-decor:statue_jupiter” which when split with : should have length 2 which it apparently doesnt have when sponge calls it. Im confused sorry.
Relevant Mixins https://github.com/SpongePowered/SpongeCommon/blob/bleeding/src/main/java/org/spongepowered/common/mixin/blockcapturing/MixinBlock_BlockCapturing.java#L55 https://github.com/SpongePowered/SpongeCommon/blob/bleeding/src/main/java/org/spongepowered/common/mixin/core/block/MixinBlock.java#L169
Calling this from Forge gets “gss-decor:statue_jupiter” (its used from the Mixin):
Block.REGISTRY.getNameForObject((Block) (Object) this).toString();
But somehow Sponge fails at ids[1]:
String[] ids = this.getId().split(":");
String modId = ids[0];
String name = ids[1];
Exception
[22:31:23] [Server thread/ERROR] [net.minecraft.server.MinecraftServer]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Exception while ticking a block
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:760) ~[MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:396) ~[nz.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:666) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_162]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at net.minecraft.block.Block.initializeBlockCapturingState(Block.java:3705) ~[aow.class:?]
at org.spongepowered.common.event.tracking.TrackingUtil.checkAndAssignBlockTickConfig(TrackingUtil.java:335) ~[TrackingUtil.class:1.12.2-2611-7.1.0-BETA-2970]
at org.spongepowered.common.event.tracking.TrackingUtil.updateTickBlock(TrackingUtil.java:276) ~[TrackingUtil.class:1.12.2-2611-7.1.0-BETA-2970]
at net.minecraft.world.WorldServer.redirect$onUpdateTick$zll000(WorldServer.java:2248) ~[oo.class:?]
at net.minecraft.world.WorldServer.func_72955_a(WorldServer.java:737) ~[oo.class:?]
at net.minecraft.world.WorldServer.func_72835_b(WorldServer.java:223) ~[oo.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:754) ~[MinecraftServer.class:?]
... 4 more
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (9 by maintainers)
Commits related to this issue
- Add failsafe for malformed block id registrations causing a crash when loading configs. This fixes #1845.; Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com> — committed to SpongePowered/Sponge by gabizou 6 years ago
- Bump common to fix SpongePowered/SpongeCommon#1845. Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com> — committed to SpongePowered/SpongeForge by gabizou 6 years ago
- Bump common for final method changes. Due to the issues with mods unintentionally and potentially overriding a SpongeAPI mixed in method, there's no verification or "exception handler" for us to hook... — committed to SpongePowered/SpongeForge by gabizou 5 years ago
The problem is at https://gist.github.com/nihiluis/e449fe235b72f6689fab60007426ddec#file-decorative-kt-L108 - this will create
And that will override getID that is already in block class.
https://github.com/SpongePowered/SpongeCommon/commit/cc085aff33913f99ff0cc020668ebf2f8d4c4634 - this commit actually fixes this issue, sort-of …
Explanation for @nihiluis: Because sponge is mixing into Block at runtime, kotlin wont generate any errors - it checks at compile time only.
Explanation for sponge dev’s: This is kind-of an issue with kotlin and sponge mixin’s. Kotlin by itself doesn’t allow to override methods by “error” - it requires override. But it only checks for methods at compile-time only ( why should it check at runtime, huh ? ) - and this is where the core of issue is.
Right now I can’t think of any fixes that won’t touch API compatibility. And this is also repeatable in java:
… or you could rewrite mixin’s to use abstract classes instead. This won’t generate callVirtual and will generate callSpecial instead, that will try to call path/to/abstractClass.getId() - but this is only theory as I don’t know how exactly callSpeciall is implemented - but this will still break API compat/API . Or write runtime patcher that would replace callVirtual with api classes to call base class that it was mixed in.
Ok, a new build has been published (had some issues with maven dependencies), can you give it a try now?
This was only closed because I ported a commit from stable-7 to our bleeding branch with a commit message that suggested it should be closed, I’ll reopen it.