Minecraft – Take damage at night time in the overworld unless in the nether

minecraft-commandsminecraft-java-edition

I'm trying to sort out a command which forces players to return to the nether after night comes in the overword.

For example, at night all players in the overworld will be struck with the hunger effect. once they've returned to the nether, they will be cleared of the effect.

Best Answer

you can use the output of a daylight detector to determine if it is nighttime. Connecting the redstone to a commandblock, which is set to "needs redstone" and "repeat". This creats a commandblock that executes the same command over and over at night.

with the command:

/effect @a[nbt={Dimension:1}] minecraft:hunger 2 2

this will cause everyone to get the hunger debuff as long as they don't return to the nether

NOTE: If you want this to work all the time you need to place this in the spawn chunk