diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java index f32e33151..f4813015d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java @@ -31,7 +31,6 @@ import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.vehicle.BoostableVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; @@ -47,7 +46,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import java.util.UUID; -public class PigEntity extends AnimalEntity implements Tickable, ClientVehicle { +public class PigEntity extends AnimalEntity implements ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this); public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { @@ -97,11 +96,6 @@ public class PigEntity extends AnimalEntity implements Tickable, ClientVehicle { vehicleComponent.startBoost(entityMetadata.getPrimitiveValue()); } - @Override - public void tick() { - vehicleComponent.tickVehicle(this); - } - @Override public VehicleComponent getVehicleComponent() { return vehicleComponent; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java index 207f686d1..3392c3f1a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java @@ -32,7 +32,6 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.vehicle.BoostableVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; @@ -49,7 +48,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import java.util.UUID; -public class StriderEntity extends AnimalEntity implements Tickable, ClientVehicle { +public class StriderEntity extends AnimalEntity implements ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this); private boolean isCold = false; @@ -144,11 +143,6 @@ public class StriderEntity extends AnimalEntity implements Tickable, ClientVehic vehicleComponent.startBoost(entityMetadata.getPrimitiveValue()); } - @Override - public void tick() { - vehicleComponent.tickVehicle(this); - } - @Override public @NonNull VehicleComponent getVehicleComponent() { return vehicleComponent; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index 5f1925ec6..b48569381 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -36,7 +36,6 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; -import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.vehicle.CamelVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; @@ -50,11 +49,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEn import java.util.UUID; -public class CamelEntity extends AbstractHorseEntity implements Tickable, ClientVehicle { +public class CamelEntity extends AbstractHorseEntity implements ClientVehicle { public static final float SITTING_HEIGHT_DIFFERENCE = 1.43F; private final CamelVehicleComponent vehicleComponent = new CamelVehicleComponent(this); - private int dashTicks; public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); @@ -124,7 +122,7 @@ public class CamelEntity extends AbstractHorseEntity implements Tickable, Client public void setDashing(BooleanEntityMetadata entityMetadata) { if (entityMetadata.getPrimitiveValue()) { setFlag(EntityFlag.HAS_DASH_COOLDOWN, true); - dashTicks = 55; + vehicleComponent.startDashCooldown(); } } @@ -137,15 +135,6 @@ public class CamelEntity extends AbstractHorseEntity implements Tickable, Client return attributeData; } - @Override - public void tick() { - vehicleComponent.tickVehicle(this); - if (dashTicks > 0 && --dashTicks == 0) { - setFlag(EntityFlag.HAS_DASH_COOLDOWN, false); - updateBedrockMetadata(); - } - } - @Override public VehicleComponent getVehicleComponent() { return vehicleComponent; @@ -164,7 +153,7 @@ public class CamelEntity extends AbstractHorseEntity implements Tickable, Client @Override public float getVehicleSpeed() { float moveSpeed = vehicleComponent.getMoveSpeed(); - if (dashTicks == 0 && session.getPlayerEntity().getFlag(EntityFlag.SPRINTING)) { + if (!getFlag(EntityFlag.HAS_DASH_COOLDOWN) && session.getPlayerEntity().getFlag(EntityFlag.SPRINTING)) { return moveSpeed + 0.1f; } return moveSpeed; diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoostableVehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoostableVehicleComponent.java index b218b97f3..5ed9b5537 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoostableVehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoostableVehicleComponent.java @@ -53,8 +53,8 @@ public class BoostableVehicleComponent e } @Override - public void tickVehicle(T vehicle) { - super.tickVehicle(vehicle); + public void tickVehicle() { + super.tickVehicle(); if (isBoosting()) { boostTicks++; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/CamelVehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/CamelVehicleComponent.java index a1686432b..c5b91fcc3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/CamelVehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/CamelVehicleComponent.java @@ -26,12 +26,14 @@ package org.geysermc.geyser.entity.vehicle; import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.type.living.animal.horse.CamelEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; public class CamelVehicleComponent extends VehicleComponent { private float horseJumpStrength = 0.42f; // This is the default for Camels. Not sent by vanilla Java server when spawned + private int dashTick; private int jumpBoost; public CamelVehicleComponent(CamelEntity vehicle) { @@ -42,6 +44,22 @@ public class CamelVehicleComponent extends VehicleComponent { this.horseJumpStrength = horseJumpStrength; } + public void startDashCooldown() { + this.dashTick = vehicle.getSession().getTicks() + 55; + } + + @Override + public void tickVehicle() { + if (vehicle.getFlag(EntityFlag.HAS_DASH_COOLDOWN)) { + if (vehicle.getSession().getTicks() > dashTick) { + vehicle.setFlag(EntityFlag.HAS_DASH_COOLDOWN, false); + vehicle.updateBedrockMetadata(); + } + } + + super.tickVehicle(); + } + @Override public void setEffect(Effect effect, int effectAmplifier) { if (effect == Effect.JUMP_BOOST) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 48317b8ca..26f998674 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -67,6 +67,7 @@ public class VehicleComponent { "minecraft:sweet_berry_bush", Vector3f.from(0.8f, 0.75f, 0.8f) ); + protected final T vehicle; protected final BoundingBox boundingBox; protected float moveSpeed; @@ -74,16 +75,18 @@ public class VehicleComponent { protected boolean slowFalling; public VehicleComponent(T vehicle) { + this.vehicle = vehicle; + double width = Double.parseDouble(Float.toString(vehicle.getBoundingBoxWidth())); double height = Double.parseDouble(Float.toString(vehicle.getBoundingBoxHeight())); - boundingBox = new BoundingBox( + this.boundingBox = new BoundingBox( vehicle.getPosition().getX(), vehicle.getPosition().getY() + height / 2, vehicle.getPosition().getZ(), width, height, width ); - moveSpeed = GeyserAttributeType.MOVEMENT_SPEED.getDefaultValue(); + this.moveSpeed = GeyserAttributeType.MOVEMENT_SPEED.getDefaultValue(); } public void setWidth(float width) { @@ -128,7 +131,7 @@ public class VehicleComponent { return moveSpeed; } - public void tickVehicle(T vehicle) { + public void tickVehicle() { if (!vehicle.isClientControlled()) { return; } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index d10a20b3d..1e3548058 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -117,6 +117,7 @@ import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; +import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.erosion.AbstractGeyserboundPacketHandler; import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler; import org.geysermc.geyser.impl.camera.CameraDefinitions; @@ -545,6 +546,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { */ private ScheduledFuture tickThread = null; + /** + * The number of ticks that have elapsed since the start of this session + */ + private int ticks; + /** * Used to return the player to their original rotation after using an item in BedrockInventoryTransactionTranslator */ @@ -1198,6 +1204,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { isInWorldBorderWarningArea = false; } + Entity vehicle = playerEntity.getVehicle(); + if (vehicle instanceof ClientVehicle clientVehicle && vehicle.isValid()) { + clientVehicle.getVehicleComponent().tickVehicle(); + } for (Tickable entity : entityCache.getTickableEntities()) { entity.tick(); @@ -1233,6 +1243,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } catch (Throwable throwable) { throwable.printStackTrace(); } + + ticks++; } public void setAuthenticationData(AuthData authData) {