PrismarineJS / prismarine-physics

Provide the physics engine for minecraft entities
MIT License
35 stars 39 forks source link

add movementSpeed attribute support #53

Closed U5B closed 2 years ago

U5B commented 2 years ago

attribute movementSpeed is used for sprinting and effect speed modification sprinting and effect speed modification is server-side

Source Code from DecomplierMC - 1.16.4

public float getSpeed() { // net.minecraft.world.entity.player.Player
  return (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED);
}
private float getFrictionInfluencedSpeed(float f) { // net.minecraft.world.entity.LivingEntity
  if (this.onGround) {
      return this.getSpeed() * (0.21600002f / (f * f * f));
  }
  return this.flyingSpeed;
}
U5B commented 2 years ago

Marked as draft since at higher speeds (255) the bot goes faster than vanilla. (13 vs 10) in moved too quickly.

U5B commented 2 years ago

Alright I found an issue with negative acceleration causing the bot's velocity to go negative, so I set acceleration to 0 if it is negative.

To test the bot's speed is accurate enough, I did console.log((vel.x + vel.z) * 20) after moveEntity on L401 and compared it to Vanilla's speed per second on the mod MiniHud. Unfortunately, I could not find a more accurate speed counter then one to the hundredth.

U5B commented 2 years ago

Code referenced for client-side sprinting:

public void setSprinting(boolean bl) {
    super.setSprinting(bl);
    AttributeInstance attributeInstance = this.getAttribute(Attributes.MOVEMENT_SPEED);
    if (attributeInstance.getModifier(SPEED_MODIFIER_SPRINTING_UUID) != null) {
        attributeInstance.removeModifier(SPEED_MODIFIER_SPRINTING);
    }
    if (bl) {
        attributeInstance.addTransientModifier(SPEED_MODIFIER_SPRINTING);
    }
}
U5B commented 2 years ago

https://cdn.discordapp.com/attachments/413438067471548427/919712091940732978/1.16.4_Forge_Velocity_Display.jar Forge mod going to be used to compare prismarine-physics numbers to vanilla's numbers with different speed modifiers.

U5B commented 2 years ago

Waiting for https://github.com/PrismarineJS/minecraft-data/pull/486

rom1504 commented 2 years ago

https://github.com/PrismarineJS/minecraft-data/pull/486 available

rom1504 commented 2 years ago

code looks super magical what can be done to make it clearer to the reader what's going on?

U5B commented 2 years ago

I looked at vanilla code and reproduced it here. I hope this commit makes it more readable.