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:
Ursprung
32d587a65a
Commit
818bef0bdf
@ -28,7 +28,6 @@ package org.geysermc.geyser.entity.type.player;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import lombok.Setter;
|
||||
import org.cloudburstmc.math.vector.Vector2f;
|
||||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
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.util.AttributeUtils;
|
||||
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.AttributeType;
|
||||
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
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private Vector2f vehicleInput = Vector2f.ZERO;
|
||||
/**
|
||||
* Used when emulating client-side vehicles
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private int vehicleJumpStrength;
|
||||
|
||||
public SessionPlayerEntity(GeyserSession session) {
|
||||
@ -280,4 +278,15 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
public void resetAir() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ public class CamelVehicleComponent extends VehicleComponent<CamelEntity> {
|
||||
public void onDismount() {
|
||||
vehicle.setFlag(EntityFlag.HAS_DASH_COOLDOWN, false);
|
||||
vehicle.updateBedrockMetadata();
|
||||
super.onDismount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,6 +143,11 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
||||
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() {
|
||||
//
|
||||
}
|
||||
|
@ -56,6 +56,10 @@ public class JavaSetPassengersTranslator extends PacketTranslator<ClientboundSet
|
||||
session.getPlayerEntity().setVehicle(entity);
|
||||
// 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());
|
||||
|
||||
if (entity instanceof ClientVehicle clientVehicle) {
|
||||
clientVehicle.getVehicleComponent().onMount();
|
||||
}
|
||||
}
|
||||
if (passenger == null) {
|
||||
// Can occur if the passenger is outside the client's tracking range
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren