I was trying to create a machine that would take mobs and put them in minecarts when i noticed that some mobs moved their minecarts and others did not. This was weird, as mobs do not have pathfinding when riding in minecarts. For example, zombies riding minecarts do not react at all when close to villagers. Therefore it would make sense that mobs should not be able to control the minecart they are riding as they do not have pathfinding.
To investigate the cause of this bug I set up a system that places mobs in minecarts and tested it with creepers. Pictures 1 shows a creeper being placed in the mechanism. The minecart eventually comes to a stop (picture 2), showing that the creeper did not control the minecart at all. Placing cats next to the creeper (picture 3) also caused no response, which further shows that the creeper was not in control of the minecart.
For the second test, I placed a cat close to the rails and then summoned the creeper so that it would flee and thus BE IN MOTION when the minecart picks it up (picture 4). In picture 5 we see that the creeper goes forward in a similar matter to the first test. However, the creeper then stops and starts going backwards (picture 6), which is very weird.
We saw from the previous test that the cat should not affect the creeper when it is riding the minecart, and therefore there is no reason why test 1 and 2 should have different results. The only difference is that the creeper had momentum BEFORE it was picked up in test 2, whereas in test 1 it was stationary. My hypothesis is that when mobs enter minecarts, they keep whatever pathfinding they had before and try to get to the direction they were going before by controlling the minecart.
To conclude, mobs should not control minecarts, but test 2 shows that they sometimes can, and thus this bug should be fixed.
Here is a world download if you want to see the bug for yourself:
http://www.mediafire.com/download/qq1vyxuxvdcq7e1/Minecart_Bug_Demo.rar
There is a cat spawn egg for your convenience.
Edit: I uploaded Picture 7 with the debug screen so you can see the version and a better view of the machine as well.
A code analysis by @unknown can be found here.
Linked issues
is duplicated by 13
relates to 2
Attachments
Comments 46
Confirmed for
1.8.6 Only for chicken jockeys:
/summon Zombie ~ ~1 ~ {Invulnerable:1,HealF:0.1,Riding:{id:Chicken,HealF:0.1,Riding:{id:MinecartRideable}}}
This even overwrites NoAI
of the chicken, see also MC-41566
However it seems like mobs in minecarts aren't as fast as players in minecarts when they are driving rather fast (without pressing any key), but when the minecarts slow down, the mob is faster than the player resulting it both player and mob travelled the same distance at the end.
Here's a video showing a villager "controlling" a minecart. It's standing on an unpowered rail and should remain still as long as there's no power. But as soon as the villager tries to move or turn, the minecart goes off. This is in snapshot 15w38a.
Edit: Still present in 15w40b.
Edit 2: looks like it's been fixed in 15w41b.
@Guerin Since 1.11, they don't spawn anymore, because they are separate entities and no longer variants of a skeleton. But I guess it would be fine to make any rider control a horse, in case map makers want to use it.
@Eta740 I guess I didn't realise that this change affected tat. So my super idea for an unusual wither skeleton farm is no longer usable.
The behaviour to change all entity's controlling the minecart is quite simple. In EntityMinecart.java a simple if statement can be changed to make only players control the minecart.
line 545:
if (entity instanceof EntityLivingBase)
{
double d6 = (double)((EntityLivingBase)entity).field_191988_bg;
if (d6 > 0.0D)
{
double d7 = -Math.sin((double)(entity.rotationYaw * 0.017453292F));
double d8 = Math.cos((double)(entity.rotationYaw * 0.017453292F));
double d9 = this.motionX * this.motionX + this.motionZ * this.motionZ;
if (d9 < 0.01D)
{
this.motionX += d7 * 0.1D;
this.motionZ += d8 * 0.1D;
flag1 = false;
}
}
}
changed to
if (entity instanceof EntityPlayer)
{
double d6 = (double)((EntityLivingBase)entity).field_191988_bg;
if (d6 > 0.0D)
{
double d7 = -Math.sin((double)(entity.rotationYaw * 0.017453292F));
double d8 = Math.cos((double)(entity.rotationYaw * 0.017453292F));
double d9 = this.motionX * this.motionX + this.motionZ * this.motionZ;
if (d9 < 0.01D)
{
this.motionX += d7 * 0.1D;
this.motionZ += d8 * 0.1D;
flag1 = false;
}
}
}
Changing EntityLivingBase to EntityPlayer makes the minecart only be controllable by the player.
I think this is intentional, because when you press the button for moving forward, the minecart moves forward, and if you press the button for moving backwards, the minecart moves backwards.
This also happens to the mobs, but they are not players, so their code tells them to move forward, and the minecart is programmed to move forward when the thing inside of it gives the signal that they are, or want to move in any direction.
After a bit more testing, I have determined the following things:
-Mobs in minecarts actually track a block, not a direction; they will always face this block when in a minecart.
-Mobs will continue to go towards that block after the minecart is broken and they are free to move.
-Mobs will continue to target that block even if the block is located in unloaded chunks.