The Meaning of Life, the Universe, and Everything.
Location:
Las Vegas
Join Date:
12/15/2012
Posts:
103
Member Details
Been doing plugins for Bukkit for a while now, but needed to get some things done for a new Forge server we're working on.
I found countless tutorials on how to add new villager types and how to change villager trades on the global scale, but both are fairly overkill - and the former requires a client side mod also.
What I'm trying to do is to have a SPECIFIC villager have specific trades; That is, I'd like Villager 'Bob' at spawn to have these new trades, and ONLY Bob. I don't want to add a new class to the rotation, nor do I want all 'Librarian' types to now offer Gold Bars for Plants (for example). Bob is the only crazy hippy villager that would do that. (If you're familiar with Bukkit plugins, I'm trying to do something similar to the Shopkeepers plugin)
Is this possible, or am I stuck creating a whole new villager type and editing it that way? On that note, if I DO have to create a new villager type, is there some way to prevent them from spawning naturally in villages?
Well there are probably a lot of ways to do this. What comes to mind to me (based on you not wanting to add new classes or village types) is to simply check when a village is created and decide which one of the villagers is your special villager and then just keep track of that one (by entity instance or something) and then intercept the events when players interact with villagers and check if it is your special one and then act accordingly.
The Meaning of Life, the Universe, and Everything.
Location:
Las Vegas
Join Date:
12/15/2012
Posts:
103
Member Details
Unless I'm misunderstanding, that wouldn't solve the issue of being able to edit/change the trades of one specific villager, which is what I'm really hoping to be able to do. Like I said, I CAN add new villager types - I just did not want to, if not necessary, as unless I'm mistaken on that, it will require a client mod as well. Was trying to cut down on the things folks have to download.
The Meaning of Life, the Universe, and Everything.
Location:
Las Vegas
Join Date:
12/15/2012
Posts:
103
Member Details
Also, When changing the trades a villager has using the VillagerRegistry, does it create the standard rotation, like vanilla villagers, or will it add all the recipes I wanted to the villager? This was so much less confusing as a plugin. lol
Okay, when you want to change vanilla behavior you should try to find a solution in the following order (of increasing difficulty):
1. See if there are public methods or classes that are already accessible. For example, if you wanted to change texture of a vanilla block this is accessible through public calls, or if you wanted to change motion of a vanilla entity instance.
2. See if Forge or FML provides an event to allow you to intercept the vanilla behavior. This is one of the primary uses for events -- you get a chance to call your code prior to vanilla code (and in many cases you can cancel the vanilla behavior).
3. See if you can use Java "reflection" techniques to inspect and modify the vanilla behavior.
4. See if you can use access transformers to modify the vanilla behavior.
In your case, I'm not sure whether villager class provides public methods to differentiate specific villagers, so I'm not sure that you can do #1 (although you may want to look for such)
I suggest you try #2. With event handling you could handle the EntityInteractEvent, check if it is the specific villager, and change the behavior how you want. You definitely could change individual villager behavior with event handling.
You don't really need a mod to do this, You can summon villagers with custom trades,
is an example
.......................................................................... I both REAAAALLY hate you and REAAAAAALLY love you at the same time... I've spent literally about 26 hours on this over the last few days ... to find out I can do it all with a quick command block. Goddamnit. lol
I found countless tutorials on how to add new villager types and how to change villager trades on the global scale, but both are fairly overkill - and the former requires a client side mod also.
What I'm trying to do is to have a SPECIFIC villager have specific trades; That is, I'd like Villager 'Bob' at spawn to have these new trades, and ONLY Bob. I don't want to add a new class to the rotation, nor do I want all 'Librarian' types to now offer Gold Bars for Plants (for example). Bob is the only crazy hippy villager that would do that. (If you're familiar with Bukkit plugins, I'm trying to do something similar to the Shopkeepers plugin)
Is this possible, or am I stuck creating a whole new villager type and editing it that way? On that note, if I DO have to create a new villager type, is there some way to prevent them from spawning naturally in villages?
Thanks!
Get what I mean?
1. See if there are public methods or classes that are already accessible. For example, if you wanted to change texture of a vanilla block this is accessible through public calls, or if you wanted to change motion of a vanilla entity instance.
2. See if Forge or FML provides an event to allow you to intercept the vanilla behavior. This is one of the primary uses for events -- you get a chance to call your code prior to vanilla code (and in many cases you can cancel the vanilla behavior).
3. See if you can use Java "reflection" techniques to inspect and modify the vanilla behavior.
4. See if you can use access transformers to modify the vanilla behavior.
In your case, I'm not sure whether villager class provides public methods to differentiate specific villagers, so I'm not sure that you can do #1 (although you may want to look for such)
I suggest you try #2. With event handling you could handle the EntityInteractEvent, check if it is the specific villager, and change the behavior how you want. You definitely could change individual villager behavior with event handling.
is an example
.......................................................................... I both REAAAALLY hate you and REAAAAAALLY love you at the same time... I've spent literally about 26 hours on this over the last few days ... to find out I can do it all with a quick command block. Goddamnit. lol
Thank you