Skip to content

Commit

Permalink
Fix boost ticking
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Ferguson committed May 20, 2024
1 parent 16d766d commit de5b1a2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ public VehicleComponent<?> getVehicleComponent() {
}

@Override
public boolean isClientControlled() {
return getFlag(EntityFlag.SADDLED)
&& !passengers.isEmpty()
&& passengers.get(0) == session.getPlayerEntity()
&& session.getPlayerInventory().isHolding(Items.CARROT_ON_A_STICK);
public Vector2f getAdjustedInput(Vector2f input) {
return Vector2f.UNIT_Y;
}

@Override
Expand All @@ -115,7 +112,10 @@ public float getVehicleSpeed() {
}

@Override
public Vector2f getAdjustedInput(Vector2f input) {
return Vector2f.UNIT_Y;
public boolean isClientControlled() {
return getFlag(EntityFlag.SADDLED)
&& !passengers.isEmpty()
&& passengers.get(0) == session.getPlayerEntity()
&& session.getPlayerInventory().isHolding(Items.CARROT_ON_A_STICK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,26 @@ public void setBoost(IntEntityMetadata entityMetadata) {
}

@Override
public @NonNull VehicleComponent<?> getVehicleComponent() {
public VehicleComponent<?> getVehicleComponent() {
return vehicleComponent;
}

@Override
public @NonNull Vector2f getAdjustedInput(Vector2f input) {
public Vector2f getAdjustedInput(Vector2f input) {
return Vector2f.UNIT_Y;
}

@Override
public boolean isClientControlled() {
// Does not require saddle
return !passengers.isEmpty()
&& passengers.get(0) == session.getPlayerEntity()
&& session.getPlayerInventory().isHolding(Items.WARPED_FUNGUS_ON_A_STICK);
public float getVehicleSpeed() {
return vehicleComponent.getMoveSpeed() * (isCold ? 0.35f : 0.55f) * vehicleComponent.getBoostMultiplier();
}

@Override
public float getVehicleSpeed() {
return vehicleComponent.getMoveSpeed() * (isCold ? 0.35f : 0.55f) * vehicleComponent.getBoostMultiplier();
public boolean isClientControlled() {
return getFlag(EntityFlag.SADDLED)
&& !passengers.isEmpty()
&& passengers.get(0) == session.getPlayerEntity()
&& session.getPlayerInventory().isHolding(Items.WARPED_FUNGUS_ON_A_STICK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public BoostableVehicleComponent(T vehicle, float stepHeight) {

public void startBoost(int boostLength) {
this.boostLength = boostLength;
this.boostTicks = 0;
this.boostTicks = 1;
}

public float getBoostMultiplier() {
if (isBoosting()) {
return 1.0f + 1.15f * TrigMath.sin((float)boostTicks / (float)boostLength * TrigMath.PI);
return 1.0f + 1.15f * TrigMath.sin((float) boostTicks / (float) boostLength * TrigMath.PI);
}
return 1.0f;
}
Expand All @@ -53,10 +53,12 @@ public boolean isBoosting() {
}

@Override
public void tickVehicle() {
super.tickVehicle();
if (isBoosting()) {
public boolean tickVehicle() {
boolean clientControlled = super.tickVehicle();
if (clientControlled && isBoosting()) {
boostTicks++;
}

return clientControlled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void startDashCooldown() {
}

@Override
public void tickVehicle() {
public boolean tickVehicle() {
if (this.dashTick != 0) {
if (vehicle.getSession().getTicks() > this.dashTick) {
vehicle.setFlag(EntityFlag.HAS_DASH_COOLDOWN, false);
Expand All @@ -68,7 +68,7 @@ public void tickVehicle() {
vehicle.setFlag(EntityFlag.CAN_DASH, vehicle.getFlag(EntityFlag.SADDLED) && !isStationary());
vehicle.updateBedrockMetadata();

super.tickVehicle();
return super.tickVehicle();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public interface ClientVehicle {

Vector2f getAdjustedInput(Vector2f input);

boolean isClientControlled();

float getVehicleSpeed();

boolean isClientControlled();

default boolean canWalkOnLava() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public void onDismount() {
//
}

public void tickVehicle() {
public boolean tickVehicle() {
if (!vehicle.isClientControlled()) {
return;
return false;
}

ObjectDoublePair<Fluid> fluidHeight = updateFluidMovement();
Expand All @@ -164,6 +164,8 @@ public void tickVehicle() {
}
case EMPTY -> landMovement();
}

return true;
}

protected ObjectDoublePair<Fluid> updateFluidMovement() {
Expand Down

0 comments on commit de5b1a2

Please sign in to comment.