"Resting" entities interacting with Horse Power devices
noobanidus opened this issue ยท 2 comments
Greetings!
I've recently been working on compatibility between my mod (Dude! Where's my Horse?) and a number of other mods that add additional rideable entities. As Animania horses derive indirectly from AbstractHorse, they're working just fine.
However, one of the things I noticed was an animation issue with Horse Power Grindstones (and other devices). Horse Power is a mod that allows you to do simple automation by attaching an entity (generally just a horse but you can define a list) via leash to the grind stone.
In order to prevent entities attached to such a device from being summoned by my ocarina, I added checks to make sure that a horse wasn't "working". In the process of testing, in my world, it became night, and the Animania steed went into "sleep" mode. However, as it was still attached to the grind-stone, it began to perform its rotational animation in the "sleep" pose.
Expected Behavior
That the animal would remain standing despite it being night. (I have no idea if this has any in-game implications if a horse does not get sufficient sleep: unfortunately my delving into Animania has purely been limited to working out compatibility).
Actual Behavior
https://gfycat.com/ImprobableMixedAmericanbadger
As you can see, the stallion continues to rotate around the grindstone (mounted upon a fence) while in the sleeping pose.
Steps to Reproduce
- Install "Horse Power" by Gory Moon.
- Using /hp entity to target an Animania horse, obtain on the clipboard the correct path for that horse.
- Using the in-game configuration, click on "Mob list" and make an additional entry using this information.
- Alternately, enter the information manually into the configuration file.
- In an empty area, place down a solid block, and then a grind-stone block upon it.
- Attach a lead to a stallion and then to the grindstone block.
- Place wheat in the grindstone block, using the default recipe to make flour.
- The horse will begin to path around the block as expected.
- Using /time set night or some other method of changing the time, progress the time until day.
- At this point, the stallion/mare will enter the "sleeping" mode.
I've specifically noticed that when directly attaching a lead to an Animania horse, it immediately comes out of its "sleeping"/"resting" mode, implying that some check is being made for the mode and the getLeashed() status. However, HorsePower does not affect getLeashed().
The simplest method I've determined to work out if an entity is attached to a HorsePower device (without actually checking any HorsePower code), is the following:
if (animal.hasHome() && animal.world.getTileEntity(animal.getHomePosition()) != null)
As the Horse Power device automatically sets the animal's home to its location, and it's location is also the location of a tile entity. This check appears to be relatively free, and you could even conditionalise it further with a call to Loader.isModLoaded("horsepower") so that the check is only made if Horse Power is indeed installed.
I'm considering making an additional PR for Horse Power that uses reflection to modify the value of "isLeashed" for the duration of time that an entity is attached to a Horse Power device. In the meantime, this solution allows my mod to specify whether a horse is merely leashed to a fence, or if it is "working".
Version of Minecraft, version of Animania, Single Player or Server
Minecraft: 1.12.2
Forge: 2796
Animania: 1.6.2
Integrated server (I believe this issue will also occur on dedicated servers and once I've finished internal testing, I will be testing it with a dedicated server)
Screenshots encouraged
The video linked above should give sufficient information.
Please feel free to comment with any further questions. I fear I've tried to give too much information and that it may have become difficult to read/comprehend.
I'm currently a member of your discord (nooby) if you wish to message me directly with any questions.
Ok, so this looks like a compat issue with Horsepower. There are basically two things we could do:
- We modify our code to check if an animal is leashed to a TE and horsepower is installed, that the animal won't go to sleep.
- Horsepower adds a check to see if our animals are sleeping, probably best via casting the entity to ISleeping and checking getSleeping(). They would probably want to do some cached reflection rather than adding a build dependecy.
I personally would prefer the second option, not because I then don't have to change our code, but because I think it would feel more immersive if the animals stopped working when sleeping instead of just deciding not to sleep.
Yes, sorry, I probably should've clarified that. I think another move Horse Power could do, which would be much simpler (as I'm not sure how much of your API they want to absorb), would be to simply ensure that getLeashed() returns true while a horse is attached to a Horse Power device. I'll open an issue on their end about this.