Jump to content

day / night cycle


LaurentOutang

Recommended Posts

Hello, 
Do you know a way to modify the length of a day (and a nigth) without doing a new WorldProvider. I want that the length of a day follows a function like : 5 * sin( 2*pi*f*DAY_COUNT + p ) + 10 in order to put a 15m day in summer and a 5m day in winter. Thank's for the help and sorry for my english.

Link to comment
Share on other sites

Did you search the forums? There are lots of lengthy discussions on this topic which don't need to be repeated here. Basically, to do it properly is complicated because you have handle things like the time command, sleep cycles, and some mod compatibilities such as sky animations. And yes generally it requires a replacement world provider.

 

However, if you want a really crude way of doing it you can add or subtract ticks to the world tick counter -- basically like a "leap second" sort of approach but there are dangers to that as discussed at length in previous threads.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Yes I searched but I didn't find something really detailed. If I change ticks, does it affect the render like player speed on screen or this kind of stuff ? If I want that snow fall from the sky in winter should I also do a WorldProvider (if I must do this I will probably take the WorldProvider option for the time) ? Thank you

Link to comment
Share on other sites

2 minutes ago, LaurentOutang said:

If I change ticks

...what?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It's possible that you could bypass the WorldProvider, when rendering the sky, but I doubt that would be a good solution

Edit: I almost forgot that the sky if far from the only difference between night and day

Edited by Ruukas
Link to comment
Share on other sites

3 minutes ago, LaurentOutang said:

+- 1 tick

 

Ok thank you

Game Ticks != Render Ticks

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

16 minutes ago, LaurentOutang said:

Yes I searched but I didn't find something really detailed. If I change ticks, does it affect the render like player speed on screen or this kind of stuff ? If I want that snow fall from the sky in winter should I also do a WorldProvider (if I must do this I will probably take the WorldProvider option for the time) ? Thank you

 

Rendering is done in separate thread (I think) which updates every screen refresh (like 60Hz or even 120Hz depending on display). The main game logic loops in "ticks" which are 20 per second (unless lagging). Since the rendering and main loop are not really synced up specifically, there is concept of "partial ticks" used to help smooth out some animations.

 

So if you did something like simply changing the world tick count, it wouldn't directly affect rendering. However, it could affect other things. For example, I think the the sleep cycle uses it (like in WorldServer#tick() metho), and world difficulty uses world tick count for the increasing difficulty, I think the map spinning might use it, And some mods might use it for timing things. So there might be some side effects.

 

But it would be fun to try. Just use a tick handler and use the World#setWorldTime() method as you wish and see what happens.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

2 minutes ago, Ruukas said:

I remember seeing timelapse (speeding up time) mods. I'm not sure exactly how they worked, but I don't think they used WorldProvider

No, they do. They'd have to.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Another point. The world info contains two "time" fields. There is totalTime and worldTime. The latter only cycles through the 24000 of the day cycle and is used for things like celestial angle. The totalTime is the time since the world started. There is the corresponding World#setTime() and World#setWorldTotalTime() methods.

 

The total time is used for a lot of stuff. If you look at the call hierarchy it is used for things like armor stand rendering applyRotations() method, used to "pace" some updates from happening too , quickly (like it waits every 600 ticks to update the "calendar date"), used in animations of items and TESR, checking for redstone torches to burn out, and many other things.

 

In other words, if you slow down the "day / night" cycle by affect the rate of tick counters like totalTime you will likely slow down many other things. So it wouldn't just be a langer day, some things would also happen slower and some things might happen multiple times like command block triggers. Now that might be what you want to have happen -- if the day is longer maybe you would want some things to be slower. But just wanted to point that out.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

6 minutes ago, Ruukas said:

What if you replicate /time set and /gamerule doDayLightCycle to keep the sun in place, or skip some time? Not sure if that has the same implications as directly changing ticks.

If you just want the sky to move slower, that works pretty much like you just suggested -- basically you can affect the time of day direcly with World#setWorldTime() and it mostly just affects the celestial angle. However, as mentioned above you will then get out of sync with other functionality like sleep cycles (which will force the time to advance expecting vanilla day duration) and the "calendar" system. And if you try to fix everything it will get complicated because then you need also change the totalWorldTime and that is used by a lot of things.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.