1

Help with /testfor command

whick 5/17/15 5:51 pm
690
5/20/2015 1:36 pm
Hey! This is my first post - been tinkering with the /testfor command for many hours now and finally decided to reach out for help.

Basically I need to test when a player has a certain color Firework in their inventory. Either red or blue, to be exact. I am running a constant redstone loop hooked up to a command block with the following command:

/testfor @a {Inventory:{Item:{id:minecraft:fireworks:{Explosions:{Color:{"red"}}}}}}

However when I have a red colored firework in my inventory, it does not trigger a success.

Please help if you know how to detect a certain color firework.

-Whick
Posted by
whick
Level 1 : New Miner
0

  Have something to say?

JoinSign in

7

Crazy_Clamp
05/20/2015 1:36 pm
Level 14 : Journeyman Architect
Hey there, I confirm what Jmal116 told you regarding naming items after a player.
It's impossible. I was asking the same thing lately to a friend (Rubisk on minecraftforum.net) and it turns out like Jmal116 said that the selector command can't be use because you can't use json in simple strings like that.

For the rest of your question as explained by Jmal116 isn't problem.
1
Jmal116
05/17/2015 8:33 pm
Level 34 : Artisan System
Unfortunately, I don't think there's any way to name items with the names of players like that. It is possible to change the name of an item to just plain text, but usually for player names I would use the 'selector' argument for things like tellraw. But I don't think items will accept json in their names, and I couldn't get it to work in a couple minutes.

It is possible to detect when a block is broken though. You could use the /testforblock command:testforblock x y z trapped_chestJust note that the comparator will be on until the block is destroyed, so either invert it or account for that in your circuit.

However I would suggest using scoreboards, especially if there's only one chest like this. This would prevent you from destroying and losing your commands whenever you want to test the map. You can make an objective automatically track when the chest is broken by changing the type of objective:/scoreboard objectives add dstryBzzLghtyr stat.mineBlock.minecraft.trapped_chestWhenever a player destroys a trapped chest, their score will increase by one. Then you can give a player with a score of one an item:give @a[score_dstryBzzLghtyr=1,score_dstryBzzLghtyr_min=1] .....And then immediately set their score to 2:scoreboard players set @a[score_dstryBzzLghtyr=1,score_dstryBzzLghtyr_min=1] dstryBzzLghtyr 2This will stop any players from using the system twice. Best part is then you can just run the 2 commands on a clock, you don't have to worry about comparator delay or other wierdness.

Also you could change the objective name to whatever you want, I'd suggest something a bit less long.

Man, I sure have a way of turning 2 commands into a full length essay
1
whick
05/17/2015 8:13 pm
Level 1 : New Miner
Cool.

So I might be attempting to do something that isn't possible, but that's why I am asking. It might be able to be accomplished through command blocks.

I am making a map for server that doesn't let players access trapped chests unless you break them, thus pouring the contents out onto the ground. I would like to use a /testfor command to tell when the spot the chest was in is filled with an air block instead (thus implying a player broke the chest).

After it is confirmed that the chest has been broken, I'd like to use a /give command to give @p[r=1] of the spot the chest used to be a sword with their name on it. Such as "Whick's Mind". Basically the logic is @p[r=1] + "'s Mind".

After these commands have executed, I will place an airblock where the command block was that gave players the sword. This prevents players from placing a block where the chest was, then breaking the block again to get another sword (the smart ones, or even the lucky ones who do it by accident at least).

Basically I'd like a custom named item that gets name right on the spot based on the player who breaks the chest. If it's impossible, just say the word!

-Whick
1
AkirAssasin
05/17/2015 7:41 pm
Level 34 : Artisan Ninja
I think you can.
1
whick
05/17/2015 7:39 pm
Level 1 : New Miner
I have another redstone/command block related question - would you mind if I asked it of you here? If not, I'll make a new topic.

Thanks again,
Whick
1
whick
05/17/2015 7:24 pm
Level 1 : New Miner
Thank you for taking the time to straighten out my command. I checked out your YouTube channel before plugging in the code and I see you are well versed in redstone, so I had no doubt it would work.

I opened up MCEDIT with the NBT filter to identify the proper color, and sure enough it worked. Check out the result!

Thank you so much!
Whick
1
Jmal116
05/17/2015 6:59 pm
Level 34 : Artisan System
Well welcome to the forums!

There's a couple things going on in you command. First off, the 'Inventory' tag is a list, so it should use square brackets instead of curly brackets.

From there, each item you want to include in the testfor is its own set of curly brackets, rather than using the 'Item' tag (that's only used for items on the ground).

The actual method of defining the item with the 'id' tag is correct, however the part after it with the explosion data is not. Since the explosion is extra nbt data on that item, you add the 'tag' tag right next to the id. This contains the explosion data.

From there you only have to worry about what the explosion data actually is, which is... well... weird, to say the least. Especially the colors. I'll make it short, here's some data I made for a red firework:{Fireworks:{Explosions:[{Colors:[16711680]}]}}This will give you a rocket with a color value of #ff0000, or 255,0,0 (RGB), which is red. The number in the fireworks data is that hexadecimal number (ff0000) converted into decimal. So yeah, there ya go. Insert that data into the testfor command, and you should end up with something like this:testfor @a {Inventory:[{id:minecraft:fireworks,tag:{Fireworks:{Explosions:[{Colors:[16711680]}]}}}]}This command worked ok for me when I used to /give to get a firework, try it out.

One last note. I'm not sure if the game gives you that exact red color when you craft one. If it work with fireworks gained from the /give command, but not for crafted fireworks, try using MCedit or an NBT editor to see what the actual color value is.
1

Welcome