mcmonkeyprojects / Sentinel

Combat NPCs for Spigot!
MIT License
165 stars 85 forks source link

Add Iron Golem attack animation #351

Closed embeddedt closed 3 years ago

embeddedt commented 4 years ago

The output of command /version on my server is: CraftBukkit version git-Spigot-db6de12-18fbb24 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT) The output of command /version citizens on my server is: Citizens version 2.0.27-SNAPSHOT The output of command /version sentinel on my server is: Sentinel version 2.2.0-SNAPSHOT A pastebin.com link to my (full!) Sentinel/config.yml file is: https://pastebin.com/4AQGRLLt

I'm using Sentinel to customize the behavior of mobs on my server, as I'm using them as defenders and not like normal mobs. I noticed that when a Sentinel-controlled iron golem attacks players, it does not play its arm-swinging attack animation. Is there a config option that needs to be enabled? I didn't find anything online.

Thanks for making this plugin.

embeddedt commented 3 years ago

Found a somewhat hacky workaround using NMS:

@EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent e) {
    Entity damager = e.getDamager();
    Player target = (Player)e.getEntity(); /* Check if this is a player in real code */
    if(damager instanceof IronGolem) {
        target.setVelocity(target.getVelocity().add(new Vector(0, 0.4000000059604645D, 0)));
        net.minecraft.server.v1_8_R3.EntityIronGolem golem = (net.minecraft.server.v1_8_R3.EntityIronGolem)((CraftEntity)damager).getHandle();
        golem.world.broadcastEntityEffect(golem, (byte) 4);
   }
}

Credit for this goes to a (2015!) post on the Bukkit forums.

I originally tried putting this in SentinelAttackEvent, but that seems to fire even when the golem is still walking towards the player.

mcmonkey4eva commented 3 years ago

To add the attack externally (which tbh might be required if NMS is the only way to do, as Sentinel explicitly doesn't use NMS for compatibility's sake), you should add a custom SentinelIntegration and operate it as though iron golems have their own personal weapons - akin to how the CrackShot sample integration works: https://github.com/mcmonkeyprojects/Sentinel/blob/master/src/main/java/org/mcmonkey/sentinel/integration/SentinelCrackShot.java

mcmonkey4eva commented 3 years ago

Welp, I kinda hate it, but I added a reflection-based semi-safe NMS call to animate iron golem attacks.

embeddedt commented 3 years ago

Awesome! I understand the hesitation to use NMS, but this looks great!