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,
      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

prismarine-physics's People

Contributors

archengius avatar atxltheaxolotl avatar bendgk avatar dependabot-preview[bot] avatar dependabot[bot] avatar embeddedt avatar flonja avatar icetank avatar idanho avatar karang avatar kashalls avatar killbinvlog avatar lkwilson avatar mat-1 avatar olie304 avatar pondwader avatar rom1504 avatar rom1504bot avatar sinevector241 avatar suficio avatar thedudefromci avatar u5b avatar vakore avatar zubearc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

prismarine-physics's Issues

Soulsand not slowing down player

Soulsand is not slowing down the bot when using mineflayer.
I tested this on 1.16 with pathfinder and it did not slow down the bot at all.
When testing I also noticed a anticheat warning about flying. This might be a different Issue but it seams as if the bot does not sink into the soulsand block as a normal player would do.

Bot can travel through worldborder

The bot does not collide with the worldborder, and instead can move through it
Not a big issue, just something I noticed after experimentation

No.collision.worldborder.mp4

Depth Strider Enchantment not working

PlayerState in index.js checks in line 598:
const boots = bot.inventory.items()[7]
but items() returns all items in the inventory not items in the armor slot.

I suggest changing the line to:
const boots = bot.inventory.slots[8]

Exception thrown while picking up exp points

I get the following exception that crashes mineflayer. So, what's happened: bot killed a creeper and got exp points, after that the bot crashed and every time it joins the server it crashes again

bot/node_modules/prismarine-physics/index.js:599
    this.depthStrider = boots && boots.nbt.value.Enchantments && boots.nbt.value.Enchantments.some(x => x.id === mcData.enchantmentsByName.depth_strider.id)
                                           ^

TypeError: Cannot read property 'value' of null
    at new PlayerState (bot/node_modules/prismarine-physics/index.js:599:44)
    at Timeout.doPhysics [as _onTimeout] (bot/node_modules/mineflayer/lib/plugins/physics.js:61:32)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

Fix walking and eating

when you are walking while eating, you move slower, similar to holding a shield/crouching

Bedrock - Falling through partial blocks.

I'm attempting to get physics to work somewhat reliably on bedrock. There's a quirk I can seem to figure out.

When standing on a partial block, eg farmland, mud, etc, and the block gets converted into a solid block, eg. dirt or clay, the bot falls thought the block.

What is the the difference between how BBs are handled Java and Bedrock?

I have added a temporary hack in moveEntity() to prevent this from happening:

...

