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:
Ursprung
72309fbe94
Commit
4417331c51
@ -31,7 +31,6 @@ import org.cloudburstmc.math.vector.Vector2f;
|
|||||||
import org.cloudburstmc.math.vector.Vector3f;
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import org.geysermc.geyser.entity.EntityDefinition;
|
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.BoostableVehicleComponent;
|
||||||
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
||||||
import org.geysermc.geyser.entity.vehicle.VehicleComponent;
|
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;
|
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);
|
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) {
|
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());
|
vehicleComponent.startBoost(entityMetadata.getPrimitiveValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
vehicleComponent.tickVehicle(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VehicleComponent<?> getVehicleComponent() {
|
public VehicleComponent<?> getVehicleComponent() {
|
||||||
return vehicleComponent;
|
return vehicleComponent;
|
||||||
|
@ -32,7 +32,6 @@ import org.cloudburstmc.math.vector.Vector3f;
|
|||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import org.geysermc.geyser.entity.EntityDefinition;
|
import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
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.BoostableVehicleComponent;
|
||||||
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
||||||
import org.geysermc.geyser.entity.vehicle.VehicleComponent;
|
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;
|
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 final BoostableVehicleComponent<StriderEntity> vehicleComponent = new BoostableVehicleComponent<>(this);
|
||||||
private boolean isCold = false;
|
private boolean isCold = false;
|
||||||
@ -144,11 +143,6 @@ public class StriderEntity extends AnimalEntity implements Tickable, ClientVehic
|
|||||||
vehicleComponent.startBoost(entityMetadata.getPrimitiveValue());
|
vehicleComponent.startBoost(entityMetadata.getPrimitiveValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
vehicleComponent.tickVehicle(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull VehicleComponent<?> getVehicleComponent() {
|
public @NonNull VehicleComponent<?> getVehicleComponent() {
|
||||||
return vehicleComponent;
|
return vehicleComponent;
|
||||||
|
@ -36,7 +36,6 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType;
|
|||||||
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
|
||||||
import org.geysermc.geyser.entity.EntityDefinition;
|
import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
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.CamelVehicleComponent;
|
||||||
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
|
||||||
import org.geysermc.geyser.entity.vehicle.VehicleComponent;
|
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;
|
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;
|
public static final float SITTING_HEIGHT_DIFFERENCE = 1.43F;
|
||||||
|
|
||||||
private final CamelVehicleComponent vehicleComponent = new CamelVehicleComponent(this);
|
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) {
|
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);
|
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) {
|
public void setDashing(BooleanEntityMetadata entityMetadata) {
|
||||||
if (entityMetadata.getPrimitiveValue()) {
|
if (entityMetadata.getPrimitiveValue()) {
|
||||||
setFlag(EntityFlag.HAS_DASH_COOLDOWN, true);
|
setFlag(EntityFlag.HAS_DASH_COOLDOWN, true);
|
||||||
dashTicks = 55;
|
vehicleComponent.startDashCooldown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,15 +135,6 @@ public class CamelEntity extends AbstractHorseEntity implements Tickable, Client
|
|||||||
return attributeData;
|
return attributeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
vehicleComponent.tickVehicle(this);
|
|
||||||
if (dashTicks > 0 && --dashTicks == 0) {
|
|
||||||
setFlag(EntityFlag.HAS_DASH_COOLDOWN, false);
|
|
||||||
updateBedrockMetadata();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VehicleComponent<?> getVehicleComponent() {
|
public VehicleComponent<?> getVehicleComponent() {
|
||||||
return vehicleComponent;
|
return vehicleComponent;
|
||||||
@ -164,7 +153,7 @@ public class CamelEntity extends AbstractHorseEntity implements Tickable, Client
|
|||||||
@Override
|
@Override
|
||||||
public float getVehicleSpeed() {
|
public float getVehicleSpeed() {
|
||||||
float moveSpeed = vehicleComponent.getMoveSpeed();
|
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 + 0.1f;
|
||||||
}
|
}
|
||||||
return moveSpeed;
|
return moveSpeed;
|
||||||
|
@ -53,8 +53,8 @@ public class BoostableVehicleComponent<T extends LivingEntity & ClientVehicle> e
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickVehicle(T vehicle) {
|
public void tickVehicle() {
|
||||||
super.tickVehicle(vehicle);
|
super.tickVehicle();
|
||||||
if (isBoosting()) {
|
if (isBoosting()) {
|
||||||
boostTicks++;
|
boostTicks++;
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,14 @@
|
|||||||
package org.geysermc.geyser.entity.vehicle;
|
package org.geysermc.geyser.entity.vehicle;
|
||||||
|
|
||||||
import org.cloudburstmc.math.vector.Vector3f;
|
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.living.animal.horse.CamelEntity;
|
||||||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
|
||||||
|
|
||||||
public class CamelVehicleComponent extends VehicleComponent<CamelEntity> {
|
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 float horseJumpStrength = 0.42f; // This is the default for Camels. Not sent by vanilla Java server when spawned
|
||||||
|
private int dashTick;
|
||||||
private int jumpBoost;
|
private int jumpBoost;
|
||||||
|
|
||||||
public CamelVehicleComponent(CamelEntity vehicle) {
|
public CamelVehicleComponent(CamelEntity vehicle) {
|
||||||
@ -42,6 +44,22 @@ public class CamelVehicleComponent extends VehicleComponent<CamelEntity> {
|
|||||||
this.horseJumpStrength = horseJumpStrength;
|
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
|
@Override
|
||||||
public void setEffect(Effect effect, int effectAmplifier) {
|
public void setEffect(Effect effect, int effectAmplifier) {
|
||||||
if (effect == Effect.JUMP_BOOST) {
|
if (effect == Effect.JUMP_BOOST) {
|
||||||
|
@ -67,6 +67,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
|||||||
"minecraft:sweet_berry_bush", Vector3f.from(0.8f, 0.75f, 0.8f)
|
"minecraft:sweet_berry_bush", Vector3f.from(0.8f, 0.75f, 0.8f)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected final T vehicle;
|
||||||
protected final BoundingBox boundingBox;
|
protected final BoundingBox boundingBox;
|
||||||
|
|
||||||
protected float moveSpeed;
|
protected float moveSpeed;
|
||||||
@ -74,16 +75,18 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
|||||||
protected boolean slowFalling;
|
protected boolean slowFalling;
|
||||||
|
|
||||||
public VehicleComponent(T vehicle) {
|
public VehicleComponent(T vehicle) {
|
||||||
|
this.vehicle = vehicle;
|
||||||
|
|
||||||
double width = Double.parseDouble(Float.toString(vehicle.getBoundingBoxWidth()));
|
double width = Double.parseDouble(Float.toString(vehicle.getBoundingBoxWidth()));
|
||||||
double height = Double.parseDouble(Float.toString(vehicle.getBoundingBoxHeight()));
|
double height = Double.parseDouble(Float.toString(vehicle.getBoundingBoxHeight()));
|
||||||
boundingBox = new BoundingBox(
|
this.boundingBox = new BoundingBox(
|
||||||
vehicle.getPosition().getX(),
|
vehicle.getPosition().getX(),
|
||||||
vehicle.getPosition().getY() + height / 2,
|
vehicle.getPosition().getY() + height / 2,
|
||||||
vehicle.getPosition().getZ(),
|
vehicle.getPosition().getZ(),
|
||||||
width, height, width
|
width, height, width
|
||||||
);
|
);
|
||||||
|
|
||||||
moveSpeed = GeyserAttributeType.MOVEMENT_SPEED.getDefaultValue();
|
this.moveSpeed = GeyserAttributeType.MOVEMENT_SPEED.getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWidth(float width) {
|
public void setWidth(float width) {
|
||||||
@ -128,7 +131,7 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
|||||||
return moveSpeed;
|
return moveSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tickVehicle(T vehicle) {
|
public void tickVehicle() {
|
||||||
if (!vehicle.isClientControlled()) {
|
if (!vehicle.isClientControlled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ import org.geysermc.geyser.entity.type.Entity;
|
|||||||
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
||||||
import org.geysermc.geyser.entity.type.Tickable;
|
import org.geysermc.geyser.entity.type.Tickable;
|
||||||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
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.AbstractGeyserboundPacketHandler;
|
||||||
import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler;
|
import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler;
|
||||||
import org.geysermc.geyser.impl.camera.CameraDefinitions;
|
import org.geysermc.geyser.impl.camera.CameraDefinitions;
|
||||||
@ -545,6 +546,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||||||
*/
|
*/
|
||||||
private ScheduledFuture<?> tickThread = null;
|
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
|
* 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;
|
isInWorldBorderWarningArea = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entity vehicle = playerEntity.getVehicle();
|
||||||
|
if (vehicle instanceof ClientVehicle clientVehicle && vehicle.isValid()) {
|
||||||
|
clientVehicle.getVehicleComponent().tickVehicle();
|
||||||
|
}
|
||||||
|
|
||||||
for (Tickable entity : entityCache.getTickableEntities()) {
|
for (Tickable entity : entityCache.getTickableEntities()) {
|
||||||
entity.tick();
|
entity.tick();
|
||||||
@ -1233,6 +1243,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthenticationData(AuthData authData) {
|
public void setAuthenticationData(AuthData authData) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren