3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Only tick active vehicle

Dieser Commit ist enthalten in:
AJ Ferguson 2024-05-16 02:57:13 -04:00
Ursprung 72309fbe94
Commit 4417331c51
7 geänderte Dateien mit 43 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -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<PigEntity> 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;

Datei anzeigen

@ -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<StriderEntity> 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;

Datei anzeigen

@ -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;

Datei anzeigen

@ -53,8 +53,8 @@ public class BoostableVehicleComponent<T extends LivingEntity & ClientVehicle> e
}
@Override
public void tickVehicle(T vehicle) {
super.tickVehicle(vehicle);
public void tickVehicle() {
super.tickVehicle();
if (isBoosting()) {
boostTicks++;
}

Datei anzeigen

@ -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<CamelEntity> {
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<CamelEntity> {
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) {

Datei anzeigen

@ -67,6 +67,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
"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<T extends LivingEntity & ClientVehicle> {
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<T extends LivingEntity & ClientVehicle> {
return moveSpeed;
}
public void tickVehicle(T vehicle) {
public void tickVehicle() {
if (!vehicle.isClientControlled()) {
return;
}

Datei anzeigen

@ -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) {