4

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).

  • What does happen when you leave out the Tags:[] part? – Fabian Röling Aug 27 '17 at 9:53
  • @Fabian Without the Tags:[] it's basically command #1 from the list, so then I get the behaviour which this question is about. The skull would get both the D_InventorSkull and baseSkull tag. – D-Inventor Aug 27 '17 at 9:59
  • 1. The two last command blocks don't have to be conditional. But it doesn't hurt I guess. 2. I would put c=1 in all the executes. – Fabian Röling Aug 27 '17 at 10:40
2

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]
  • Thank you for your answer. Are you sure that the extra argument to the selector works? I remember reading somewhere that using multiple arguments with the same name(tag and tag in this case) would cause the game to only use the last argument, but I don't recall where I found that. It may be outdated. I'll try it and come back at you with the result. I want this to be easily scalable, because I am implementing this in a realms survival server with 10+ players. – D-Inventor Aug 27 '17 at 11:02
  • About the tags: Yes, it works, I did it with exactly these commands and I got your head. In general: All selector arguments are AND-connected, meaning that it only selects entities that match all criteria. So in this case it only tags entities that are of the type "item", don't have the "baseSkull" tag, don't have the "inventorySkull" tag and (because of the /scoreboard syntax) match the given NBT. About scalability: You already designed your program in a way that it can be scaled, even if 10 players do the ritual at once, it works (as long as they don't do it side by side). But to prevent – Fabian Röling Aug 27 '17 at 11:10
  • possible bugs (for example when someone throws two skulls and then a mushroom), I would add c=1 to all the executes. And in general, you should always try to think about what a very stupid user could do and what a very intelligent, but evil user could do. Btw, do you want me to make your system 1.13-compatible, too? – Fabian Röling Aug 27 '17 at 11:13
  • The c=1 is a good idea! However, multiple items of the same type can stack together on the floor and become 1 entity together, which would render the c=1 useless. If you feel like making my system 1.13 compatible, then you'd make me very happy. And uh... Feel free to distribute and take credit for it if you want to. It would be kind to also credit me a little if you decide to distribute it. – D-Inventor Aug 27 '17 at 11:21
  • I have tried the extra argument. Newly created heads no longer get the baseSkull tag, but if I throw a skull on the ground, it repeatedly adds the baseSkull tag on it. It looks like the selector actually only uses the last tag argument. I can link you to a zip so you can download my test world and try it for yourself? The Arrow was intentional btw, but thanks for pointing it out anyway. – D-Inventor Aug 27 '17 at 11:40
0

The skull got deleted because it has both the D_InventorSkull tag and the baseSkull tag. A workaround would be to add an extra command block which would remove the D_InventorSkull tag after it is done processing. Now The system only uses the D_InventorSkull tag to delete the ingredients. After that, the tag is removed and the skull is no longer targeted to delete any items.

The sixth command would be:

scoreboard players tag @e[tag=D_InventorSkull] remove D_InventorSkull

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.