#set night to day if block is placed in world
42 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
maybe onBlockPlaced, but if I leave the world, what happens? the code should not happen until I place the block again, right?
??xy
The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.
This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.
Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.
what are you actually trying to do?
(like from a user perspective, ie having a bed that always skips night for the player)
does it do it once, when placed? or all the time? or only when its night time?
based on your level tick code its only when night
should do every time is night
the best way to do this would be to use the new block entities
you could just set it to day and stop the time, instead of spamming it per tick
but i don't know how those work so cant really help with that
oh didn't knew about that, way more optimized than this
gamerules
just did a sample code to improve later
doDaylightCycle false
where can I find more information about this?
if i remember correctly
made a quick bot macro
To change gamerules properly, instead of running commands, you can do it like this:
ServerEvents.loaded(e => {
if (e.server.persistentData.gameRules) return
e.server.gameRules.set("doMobSpawning", false)
e.server.gameRules.set("mobGriefing", false)
e.server.gameRules.set("doDaylightCycle", false)
e.server.persistentData.gameRules = true
})
Keep in mind this is just an example, your event/context may vary.
so that it only happens on first world load, incase someone wants to change it (ie dev world)
no
unless the example is changed to be 'default gamerules'
cause that is what the script is
@dull valley updated macro __tips_gamerules!
Be careful with pausing time because some mods may depend on that
daytime/night time and game time are different things that mods hopefully shouldnt be confusing
for TFC if you set cycle to false all your foods will never expire, like cheating
after some search, I found the block entity example, working fine
the plan is keep this way and implement energy to clear time/rain
StartupEvents.registry("block", (event) => {
event.create('cycle_stopper').blockEntity(entityInfo => {
entityInfo.serverTick(20, 0, entity => {
const level = entity.getLevel();
const server = level.server;
if (level.isNight()) {
server.runCommandSilent('time set day');
}
if (level.isRaining()) {
server.runCommandSilent('weather clear');
}
})
})
})
thanks for the tips, really appreciated!
