Skip to content

Commit

Permalink
Fix stamina cost of boat
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCheung0422 committed Oct 11, 2024
1 parent 21efaa8 commit f362e93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/client/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void tick() {

if (isSwimming() && !potioneffects.containsKey(PotionType.Swim) && ride == null)
staminaRecharge = 0; // Don't recharge stamina while swimming.
if (ride != null && ((Boat)ride).isMoving())
if (ride instanceof Boat && ((Boat) ride).isMoving())
staminaRecharge = 0; // Don't recharge stamina while rowing the boat.

// Recharge a bolt for each multiple of maxStaminaRecharge.
Expand Down
41 changes: 18 additions & 23 deletions src/client/java/minicraft/entity/vehicle/Boat.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ public class Boat extends Entity implements PlayerRideable {
};

private static final int MOVE_SPEED = 1;
private static final int STAMINA_COST_TIME = 45; // a unit of stamina is consumed per this amount of time of move

private @Nullable Entity passenger;

private @NotNull Direction dir;

private int walkDist = 0;

private boolean moving = false;
private int unitMoveCounter = 0;

public Boat(@NotNull Direction dir) {
super(6, 6);
Expand Down Expand Up @@ -132,50 +131,44 @@ public boolean canSwim() {
@Override
public boolean rideTick(Player passenger, Vector2 vec) {
if (this.passenger != passenger) return false;

if (unitMoveCounter >= STAMINA_COST_TIME) {
passenger.payStamina(1);
unitMoveCounter -= STAMINA_COST_TIME;
}

boolean inLava = isInLava(), inWater = isInWater();
if (inLava) {
if (Updater.tickCount % 2 != 0) return true; // A bit slower when in lava.
} else if (!inWater && Updater.tickCount % 4 != 0) return true; // Slower when not in water.
int xd = (int) (vec.x * MOVE_SPEED);
int yd = (int) (vec.y * MOVE_SPEED);
dir = Direction.getDirection(xd, yd);
if (move(xd, yd)) {
if (passenger.stamina > 0 && move(xd, yd)) {
if (!(inWater || inLava) || (inLava && Updater.tickCount % 4 == 0) ||
(inWater && Updater.tickCount % 2 != 0)) walkDist++; // Slower the animation
syncPassengerState(passenger);
if (Updater.tickCount % 60 == 0) {
passenger.payStamina(1);
}
moving = true;
} else moving = false;
return true;
}

@Override
public boolean move(int xd, int yd) {
if (passenger != null) {
if (((Player) passenger).stamina > 0 && ((Player) passenger).staminaRechargeDelay == 0) {
return super.move(xd, yd);
} else if (((Player) passenger).staminaRechargeDelay == 0) {
((Player) passenger).staminaRechargeDelay = 5;
return false;
}
unitMoveCounter++;
return true;
} else {
if (unitMoveCounter > 0) unitMoveCounter--;
return false;
}
return false;
}

public @NotNull Direction getDir() {
return dir;
}

public boolean isMoving() {
return moving;
return unitMoveCounter > 0;
}

@Override
public boolean startRiding(Player player) {
if (passenger == null) {
passenger = player;
unitMoveCounter = 0;
syncPassengerState(passenger);
return true;
} else
Expand All @@ -186,6 +179,8 @@ public boolean startRiding(Player player) {
public void stopRiding(Player player) {
if (passenger == player) {
passenger = null;
moving = false;
unitMoveCounter = 0; // reset counters
}
}
}

0 comments on commit f362e93

Please sign in to comment.