mojira.dev
MC-41893

Breaking a minecart with command block in creative drops a minecart after reloading the world

How to reproduce

  1. Place a minecart with command block

  2. Leave and reopen the world

  3. Destroy it in creative mode using your hand, a sword / tool or an arrow
    → The minecart with command block drops a (regular) minecart (item) named "@", whereas an empty / normal minecart would’ve dropped nothing after these steps. Also if you don’t leave and reopen the world first, the minecart with command blocks drops nothing either.

Code analysis

The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.

The reason why this happens is that the public void writeDataToNBT(NBTTagCompound p_145758_1_) method of the net.minecraft.command.server.CommandBlockLogic class always saves the CustomName in the NBT data. As this only happens when you unload the minecart or reopen the world a MinecartCommandBlock that is summoned and directly destroyed does not cause this. Instead the method should only save the CustomName if it is not "@".

/**
 * Stores data to NBT format.
 */
public void writeDataToNBT(NBTTagCompound p_145758_1_)
{
    p_145758_1_.setString("Command", this.commandStored);
    p_145758_1_.setInteger("SuccessCount", this.successCount);
    
    // Replaced this
    //p_145758_1_.setString("CustomName", this.customName);
    if (!this.customName.equals("@")) {
        p_145758_1_.setString("CustomName", this.customName);    
    }
    
    p_145758_1_.setBoolean("TrackOutput", this.trackOutput);

    if (this.lastOutput != null && this.trackOutput)
    {
        p_145758_1_.setString("LastOutput", IChatComponent.Serializer.componentToJson(this.lastOutput));
    }

    this.field_175575_g.func_179670_b(p_145758_1_);
}

Linked issues

Attachments

Comments 23

Confirmed

Confirmed for

  • 15w34d

  • 15w35b

Incorrect duplicate link
This report is about unnamed MinecartCommandBlocks

[Mod] redstonehelper

MinecartCommandBlocks are actually named.

Confirmed for

  • 1.9-pre1

@unknown this is a bug that only occurs when you reload the world

Please link to this comment in the description

The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.

The reason why this happens is that the public void writeDataToNBT(NBTTagCompound p_145758_1_) method of the net.minecraft.command.server.CommandBlockLogic class always saves the CustomName in the NBT data. As this only happens when you unload the minecart or reopen the world a MinecartCommandBlock that is summoned and directly destroyed does not cause this. Instead the method should only save the CustomName if it is not "@".

/**
 * Stores data to NBT format.
 */
public void writeDataToNBT(NBTTagCompound p_145758_1_)
{
    p_145758_1_.setString("Command", this.commandStored);
    p_145758_1_.setInteger("SuccessCount", this.successCount);
    
    // Replaced this
    //p_145758_1_.setString("CustomName", this.customName);
    if (!this.customName.equals("@")) {
        p_145758_1_.setString("CustomName", this.customName);    
    }
    
    p_145758_1_.setBoolean("TrackOutput", this.trackOutput);

    if (this.lastOutput != null && this.trackOutput)
    {
        p_145758_1_.setString("LastOutput", IChatComponent.Serializer.componentToJson(this.lastOutput));
    }

    this.field_175575_g.func_179670_b(p_145758_1_);
}
13 more comments

Affects 1.17 Pre-release 1

Affects 1.17

Can confirm in 1.19.2.

Destroying one that is renamed without relogging drops a regular minecart, with the same name. Though, placing it down and relogging still drops a minecart named "@".

Cannot reproduce in 1.21.2  Pre-Release 3
Tested with experimental minecart improvements datapack enabled.

Frank Steffahn

[Mod] markderickson

(Unassigned)

Confirmed

Platform

Low

Minecart

command_block_minecart, drop

Minecraft 1.7.4, Minecraft 1.9 Pre-Release 2, Minecraft 16w43a, Minecraft 1.11.2, Minecraft 17w15a, ..., 22w06a, 22w14a, 1.19.2, 1.19.4, 1.20.2 Pre-release 2

Retrieved