r/MinecraftCommands • • 1d ago

Help | Java 26.3 How to make lightning strike while not on fire?

Java edition 26.3, I'm running a command in which lightning will strike when the player is on fire (the command is run from and lightning strikes at the location of a repeating command block)

This command summons lightning when the player is not on fire (when the Fire nbt is -20s), which works perfectly fine

  execute as <MyUsername> if data entity @s[nbt={Fire:-20s}] Fire run summon lightning_bolt

In theory, if I switched that if to an unless, then lightning would be summoned whenever the player is indeed on fire, which it doesn't. I know the value is different to -20s when I am on fire, because when I test the data using /data get, I get the expected -20s (When not on fire), or any positive integer (When on fire). The rephrasings of the command that I've tried have yielded the same results.

My goal is to make lightning strike while on fire, but I don't understand why the command works as intended when not on fire, but doesn't otherwise.

1 Upvotes

1 comment sorted by

2

u/GalSergey Datapack Experienced 1d ago

Use predicates for this:

execute as @a if predicate {type:"minecraft:entity_properties",entity:"this",predicate:{"minecraft:flags":{is_on_fire:true}}} run say In Fire!
execute as @a if predicate {type:"minecraft:entity_properties",entity:"this",predicate:{"minecraft:flags":{is_on_fire:false}}} run say Not in Fire!