Rename the walkingSpeed ability to fieldViewModifier, the movement speed attribute should be used instead for speed

This commit is contained in:
themode 2020-12-15 13:41:42 +01:00
parent 892c1d5806
commit 7bcca8ff9f
3 changed files with 11 additions and 23 deletions

View File

@ -515,10 +515,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
property.instance = instances[i]; property.instance = instances[i];
property.attribute = instances[i].getAttribute(); property.attribute = instances[i].getAttribute();
if (getEntityType() == EntityType.PLAYER && instances[i].getAttribute().equals(Attributes.MOVEMENT_SPEED)) property.value = value;
property.value = ((Player) this).getWalkingSpeed();
else
property.value = value;
properties[i] = property; properties[i] = property;
} }

View File

@ -3,7 +3,6 @@ package net.minestom.server.entity;
import com.google.common.collect.Queues; import com.google.common.collect.Queues;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.advancements.AdvancementTab; import net.minestom.server.advancements.AdvancementTab;
import net.minestom.server.attribute.Attribute;
import net.minestom.server.attribute.AttributeInstance; import net.minestom.server.attribute.AttributeInstance;
import net.minestom.server.attribute.Attributes; import net.minestom.server.attribute.Attributes;
import net.minestom.server.bossbar.BossBar; import net.minestom.server.bossbar.BossBar;
@ -183,7 +182,7 @@ public class Player extends LivingEntity implements CommandSender {
private boolean allowFlying; private boolean allowFlying;
private boolean instantBreak; private boolean instantBreak;
private float flyingSpeed = 0.05f; private float flyingSpeed = 0.05f;
private float walkingSpeed = 0.1f; private float fieldViewModifier = 0.1f;
// Statistics // Statistics
private final Map<PlayerStatistic, Integer> statisticValueMap = new Hashtable<>(); private final Map<PlayerStatistic, Integer> statisticValueMap = new Hashtable<>();
@ -216,6 +215,7 @@ public class Player extends LivingEntity implements CommandSender {
this.dimensionType = DimensionType.OVERWORLD; this.dimensionType = DimensionType.OVERWORLD;
this.levelFlat = true; this.levelFlat = true;
refreshPosition(0, 0, 0); refreshPosition(0, 0, 0);
getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.1f);
// FakePlayer init its connection there // FakePlayer init its connection there
playerConnectionInit(); playerConnectionInit();
@ -323,14 +323,6 @@ public class Player extends LivingEntity implements CommandSender {
this.playerConnection.setPlayer(this); this.playerConnection.setPlayer(this);
} }
@Override
public float getAttributeValue(@NotNull Attribute attribute) {
if (attribute == Attributes.MOVEMENT_SPEED) {
return walkingSpeed;
}
return super.getAttributeValue(attribute);
}
@Override @Override
public void update(long time) { public void update(long time) {
// Network tick // Network tick
@ -2139,12 +2131,12 @@ public class Player extends LivingEntity implements CommandSender {
refreshAbilities(); refreshAbilities();
} }
public float getWalkingSpeed() { public float getFieldViewModifier() {
return walkingSpeed; return fieldViewModifier;
} }
public void setWalkingSpeed(float walkingSpeed) { public void setFieldViewModifier(float fieldViewModifier) {
this.walkingSpeed = walkingSpeed; this.fieldViewModifier = fieldViewModifier;
refreshAbilities(); refreshAbilities();
} }
@ -2170,8 +2162,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
/** /**
* Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields * Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields.
* (walkingSpeed set to 0.1).
*/ */
protected void refreshAbilities() { protected void refreshAbilities() {
PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket(); PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket();
@ -2180,7 +2171,7 @@ public class Player extends LivingEntity implements CommandSender {
playerAbilitiesPacket.allowFlying = allowFlying; playerAbilitiesPacket.allowFlying = allowFlying;
playerAbilitiesPacket.instantBreak = instantBreak; playerAbilitiesPacket.instantBreak = instantBreak;
playerAbilitiesPacket.flyingSpeed = flyingSpeed; playerAbilitiesPacket.flyingSpeed = flyingSpeed;
playerAbilitiesPacket.walkingSpeed = 0.1f; playerAbilitiesPacket.fieldViewModifier = fieldViewModifier;
playerConnection.sendPacket(playerAbilitiesPacket); playerConnection.sendPacket(playerAbilitiesPacket);
} }

View File

@ -15,7 +15,7 @@ public class PlayerAbilitiesPacket implements ServerPacket {
// Options // Options
public float flyingSpeed; public float flyingSpeed;
public float walkingSpeed; public float fieldViewModifier;
@Override @Override
public void write(@NotNull BinaryWriter writer) { public void write(@NotNull BinaryWriter writer) {
@ -31,7 +31,7 @@ public class PlayerAbilitiesPacket implements ServerPacket {
writer.writeByte(flags); writer.writeByte(flags);
writer.writeFloat(flyingSpeed); writer.writeFloat(flyingSpeed);
writer.writeFloat(walkingSpeed); writer.writeFloat(fieldViewModifier);
} }
@Override @Override