Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash with Plenty of golems (1.19.2) #2

Closed
5stigma opened this issue Dec 18, 2023 · 12 comments
Closed

crash with Plenty of golems (1.19.2) #2

5stigma opened this issue Dec 18, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@5stigma
Copy link

5stigma commented Dec 18, 2023

crash-2023-12-18_03.16.47-server.txt

1.- Used jungle golem
2.- Crash

@TheGridExpert
Copy link
Owner

TheGridExpert commented Dec 18, 2023

Do you mean that you spawned a golem in jungle and then it crashed? What were the conditions?

@5stigma
Copy link
Author

5stigma commented Dec 18, 2023

The jungle golem can be picked up and used as a gun, it shoots cocoa bullets but when it collides with an enemy, it crashes.

@TheGridExpert
Copy link
Owner

TheGridExpert commented Dec 18, 2023

What mods do you have installed except for vampire's delight and Plenty of golems?

@5stigma
Copy link
Author

5stigma commented Dec 18, 2023

pfff, like 600 more mods, and among them, optimization mods, It was fixed with Neruina Mod but annoying messages appear

@TheGridExpert
Copy link
Owner

Oh, ok, I'll look what may cause the crush, the crash report looks quite weird

@5stigma
Copy link
Author

5stigma commented Dec 18, 2023

Yes, It must be one of the optimization mods, thanks to one who told me which ones were possibly responsible for the crash, I was able to know that it was this mod that caused it

@TheGridExpert
Copy link
Owner

It looks like it tries to use vampire bite enchantment on cocoa bullet or something like that.

@5stigma
Copy link
Author

5stigma commented Dec 18, 2023

yes, I noticed that in the report, but I couldn't figure out why it did it, and I suspect it may happen with more similar entities.

@5stigma
Copy link
Author

5stigma commented Dec 18, 2023

I will try some things and combinations of mods that I think may be responsible and if I find something I will report it to you.

@5stigma
Copy link
Author

5stigma commented Dec 19, 2023

Yes. is VampiresDelight, I have isolated the mods and I confirm that it is between the 2 mods

@Cheaterpaul
Copy link
Contributor

Solution

@TheGridExpert
you can optimize the method from

public static void onVampireBite(LivingHurtEvent event) {
LivingEntity attacker = (LivingEntity) event.getSource().getEntity();
if (attacker instanceof Player) {
ItemStack weapon = ((Player) attacker).getMainHandItem();
int enchantmentLevel = EnchantmentHelper.getItemEnchantmentLevel(VDEnchantments.VAMPIRE_BITE.get(), weapon);
Level level = event.getEntity().getCommandSenderWorld();
if (!level.isClientSide) {
healFromDamage(attacker, enchantmentLevel, event.getAmount());
}
}
}

to

@SubscribeEvent
public static void onVampireBite(LivingHurtEvent event) {
    if (event.getSource().getEntity() instanceof Player player) {
        ItemStack weapon = player.getMainHandItem();
        int enchantmentLevel = EnchantmentHelper.getItemEnchantmentLevel(VDEnchantments.VAMPIRE_BITE.get(), weapon);
        Level level = event.getEntity().getCommandSenderWorld();
        if (!level.isClientSide) {
            healFromDamage(player, enchantmentLevel, event.getAmount());
        }
    }
}

That way your code looks a little more fancy and you do not manually cast the Entity to LivingEntity.

Advice

And a piece of advice for the future.
You should only cast objects, if you either make an instanceof check or if you are 100% sure that the cast will be successful. For your own code and APIs that might be ok, like in Vampirism we can safely cast IVampirePlayer to VampirePlayer without checking, but if you work with Minecraft, Forge or other APIs you should always assume that the return type of a methods or attribute only guarantees you that you will get the type it specifies. Vanilla Minecraft might give you a specific subclass of the type for all their use cases, but other mods might break it.

@TheGridExpert
Copy link
Owner

Thank you. I'll change it in the next update

@TheGridExpert TheGridExpert added the bug Something isn't working label Jan 4, 2024
@PanPatrik PanPatrik mentioned this issue Apr 7, 2024
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants