|
1 | 1 | const { Vec3 } = require('vec3') |
2 | 2 | const conv = require('../conversions') |
3 | | -const NAMED_ENTITY_HEIGHT = 1.62 |
4 | | -const NAMED_ENTITY_WIDTH = 0.6 |
5 | | -const CROUCH_HEIGHT = NAMED_ENTITY_HEIGHT - 0.08 |
| 3 | +// These values are only accurate for versions 1.14 and above (crouch hitbox changes) |
| 4 | +// Todo: hitbox sizes for sleeping, swimming/crawling, and flying with elytra |
| 5 | +const PLAYER_HEIGHT = 1.8 |
| 6 | +const CROUCH_HEIGHT = 1.5 |
| 7 | +const PLAYER_WIDTH = 0.6 |
| 8 | +const PLAYER_EYEHEIGHT = 1.62 |
| 9 | +const CROUCH_EYEHEIGHT = 1.27 |
6 | 10 |
|
7 | 11 | module.exports = inject |
8 | 12 |
|
@@ -102,6 +106,9 @@ function inject (bot) { |
102 | 106 | bot.entity.username = bot._client.username |
103 | 107 | bot.entity.type = 'player' |
104 | 108 | bot.entity.name = 'player' |
| 109 | + bot.entity.height = PLAYER_HEIGHT |
| 110 | + bot.entity.width = PLAYER_WIDTH |
| 111 | + bot.entity.eyeHeight = PLAYER_EYEHEIGHT |
105 | 112 | }) |
106 | 113 |
|
107 | 114 | bot._client.on('entity_equipment', (packet) => { |
@@ -130,11 +137,13 @@ function inject (bot) { |
130 | 137 | }) |
131 | 138 |
|
132 | 139 | bot.on('entityCrouch', (entity) => { |
| 140 | + entity.eyeHeight = CROUCH_EYEHEIGHT |
133 | 141 | entity.height = CROUCH_HEIGHT |
134 | 142 | }) |
135 | 143 |
|
136 | 144 | bot.on('entityUncrouch', (entity) => { |
137 | | - entity.height = NAMED_ENTITY_HEIGHT |
| 145 | + entity.eyeHeight = PLAYER_EYEHEIGHT |
| 146 | + entity.height = PLAYER_HEIGHT |
138 | 147 | }) |
139 | 148 |
|
140 | 149 | bot._client.on('collect', (packet) => { |
@@ -184,8 +193,9 @@ function inject (bot) { |
184 | 193 | entity.username = bot.uuidToUsername[uuid] |
185 | 194 | entity.uuid = uuid |
186 | 195 | updateEntityPos(entity, pos) |
187 | | - entity.height = NAMED_ENTITY_HEIGHT |
188 | | - entity.width = NAMED_ENTITY_WIDTH |
| 196 | + entity.eyeHeight = PLAYER_EYEHEIGHT |
| 197 | + entity.height = PLAYER_HEIGHT |
| 198 | + entity.width = PLAYER_WIDTH |
189 | 199 | if (bot.players[entity.username] !== undefined && !bot.players[entity.username].entity) { |
190 | 200 | bot.players[entity.username].entity = entity |
191 | 201 | } |
|
0 commit comments