From 7bcca8ff9f6901d98c183661f9a430eccbec47cd Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 15 Dec 2020 13:41:42 +0100 Subject: [PATCH] Rename the walkingSpeed ability to fieldViewModifier, the movement speed attribute should be used instead for speed --- .../minestom/server/entity/LivingEntity.java | 5 +--- .../net/minestom/server/entity/Player.java | 25 ++++++------------- .../server/play/PlayerAbilitiesPacket.java | 4 +-- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index 4f3c7c4c0..aa3045f8c 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -515,10 +515,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { property.instance = instances[i]; property.attribute = instances[i].getAttribute(); - if (getEntityType() == EntityType.PLAYER && instances[i].getAttribute().equals(Attributes.MOVEMENT_SPEED)) - property.value = ((Player) this).getWalkingSpeed(); - else - property.value = value; + property.value = value; properties[i] = property; } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 15ef8999f..2d7a9fb72 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -3,7 +3,6 @@ package net.minestom.server.entity; import com.google.common.collect.Queues; import net.minestom.server.MinecraftServer; import net.minestom.server.advancements.AdvancementTab; -import net.minestom.server.attribute.Attribute; import net.minestom.server.attribute.AttributeInstance; import net.minestom.server.attribute.Attributes; import net.minestom.server.bossbar.BossBar; @@ -183,7 +182,7 @@ public class Player extends LivingEntity implements CommandSender { private boolean allowFlying; private boolean instantBreak; private float flyingSpeed = 0.05f; - private float walkingSpeed = 0.1f; + private float fieldViewModifier = 0.1f; // Statistics private final Map statisticValueMap = new Hashtable<>(); @@ -216,6 +215,7 @@ public class Player extends LivingEntity implements CommandSender { this.dimensionType = DimensionType.OVERWORLD; this.levelFlat = true; refreshPosition(0, 0, 0); + getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.1f); // FakePlayer init its connection there playerConnectionInit(); @@ -323,14 +323,6 @@ public class Player extends LivingEntity implements CommandSender { this.playerConnection.setPlayer(this); } - @Override - public float getAttributeValue(@NotNull Attribute attribute) { - if (attribute == Attributes.MOVEMENT_SPEED) { - return walkingSpeed; - } - return super.getAttributeValue(attribute); - } - @Override public void update(long time) { // Network tick @@ -2139,12 +2131,12 @@ public class Player extends LivingEntity implements CommandSender { refreshAbilities(); } - public float getWalkingSpeed() { - return walkingSpeed; + public float getFieldViewModifier() { + return fieldViewModifier; } - public void setWalkingSpeed(float walkingSpeed) { - this.walkingSpeed = walkingSpeed; + public void setFieldViewModifier(float fieldViewModifier) { + this.fieldViewModifier = fieldViewModifier; refreshAbilities(); } @@ -2170,8 +2162,7 @@ public class Player extends LivingEntity implements CommandSender { } /** - * Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields - * (walkingSpeed set to 0.1). + * Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields. */ protected void refreshAbilities() { PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket(); @@ -2180,7 +2171,7 @@ public class Player extends LivingEntity implements CommandSender { playerAbilitiesPacket.allowFlying = allowFlying; playerAbilitiesPacket.instantBreak = instantBreak; playerAbilitiesPacket.flyingSpeed = flyingSpeed; - playerAbilitiesPacket.walkingSpeed = 0.1f; + playerAbilitiesPacket.fieldViewModifier = fieldViewModifier; playerConnection.sendPacket(playerAbilitiesPacket); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java index 5aa879c74..e5c8f58a1 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java @@ -15,7 +15,7 @@ public class PlayerAbilitiesPacket implements ServerPacket { // Options public float flyingSpeed; - public float walkingSpeed; + public float fieldViewModifier; @Override public void write(@NotNull BinaryWriter writer) { @@ -31,7 +31,7 @@ public class PlayerAbilitiesPacket implements ServerPacket { writer.writeByte(flags); writer.writeFloat(flyingSpeed); - writer.writeFloat(walkingSpeed); + writer.writeFloat(fieldViewModifier); } @Override