From a8d80a92e2bea9fed6da15467fc4308d749fe9f1 Mon Sep 17 00:00:00 2001 From: aromaa Date: Tue, 19 Dec 2023 00:23:28 +0200 Subject: [PATCH] Add Ticks#infinite --- .../RangedAttackAgainstAgentGoal.java | 1 + .../entity/living/player/CooldownTracker.java | 1 + .../item/recipe/cooking/CookingRecipe.java | 1 + .../api/scheduler/ScheduledUpdateList.java | 5 ++++ .../org/spongepowered/api/scheduler/Task.java | 4 +-- .../api/util/MinecraftDayTime.java | 7 +++-- .../org/spongepowered/api/util/Ticks.java | 29 +++++++++++++++++++ .../spongepowered/api/world/chunk/Chunk.java | 1 + .../api/world/server/ServerLocation.java | 4 +++ .../server/storage/ServerWorldProperties.java | 1 + .../api/world/weather/Weather.java | 2 ++ .../api/world/weather/WeatherUniverse.java | 1 + 12 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/spongepowered/api/entity/ai/goal/builtin/creature/RangedAttackAgainstAgentGoal.java b/src/main/java/org/spongepowered/api/entity/ai/goal/builtin/creature/RangedAttackAgainstAgentGoal.java index 61c235ab41..4b51d15578 100644 --- a/src/main/java/org/spongepowered/api/entity/ai/goal/builtin/creature/RangedAttackAgainstAgentGoal.java +++ b/src/main/java/org/spongepowered/api/entity/ai/goal/builtin/creature/RangedAttackAgainstAgentGoal.java @@ -77,6 +77,7 @@ static Builder builder() { * * @param delay The delay, in ticks * @return This goal, for chaining + * @throws IllegalArgumentException if the delay is infinite */ RangedAttackAgainstAgentGoal setDelayBetweenAttacks(Ticks delay); diff --git a/src/main/java/org/spongepowered/api/entity/living/player/CooldownTracker.java b/src/main/java/org/spongepowered/api/entity/living/player/CooldownTracker.java index 9a0c181506..b1265712fa 100644 --- a/src/main/java/org/spongepowered/api/entity/living/player/CooldownTracker.java +++ b/src/main/java/org/spongepowered/api/entity/living/player/CooldownTracker.java @@ -62,6 +62,7 @@ public interface CooldownTracker { * @param ticks The amount of ticks to set the item type on cooldown for * @return False if setting the cooldown failed, possibly due to the event * being cancelled + * @throws IllegalArgumentException if the ticks is infinite */ boolean setCooldown(ItemType type, Ticks ticks); diff --git a/src/main/java/org/spongepowered/api/item/recipe/cooking/CookingRecipe.java b/src/main/java/org/spongepowered/api/item/recipe/cooking/CookingRecipe.java index 622eaf6de2..8cdf3adbae 100644 --- a/src/main/java/org/spongepowered/api/item/recipe/cooking/CookingRecipe.java +++ b/src/main/java/org/spongepowered/api/item/recipe/cooking/CookingRecipe.java @@ -239,6 +239,7 @@ interface EndStep extends Builder, * @param ticks the cookingTime * * @return This builder, for chaining + * @throws IllegalArgumentException if the ticks is infinite */ EndStep cookingTime(Ticks ticks); diff --git a/src/main/java/org/spongepowered/api/scheduler/ScheduledUpdateList.java b/src/main/java/org/spongepowered/api/scheduler/ScheduledUpdateList.java index f5259d1a8f..90d76b3870 100644 --- a/src/main/java/org/spongepowered/api/scheduler/ScheduledUpdateList.java +++ b/src/main/java/org/spongepowered/api/scheduler/ScheduledUpdateList.java @@ -196,6 +196,7 @@ default ScheduledUpdate 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 schedule( final int x, final int y, final int z, final T target, final Ticks ticks, final DefaultedRegistryReference priority) { @@ -210,6 +211,7 @@ default ScheduledUpdate schedule( * @param target The target * @param delay The delay * @return The scheduled update + * @throws IllegalArgumentException if the delay is infinite */ default ScheduledUpdate schedule(int x, int y, int z, final T target, final Ticks delay) { return this.schedule(x, y, z, target, delay, TaskPriorities.NORMAL.get()); @@ -221,6 +223,7 @@ default ScheduledUpdate 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 schedule(final Vector3i pos, final T target, final Ticks delay) { return this.schedule(pos.x(), pos.y(), pos.z(), target, delay, TaskPriorities.NORMAL.get()); @@ -233,6 +236,7 @@ default ScheduledUpdate 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 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); @@ -263,6 +267,7 @@ default ScheduledUpdate 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 schedule(int x, int y, int z, T target, Ticks delay, TaskPriority priority); diff --git a/src/main/java/org/spongepowered/api/scheduler/Task.java b/src/main/java/org/spongepowered/api/scheduler/Task.java index fdae6a5694..6c7e3c71e3 100644 --- a/src/main/java/org/spongepowered/api/scheduler/Task.java +++ b/src/main/java/org/spongepowered/api/scheduler/Task.java @@ -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); @@ -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); diff --git a/src/main/java/org/spongepowered/api/util/MinecraftDayTime.java b/src/main/java/org/spongepowered/api/util/MinecraftDayTime.java index 54517a6263..7d3c301db4 100644 --- a/src/main/java/org/spongepowered/api/util/MinecraftDayTime.java +++ b/src/main/java/org/spongepowered/api/util/MinecraftDayTime.java @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/src/main/java/org/spongepowered/api/util/Ticks.java b/src/main/java/org/spongepowered/api/util/Ticks.java index 53fe5b3476..3a204bf053 100644 --- a/src/main/java/org/spongepowered/api/util/Ticks.java +++ b/src/main/java/org/spongepowered/api/util/Ticks.java @@ -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. * @@ -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); @@ -306,6 +316,7 @@ static Ticks ofMinecraftDays(final Engine engine, final long days) { * session.

