77import net .minecraft .resources .ResourceKey ;
88import net .minecraft .server .MinecraftServer ;
99import net .minecraft .world .Difficulty ;
10+ import net .minecraft .world .clock .ClockState ;
1011import net .minecraft .world .clock .PackedClockStates ;
1112import net .minecraft .world .clock .ServerClockManager ;
13+ import net .minecraft .world .clock .WorldClock ;
1214import net .minecraft .world .level .chunk .ChunkGenerator ;
1315import net .minecraft .world .level .dimension .DimensionType ;
1416import net .minecraft .world .level .dimension .LevelStem ;
1719import org .jetbrains .annotations .Nullable ;
1820import xyz .nucleoid .fantasy .util .GameRuleStore ;
1921
22+ import java .util .HashMap ;
2023import java .util .Map ;
2124import java .util .function .BiFunction ;
2225import java .util .function .BooleanSupplier ;
@@ -40,7 +43,8 @@ public final class RuntimeLevelConfig {
4043 private boolean mirrorOverworldDifficulty = false ;
4144 private boolean mirrorOverworldClocks = false ;
4245 private RuntimeLevel .Constructor levelConstructor = RuntimeLevel ::new ;
43- private Function <BooleanSupplier , RuntimeClockManager > clockManagerConstructor = s -> new RuntimeClockManager (PackedClockStates .EMPTY , s );
46+ private BiFunction <PackedClockStates , BooleanSupplier , RuntimeClockManager > clockManagerConstructor = (c , s ) -> new RuntimeClockManager (c , s );
47+ private final Map <ResourceKey <WorldClock >, ClockState > clockState = new HashMap <>();
4448
4549 private long gameTime = 0 ;
4650 private TriState flat = TriState .DEFAULT ;
@@ -77,7 +81,7 @@ public RuntimeLevelConfig setLevelConstructor(RuntimeLevel.Constructor construct
7781 * @return The same instance of {@link RuntimeLevelConfig}
7882 */
7983 public RuntimeLevelConfig setClockManagerConstructor (PackedClockStates clockStates ) {
80- this .clockManagerConstructor = s -> new RuntimeClockManager (clockStates , s );
84+ this .clockManagerConstructor = ( _ , s ) -> new RuntimeClockManager (clockStates , s );
8185 return this ;
8286 }
8387
@@ -89,10 +93,39 @@ public RuntimeLevelConfig setClockManagerConstructor(PackedClockStates clockStat
8993 * @return The same instance of {@link RuntimeLevelConfig}
9094 */
9195 public RuntimeLevelConfig setClockManagerConstructor (Function <BooleanSupplier , RuntimeClockManager > clockManagerConstructor ) {
96+ this .clockManagerConstructor = (_ , s ) -> clockManagerConstructor .apply (s );
97+ return this ;
98+ }
99+
100+ /**
101+ * Sets the clock manager constructor
102+ *
103+ * @param clockManagerConstructor The clock manager constructor to use
104+ *
105+ * @return The same instance of {@link RuntimeLevelConfig}
106+ */
107+ public RuntimeLevelConfig setClockManagerConstructor (BiFunction <PackedClockStates , BooleanSupplier , RuntimeClockManager > clockManagerConstructor ) {
92108 this .clockManagerConstructor = clockManagerConstructor ;
93109 return this ;
94110 }
95111
112+ public RuntimeLevelConfig setClockTime (ResourceKey <WorldClock > clock , int time ) {
113+ return this .setClockTime (clock , new ClockState (time , 0 , 1 , false ));
114+ }
115+
116+ public RuntimeLevelConfig setClockTime (ResourceKey <WorldClock > clock , int time , float rate ) {
117+ return this .setClockTime (clock , new ClockState (time , 0 , rate , false ));
118+ }
119+
120+ public RuntimeLevelConfig setClockTime (ResourceKey <WorldClock > clock , int time , boolean paused ) {
121+ return this .setClockTime (clock , new ClockState (time , 0 , 1 , paused ));
122+ }
123+
124+ public RuntimeLevelConfig setClockTime (ResourceKey <WorldClock > clock , ClockState state ) {
125+ this .clockState .put (clock , state );
126+ return this ;
127+ }
128+
96129 /**
97130 * Sets the level dimension type
98131 *
@@ -193,8 +226,6 @@ public RuntimeLevelConfig setDifficulty(Difficulty difficulty) {
193226
194227 /**
195228 * Modifies a gamerule
196- * <br/>
197- * <b>Does nothing if {@link RuntimeLevelConfig#mirrorOverworldGameRules} is true</b>
198229 *
199230 * @param key The gamerule to modify
200231 * @param value The value of the gamerule
@@ -242,6 +273,13 @@ public RuntimeLevelConfig setMirrorOverworldClocks(boolean mirror) {
242273 return this ;
243274 }
244275
276+ public RuntimeLevelConfig mirrorOverworldGameState () {
277+ this .setMirrorOverworldGameRules (true );
278+ this .setMirrorOverworldClocks (true );
279+ this .setMirrorOverworldDifficulty (true );
280+ return this ;
281+ }
282+
245283 /**
246284 * Defines if the level is a flat level or not
247285 *
@@ -352,8 +390,16 @@ public ServerClockManager getClockManager(MinecraftServer server, GameRules game
352390 if (this .mirrorOverworldClocks ) {
353391 return server .clockManager ();
354392 }
393+ PackedClockStates states = PackedClockStates .EMPTY ;
394+ if (!this .clockState .isEmpty ()) {
395+ var map = new HashMap <Holder <WorldClock >, ClockState >();
396+ for (var entry : this .clockState .entrySet ()) {
397+ map .put (server .registryAccess ().getOrThrow (entry .getKey ()), entry .getValue ());
398+ }
399+ states = new PackedClockStates (map );
400+ }
355401
356- var t = this .clockManagerConstructor .apply (() -> gameRules .get (GameRules .ADVANCE_TIME ));
402+ var t = this .clockManagerConstructor .apply (states , () -> gameRules .get (GameRules .ADVANCE_TIME ));
357403 t .init (server );
358404
359405 return t ;
0 commit comments