MC Dungeons Weapons

MC Dungeons Weapons

12M Downloads

ClassCastException / Ticking entity crash

obernulpe opened this issue ยท 4 comments

commented

I was trying out the mining dimension of Gobber (duplicates Overworld) and found a Pillager Outpost with a dozen of Pillager around. After a minute of fighting the game crashed. Trying to rejoin the world results in the same crash.

This seems to be the same crash as #15 but in a different method.
After adding the fix for #15 to every method that injects into applyDamage() and didn't already check before casting, I can enter the world again.

---- Minecraft Crash Report ----
// Sorry :(

Time: 1/9/21, 6:16 PM
Description: Ticking entity

java.lang.ClassCastException: class net.minecraft.class_1667 cannot be cast to class net.minecraft.class_1309 (net.minecraft.class_1667 and net.minecraft.class_1309 are in unnamed module of loader net.fabricmc.loader.launch.knot.KnotClassLoader @5167f57d)
	at net.minecraft.class_1309.handler$zlm000$applyCommittedEnchantmentDamage(class_1309.java:6683)
	at net.minecraft.class_1309.method_6074(class_1309.java)
	at net.minecraft.class_1309.method_5643(class_1309.java:1035)
	at net.minecraft.class_1588.method_5643(class_1588.java:73)
	at net.minecraft.class_3763.method_5643(class_3763.java:295)
	at net.minecraft.class_1665.method_7454(class_1665.java:374)
	at net.minecraft.class_1676.method_7488(class_1676.java:118)
	at net.minecraft.class_1665.method_5773(class_1665.java:227)
	at net.minecraft.class_1667.method_5773(class_1667.java:103)
	at net.minecraft.class_3218.method_18762(class_3218.java:621)
	at net.minecraft.class_1937.method_18472(class_1937.java:561)
	at net.minecraft.class_3218.method_18765(class_3218.java:411)
	at net.minecraft.server.MinecraftServer.method_3813(MinecraftServer.java:871)
	at net.minecraft.server.MinecraftServer.method_3748(MinecraftServer.java:811)
	at net.minecraft.class_1132.method_3748(class_1132.java:91)
	at net.minecraft.server.MinecraftServer.handler$cln000$modifiedRunLoop(MinecraftServer.java:7310)
	at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:651)
	at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:257)
	at java.base/java.lang.Thread.run(Thread.java:834)
   
   -- Entity being ticked --
Details:
	Entity Type: minecraft:arrow (net.minecraft.class_1667)
	Entity ID: 322
	Entity Name: Arrow
	Entity's Exact location: -419.41, 66.29, -165.24
	Entity's Block location: World: (-420,66,-166), Chunk: (at 12,4,10 in -27,-11; contains blocks -432,0,-176 to -417,255,-161), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Entity's Momentum: 0.00, -0.05, 0.00
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
commented

I'm so sorry that happened. I've been chasing these ClassCastExceptions around like crazy. Could you give the latest version of Mcdw a go? It should fix this issue. (https://www.curseforge.com/minecraft/mc-mods/mcdw/files/3163525)

commented

The latest version also crashes.
I debugged the world with the source code imported in IDEA. The exception is thrown at:

public void applyCommittedEnchantmentDamage(DamageSource source, float amount, CallbackInfo info) {
        LivingEntity user = (LivingEntity) source.getAttacker(); // <-- ClassCastException here
        LivingEntity target = (LivingEntity) (Object) this;

So for whatever reason source.getAttacker() returns an ArrowEntity which cannot be casted into LivingEntity. I added the check before that line which fixes it for applyCommittedEnchantmentDamage():

public void applyCommittedEnchantmentDamage(DamageSource source, float amount, CallbackInfo info) {
        if(!(source.getAttacker() instanceof PlayerEntity)) return;
        LivingEntity user = (LivingEntity) source.getAttacker();

But after adding that line the game still crashes, this time at applyCriticalHitEnchantmentDamage(). So I do the same there and the crash occurs at the next method (applyEchoEnchantmentDamage) and so on.

In my understanding of the code every method that injects into applyDamage() will execute and crash here if there is no check before casting source.getAttacker() to LivingEntity.
So I added the same line to every of these methods and I could enter the world again. This seems to have fixed it.

commented

Thank you so much for digging into the code on this one. I'll be able to apply the fixes tomorrow. I am, unfortunately, fighting some illness the last few days but should be up and running tomorrow :)

commented

You're welcome :) wish you a speedy recovery!