Skip to content

Commit

Permalink
WorldTag.duration_since_created mech
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 5, 2023
1 parent db91231 commit a05047b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Expand Up @@ -33,4 +33,8 @@ default Location getNearestBiomeLocation(Location start, BiomeTag biome) {

/** for clearing weather without ignoring possible raised event results */
void clearWeather(World world);

default void setGameTime(World world, long time) {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -604,6 +604,7 @@ public static void register() {

// <--[tag]
// @attribute <WorldTag.duration_since_created>
// @mechanism WorldTag.duration_since_created
// @returns DurationTag
// @description
// Returns the total duration of time since this world was first created.
Expand Down Expand Up @@ -1365,6 +1366,19 @@ public void adjust(Mechanism mechanism) {
NMSHandler.worldHelper.setDayTime(world, world.getFullTime() + mechanism.getValue().asInt());
}

// <--[mechanism]
// @object WorldTag
// @name duration_since_created
// @input DurationTag
// @description
// Changes the world's internal time-since-created value.
// @tags
// <WorldTag.duration_since_created>
// -->
if (mechanism.matches("duration_since_created") && mechanism.requireObject(DurationTag.class)) {
NMSHandler.worldHelper.setGameTime(getWorld(), mechanism.valueAsType(DurationTag.class).getTicks());
}

// <--[mechanism]
// @object WorldTag
// @name skip_night
Expand Down
Expand Up @@ -81,6 +81,11 @@ public void setDayTime(World world, long time) {
((CraftWorld) world).getHandle().setDayTime(time);
}

@Override
public void setGameTime(World world, long time) {
((PrimaryLevelData) ((CraftWorld) world).getHandle().levelData).setGameTime(time);
}

// net.minecraft.server.level.ServerLevel#wakeUpAllPlayers()
@Override
public void wakeUpAllPlayers(World world) {
Expand Down

0 comments on commit a05047b

Please sign in to comment.