if (dy != 0 && entity.onGround) {
for (const blockBB of surroundingBBs) {
  dy = blockBB.computeOffsetY(playerBB, dy)
}

if (dy != 0 && entity.onGround) {

  const block = world.getBlock(pos)

  for (const shape of block.shapes) {

    const BB = new AABB(shape[0], shape[1], shape[2], shape[3], shape[4], shape[5])
    BB.offset(block.position.x, block.position.y, block.position.z)

    console.log(JSON.stringify(shape), playerBB.intersects(BB))

    if (playerBB.intersects(BB)) {

      dy = Math.abs(block.position.y - pos.y)
      break
    }
  }
}

`

onGround is false when running into fences

When the bot has this control state set to forward and is colliding with fences the onGround variable is not always true. This does not happen when colliding with solid blocks.
Tested on version 1.12.2

1.18 Physics Issues

1.18 made changes to physics that cause the bot to get stuck due to the server's anticheat disallowing movements and rubberbanding the player. I made a PR on pathfinder because I assumed it was an issue with that library, but it turns out it works fine on lower versions and is an issue with 1.18 physics.

An easy way to observe this is to get pathfinder to slide across blocks during diagonal movements like so. In the current implementation, it will get stuck forever. It can also happen when jumping up blocks.

Bunch of questions - is this repo abandoned ?

Seems to be outdated

  1. No typescript support, it it planned ?

  2. Is this repo abandoned ? latest commits date 4 months ago

  3. Is it vanilla ? is this physics same as vanilla ?

  4. For which version of mineflayer it intended ? tried it on lates - got bunch of errors, for exampel pos used instead of position, vel instead of velocity and so on

boots.nbt.value.Enchantments.some is not a function

../node_modules/prismarine-physics/index.js:599
    this.depthStrider = boots && boots.nbt.value.Enchantments && boots.nbt.value.Enchantments.some(x => x.id === mcData.enchantmentsByName.depth_strider.id)
                                                                                              ^

TypeError: boots.nbt.value.Enchantments.some is not a function
    at new PlayerState (../node_modules/prismarine-physics/index.js:599:95)
    at Timeout.doPhysics [as _onTimeout] (../node_modules/mineflayer/lib/plugins/physics.js:61:32)
    at listOnTimeout (internal/timers.js:551:17)

    at processTimers (internal/timers.js:494:7)

I suspect this has to do with 1.16

Proposal to further fine tune bot physics

So far mineflayer has worked beautifully on every server I have tried it on. Except for my favorite server, 2b2t.org. I have found that on 2b2t, my mineflayer bot gets rubber banded extremely hard, and can't get very far. It happens not just with mineflayer-pathfinder but also just with regular control states.

I noticed it had something to do with the bounding box of the player, so I tried to increase the bot.physics.playerHalfWidth, but this then caused the bot to rubber-band because he would be able to walk farther off the edge of a block without falling off. It seems that this server uses an EXTREMELY strict anti-cheat that is somehow detecting the slight discrepancies in the bot's physics. Furthermore, I noticed the bot getting rubber-banding when falling, seeming to fall and then teleport back over and over because of some slight differences in airdrag, velocity, what have you.

I am not certain what anti-cheat the server uses, I believe it may be AAC, but if I can find out exactly what it is I would be willing to purchase the anti-cheat and put up a test server for us to fine tune the bot's physics on. The more accurate we can get this to an actual Minecraft client the better.

So, what can we do other than that to improve this? Where would be a good place for me to look? If you need a video of what I am talking about I would be happy to provide it and once again- I only see this on 2b2t. No other server that I have found has such strict anti-cheat. The server itself often gives false positives for my normal client however with the bot it is virtually unusable.

Thanks for listening and all your hard work.

Add a Example with a working bot

Please add a example how you would use this with mineflyer, the example given in the README dosent really help new people that don't know much about coding or other.

Add elytra flight?

It would be nice to simulate elytra flight(and add control state like elytra-flying?)

Feature lists is not updated

"name": "climbUsingJump",
"description": "Entity can climb ladders and vines by pressing jump",
"versions": ["1.14", "1.15", "1.17", "1.18"]

For example, this list should contain every version after 1.14. I think we should add a better versioning syntax like >= 1.14.

enchantments.find is undefined

Version:
"mineflayer": "^2.28.1"
"prismarine-physics": "^1.0.4", <- package-lock.json

Error:

D:\Projects\test-bot\node_modules\prismarine-physics\index.js:602
const depthEnchant = enchantments.find(x => x.id === mcData.enchantmentsByName.depth_strider.id || x.id === ('minecraft:' + mcData.enchantmentsByName.depth_strider.name))
                                        ^

TypeError: Cannot read property 'find' of undefined
    at new PlayerState (D:\Projects\test-bot\node_modules\prismarine-physics\index.js:602:41)
    at Timeout.doPhysics [as _onTimeout] (D:\Projects\test-bot\node_modules\mineflayer\lib\plugins\physics.js:61:32)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

Fix jumping in water

When holding jump in water, it doesnt give the same result as a player:

Player:

68.13436523348093 <= jump=true
68.23519531160593
68.42513671785593
68.67269531160593
68.95711913973093
69.09969726473093
68.92635742098093
68.48934570223093
68.24789062410593
68.21273437410593
68.32650390535593
68.52108398348093
68.77132812410593
69.01766601473093
68.69515624910593
68.55428710848093
68.58993163973093
68.73885742098093
68.96029296785593
69.04940429598093
68.84237304598093
68.54989257723093
68.49642578035593
68.53548828035593
68.50374999910593
68.46859374910593
68.42806640535593
68.38412109285593
68.33797851473093
68.29037109285593
68.24203124910593
68.19295898348093
68.14364257723093
68.09408203035593
68.04427734285593
68                               <= jump=false

Bot:

68 68                                 <= jump=true
68 68.035
68 68.098
68 68.1834
68 68.28672
68 68.404376
68 68.5335008
68 68.67180064
68 68.777440512
68 68.80256758656
68 68.7487921196288
68 68.61769216203622
68 68.41081420359549
68 68.16967380432358
68 68.01176148490605
68 68
68 68.035
68 68.098
68 68.1834
68 68.28672
68 68.404376
68 68.5335008
68 68.67180064
68 68.777440512
68 68.80256758656
68 68.7487921196288
68 68.61769216203622
68 68.41081420359549
68 68.16967380432358
68 68.01176148490605
68 68                                 <= jump=false

Improve playerstate situation

  1. Define cleanly what player state object should contain (in the readme)
  2. Add a function that check that the object fit this spec, call it in the simulate function (with an option not to call it for case where it could affect speed like pathfinder)
  3. Move translation from mineflayer to prismarine-physics in mineflayer, to avoid having mineflayer specific code here

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.