3

How can I detect when player ignite a TNT block, using flint and steel, and identify which player it is?

I want to then show a tellraw message. I have tried creating a scoreboard that detects when a player uses a flint and steel:

/scoreboard objectives add igniteTNT
/stat.useItem.minecraft.flint_and_steel

Then running the following on a fill clock:

/execute @e[type=PrimedTnt]
/execute @p[score_igniteTNT_min=1]
/tellraw @a [{selector:"@p",color:none},{text:" has ignited a tnt!",color:red}]
/scoreboard players reset @a igniteTNT

It seems like the stat.useItem.minecraft.flint_and_steel doesn't go up when using flint and steel on a TNT block.

2
+50

After playing around a bit, I have found a workaround for the non-functioning stat objective. It works by using Flint and Steel with a durability of 0 (i.e. Damage of 64), which are automatically given to every player that does not currently have flint and steel somewhere in his inventory.

First, set up the objective as a dummy, also set up an objective tracking whether or not a TNT was already ignited.

/scoreboard objectives add hasFlintAndSteel dummy
/scoreboard objectives add Fuse dummy

Now create a fill clock and run the following 4 commands (in this order):

/scoreboard players set @a hasFlintAndSteel 0
/scoreboard players set @a hasFlintAndSteel 1 {Inventory:[{id:minecraft:flint_and_steel}]}
/scoreboard players add @e[type=PrimedTnt] Fuse 1
/execute @e[type=PrimedTnt,score_Fuse=1] ~ ~ ~ execute @p[score_flintandsteel=0,r=5] ~ ~ ~ tellraw @a ["",{selector:@p,bold:true}," has set us up the bomb!"]
/give @a[score_flintandsteel=0] minecraft:flint_and_steel 1 64
  • The first two commands determine whether a player currently has flint and steel in this clock cycle/tick.
  • The third command tracks the fuse time of all primed TNT entities. It is used to execute only on newly ignited TNT.
  • The forth command checks for a player who just used his flint and steel in a 5 block radius around every freshly primed TNT. If a player is found, the tellraw command is executed at that player.
  • The fith command gives an almost broken flint and steel to every player without one.

Since this method requires the Flint and Steel to break, this will only work in Survival or Adventure mode. Also, there is an annoying clunk sound and particles on screen every time you use your Flint and Steel.

If not everyone in your game has access to Flint and Steel, you can use another objective to only give it to the players that do in the 5th command.

|improve this answer|||||
  • 1
    @CommandFox no problem, I appreciate these kind of challenges. I'd really love if entitydata worked on player's though. You could just detect 63 durability and instant-repair it. – MrLemon Jul 12 '15 at 19:12
-1

If you have a clock set up at spawn, you could check for an activated tnt in a radius.

/testfor @e[type=PrimedTnt,r=300]

This would check for primed tnt in a radius of 300 blocks, for example...

|improve this answer|||||
  • This doesn't show who has activated the tnt. – Jacques Marais Jul 12 '15 at 6:53
-1

Firstly the /scoreboard command should be

/scoreboard objectives add igniteTNT stat.useItem.minecraft.flint_and_steel igniteTNT

Secondly, you should have a commandblock fill clock. The first command should be the command to test if a player has ignited the TNT.

/execute @p[score_igniteTNT_min=1] ~ ~ ~ /execute @e[type=PrimedTnt,r=4] ~ ~ ~ /tellraw @a ["",{"selector":"@p"},{"text":" has ignited the TNT"}]

and the second should be

/scoreboard players set @a igniteTnt 0
|improve this answer|||||
  • As OP stated in the question, stat.useItem.minecraft.flint_and_steel does not increase when you ignite TNT. While this is probably a bug (stat tracking is full of those), this still means your answer won't work. – MrLemon Jul 12 '15 at 15:07

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.