0

I am attempting to create a Minecart mechanic where once the player is in the Minecart it starts moving in a certain direction. I am not a beginner with command blocks, so in your answer you can talk technical with me. I am just not familiar with the new 1.9 tags.

I have attempted (on an active 20hz or repeating clock)

I.

1. /scoreboard players set @a ridingCart 0
2. /scoreboard players set @a ridingCart 1 {Passengers:[{id:"MinecartRideable"}]}

II.

1. /scoreboard players set @e[type=MinecartRideable] ridingCart 0
2. /scoreboard players set @e[type=MinecartRideable] ridingCart 1 {Passengers:[{id:"Player"}]}

Neither of these two separate attempts have worked. I am unsure if this is a bug with the game to where you cannot /testfor with the Passengers tag or if it is a mistake on my end. Thanks!

4

When a player is a passenger to an entity, that player is not saved with the entity in the region files (side-note that Player is not a valid entity ID and is simply a feature of selector syntax).

The entity is instead saved with the player via the RootVehicle compound in player files and is no longer saved within the chunk region files. Example structure within player.dat:

{
    Sleeping:0b,
    Inventory:[],
    RootVehicle:{
        AttachLeast:1l,
        AttachMost:1l,
        Entity:{
            id:"MinecartRideable"
        }
    }
}

To detect when a player is riding anything, you'll check the RootVehicle tag:

/scoreboard players set @a ridingCart 1 {RootVehicle:{Entity:{id:"MinecartRideable"}}}

The entity, when ridden by a player, will not have the Passengers tag containing the player and will not exist if only the player is riding it. If there are non-player entities riding the same vehicle as the player (such as a pig and player inside a boat), the Passengers tag will exist on the boat within RootVehicle but will only contain the pig.

If the vehicle has non-player passengers but no player passenger, Passengers will exist like normal and the vehicle is stored within region files.

If the vehicle itself is riding another entity (such as a boat riding an armor stand), and the player rides the vehicle, the AttachLeast and AttachMost will be the UUID of the vehicle the player is riding (the boat) while Entity starts with the bottom-most entity (the armor stand), complete with Passengers containing the boat.

Note that thus far into 1.9 (15w47c), RootVehicle is only available on players, meaning you cannot detect what a non-player entity is a passenger of.

| improve this answer | |
  • Thanks for this! Also, you said that if you and a pig are in a boat the boat will only have the Pig in the Passengers tag. What would happen if you changed the data of the boat while you were riding in it to contain two entities? – creeperpig28 Nov 26 '15 at 3:44
  • @creeperpig28 That would involve instantiating new entities, while /entitydata can only modify data. /summon has a special case to instantiate new entities if the Passengers (previously Riding) tag was defined; that would have to be extended to /entitydata, although there is the other issue of specifying a list-type tag which overwrites all pre-existing data within the list prior. And while you can modify the Passengers tag with /entitydata, any changes you make won't matter since the real passengers are determined on chunk loading, not from NBT merging. – Skylinerw Nov 26 '15 at 3:49
  • @Skylinerw if the Passengers tag is inside the RootVehicle Tag which a tag of the player's, entitydata shouldn't be able to do anything since it can't act on players in the first place. – MrLemon Nov 26 '15 at 9:49
  • @MrLemon Target selectors will target the instantiated entity. You can still target the vehicle while the player is riding it to change its data, just not through the player (that is, by targeting the boat or minecart directly, not the player's RootVehicle data). – Skylinerw Nov 26 '15 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.