Coder Social home page Coder Social logo

prismarine-physics's Introduction

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,
      yaw: 0
    },
    jumpTicks: 0,
    jumpQueued: false
  }
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 ?
  • 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

Read only properties:

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

prismarine-physics's People

Contributors

karang avatar idanho avatar rom1504 avatar thedudefromci avatar suficio avatar dependabot-preview[bot] avatar embeddedt avatar mat-1 avatar zubearc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.