* * @return The number of ticks that this represents. + * @throws IllegalStateException If {@see isInfinite} is true. */ long ticks(); @@ -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); @@ -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. + * + *

When this is true all other methods throw {@link IllegalStateException}.

+ * + * @return True if this represents infinite ticks. + */ + boolean isInfinite(); + /** * Produces {@link Ticks} objects. */ @@ -408,6 +430,13 @@ interface Factory { */ Ticks minecraftDay(); + /** + * @see Ticks#infinite() + * + * @return A {@link Ticks} + */ + Ticks infinite(); + } } diff --git a/src/main/java/org/spongepowered/api/world/chunk/Chunk.java b/src/main/java/org/spongepowered/api/world/chunk/Chunk.java index b3ef032d8e..8d675f5af5 100644 --- a/src/main/java/org/spongepowered/api/world/chunk/Chunk.java +++ b/src/main/java/org/spongepowered/api/world/chunk/Chunk.java @@ -120,6 +120,7 @@ public interface Chunk

> 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); diff --git a/src/main/java/org/spongepowered/api/world/server/ServerLocation.java b/src/main/java/org/spongepowered/api/world/server/ServerLocation.java index da201f71f6..dd1b726b6c 100644 --- a/src/main/java/org/spongepowered/api/world/server/ServerLocation.java +++ b/src/main/java/org/spongepowered/api/world/server/ServerLocation.java @@ -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 scheduleBlockUpdate(Ticks delay, TaskPriority priority); @@ -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 scheduleBlockUpdate(Ticks delay); @@ -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 scheduleFluidUpdate(Ticks ticks); @@ -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 scheduleFluidUpdate(Ticks ticks, TaskPriority priority); diff --git a/src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java b/src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java index 93efda5ece..ab17a4a819 100644 --- a/src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java +++ b/src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java @@ -280,6 +280,7 @@ default void setSerializationBehavior(SerializationBehavior behavior) { * Sets the delay before a {@link WanderingTrader} will be spawned. * * @param delay The delay, in ticks + * @throws IllegalArgumentException if the delay is infinite */ void setWanderingTraderSpawnDelay(Ticks delay); diff --git a/src/main/java/org/spongepowered/api/world/weather/Weather.java b/src/main/java/org/spongepowered/api/world/weather/Weather.java index 573d28b81a..d317843c7a 100644 --- a/src/main/java/org/spongepowered/api/world/weather/Weather.java +++ b/src/main/java/org/spongepowered/api/world/weather/Weather.java @@ -72,6 +72,7 @@ static Weather of(Supplier type, long duration) { * @param duration The weather remaining duration * * @return The new weather + * @throws IllegalArgumentException if the duration is infinite */ static Weather of(Supplier type, Ticks duration) { return Sponge.game().factoryProvider().provide(Factory.class).of(type.get(), duration, Ticks.of(0)); @@ -96,6 +97,7 @@ static Weather of(WeatherType type, long duration) { * @param duration The weather remaining duration * * @return The new weather + * @throws IllegalArgumentException if the duration is infinite */ static Weather of(WeatherType type, Ticks duration) { return Sponge.game().factoryProvider().provide(Factory.class).of(type, duration, Ticks.of(0)); diff --git a/src/main/java/org/spongepowered/api/world/weather/WeatherUniverse.java b/src/main/java/org/spongepowered/api/world/weather/WeatherUniverse.java index 4dabcf677b..c05ec5c348 100644 --- a/src/main/java/org/spongepowered/api/world/weather/WeatherUniverse.java +++ b/src/main/java/org/spongepowered/api/world/weather/WeatherUniverse.java @@ -53,6 +53,7 @@ interface Mutable extends WeatherUniverse { * * @param type The weather that should be switched to * @param ticks The specified tick duration + * @throws IllegalArgumentException if the duration is infinite */ void setWeather(WeatherType type, Ticks ticks); }