[enhancement] Include code to tame mobs (I've already written much of it)
Opened this issue · 5 comments
I liked how it was possible to partially tame a mob by using a boxed lunch, but wished it provided functionality closer to what's possible with Vanilla wolves. So I decided to try and implement it myself. I'm completely new to Minecraft modding and pretty rusty with Java, so it took a while, but I think I've made some pretty good progress. I'm not actually suggesting the code I've written so far be included in GoG. I'd just like some feedback on the changes I'm proposing and to know if the code might be included in the official mod once some of the issues are sorted out. (Especially the balance issues)
Working on the master branch, I made it so that a hostile mob that you tame using a boxed lunch has a lot of the behaviors you'd expect from a useful combat assistance mob.
Specifically, the changes I made are:
-
Once you tame a Gaia mob (note it must be an EntityMobHostileBase and must not override the 'define right click functionality' method of EntityMobHostileBase), right clicking on it with a stick in hand will open up the tame mob control interface. There will be six buttons that determine the mob's behavior.
- The first button determines if the tame mob will attack other hostile mobs once the tame mob becomes aware of them. Note it will target any EntityMob, except for an EntityMobHostileBase that's tame. Slimes, for example, are ignored. That's an issue I need to fix.
- The second button determines if the tame mob will attack entities that attack their tamer.
- The third button determines if the tame mob will follow the player.
- The fourth button will eventually determine if the tame mob is sitting/stationary. I haven't implemented this yet, and I'm not sure how to go about it. Do we want the mob to just not move? or should it actively try to remain where you initially told it to sit?
- The fifth button is the "followPlayerNOW" which if toggled, will cause the mob to drop every other task (including defending itself/retaliating against attacks) and follow the player at around double its normal movement speed. It's useful if you're in creative and want the mob to keep up with your flight or if there are lots of enemies around and you want your mob to run without tying to fight any of them.
- The sixth button determines if the tame mob will attack any target you attack. If this is on and you punch a sheep, your mob will start attacking it too.
-
Note all these flags are initially set to false on all recently tamed mobs. They are also saved in NBT data, so they persist across reloads.
-
Once a mob is tame, right clicking on it with a food item in hand will heal the mob for twice the satiety value of the food.
-
In addition, I've implemented an "anger" mechanic. If you attack one of your tamed mobs, it will gain anger towards you. Specifically, it will gain 5 times the amount of damage you deal to it in anger. It will only become aggressive towards you if its anger becomes as high as its maximum health. (Meaning when you've delt 20% of its health in damage to it) At this point, it becomes aggressive to you and to all other players. You also will not be able to control it though the interface when its angry. (There are some client/server syncing issues here. You're not supposed to be able to access the interface of an angry mob, but the client can get confused about whether or not a mob is angry, so it will show you the gui, even if you can't use it)
-
Feeding mobs also lowers their anger by twice the the satiety value of the food. You must drop their anger to half of their maximum health before they stop attacking players. Note that anger is stored in NBT data, so relogging won't stop them attacking you.
-
I've also prevented all tame mobs from despawning.
-
I included an xp counter for the mobs that increases as deal damage (only melee attacks for now) and are hit by attacks. I don't actually do anything with the xp value, but I plan to in the future. Minecraft is all about progression. Anything you have, you should be able to upgrade, so if you have a tame mob, you should be able to upgrade it somehow. A well-implemented mob xp system could also allow for untamed mobs the player fights to have a more fine-tuned difficulty level.
That's most of the content I added. To do this, I made modifications to the EntityMobHostileBase class (for the behavioral logic mostly), and the CommonProxy.java file (to listen for gui open events/button pushes and take the correct actions). I added the EntityAIFollowTamer, EntityAIHurtByTargetGaiaTame, EntityAINearestAttackableTargetTamed, EntityAIOwnerHurtByTargetGaia and EntityAIOwnerHurtTargetGaia classes to the ai package, which handle the various ai tasks I added. Finally, I created a new package called client in the root directory, which has the GaiaGuiButton and the GaiaTameEntityControlGui classes that handle gui construction/display. I also added a gui folder to the textures, which has the file GaiaMobControlGuiGrid.png, that's displayed when the mob control gui opens.
Current issue / things to do:
-
Making tamed creatures properly attack untamed, hostile mobs (they don't target slimes for example).
-
Implement sitting properly
-
Make the xp system do something
-
Make tame mobs call out to other tame mobs (with the same tamer) for help when they are attacked. There should be a button to enable/disable this.
-
Make mobs controllable from a range. Maybe add an item that you can bind to one or more tame mobs, and right clicking it allows you to send them all commands like 'disengage current target' or 'come defend me.' This could be useful for dealing with the issue where tame mobs that are set to attack other hostiles can get lost by going after a chain of attack targets, leading the tame mob away from the player.
- Another function such an item would have is one where, when you activate it, all linked mobs will stop attacking their current target and put that entity on an "attack blacklist," where they'll ignore it until you take it off the blacklist by hitting it.
- In general, I intend to add much more fine-grain controls to tame mob behavior, things like adjustable follow distance, whether they respond to ranged attacks, things like that. I intend to go WAY beyond what wolves/most other companion mods allow.
- One thing I really need to add is an adjustable aggro radius for mobs set to attack other hostiles.
-
Deal with the various monster-specific issues that require editing the individual mob files. I didn't do too much testing with this, but I found a few issues:
- Ant workers will not attack other untamed ants in retaliation for the untamed ant attacking the player (though this may have been the result of a different issue that's now (hopefully) solved).
- Anubi will attack their summoned skeletons when hit by their arrows. Untamed Anubi won't do this, but tamed ones seem retaliate against their summons much more aggressively.
- Make the spawns of tamed entities respect their spawner's taming state (Vampires, for example)
- The summoned mobs will have to be tame, but we also need to let them despawn, or else they'll just clutter your base up forever.
- Some mobs shouldn't be tamable. The mimic itself, for example. It's a bit SOD breaking that the player apparently shares a meal with an animated storage chest and befriends it. Also, tame mimics look really dumb. It's one thing to have the chest make its biting animation while rushing towards you, about to attack. It's another to see it just sort of wandering around going 'nom nom nom' all the time.
-
Improve the gui appearance. It looks like crap at the moment, and doesn't match the mod's overall theme.
- Also need to include localization for the button descriptions/states. Currently, button descriptions are actually part of the gui's image file, rather than text strings displayed over the image. This should change so that we can load localizations from file.
-
(Maybe?) make non hostile mobs tamable
-
Make taming fail for mobs you've damaged or make taming remove their current target. Currently, they'll be tamed, but they will keep attacking you. Re-logging fixes it.
-
if your tamed mobs are attacking a thing and you tame it, your mobs should stop attacking. Otherwise, they'll keep fighting and then your new tame mob will retaliate. Re-logging fixes.
- That, or make being attacked by a tame mob prevent you from taming the attacked mob.
- At the least, taming a mob should remove it from the active targets list of the other tame mobs. Right now, if one of your tame mobs decides to attack an untamed mob, it will not stop if you tame the target before it attacks.
-
Make it a bit harder to lose tamed creatures to chunk unloading.
- Also make it so they don't crowd you as much. They're bigger than wolves, so it's kind of annoying.
Balance Issues:
- If taming becomes a much more important part of the mod, we may want to adjust the distribution of boxed lunches so that people have a more reliable way of finding them than by killing Mimics or Futakuchi-Onnas. Specifically, I think it should be on average harder to get them, but getting them should be based less on random chance as well.
- Currently, it's actually far more difficult to tame a Creep than it is to tame a Valkyrie. (Creeps have smaller hit boxes and often blow up after taming, since taming doesn't remove their fuse) It should be the other way around, because a Valkyrie is probably the most useful tame mob, while a Creep is mostly useless. Taming difficulty should be proportional to how valuable the tamed mob would be.
- Currently, healing and "apologizing" to angry mobs are both rather cheap in terms of resources lost / the challenge involved. I think healing should be more expensive and apologizing should cost you more. Maybe they won't speak to you for a while or it takes some specific action on your part?
- It's currently possible to build an army of tame mobs, which destroys all the challenge of the game. The simple solution is to put a cap on the number of tame mobs you can have.
- A more complex and interesting solution is to implement a "contentedness" system, where you have to take certain actions to keep your mobs content, or they leave you. Having more mobs could cause each one's contentedness to drop faster, effectively caping the number you can have.
- Limits on the maximum number you can have following you might be appropriate too.
- Some mobs are too powerful to let the player tame them without destroying game balance. Though, this should probably be based on config settings, so people can fine-tune their worlds/servers.
Bug testing:
- I've done some, but not a lot, and I haven't done any on multiplayer.
Things that would be neat, but seem pretty hard (Basically, a wish list for things I'd like to see if someone with far more time and skill than I were to do them):
- Include interesting dialog - something that gives the impression that the tame mobs have their own lives/perspectives/internal narratives .
- For example, if you try to open the control interface for an angry mob, they could say something to the effect of "I'm through with you!" or "Go to hell!"
- Or while exploring, they could express derision when you encounter a hostile mob of a lower tier than the tame mob, or fear if it's of a higher tier.
- Include tasks that tame mobs ask of you.
- For example, they could say "Let's spar" and then if you accept, they gain a special ai task which makes them aggressive towards you until either you or they reach half-health, at which point they stop attacking and declare themselves the winner/looser.
- Another possible task is a sort of 'exploration thing,' where your mob tells you that they want to explore somewhere new. If you accept, they start following you. Then, you have to move at least a certain distance within a certain time. Alternatively, the mob needs to visit at lest X number of unique chunks in Y amount of time across at least Z different biomes.
- Mobs could also ask to build a house with you. They would then start following you and you'd need to place at least a certain number of blocks within a certain time. After you finish, the mob could then make ambiguous comments about the building that could be interpreted as sarcastic or genuine, like "I can see how much time you put into planning this. It really shows." This way we can avoid having to actually evaluate how well the player did at building, just count the number of blocks they place. No matter how well the player actually did, the mob delivers correct dialog.
- Of course, we'd have to reward the player for completing those sorts of tasks. Maybe with extra xp for the mob, if we make xp actually do something for tame mobs.
- If I add contentedness as a mechanic, these sorts of tasks might increase it, and failing at them/declining when the mob asks would decrease it.
- Tame mobs should have some minimum standard of living.
- For example, if you leave them in a room for a while, they could get annoyed if they don't have access to a bed, chest, crafting table and furnace or if the room is too small. They could even "claim" a chest and add random items into it, then get mad if you "steal" from that chest.
- Being a dick to your mob should make them angry. For example, if you leave them outside in the rain, they could get mad at you and complain. Running away and leaving the tame mob to fight should really piss them off.
So that's a summary of where I'm at right now. This is a great mod and I'd be happy to contribute to it. Working source code for my modified version of GoG should be in my GrimoireOfGaia repository, but I'm fairly new to Github, so if I've made any mistakes, please let me know.
Just in case, I've added a compiled jar file that works when I use it (with the MultiMC launcher, forge version 1.10.2-12.18.3.2221 and with Infernal Mobs, Optifine, JourneyMap, JEI and Waila) to my GoG repository.
Also, do you mind if I post the jar in the GoG minecraftforum.net thread to get some more feedback/bugtesting?
Such a shame that the OP disappeared off the face of the earth. Being able to tame the monsters would increase my enjoyment of this mod tenfold. I imagine what's left is too outdated to be worked with, and even if it wasn't, there isn't much apparent motivation to do anything with it.
This is absolutely amazing. I’ve always wanted this. Now I just wish boxed lunch was craftable.