I'm no expert at Java, so this isn't a decisive answer, but I figure it can't hurt to post the code here anyway for others to decipher. From SpawnerAnimals.java
:
(Comments mine)
private static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType enumcreaturetype, World world, int i, int j, int k)
{
if(enumcreaturetype.getCreatureMaterial() == Material.water)
// If it's a water creature...
{
return world.getBlockMaterial(i, j, k).getIsLiquid() && !world.isBlockNormalCube(i, j + 1, k);
// Make sure it spawns in water
} else
{
return world.isBlockNormalCube(i, j - 1, k) && !world.isBlockNormalCube(i, j, k) && !world.getBlockMaterial(i, j, k).getIsLiquid() && !world.isBlockNormalCube(i, j + 1, k);
// Makes sure the block it's spawning on is opaque, that it's not water, and that there are at least 2 blocks of air overhead.
}
}
It does not appear that it checks whether the mob is spawning underground or not.
Anecdotally, wandering around for a while with an Xray texture pack produced only surface mobs, so I'm not sure what other guards might be put in place to prevent underground spawns.
Mobs that attack each other:
- Golems (iron and snow) > all hostile mobs
- all hostile mobs > you, anything that attacks them (skeleton shoots a zombie by accident zombie attacks skeleton)
- Cats > Chicken
- Wolves > Sheep
- Zombies > Villagers
- Iron Golems > any player that attacks them or nearby villagers, skeletons, zombies, and witches
- Tamed wolf > anything player attacks or is attacked by
In answer to your question, your livestock should be safe from anything but wild wolves and cats (except for splash damage from witches or creepers, or stray skeleton shots).
Best Answer
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:
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: