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

Clamp user input

Dieser Commit ist enthalten in:
AJ Ferguson 2024-05-23 05:25:29 -04:00
Ursprung 32d587a65a
Commit 818bef0bdf
4 geänderte Dateien mit 22 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -28,7 +28,6 @@ package org.geysermc.geyser.entity.type.player;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import lombok.Setter;
import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector2f;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.AttributeData;
@ -39,6 +38,7 @@ import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.AttributeUtils; import org.geysermc.geyser.util.AttributeUtils;
import org.geysermc.geyser.util.DimensionUtils; import org.geysermc.geyser.util.DimensionUtils;
import org.geysermc.geyser.util.MathUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.Attribute; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.Attribute;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
@ -70,13 +70,11 @@ public class SessionPlayerEntity extends PlayerEntity {
* Used when emulating client-side vehicles * Used when emulating client-side vehicles
*/ */
@Getter @Getter
@Setter
private Vector2f vehicleInput = Vector2f.ZERO; private Vector2f vehicleInput = Vector2f.ZERO;
/** /**
* Used when emulating client-side vehicles * Used when emulating client-side vehicles
*/ */
@Getter @Getter
@Setter
private int vehicleJumpStrength; private int vehicleJumpStrength;
public SessionPlayerEntity(GeyserSession session) { public SessionPlayerEntity(GeyserSession session) {
@ -280,4 +278,15 @@ public class SessionPlayerEntity extends PlayerEntity {
public void resetAir() { public void resetAir() {
this.setAirSupply(getMaxAir()); this.setAirSupply(getMaxAir());
} }
public void setVehicleInput(Vector2f vehicleInput) {
this.vehicleInput = Vector2f.from(
MathUtils.clamp(vehicleInput.getX(), -1.0f, 1.0f),
MathUtils.clamp(vehicleInput.getY(), -1.0f, 1.0f)
);
}
public void setVehicleJumpStrength(int vehicleJumpStrength) {
this.vehicleJumpStrength = MathUtils.constrain(vehicleJumpStrength, 0, 100);
}
} }

Datei anzeigen

@ -75,6 +75,7 @@ public class CamelVehicleComponent extends VehicleComponent<CamelEntity> {
public void onDismount() { public void onDismount() {
vehicle.setFlag(EntityFlag.HAS_DASH_COOLDOWN, false); vehicle.setFlag(EntityFlag.HAS_DASH_COOLDOWN, false);
vehicle.updateBedrockMetadata(); vehicle.updateBedrockMetadata();
super.onDismount();
} }
@Override @Override

Datei anzeigen

@ -143,6 +143,11 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
this.stepHeight = MathUtils.clamp(stepHeight, 1.0f, 10.0f); this.stepHeight = MathUtils.clamp(stepHeight, 1.0f, 10.0f);
} }
public void onMount() {
vehicle.getSession().getPlayerEntity().setVehicleInput(Vector2f.ZERO);
vehicle.getSession().getPlayerEntity().setVehicleJumpStrength(0);
}
public void onDismount() { public void onDismount() {
// //
} }

Datei anzeigen

@ -56,6 +56,10 @@ public class JavaSetPassengersTranslator extends PacketTranslator<ClientboundSet
session.getPlayerEntity().setVehicle(entity); session.getPlayerEntity().setVehicle(entity);
// We need to confirm teleports before entering a vehicle, or else we will likely exit right out // We need to confirm teleports before entering a vehicle, or else we will likely exit right out
session.confirmTeleport(passenger.getPosition().sub(0, EntityDefinitions.PLAYER.offset(), 0).toDouble()); session.confirmTeleport(passenger.getPosition().sub(0, EntityDefinitions.PLAYER.offset(), 0).toDouble());
if (entity instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().onMount();
}
} }
if (passenger == null) { if (passenger == null) {
// Can occur if the passenger is outside the client's tracking range // Can occur if the passenger is outside the client's tracking range