Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ticks#infinite #2480

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -1408,16 +1408,6 @@ public final class Keys {
*/
public static final Key<Value<Tag<BlockType>>> INFINIBURN = Keys.key(ResourceKey.sponge("infiniburn"), new TypeToken<Tag<BlockType>>() {});

/**
* Whether an {@link Item} will not despawn for an infinite time.
*/
public static final Key<Value<Boolean>> INFINITE_DESPAWN_DELAY = Keys.key(ResourceKey.sponge("infinite_despawn_delay"), Boolean.class);

/**
* Whether an {@link Item} has an infinite pickup delay.
*/
public static final Key<Value<Boolean>> INFINITE_PICKUP_DELAY = Keys.key(ResourceKey.sponge("infinite_pickup_delay"), Boolean.class);

/**
* Whether a world of a {@link ServerWorldProperties} was initialized.
*/
Expand Down Expand Up @@ -2087,8 +2077,7 @@ public final class Keys {
* <p>When this value hits 0 or lower, the Vex will receive damage and
* then the value will set back to 20 until the Vex dies.</p>
*
* <p>If the Vex was summoned by a player, this value will be pegged at 0
* and the Vex will not take any damage.</p>
* <p>If the Vex was summoned by a player, this value will be {@link Ticks#infinite()}</p>
*/
public static final Key<Value<Ticks>> LIFE_TICKS = Keys.key(ResourceKey.sponge("life_ticks"), Ticks.class);

Expand Down
18 changes: 0 additions & 18 deletions src/main/java/org/spongepowered/api/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ default Value.Mutable<Ticks> despawnDelay() {
return this.requireValue(Keys.DESPAWN_DELAY).asMutable();
}

/**
* {@link Keys#INFINITE_DESPAWN_DELAY}
*
* @return Whether the item will not despawn for an infinite time
*/
default Value.Mutable<Boolean> infiniteDespawnDelay() {
return this.requireValue(Keys.INFINITE_DESPAWN_DELAY).asMutable();
}

/**
* {@link Keys#INFINITE_PICKUP_DELAY}
*
* @return Whether the item has an infinite pickup delay
*/
default Value.Mutable<Boolean> infinitePickupDelay() {
return this.requireValue(Keys.INFINITE_PICKUP_DELAY).asMutable();
}

/**
* {@link Keys#PICKUP_DELAY}
*
Expand Down
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 {@link Ticks#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 {@link Ticks#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 {@link Ticks#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 {@link Ticks#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