3

I have been making a custom UHC map for a while now. It wouldn't be PVP-based, just try to last the longest, but the catch is that after dying, that's it: you are back to spawn, then teleported to a new random location in the world, from -1000000 to 1000000.
If the players were to sleep, their spawn point would be their bed, which would mean that if they'd die, they could respawn at their bed, collect items, and go on with their day. This is not how I want it to work (UHC is where you only regenerate with golden apples or potions, so hearts are valuable).

  • Have you thought of other ways to tackle the problem? Trying to avoid them respawning at their beds, for example? – Joachim Apr 27 '19 at 17:43
  • Is there a way to stop this happening? To spawn them at spawn? (The setspawn) – Goofball 2 Apr 29 '19 at 15:46
  • 4
    Possible duplicate of Force a Player out of bed on a certain night? – pppery Jan 22 at 18:13
  • I'm voting against the duplicate vote because this question specifically asks about preventing the respawn mechanics of beds, not preventing the ability to sleep altogether. Players in this UHC map might want to sleep the night away, which is different mechanic than respawning at a bed. – Gigazelle Jan 23 at 22:05
3

You can track people who sleep with the sleep_in_bed scoreboard:

/scoreboard objectives add sleeping minecraft.custom:minecraft.sleep_in_bed

Then you can remove beds around people who are sleeping:

/execute at @e[scores={sleeping=1..}] run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace #beds

And finally reset the score:

/scoreboard players reset @e sleeping
| improve this answer | |
  • Thank you! I am going to try this solution. I may do some tests myself to see if the split second they would be in the bed for would stop phantoms or not. I also would like them to be able to sleep to stop phantoms but this could be difficult. Will do tests. Thank you. Also, I assume this has to be in spawn chunks? – Goofball 2 Apr 29 '19 at 12:48
  • Does this work in minecraft 1.13+ with the new command block changes? As there is no 'sleep_in_bed' apparently? – Goofball 2 Apr 29 '19 at 12:51
  • If you use command blocks, they have to be loaded, sure. Or you use a function. I think that the subtick of sleeping time might actually be enough to prevent phantoms, yes. The solution for this would be to throw away all this sleeping detection and just run execute at @a run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace bed all the time, thereby deleting all beds around players. Edit: I just increased the range in this comment and the answer from 3 to 5, because with a range of 3, players might still be able to click on beds. – Fabian Röling Apr 29 '19 at 13:24
  • Sorry, I misread the wiki before, the command is now fixed, using the correct scoreboard minecraft.custom:minecraft.sleep_in_bed. – Fabian Röling Apr 29 '19 at 13:26
  • Sorry I am really bad with command blocks; so I need to just have the 1 command block running execute at @a run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace bed? Or do I need the scoreboard one minecraft.custom:minecraft.sleep_in_bed ? – Goofball 2 Apr 29 '19 at 15:43
1

If you just want to a player out of bed after a small delay, without destroying the bed (that it drops instead of being overwritten by air in my other solution is caused by a bug), you can explode him out of it! But carefully, of course…

You still need the sleeping scoreboard:

/scoreboard players add sleeping custom:sleep_in_bed

These are the looped commands, they should be in a repeating command block chain or function:

execute at @a[scores={sleeping=1..}] run summon fireball ~ ~1 ~ {ExplosionPower:0,direction:[0.0,-1.0,0.0]}
effect give @a[scores={sleeping=1..}] resistance 1 5 true
scoreboard players reset @a[scores={sleeping=1..}] sleeping

The first command creates a fireball above the player's head that flies downwards very quickly. It has an explosion power of 0, so it won't damage the environment, even the bed stays where it is.
But you still get damage from it (probably because it's still a burning ball of stone hitting your head), so you are protected from that with a resistance effect that is so high that it absorbs all damage. This would in theory interfere slightly with effects like poison, but you can't sleep while poisoned anyway, so it's not too bad.
And finally, the last command resets the scoreboard so that you don't summon an army of fireballs on top of you every tick.

| improve this answer | |
  • Wow this did not work lol. I had like 1000 fireballs flying at me, will try putting the commands in reverse lol – Goofball 2 Apr 30 '19 at 14:58
  • You probably didn't actually reset the scoreboard. Just put those three commands into a repeating and two chain command blocks or into a function. – Fabian Röling May 1 '19 at 2:06
0

If you don't mind it being constantly day, you could have two repeating command blocks setting the time to noon, and the weather to clear, because those are the only times they can sleep: time set day and weather clear.

If you wanted to have the sun rise, go all the way across and then reset back to rising, you'd need a repeating command block detecting a scoreboard, which when the scoreboard (let's call it stopSleep) is 12000 (sunset) it triggers this command: execute if score @a stopSleep matches 12000.. run time set day. Then, you'd need another standalone repeating command block setting the score of stopSleep to the current time of day: execute store result score @a run time query daytime. What this does is when the current time is 12000, which is tracked in the scoreboard, the command block runs and resets the time to 1000, meaning no one could sleep. You'd still need another one keeping the weather clear. Hope this helps.

| improve this answer | |
  • This is a Survival challenge, disabling night is not an option. – Fabian Röling Apr 27 '19 at 18:07
  • Thanks but I'd rather have night to add the difficulty of surviving. Thanks though :) – Goofball 2 Apr 29 '19 at 12:47
0

The easiest way to it is: /time set

then do: /gamerule doDayLightCycle false

| improve this answer | |
  • This is a Survival challenge, disabling night is not an option. – Fabian Röling Apr 27 '19 at 18: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.