LookAtMySuitBot/js/node_modules/prismarine-physics/examples/basic.js

60 lines
1.3 KiB
JavaScript

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 fakeWorld = {
getBlock: (pos) => {
const type = (pos.y < 60) ? mcData.blocksByName.stone.id : mcData.blocksByName.air.id
const b = new Block(type, 0, 0)
b.position = pos
return b
}
}
function fakePlayer (pos, baseVersion) {
return {
entity: {
position: pos,
velocity: new Vec3(0, 0, 0),
onGround: false,
isInWater: false,
isInLava: false,
isInWeb: false,
elytraFlying: false,
isCollidedHorizontally: false,
isCollidedVertically: false,
yaw: 0,
pitch: 0,
effects: []
},
inventory: {
slots: []
},
jumpTicks: 0,
jumpQueued: false,
fireworkRocketDuration: 0,
version: baseVersion
}
}
const physics = Physics(mcData, fakeWorld)
const controls = {
forward: false,
back: false,
left: false,
right: false,
jump: false,
sprint: false,
sneak: false
}
const player = fakePlayer(new Vec3(0, 80, 0), mcData.version.version)
const playerState = new PlayerState(player, controls)
while (!player.entity.onGround) {
physics.simulatePlayer(playerState, fakeWorld).apply(player)
}
console.log(player.entity.position)