npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mineflayer-physics

v0.0.9

Published

<div align="center"> <h1>Mineflayer Physics</h1> <img src="https://img.shields.io/npm/v/mineflayer-physics?style=flat-square"> <img src="https://img.shields.io/github/license/firejoust/mineflayer-physics?style=flat-square"> <img src="https://img.s

Downloads

8

Readme

Features

Overview

  • Get a player's state in the next tick (position, velocity, etc)
  • Predict a player's control states based on their current/last state
  • Simulate a player's trajectory over a period of time (ticks)

Note:

This plugin will inject a new property named lastState into all players

API

Types

class PrismarineEntity; // https://github.com/PrismarineJS/prismarine-entity
class Vec3;             // https://github.com/PrismarineJS/node-vec3
/*
  https://github.com/PrismarineJS/mineflayer/blob/2c7103062535c12746c312371e647a7b141547bd/index.d.ts#L526-L534
*/

interface ControlStateStatus {
  forward: boolean
  back: boolean
  left: boolean
  right: boolean
  jump: boolean
  sprint: boolean
  sneak: boolean
}

interface PlayerState {
  pos: Vec3,
  vel: Vec3,
  onGround: boolean,
  isInWater: boolean,
  isInLava: boolean,
  isInWeb: boolean?,
  isCollidedHorizontally: boolean,
  isCollidedVertically: boolean,
  jumpTicks: number,
  jumpQueued: boolean,
  attributes: Object,
  yaw: number,
  control: ControlStateStatus,
  jumpBoost: number,
  speed: number,
  slowness: number,
  dolphinsGrace: number,
  slowFalling: number,
  levitation: number,
  depthStrider: number
}

Loading the plugin

const mineflayer = require("mineflayer")
const physics = require("mineflayer-physics")

const bot = mineflayer.createBot( ... )

...

bot.loadPlugin(physics.plugin)

Methods

/*
  Get the player's state in the next tick
  
  Arguments:
  - entity (PrismarineEntity): the player's entity
  - controlState (ControlStateStatus): the player's active control states
  
  Returns: PlayerState
*/
bot.physics.getNextState(entity, controlState)

/*
  Predict another player's control states based on their velocity
  
  Note that:
  - the "sprint" state has not been implemented
  - velocity applied by the server and connection latency can cause inaccuracy
  
  Arguments:
  - entity (PrismarineEntity): the player's entity
  
  Returns: ControlStateStatus
*/
bot.physics.getControls(entity)

Player Simulation

/*
  Simulate a player's motion over a period of ticks.
  
  Arguments:
  - entity (PrismarineEntity) the player's entity
  
  Setters:
  - velocity: - initial velocity in the x, y, z direction
  - controls: - the control states enabled in the simulation
  - yaw:      - the yaw angle used during the simulation
  - ticks:    - how long the simulation will execute for
  - until:    - the callback function; simulation will continue until this returns true
*/

const Simulation = new bot.physics.Simulation(entity)
  .velocity(x, y, z)
  .controls(controls)
  .yaw(yaw)
  .ticks(ticks) 
  .until(state => true)

Running the Simulation

/*
  Executes the simulation and returns the callback status
*/
const status: boolean = Simulation.execute()

/*
  Executes the simulation and returns the player's position in each tick
*/
const trajectory: Vec3[] = Simulation.trajectory()