Minecraft floor crafting deletes previous results

minecraft-commandsminecraft-java-edition

I want to make a command block system that allow players to craft custom heads using a regular player head and a specific item by throwing these items on the floor. The system works fine, except for one thing. When i craft a custom head and leave it on the ground and craft another head the same way, the first head gets killed by the command blocks. This is ofcourse undesirable, therefore I would like to ask this community for some help.

Before anyone asks: all command blocks are always active, the first command block is in repeat mode and the rest is in chain mode. The last two command blocks are conditional.
These are the commands in the order of the command blocks:

1) scoreboard players tag @e[type=Item,tag=!baseSkull] add baseSkull {Item:{id:"minecraft:skull",Damage:3s,Count:1b}}
2) scoreboard players tag @e[type=Item,tag=!D_InventorItem] add D_InventorItem {Item:{id:"minecraft:red_mushroom",Count:1b}}
3) /execute @e[tag=baseSkull] ~ ~ ~ execute @e[tag=D_InventorItem,r=1] ~ ~ ~ execute @e[type=Arrow,r=1,c=1] ~ ~ ~ summon Item ~ ~ ~ {Item:{id:"minecraft:skull",Damage:3s,Count:1b,tag:{SkullOwner:"D_Inventor"}},Tags:["D_InventorSkull"]}
4) /execute @e[tag=D_InventorSkull] ~ ~ ~ kill @e[tag=baseSkull,r=1]
5) /execute @e[tag=D_InventorSkull] ~ ~ ~ kill @e[tag=D_InventorItem,r=1]

Clarification:

1) Tag all player heads with the baseSkull tag if they don't have it already.

2) Tag all red mushroom items with the D_InventorItem tag if they don't have it already. The red mushroom is therefore the item to get my head.

3) summon a player skull with the D_Inventor skin at the location of the items. This skull spawns with the D_InventorSkull tag already present. Notice that this command only works if there is an Arrow entity in the area, therefore you have to shoot the items with a bow to complete the crafting.

4 + 5) delete all the ingredients around the custom player head.

I know where this goes wrong. The custom player head has the same id and damage value as a regular player head. When a custom player head spawns, it is tagged with the baseSkull tag in the next cycle, so it has both the D_InventorSkull tag and the baseSkull tag. When I craft a new custom head, the fourth command block executes at all the D_InventorSkull items and deletes all the baseSkull items around it. Since the first skull has both the baseSkull and the D_InventorSkull tag, it deletes itself.
When I pick up the custom head and then throw it on the ground, it loses its D_InventorSkull tag and then the custom head doesn't get deleted when I craft a new one.

The question is: How do I solve this?
My first solution was to check for each playerskull if it has no tags and only then tag it with the baseSkull tag. The command would the look like this:

scoreboard players tag @e[type=Item,tag=!baseSkull] add baseSkull {Item:{id:"minecraft:skull",Damage:3s,Count:1b},Tags:[]}

Unfortunately this doesn't seem to work. When I throw a regular player skull on the ground, the command block gives an error saying that the DataTag doesn't match. This error doesn't occur when I don't use the extra Tags:[] DataTag.

so… What would be the correct way to prevent previous skulls from deleting themselves when I craft a new skull?

I play in the latest release(1.12.1).

Best Answer

This took me a while, I even manually went through all the steps (which is my last hope against bugs), but then I got it:

You just need to add ,tag=!D_InventorSkull to the selector in the first command.
That way the skinned head doesn't get the baseSkull tag and the first execute in the third command doesn't trigger a second time.

scoreboard players tag @e[type=Item,tag=!baseSkull,tag=!D_InventorSkull] add baseSkull {Item:{id:"minecraft:skull",Damage:3s,Count:1b}}

Also, are you sure you don't want to kill the arrow, too? In that case you should add a sixth command:

execute @e[tag=D_InventorSkull] ~ ~ ~ kill @e[type=arrow,r=1]

In 1.13:

execute as @e[tag=D_InventorSkull] at @s run kill @e[type=arrow,distance=..1]