1.17.1 Servercrash by customentity

Discussion in 'Spigot Plugin Development' started by Diliard, Jul 31, 2021.

  1. Hello, I am writing a plugin which is supposed to turn all animals evil and attack you,
    right now I only wrote the pig to be evil but every time I leave the pig's range/the pig loses me the server crashes, and when I summon a pig I get a StackOverflow in my Console (It does not crash the server)

    Crash: Crash - Pastebin.com
    Custom pig code: AggressivePig - Pastebin.com
    Spawn code: Spawnevent - Pastebin.com
    Thanks for any help!
  2. Can you check the returning value (bool) of the method WordServer#addEntity
  3. It returns true, the pig also spawns, but the server crashes as soon as the pig loses me, I assume it's because the pig despawns (? not sure)
  4. EntityLiving var0 = this.a.getGoalTarget(); returns null
    Which means the Pig currently has no locked target as variable.
    In order to set one, you must call
    Code (Java):
    net.minecraft.world.entity.EntityInsentient#setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent);
    I'm not sure if this should be done manually by the server.
    But this explains the NullPointerException.

    Update: Maybe setting the priotity to 2 instead of 3.
  5. I'm sorry if this is a stupid question but do the priority levels have different effects except well setting the priority in which the goals are executed? (Changing from 3 to 2 still crashed the server but still thanks!!)

    I think the best way to fix this issue would be to see how other mobs from vanilla handle having no target(?) I think that's a good point where I can continue to search for the reason
  6. I have to admit that this is not the subject I am especially experienced with.
    But nevertheless, you can try one more thing that I have up my sleeve.

    I've read somewhere that MeleeAtttackPathGoal is not applicable for the EntityPig.
    And therefore, you must remove that pathfindinggoal and replace it with an attribute such as:
    Code (Java):
    Disclaimer: I might be completely wrong, so don't take my word for it.
    #6 DanielTheDev, Jul 31, 2021
    Last edited: Jul 31, 2021
  7. Setting just the value to 1.0D didn't cause any big errors (the Stackoverflow didn't appear either which seems like only appears if a pig is summoned with the MeleeAttackPathGoal(?), I'm trying to write my own little targeting code right now to check if that maybe fixes it but I doubt itll work out, again thanks for your help^^