1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-26 10:19:12 +00:00

A few comments / start implementing happy ghast movements

This commit is contained in:
onebeastchris
2025-06-24 19:33:20 +02:00
parent a26cf54fbb
commit 135eb44a7f
3 changed files with 65 additions and 12 deletions

View File

@@ -528,6 +528,11 @@ public class LivingEntity extends Entity {
setAttributeScale((float) AttributeUtils.calculateValue(javaAttribute));
updateBedrockMetadata();
}
case WATER_MOVEMENT_EFFICIENCY -> {
if (this instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().setWaterMovementEfficiency(AttributeUtils.calculateValue(javaAttribute));
}
}
}
}
}

View File

@@ -25,10 +25,13 @@
package org.geysermc.geyser.entity.vehicle;
import it.unimi.dsi.fastutil.objects.ObjectDoublePair;
import lombok.Setter;
import org.cloudburstmc.math.vector.Vector2f;
import org.cloudburstmc.math.vector.Vector3f;
import org.geysermc.geyser.entity.type.living.animal.HappyGhastEntity;
import org.geysermc.geyser.level.block.Fluid;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType;
public class HappyGhastVehicleComponent extends VehicleComponent<HappyGhastEntity> {
@@ -37,6 +40,35 @@ public class HappyGhastVehicleComponent extends VehicleComponent<HappyGhastEntit
public HappyGhastVehicleComponent(HappyGhastEntity vehicle, float stepHeight) {
super(vehicle, stepHeight);
flyingSpeed = (float) AttributeType.Builtin.FLYING_SPEED.getDef();
}
/**
* Called every session tick while the player is mounted on the vehicle.
*/
public void tickVehicle() {
if (!vehicle.isClientControlled()) {
return;
}
// LivingEntity#travelFlying
VehicleContext ctx = new VehicleContext();
ctx.loadSurroundingBlocks();
// TODO tickRidden here (deals with rotations)
// TODO verify that updateFluidMovement applies to happy ghasts
ObjectDoublePair<Fluid> fluidHeight = updateFluidMovement(ctx);
// HappyGhast#travel
float speed = flyingSpeed * 5.0f / 3.0f;
// TODO implement LivingEntity#travelFlying cases
// switch (fluidHeight.left()) {
// default -> {
// throw new GoodLuckImplementingThisException();
// }
// }
}
protected Vector3f getInputVelocity(VehicleContext ctx, float speed) {
@@ -66,4 +98,7 @@ public class HappyGhastVehicleComponent extends VehicleComponent<HappyGhastEntit
return Vector3f.from(x, y, z).mul(3.9F * flyingSpeed);
}
public class GoodLuckImplementingThisException extends RuntimeException {
}
}

View File

@@ -26,6 +26,8 @@
package org.geysermc.geyser.entity.vehicle;
import it.unimi.dsi.fastutil.objects.ObjectDoublePair;
import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.TrigMath;
import org.cloudburstmc.math.vector.Vector2f;
@@ -64,11 +66,15 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
private static final float MIN_VELOCITY = 0.003f;
protected final T vehicle;
@Getter
protected final BoundingBox boundingBox;
protected float stepHeight;
@Getter @Setter
protected float moveSpeed;
protected double gravity;
@Getter @Setter
protected double waterMovementEfficiency;
protected int effectLevitation;
protected boolean effectSlowFalling;
protected boolean effectWeaving;
@@ -78,6 +84,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
this.stepHeight = stepHeight;
this.moveSpeed = (float) AttributeType.Builtin.MOVEMENT_SPEED.getDef();
this.gravity = AttributeType.Builtin.GRAVITY.getDef();
this.waterMovementEfficiency = AttributeType.Builtin.WATER_MOVEMENT_EFFICIENCY.getDef();
double width = vehicle.getBoundingBoxWidth();
double height = vehicle.getBoundingBoxHeight();
@@ -117,10 +124,6 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
boundingBox.translate(vec);
}
public BoundingBox getBoundingBox() {
return this.boundingBox;
}
public void setEffect(Effect effect, int effectAmplifier) {
switch (effect) {
case LEVITATION -> effectLevitation = effectAmplifier + 1;
@@ -137,14 +140,6 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
}
}
public void setMoveSpeed(float moveSpeed) {
this.moveSpeed = moveSpeed;
}
public float getMoveSpeed() {
return moveSpeed;
}
public void setStepHeight(float stepHeight) {
this.stepHeight = MathUtils.clamp(stepHeight, 1.0f, 10.0f);
}
@@ -208,6 +203,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
BlockPositionIterator iter = BlockPositionIterator.fromMinMax(min.getFloorX(), min.getFloorY(), min.getFloorZ(), max.getFloorX(), max.getFloorY(), max.getFloorZ());
// Mojmap Entity#updateInWaterStateAndDoFluidPushing
double waterHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.WATER, 0.014, min.getY());
double lavaHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.LAVA, vehicle.getSession().getDimensionType().ultrawarm() ? 0.007 : 0.007 / 3, min.getY());
@@ -373,6 +369,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
return BlockUtils.getCollision(adjacentBlockId) instanceof SolidCollision;
}
// Mojmap: LivingEntity#travelInFluid
protected void waterMovement(VehicleContext ctx) {
double gravity = getGravity();
float drag = vehicle.getFlag(EntityFlag.SPRINTING) ? 0.9f : 0.8f; // 0.8f: getBaseMovementSpeedMultiplier
@@ -380,6 +377,21 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
boolean falling = vehicle.getMotion().getY() <= 0;
// NOT IMPLEMENTED: depth strider and dolphins grace
// float g = 0.02f;
// float waterMovementEfficiencyMultiplier = (float) waterMovementEfficiency;
// if (!vehicle.isOnGround()) {
// // TODO test
// waterMovementEfficiencyMultiplier *= 0.5f;
// }
//
// if (waterMovementEfficiencyMultiplier > 0.0F) {
// drag += (0.54600006F - drag) * waterMovementEfficiencyMultiplier;
// g += (this.getSpeed() - g) * waterMovementEfficiencyMultiplier;
// }
// if (this.hasEffect(MobEffects.DOLPHINS_GRACE)) {
// drag = 0.96F;
// }
boolean horizontalCollision = travel(ctx, 0.02f);
@@ -570,6 +582,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
*
* @return true if there was a horizontal collision
*/
// Mojmap: LivingEntity#moveRelative
protected boolean travel(VehicleContext ctx, float speed) {
Vector3f motion = vehicle.getMotion();