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_);
}

Related issues

Attachments

Comments

migrated
[media]
galaxy_2alex

Confirmed

marcono1234

Confirmed for

  • 15w34d

  • 15w35b

Incorrect duplicate link
This report is about unnamed MinecartCommandBlocks

migrated

MinecartCommandBlocks are actually named.

marcono1234

Confirmed for

  • 1.9-pre1

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

marcono1234

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_);
}
migrated

So how is this not a duplicate of MC-10366?

marcono1234

This one here is about the fact that when a MinecartCommandBlock gets saved the default CustomName is always saved, even if it is the default one which causes it to always drop the Minecart.
This bug here also happens in survival mode.

migrated

I don't see anything wrong with saving the default CustomName.

marcono1234

Saving the default name as CustomName causes this problem, that breaking the Minecart if its NBT data was not saved already does not drop anything, however once its NBT data was saved it drops a renamed minecart.

Anyways it is definitely not a duplicate of MC-10366 because the bug described in this report happen in Survival mode as well

migrated

I think we're talking over each other. I'm saying "Minecarts even save the default custom name (a preset, if you will)" is not a bug. The fact that command block minecarts drop when destroyed after reloading is caused by MC-10366. When MC-10366 is fixed, minecart command blocks will stop dropping when destroyed after reloading.

that breaking the Minecart if its NBT data was not saved already does not drop anything

I do not consider this a problem - minecart command blocks, just like command blocks, are not meant for survival, so they don't drop in survival. They don't drop in creative because minecarts in general don't drop in creative.

I agree, the fact that renamed command block minecarts drop themselves in survival is a bug. Please create a separate ticket for that.

marcono1234

I agree, the fact that renamed command block minecarts drop themselves in survival is a bug. Please create a separate ticket for that.

As they only drop a minecart item, but no command block, I am not sure if this is really a bug, but it could be, see MC-11765.

However as long as it is not confirmed to be a bug this report here has to stay open.
Like I said these are two different bugs and many of the optional tags like NoAI are not saved if they contain the default value.

Even if it is confirmed to be bug, this report is still no duplicate of MC-10366.

Edit: It could be solved indeed better by only saving the custom name if one is set and having a constant which stores the default custom name.

marcono1234

MC-48862, MC-33178 are duplicates of this report instead of MC-10366.

migrated

Reopened. I completely missed that they drop regular minecarts instead of command block minecarts.

marcono1234

Thank you 🙂

That is however intended, see MC-54899

Please update the link accordingly as it still says "duplicates" MC-10366 instead of "relates to"

JUE13

Confirmed for 1.12-pre5

pokechu22

In the code analysis you write if (this.customName != "@"); this won't work and should be if (!this.customName.equals("@")).

[Mod] markderickson

Hi there!

Can confirm in 1.16.1.

pulpetti

Affects 1.16

migrated

Affects 1.17 Pre-release 1

migrated

Affects 1.17

Avoma

Can confirm in 1.19.2.

PurPur134

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 "@".

migrated

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

[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