How do I turn Passive mobs Hostile?
Solution 1:
As of 1.9, if a mob is the passenger of another mob, it will control the pathfinding of its host. For example, if you had a zombie riding an iron golem, the iron golem will chase the player due to the zombie targeting the player.
However, the iron golem will still attempt to attack enemy mobs. While normally you can circumvent this by adding both mobs to the same team, which is intended to prevent hostility between the two, this does not work with iron golems while an enemy is its passenger. Even setting the iron golem's generic.followRange
attribute to 0 will not prevent it from trying to attack the enemy mob riding it.
What you can use instead is a mob that the golem will not attack but will still target players, being a creeper. You can give the creeper a Fuse
value of 32767 to make it take roughly 27 minutes before it explodes, which resets if the player moves out of range, just to ensure it does not explode.
An example command that summons an iron golem being controlled by a creeper:
/summon VillagerGolem ~ ~1 ~ {Passengers:[{id:"Creeper",Silent:1b,Invulnerable:1b,Fuse:32767,ActiveEffects:[{Id:14,Duration:2147483647,ShowParticles:0b}]}]}
Unfortunately this type of control does not include attacking, so the golem will simply get as close to the player as possible while its rider attempts to attack (which, in this case, it cannot). You could try to simulate attacking by using the /effect
command around the golem:
/execute @e[type=VillagerGolem] ~ ~ ~ /effect @a[r=1] minecraft:instant_damage