NMS Entity Manager?

Discussion in 'Spigot Plugin Development' started by Daskrr, Jun 12, 2019.

  1. I was wondering where do all the methods of the entities and all pathfindergoals get called. Like I get that the entity gets spawned in the world and therefore there is an instance of that entity stored somewhere (probably in the nms World) but what calls the methods of that instance, I doubt they get called from within the entity itself because I saw a bunch of them never mentioned before in all those classes.
     
  2. What I usually do is look in the decompiled NMS files that come along when you use BuildTools to compile Spigot and see where a specific method gets called. I usually resort to the dum-dum way of simply using grep to find all occurrences of a specific method. However, due to the obfuscated nature of said files, if the method is #a or something like that, you might have trouble finding the specific method at hand.
     
    • Informative Informative x 1
  3. As with most games, there's a "tick" in the game that gets called every X ms or Y times per second. In the case of the minecraft server, it's 20 times per second (at least that's the goal). That game "tick" then calls the other things that also need to be updated as time progresses, which is the world (since the game itself doesn't directly know of entities). The world then goes through each entity it knows of and does a "tick" there as well as "tick" blocks if necessary.

    Each entity then decides what to do in this "tick" which usually consists of applying movement, damage over time effects (aka burn) and of course updates its "pathfinders" (though half of them have nothing to do with pathfinding). The pathfinders internally do multiple things: check if the currently executing pathfinders should continue, if new pathfinders need to be started and update the currently executing pathfinders. When a pathfinder gets started, updated or stopped it may do a variety of things to the entity which may affect its behavior (movement and other actions like sitting or jumping) and targeting.

    The methods on the entity can basically be called from anywhere in this chain starting at the world and keep in mind that if a pathfinder calls something on one entity, that entity may then call methods on another entity, causing sort of a chain reaction.
     
    • Like Like x 1
    • Winner Winner x 1
  4. That is what I use. Initially I used to decompile the server using luyten but it's inefficient and impossible in some cases as decompiling takes some time on larger classes and some of the classes cannot be decompiled by this decompiler (e.g.: Entity, EntityLiving), so I found that BuildTools actually stores those files. Pretty helpful what you said though.
    I also used decompiler.com which was able to decompile anything I gave it.
     
  5. Alright so it's a whole mess.
    I was wondering of this because I wanted to see how it works and by finding where the obfuscated methods are called and in what context I would understand what some of them do.

    By the way, what is the method that changes an EntityVillager's profession? Do you have any idea? (1.14)
     
  6. In 1.13 there was a method setProfession on villager available, would be surprised if that was no longer mapped in 1.14.

    But I wouldn't call it a mess, it's just a little harder to understand because of all the obfusecated names and not being able use show usages in the IDE. The "ticking" specifically is pretty common across most games, so it's pretty straight forward.
     
  7. Yeah, indeed...
    Indeed, I wanted to make a game server (for a browser game) and I used the ticking as it's pretty straight-forward and simple to use...
     
  8. You'd be surprised but there isn't such a method anymore due to the change made to villagers. There is however a #setVillagerData in EntityVillager but that's not the thing I was asking, I'm wondering what changes the profession of the villager depending on blocks around the villager and if they have access to them to work and stuff. I guess i'll take a deeper look at the code. (As I'm rewriting the EntityVillager in my own custom villager (that is not supposed to change profession) it's easier to remove that thing). Anyhow, thanks for your help! :D
     
  9. Oh I see. I haven't been following the changes so I wasn't aware. A quick glance is you can do something like this:

    Code (Text):
    entityVillager.setVillagerData(entityVillager.getVillagerData().withProfession(VillagerProfession.NONE));
    This however clears the trades which you may need to initialize yourself. But I think you can work from here, given that I don't know any more info on the code either at this point
     
  10. Thank you, I want to add custom trades anyways so it doesn't bother me, anyhow I'll tinker around with it to see what I can do.
     

Share This Page