diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java index f42ba15db7..0997458ec2 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntity.java @@ -90,9 +90,15 @@ public Optional getAttribute(Attribute attribute) { return Optional.ofNullable(attributeMap.get(attribute)); } + public void setAttribute(Attribute attribute, double value) { + ValuedAttribute property = getAttribute(attribute).orElse(null); + if (property == null) throw new IllegalArgumentException("Cannot set attribute " + attribute.getName() + " for entity " + getType().getName().toString() + "!"); + property.override(value); + } + public double getAttributeValue(Attribute attribute) { return getAttribute(attribute).map(ValuedAttribute::get) - .orElseThrow(() -> new IllegalArgumentException("No such attribute exists on entity " + getType().getName().toString() + "!")); + .orElseThrow(() -> new IllegalArgumentException("Cannot get attribute " + attribute.getName() + " for entity " + getType().getName().toString() + "!")); } public void resetAttributes() { diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityCamel.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityCamel.java index 8238ecb000..e5f4e2fd14 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityCamel.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityCamel.java @@ -11,8 +11,8 @@ public class PacketEntityCamel extends PacketEntityHorse { public PacketEntityCamel(GrimPlayer player, EntityType type, double x, double y, double z, float xRot) { super(player, type, x, y, z, xRot); - getAttribute(Attributes.GENERIC_JUMP_STRENGTH).get().override(0.42f); - getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().override(0.09f); - getAttribute(Attributes.GENERIC_STEP_HEIGHT).get().override(1.5f); + setAttribute(Attributes.GENERIC_JUMP_STRENGTH, 0.42f); + setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.09f); + setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.5f); } } diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityHorse.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityHorse.java index e5d04124e9..3cb4f689bc 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityHorse.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityHorse.java @@ -15,19 +15,19 @@ public class PacketEntityHorse extends PacketEntityTrackXRot { public PacketEntityHorse(GrimPlayer player, EntityType type, double x, double y, double z, float xRot) { super(player, type, x, y, z, xRot); - getAttribute(Attributes.GENERIC_STEP_HEIGHT).get().override(1.0f); + setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.0f); final boolean preAttribute = player.getClientVersion().isOlderThan(ClientVersion.V_1_20_5); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_JUMP_STRENGTH, 0.7, 0, preAttribute ? 2 : 32)); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.225f, 0, 1024)); if (EntityTypes.isTypeInstanceOf(type, EntityTypes.CHESTED_HORSE)) { - getAttribute(Attributes.GENERIC_JUMP_STRENGTH).get().override(0.5); - getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().override(0.175f); + setAttribute(Attributes.GENERIC_JUMP_STRENGTH, 0.5); + setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.175f); } if (type == EntityTypes.ZOMBIE_HORSE || type == EntityTypes.SKELETON_HORSE) { - getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().override(0.2f); + setAttribute(Attributes.GENERIC_MOVEMENT_SPEED, 0.2f); } } } diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityRideable.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityRideable.java index 177d28d857..86919fd6e1 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityRideable.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntityRideable.java @@ -13,7 +13,7 @@ public class PacketEntityRideable extends PacketEntity { public PacketEntityRideable(GrimPlayer player, EntityType type, double x, double y, double z) { super(player, type, x, y, z); - getAttribute(Attributes.GENERIC_STEP_HEIGHT).get().override(1.0f); + setAttribute(Attributes.GENERIC_STEP_HEIGHT, 1.0f); trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.1f, 0, 1024)); } } diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index d875ac4e6f..eee61d4ec9 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -44,7 +44,7 @@ public PacketEntitySelf(GrimPlayer player, PacketEntitySelf old) { protected void initAttributes(GrimPlayer player) { super.initAttributes(player); if (player.getClientVersion().isOlderThan(ClientVersion.V_1_8)) { - getAttribute(Attributes.GENERIC_STEP_HEIGHT).get().override(0.5f); + setAttribute(Attributes.GENERIC_STEP_HEIGHT, 0.5f); } final ValuedAttribute movementSpeed = ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_SPEED, 0.1f, 0, 1024);