Skip to content

Commit

Permalink
Add support for generic.movement_efficiency attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Aug 14, 2024
1 parent 5019dfb commit bef913d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ protected void initAttributes(GrimPlayer player) {
return value;
})
.requiredVersion(player, ClientVersion.V_1_21));
trackAttribute(ValuedAttribute.ranged(Attributes.GENERIC_MOVEMENT_EFFICIENCY, 0, 0, 1)
.requiredVersion(player, ClientVersion.V_1_21));
trackAttribute(ValuedAttribute.ranged(Attributes.PLAYER_SNEAKING_SPEED, 0.3, 0, 1)
.withGetRewriter(value -> {
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_19)) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/ac/grim/grimac/utils/nmsutil/BlockProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ public static float getBlockSpeedFactor(GrimPlayer player, MainSupportingBlockDa

WrappedBlockState inBlock = player.compensatedWorld.getWrappedBlockStateAt(playerPos.getX(), playerPos.getY(), playerPos.getZ());
float inBlockSpeedFactor = getBlockSpeedFactor(player, inBlock.getType());
if (inBlockSpeedFactor != 1.0f || inBlock.getType() == StateTypes.WATER || inBlock.getType() == StateTypes.BUBBLE_COLUMN) return inBlockSpeedFactor;
if (inBlockSpeedFactor != 1.0f || inBlock.getType() == StateTypes.WATER || inBlock.getType() == StateTypes.BUBBLE_COLUMN) {
return getModernVelocityMultiplier(player, inBlockSpeedFactor);
}

StateType underPlayer = getBlockPosBelowThatAffectsMyMovement(player, mainSupportingBlockData, playerPos);
return getBlockSpeedFactor(player, underPlayer);
return getModernVelocityMultiplier(player, getBlockSpeedFactor(player, underPlayer));
}

public static boolean onHoneyBlock(GrimPlayer player, MainSupportingBlockData mainSupportingBlockData, Vector3d playerPos) {
Expand Down Expand Up @@ -187,10 +189,18 @@ private static float getBlockSpeedFactor(GrimPlayer player, StateType type) {
if (type == StateTypes.SOUL_SAND) {
// Soul speed is a 1.16+ enchantment
// This new method for detecting soul speed was added in 1.16.2
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16_2) && player.getInventory().getBoots().getEnchantmentLevel(EnchantmentTypes.SOUL_SPEED, PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()) > 0)
// On 1.21, let attributes handle this
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_21)
&& player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16_2)
&& player.getInventory().getBoots().getEnchantmentLevel(EnchantmentTypes.SOUL_SPEED, PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()) > 0)
return 1.0f;
return 0.4f;
}
return 1.0f;
}

private static float getModernVelocityMultiplier(GrimPlayer player, float blockSpeedFactor) {
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_21)) return blockSpeedFactor;
return (float) GrimMath.lerp((float) player.compensatedEntities.getSelf().getAttributeValue(Attributes.GENERIC_MOVEMENT_EFFICIENCY), blockSpeedFactor, 1.0F);
}
}

0 comments on commit bef913d

Please sign in to comment.