Skip to content
Open
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
2 changes: 1 addition & 1 deletion SpongeAPI
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.spongepowered.common.world.border;

import org.spongepowered.api.util.Ticks;
import org.spongepowered.api.world.border.WorldBorder;
import org.spongepowered.common.accessor.world.level.border.WorldBorder_SettingsAccessor;
import org.spongepowered.common.bridge.world.level.border.WorldBorderBridge;
Expand All @@ -35,7 +36,7 @@ public final class SpongeWorldBorderBuilder implements WorldBorder.Builder {

private double diameter = -1;
private double initialDiameter = -1;
private Duration time = Duration.ZERO;
private Ticks ticks = Ticks.zero();
private Vector2d center = Vector2d.ZERO; //use a default value otherwise null is used
private Duration warningTime = Duration.ZERO;
private double warningDistance;
Expand All @@ -50,7 +51,7 @@ public WorldBorder.Builder from(final WorldBorderBridge border) {
public WorldBorder.Builder from(final WorldBorder border) {
this.diameter = border.targetDiameter();
this.initialDiameter = border.diameter();
this.time = border.timeUntilTargetDiameter();
this.ticks = border.timeUntilTargetDiameter();
this.center = border.center();
this.warningTime = border.warningTime();
this.warningDistance = border.warningDistance();
Expand All @@ -77,11 +78,8 @@ public WorldBorder.Builder targetDiameter(final double diameter) {
}

@Override
public WorldBorder.Builder timeToTargetDiameter(final Duration time) {
if (time.isNegative()) {
throw new IllegalArgumentException("time cannot be negative");
}
this.time = time;
public WorldBorder.Builder timeToTargetDiameter(final Ticks ticks) {
this.ticks = ticks;
return this;
}

Expand Down Expand Up @@ -153,7 +151,7 @@ public WorldBorder build() throws IllegalStateException {
(int) this.warningDistance,
(int) this.warningTime.getSeconds(),
this.initialDiameter == -1 ? this.diameter : this.initialDiameter,
this.time.toMillis(),
this.ticks.isInfinite() ? -1 : this.ticks.ticks(),
this.diameter
);
}
Expand All @@ -165,7 +163,7 @@ public WorldBorder.Builder reset() {
this.safeZone = 0;
this.diameter = -1;
this.initialDiameter = -1;
this.time = Duration.ZERO;
this.ticks = Ticks.zero();
this.warningDistance = 0;
this.warningTime = Duration.ZERO;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
package org.spongepowered.common.mixin.api.minecraft.world.level.border;

import net.minecraft.world.level.border.WorldBorder;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.util.SpongeTicks;
import org.spongepowered.math.vector.Vector2d;

import java.time.Duration;
Expand Down Expand Up @@ -61,8 +63,8 @@ public double targetDiameter() {
}

@Override
public Duration timeUntilTargetDiameter() {
return Duration.ofMillis(this.shadow$lerpTime());
public Ticks timeUntilTargetDiameter() {
return SpongeTicks.ticksOrInfinite(this.shadow$lerpTime(), -1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.bridge.world.level.border.WorldBorderBridge;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.util.SpongeTicks;
import org.spongepowered.common.world.border.SpongeWorldBorderBuilder;

import java.time.Duration;
Expand Down Expand Up @@ -83,13 +84,13 @@ public abstract class WorldBorderMixin implements WorldBorderBridge {
}

@Inject(method = "lerpSizeBetween", at = @At(value = "HEAD"), cancellable = true)
private void impl$onLerping(final double initial, final double target, final long milliseconds, final long delay, final CallbackInfo ci) {
private void impl$onLerping(final double initial, final double target, final long ticks, final long delay, final CallbackInfo ci) {
if (this.impl$fireEvent) {
final Supplier<org.spongepowered.api.world.border.WorldBorder> proposed =
() -> new SpongeWorldBorderBuilder().from(this)
.initialDiameter(initial)
.targetDiameter(target)
.timeToTargetDiameter(Duration.ofMillis(milliseconds))
.timeToTargetDiameter(SpongeTicks.ticksOrInfinite(ticks, -1))
.build();
if (this.impl$suppressOriginalAction(proposed)) {
ci.cancel();
Expand Down Expand Up @@ -225,7 +226,7 @@ public abstract class WorldBorderMixin implements WorldBorderBridge {
// TODO - figure out how to get the appropriate game time
((WorldBorder) (Object) this).lerpSizeBetween(worldBorder.size(), worldBorder.lerpTarget(), worldBorder.lerpTime(), SpongeCommon.server().overworld().getGameTime());
} else {
((WorldBorder) (Object) this).setSize(worldBorder.size());
((WorldBorder) (Object) this).setSize(worldBorder.lerpTime() == -1 ? worldBorder.size() : worldBorder.lerpTarget());
}
}

Expand Down
Loading