prismarine-physics
Provide the physics engine for minecraft entities
Last updated 3 years ago by rom1504 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install prismarine-physics 
SYNC missed versions from official npm registry.

prismarine-physics

NPM version Build Status Discord Gitter Irc

Try it on gitpod

Provide the physics engine for minecraft entities

Usage

const { Physics, PlayerState } = require('prismarine-physics')
const { Vec3 } = require('vec3')

const mcData = require('minecraft-data')('1.13.2')
const Block = require('prismarine-block')('1.13.2')

const physics = Physics(mcData, world)
const controls = {
  forward: false,
  back: false,
  left: false,
  right: false,
  jump: false,
  sprint: false,
  sneak: false
}
const player = {
    entity: {
      position: pos,
      velocity: new Vec3(0, 0, 0),
      onGround: false,
      isInWater: false,
      isInLava: false,
      isInWeb: false,
      isCollidedHorizontally: false,
      isCollidedVertically: false,
      elytraFlying: false,
      yaw: 0,
      pitch: 0
    },
    jumpTicks: 0,
    jumpQueued: false,
    fireworkRocketDuration: 0
  }
const playerState = new PlayerState(player, controls)

while (!player.entity.onGround) {
  // simulate 1 tick of player physic, then apply the result to the player
  physics.simulatePlayer(playerState, world).apply(player)
}

See examples/ for more.

API

Physics

simulatePlayer(playerState, world)

  • playerState : instance of the PlayerState class
  • world : interface with a function getBlock(position) returning the prismarine-block at the given position

PlayerState

A player state is an object containing the properties:

Read / Write properties:

  • pos : position (vec3) of the player entity
  • vel : velocity (vec3) of the player entity
  • onGround : (boolean) is the player touching ground ?
  • isInWater : (boolean) is the player in water ?
  • isInLava : (boolean) is the player in lava ?
  • isInWeb : (boolean) is the player in a web ?
  • isCollidedHorizontally : (boolean) is the player collided horizontally with a solid block ?
  • isCollidedVertically : (boolean) is the player collided vertically with a solid block ?
  • elytraFlying : (boolean) is the player elytra flying ?
  • jumpTicks : (integer) number of ticks before the player can auto-jump again
  • jumpQueued : (boolean) true if the jump control state was true between the last tick and the current one
  • fireworkRocketDuration : (number) how many ticks of firework boost are remaining ?

Read only properties:

  • yaw : (float) the yaw angle, in radians, of the player entity
  • pitch: (float) the pitch angle, in radians, of the player entity
  • control : (object) control states vector with properties:
    • forward
    • back
    • left
    • right
    • jump
    • sprint
    • sneak

Current Tags

  • 1.8.0                                ...           latest (a year ago)

22 Versions

  • 1.8.0                                ...           a year ago
  • 1.7.0                                ...           a year ago
  • 1.6.0                                ...           2 years ago
  • 1.5.2                                ...           2 years ago
  • 1.5.1                                ...           2 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.2                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (5)

© 2010 - cnpmjs.org x YWFE | Home | YWFE