Skip to content

Commit

Permalink
Extracted MAX_ONBOARD_TICKS from magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
m-doescode committed Aug 7, 2024
1 parent 2e97c4f commit 666446b
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -25,6 +26,11 @@ public abstract class MixinServerPlayer extends Player {
@Shadow
public abstract ServerLevel serverLevel();

// The maximum number of ticks before the player is no longer considered aboard a ship
// if they are no longer directly touching it
@Unique
private static final int MAX_ONBOARD_TICKS = 4;

public MixinServerPlayer(final Level level, final BlockPos blockPos, final float f,
final GameProfile gameProfile) {
super(level, blockPos, f, gameProfile);
Expand All @@ -39,7 +45,7 @@ void teleportToShip(final CompoundTag compoundTag, final CallbackInfo ci) {
final long lastShipId = compoundTag.getLong("LastShipId");

final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId);
// If ship doesn't exist, don't bother
// Don't teleport if the ship doesn't exist anymore
if (ship == null)
return;

Expand All @@ -58,19 +64,19 @@ void teleportToShip(final CompoundTag compoundTag, final CallbackInfo ci) {
void rememberLastShip(final CompoundTag compoundTag, final CallbackInfo ci) {
final EntityDraggingInformation draggingInformation = ((IEntityDraggingInformationProvider) this).getDraggingInformation();

if (draggingInformation.getTicksSinceStoodOnShip() > 4)
if (draggingInformation.getTicksSinceStoodOnShip() > MAX_ONBOARD_TICKS)
return;

@Nullable final Long lastShipId = draggingInformation.getLastShipStoodOn();
if (lastShipId == null)
return;

compoundTag.putLong("LastShipId", lastShipId);

final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId);
if (ship == null)
return;

compoundTag.putLong("LastShipId", lastShipId);

// Get position relative to ship
// (Technically, this grabs the position in the shipyard, but it works well enough...)
final Vector3d playerWorldPosition = new Vector3d(getX(), getY(), getZ());
Expand Down

0 comments on commit 666446b

Please sign in to comment.