Globox1997 / LevelZ

https://modrinth.com/mod/levelz
https://www.curseforge.com/minecraft/mc-mods/levelz
GNU General Public License v3.0
51 stars 50 forks source link

[crash] MCDW weapons make the game crash #79

Closed Kiryonn closed 2 years ago

Kiryonn commented 2 years ago

I don't know yet if it's doing it for all weapons or just a few but at least 2 weapons makes the game crash when using levelZ

it's hard to tell if it's comming from levelZ or mcdw since the crash report indicate that mcdw makes the game crash but i'm pretty sure it comes from levelZ.

also here is the issue made to chronosacari by someone else about something extremelly similar. let's not talk about the id of the issue x)

xillenburg commented 2 years ago

I have all of MCDungeons (weapons, armors, artifacts) mod on my world and not a single crash has occurred. I'm on 1.18 btw.

Kiryonn commented 2 years ago

i'm on 1.18.1

xillenburg commented 2 years ago

yeah im on 1.18.1. that's probably caused by other mods coz Im literally using a MCDW weapon rn (Void Touch Blade)

finallion commented 2 years ago

I'm getting the same crash log when using Levelz with The Graveyard. It crashes as soon as you use a weapon from The Graveyard in survival (not creative). The weapon extends the SwordItem class and Levelz tries to convert it to MiningToolItem causing the crash (https://pastebin.com/VvQLh6S6). It seems unlikely to be caused by the weapon - it is just extending the vanilla sword class, without adding extra stuff.

Globox1997 commented 2 years ago

We'll see here: https://github.com/chronosacaria/MCDungeonsWeapons/issues/69

MartinTornesello commented 2 years ago

The problem lies within the mixin in LevelZ for calculating max damage (PlayerEntityMixin.java row 142): it is caused because the mod uses fabric tags to determine if a toolitem is a sword, axe, hoe or else. Since many other mods dont register their items tag to be bound inside those fabric tags, even though the dagger in graveyard is a SwordItem, it is not registered in the FabricToolItems.SWORDS tag. PlayerEntityMixin.java Row 129 : if (playerEntity.getMainHandStack().isIn(FabricToolTags.SWORDS)) --> this returns false and the boolean isSword is not set to true. Because of this at line 142 the items is casted to MiningToolItem, which is not. Row 142: return zero ? 0 : original - ((MiningToolItem) playerEntity.getMainHandStack().getItem()).getAttackDamage();

A simple solution although not the best it may be to use reflection since the method in SwordItem and MiningToolItem is named the same and returns in both cases a float -> then the method can be invoked onto the item.

SO FROM Line 139: if (isSword) return zero ? 0 : original - ((SwordItem) playerEntity.getMainHandStack().getItem()).getAttackDamage(); else return zero ? 0 : original - ((MiningToolItem) playerEntity.getMainHandStack().getItem()).getAttackDamage(); }

TO

Line 139: try { Method getter = playerEntity.getMainHandStack().getItem().getClass().getDeclaredMethod("getAttackDamage"); float attackDamage = (float) getter.invoke(playerEntity.getMainHandStack().getItem()); return zero ? 0 : original - attackDamage; } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); }

Globox1997 commented 2 years ago

Thanks @MartinTornesello that is actually a very good idea, thanks for contributing

Globox1997 commented 2 years ago

Changed with https://github.com/Globox1997/LevelZ/commit/920c06effd6bf7e2f42f6fa73018cb7bb6afcabf

Globox1997 commented 2 years ago

Looks like it doesn't work outside dev env: java.lang.NoSuchMethodException: net.minecraft.class_1829.getAttackDamage()

Globox1997 commented 2 years ago

Fixed it now with https://github.com/Globox1997/LevelZ/commit/83b1519559f02606466b850ab62b9bb0e2283aac