Skip to content

Commit

Permalink
Add Ticks#infinite
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Apr 27, 2024
1 parent 3710afb commit 03ce3b9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ default ScheduledUpdate<T> schedule(
* @param ticks The delay, in {@link Ticks}
* @param priority The priority of the scheduled update
* @return The scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
default ScheduledUpdate<T> schedule(
final int x, final int y, final int z, final T target, final Ticks ticks, final DefaultedRegistryReference<? extends TaskPriority> priority) {
Expand All @@ -210,6 +211,7 @@ default ScheduledUpdate<T> schedule(
* @param target The target
* @param delay The delay
* @return The scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
default ScheduledUpdate<T> schedule(int x, int y, int z, final T target, final Ticks delay) {
return this.schedule(x, y, z, target, delay, TaskPriorities.NORMAL.get());
Expand All @@ -221,6 +223,7 @@ default ScheduledUpdate<T> schedule(int x, int y, int z, final T target, final T
* @param target The target
* @param delay The delay
* @return The scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
default ScheduledUpdate<T> schedule(final Vector3i pos, final T target, final Ticks delay) {
return this.schedule(pos.x(), pos.y(), pos.z(), target, delay, TaskPriorities.NORMAL.get());
Expand All @@ -233,6 +236,7 @@ default ScheduledUpdate<T> schedule(final Vector3i pos, final T target, final Ti
* @param delay The delay
* @param priority The priority of the scheduled update
* @return The scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
default ScheduledUpdate<T> schedule(final Vector3i pos, final T target, final Ticks delay, final TaskPriority priority) {
return this.schedule(pos.x(), pos.y(), pos.z(), target, delay, priority);
Expand Down Expand Up @@ -263,6 +267,7 @@ default ScheduledUpdate<T> schedule(final int x, final int y, final int z, final
* @param delay The delay, in {@link Ticks}
* @param priority The priority of the scheduled update
* @return The scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
ScheduledUpdate<T> schedule(int x, int y, int z, T target, Ticks delay, TaskPriority priority);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/scheduler/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ default Builder delay(final long delay, final TimeUnit unit) {
*
* @param ticks The delay in ticks
* @return This builder, for chaining
* @throws IllegalArgumentException If the delay is below 0
* @throws IllegalArgumentException If the delay is below 0 or infinite
*/
Builder delay(final Ticks ticks);

Expand Down Expand Up @@ -203,7 +203,7 @@ default Builder interval(final long interval, final TimeUnit unit) {
*
* @param ticks The {@link Ticks} between runs.
* @return This builder, for chaining
* @throws IllegalArgumentException If the interval is below 0
* @throws IllegalArgumentException If the interval is below 0 or infinite
*/
Builder interval(final Ticks ticks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static MinecraftDayTime of(final int day, final int hours, final int minutes) {
* @param engine The {@link Engine} to calculate the time for.
* @param ticks The {@link Ticks} since the Minecraft Epoch.
* @return The {@link MinecraftDayTime}
* @throws IllegalArgumentException if the tick count is negative
* @throws IllegalArgumentException if the tick count is negative or infinite
*/
static MinecraftDayTime of(final Engine engine, final Ticks ticks) {
return Sponge.game().factoryProvider().provide(MinecraftDayTime.Factory.class).of(engine, ticks);
Expand Down Expand Up @@ -164,6 +164,7 @@ static MinecraftDayTime of(final Engine engine, final Ticks ticks) {
*
* @param ticks The {@link Ticks} to add.
* @return A new {@link MinecraftDayTime}
* @throws IllegalArgumentException if the ticks is infinite
*/
MinecraftDayTime add(final Ticks ticks);

Expand All @@ -185,7 +186,7 @@ static MinecraftDayTime of(final Engine engine, final Ticks ticks) {
*
* @param ticks The {@link Ticks} to subtract.
* @return A new {@link MinecraftDayTime}
* @throws IllegalArgumentException if the result would be a negative time.
* @throws IllegalArgumentException if ticks is infinite or the result would be a negative time.
*/
MinecraftDayTime subtract(final Ticks ticks);

Expand Down Expand Up @@ -272,7 +273,7 @@ interface Factory {
* @param engine The {@link Engine} to calculate the time for.
* @param ticks The {@link Ticks} since the Minecraft Epoch.
* @return The {@link MinecraftDayTime}
* @throws IllegalArgumentException if the tick count is negative
* @throws IllegalArgumentException if the tick count is negative or infinite
*/
MinecraftDayTime of(Engine engine, Ticks ticks);

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/spongepowered/api/util/Ticks.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ static Ticks minecraftDay() {
return Sponge.game().factoryProvider().provide(Ticks.Factory.class).minecraftDay();
}

/**
* Represents infinite ticks.
*
* @return A {@link Ticks}
*/
static Ticks infinite() {
return Sponge.game().factoryProvider().provide(Ticks.Factory.class).infinite();
}

/**
* Returns a {@link Ticks} that represents the supplied number of ticks.
*
Expand Down Expand Up @@ -295,6 +304,7 @@ static Ticks ofMinecraftDays(final Engine engine, final long days) {
*
* @param engine The {@link Engine} to get the {@link Duration} for
* @return The effective {@link Duration}.
* @throws IllegalStateException If {@see isInfinite} is true.
*/
Duration expectedDuration(final Engine engine);

Expand All @@ -306,6 +316,7 @@ static Ticks ofMinecraftDays(final Engine engine, final long days) {
* session.</p>
*
* @return The number of ticks that this represents.
* @throws IllegalStateException If {@see isInfinite} is true.
*/
long ticks();

Expand All @@ -321,6 +332,7 @@ static Ticks ofMinecraftDays(final Engine engine, final long days) {
*
* @param engine The {@link Engine} to calculate the duration for.
* @return The approximate number of in-game seconds
* @throws IllegalStateException If {@see isInfinite} is true.
*/
long minecraftSeconds(final Engine engine);

Expand All @@ -333,9 +345,19 @@ static Ticks ofMinecraftDays(final Engine engine, final long days) {
*
* @param engine The {@link Engine} to calculate the duration for.
* @return A duration representing the in game time.
* @throws IllegalStateException If {@see isInfinite} is true.
*/
Duration minecraftDayTimeDuration(final Engine engine);

/**
* Whether this represents infinite ticks.
*
* <p>When this is true all other methods throw {@link IllegalStateException}.</p>
*
* @return True if this represents infinite ticks.
*/
boolean isInfinite();

/**
* Produces {@link Ticks} objects.
*/
Expand Down Expand Up @@ -408,6 +430,13 @@ interface Factory {
*/
Ticks minecraftDay();

/**
* @see Ticks#infinite()
*
* @return A {@link Ticks}
*/
Ticks infinite();

}

}
1 change: 1 addition & 0 deletions src/main/java/org/spongepowered/api/world/chunk/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public interface Chunk<P extends Chunk<P>> extends
*
* @see #inhabitedTime()
* @param newInhabitedTime The {@link Ticks} to set this value to
* @throws IllegalArgumentException If the inhabited time is infinite
*/
void setInhabitedTime(Ticks newInhabitedTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ static ServerLocation of(final ResourceKey worldKey, final Vector3i position) {
* should be processed
* @param priority The priority of the scheduled update
* @return The newly created scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay, TaskPriority priority);

Expand All @@ -287,6 +288,7 @@ static ServerLocation of(final ResourceKey worldKey, final Vector3i position) {
* @param delay The delay, in {@link Ticks}, before the scheduled update
* should be processed
* @return The newly created scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay);

Expand Down Expand Up @@ -339,6 +341,7 @@ static ServerLocation of(final ResourceKey worldKey, final Vector3i position) {
* @param ticks The delay, in {@link Ticks}, before the scheduled update
* should be processed
* @return The newly created scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks);

Expand All @@ -349,6 +352,7 @@ static ServerLocation of(final ResourceKey worldKey, final Vector3i position) {
* should be processed
* @param priority The priority of the scheduled update
* @return The newly created scheduled update
* @throws IllegalArgumentException if the delay is infinite
*/
ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks, TaskPriority priority);

Expand Down

0 comments on commit 03ce3b9

Please sign in to comment.