minecraft-renderer 0.1.70 → 0.1.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/minecraft-renderer.js +1 -1
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +56 -56
- package/package.json +1 -1
- package/src/three/entities.ts +20 -123
package/package.json
CHANGED
package/src/three/entities.ts
CHANGED
|
@@ -271,46 +271,6 @@ export class Entities {
|
|
|
271
271
|
itemFrameMaps = {} as Record<number, Array<THREE.Mesh<THREE.PlaneGeometry, THREE.MeshLambertMaterial>>>
|
|
272
272
|
pendingModelOverrides = new Map<string, { parts: EntityModelOverridePart[] }>()
|
|
273
273
|
|
|
274
|
-
private motionCache = new Map<string, { pos: THREE.Vector3, speed: number }>()
|
|
275
|
-
private readonly MOVE_ON = 0.05
|
|
276
|
-
private readonly MOVE_OFF = 0.02
|
|
277
|
-
private readonly RUN_ON = 4.8
|
|
278
|
-
private readonly RUN_OFF = 4.2
|
|
279
|
-
|
|
280
|
-
private updateAutoWalkFlags(entityKey: string, entity: SceneEntity, dt: number) {
|
|
281
|
-
if (!entity.playerObject?.animation) return
|
|
282
|
-
const anim: any = entity.playerObject.animation
|
|
283
|
-
if (!('isMoving' in anim) || !('isRunning' in anim)) return
|
|
284
|
-
if (dt <= 0) return
|
|
285
|
-
|
|
286
|
-
const cached = this.motionCache.get(entityKey)
|
|
287
|
-
if (!cached) {
|
|
288
|
-
this.motionCache.set(entityKey, { pos: entity.position.clone(), speed: 0 })
|
|
289
|
-
anim.isMoving = false
|
|
290
|
-
anim.isRunning = false
|
|
291
|
-
return
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const dx = entity.position.x - cached.pos.x
|
|
295
|
-
const dz = entity.position.z - cached.pos.z
|
|
296
|
-
cached.pos.copy(entity.position)
|
|
297
|
-
|
|
298
|
-
const instSpeed = Math.hypot(dx, dz) / Math.max(dt, 1e-6)
|
|
299
|
-
|
|
300
|
-
cached.speed = cached.speed * 0.8 + instSpeed * 0.2
|
|
301
|
-
|
|
302
|
-
const movingNow = anim.isMoving
|
|
303
|
-
? cached.speed > this.MOVE_OFF
|
|
304
|
-
: cached.speed > this.MOVE_ON
|
|
305
|
-
|
|
306
|
-
const runningNow = anim.isRunning
|
|
307
|
-
? cached.speed > this.RUN_OFF
|
|
308
|
-
: cached.speed > this.RUN_ON
|
|
309
|
-
|
|
310
|
-
anim.isMoving = movingNow
|
|
311
|
-
anim.isRunning = movingNow && runningNow
|
|
312
|
-
}
|
|
313
|
-
|
|
314
274
|
get entitiesByName(): Record<string, SceneEntity[]> {
|
|
315
275
|
const byName: Record<string, SceneEntity[]> = {}
|
|
316
276
|
for (const entity of Object.values(this.entities)) {
|
|
@@ -383,8 +343,6 @@ export class Entities {
|
|
|
383
343
|
this.entities = {}
|
|
384
344
|
this.currentSkinUrls = {}
|
|
385
345
|
|
|
386
|
-
this.motionCache.clear()
|
|
387
|
-
|
|
388
346
|
// Clean up player entity
|
|
389
347
|
if (this.playerEntity) {
|
|
390
348
|
this.worldRenderer.sceneOrigin.removeAndUntrack(this.playerEntity)
|
|
@@ -447,15 +405,13 @@ export class Entities {
|
|
|
447
405
|
this.setRendering(renderEntitiesConfig)
|
|
448
406
|
}
|
|
449
407
|
|
|
450
|
-
const
|
|
451
|
-
const dt = Math.min(dtRaw, 1 / 30)
|
|
408
|
+
const dt = Math.min(this.clock.getDelta(), 1 / 30)
|
|
452
409
|
const botPos = this.worldRenderer.viewerChunkPosition
|
|
453
410
|
const VISIBLE_DISTANCE = 10 * 10
|
|
454
411
|
|
|
455
412
|
for (const [entityIdRaw, entity] of [...Object.entries(this.entities), ['player_entity', this.playerEntity] as [string, SceneEntity | null]]) {
|
|
456
413
|
if (!entity) continue
|
|
457
414
|
|
|
458
|
-
let entityKey = entityIdRaw
|
|
459
415
|
const isPlayerEntity = entityIdRaw === 'player_entity'
|
|
460
416
|
|
|
461
417
|
if (isPlayerEntity) {
|
|
@@ -470,14 +426,10 @@ export class Entities {
|
|
|
470
426
|
this.worldRenderer.cameraWorldPos.z
|
|
471
427
|
)
|
|
472
428
|
}
|
|
473
|
-
|
|
474
|
-
entityKey = String(this.playerEntity?.originalEntity.id ?? 'player_entity')
|
|
475
429
|
}
|
|
476
430
|
|
|
477
431
|
const { playerObject } = entity
|
|
478
432
|
|
|
479
|
-
this.updateAutoWalkFlags(entityKey, entity, dtRaw)
|
|
480
|
-
|
|
481
433
|
if (playerObject?.animation) {
|
|
482
434
|
playerObject.animation.update(playerObject, dt)
|
|
483
435
|
}
|
|
@@ -778,84 +730,31 @@ export class Entities {
|
|
|
778
730
|
}
|
|
779
731
|
}
|
|
780
732
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
// while standing still. Only dedupe the persistent state animations.
|
|
788
|
-
if (animation !== 'oneSwing') {
|
|
789
|
-
if (this.playerPerAnimation[key] === animation) return
|
|
790
|
-
this.playerPerAnimation[key] = animation
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
if (entityPlayerId === 'player_entity' && this.playerEntity?.playerObject) {
|
|
794
|
-
const { playerObject } = this.playerEntity
|
|
795
|
-
if (animation === 'oneSwing') {
|
|
796
|
-
if (playerObject.animation && (playerObject.animation as any).swingArm) {
|
|
797
|
-
(playerObject.animation as any).swingArm()
|
|
798
|
-
}
|
|
799
|
-
return
|
|
800
|
-
}
|
|
733
|
+
private applyMovementAnimation(
|
|
734
|
+
playerObject: PlayerObjectType,
|
|
735
|
+
animation: 'walking' | 'running' | 'oneSwing' | 'idle' | 'crouch' | 'crouchWalking',
|
|
736
|
+
): void {
|
|
737
|
+
const anim = playerObject.animation as WalkingGeneralSwing | undefined
|
|
738
|
+
if (!anim) return
|
|
801
739
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
const anim = playerObject.animation as any
|
|
805
|
-
if (anim) {
|
|
806
|
-
anim.isMoving = animation === 'walking' || animation === 'running' || animation === 'crouchWalking'
|
|
807
|
-
anim.isRunning = animation === 'running'
|
|
808
|
-
anim.isCrouched = animation === 'crouch' || animation === 'crouchWalking'
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
740
|
+
if (animation === 'oneSwing') {
|
|
741
|
+
anim.swingArm()
|
|
812
742
|
return
|
|
813
743
|
}
|
|
814
744
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
(playerObject.animation as any).swingArm()
|
|
821
|
-
}
|
|
822
|
-
return
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
if (playerObject.animation && (playerObject.animation as any).switchAnimationCallback !== undefined) {
|
|
826
|
-
(playerObject.animation as any).switchAnimationCallback = () => {
|
|
827
|
-
const anim = playerObject.animation as any
|
|
828
|
-
if (anim) {
|
|
829
|
-
anim.isMoving = animation === 'walking' || animation === 'running' || animation === 'crouchWalking'
|
|
830
|
-
anim.isRunning = animation === 'running'
|
|
831
|
-
anim.isCrouched = animation === 'crouch' || animation === 'crouchWalking'
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
return
|
|
836
|
-
}
|
|
745
|
+
anim.switchAnimationCallback = null
|
|
746
|
+
anim.isMoving = animation === 'walking' || animation === 'running' || animation === 'crouchWalking'
|
|
747
|
+
anim.isRunning = animation === 'running'
|
|
748
|
+
anim.isCrouched = animation === 'crouch' || animation === 'crouchWalking'
|
|
749
|
+
}
|
|
837
750
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (playerEntityObject.animation && (playerEntityObject.animation as any).swingArm) {
|
|
843
|
-
(playerEntityObject.animation as any).swingArm()
|
|
844
|
-
}
|
|
845
|
-
return
|
|
846
|
-
}
|
|
751
|
+
playAnimation(entityPlayerId, animation: 'walking' | 'running' | 'oneSwing' | 'idle' | 'crouch' | 'crouchWalking') {
|
|
752
|
+
const playerObject = entityPlayerId === 'player_entity'
|
|
753
|
+
? this.playerEntity?.playerObject
|
|
754
|
+
: this.getPlayerObject(entityPlayerId) ?? this.playerEntity?.playerObject
|
|
847
755
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
const anim = playerEntityObject.animation as any
|
|
851
|
-
if (anim) {
|
|
852
|
-
anim.isMoving = animation === 'walking' || animation === 'running' || animation === 'crouchWalking'
|
|
853
|
-
anim.isRunning = animation === 'running'
|
|
854
|
-
anim.isCrouched = animation === 'crouch' || animation === 'crouchWalking'
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
756
|
+
if (!playerObject) return
|
|
757
|
+
this.applyMovementAnimation(playerObject, animation)
|
|
859
758
|
}
|
|
860
759
|
|
|
861
760
|
parseEntityLabel(jsonLike) {
|
|
@@ -1340,11 +1239,9 @@ export class Entities {
|
|
|
1340
1239
|
}
|
|
1341
1240
|
}
|
|
1342
1241
|
|
|
1343
|
-
playerPerAnimation = {} as Record<number, string>
|
|
1344
1242
|
onRemoveEntity(entity: import('prismarine-entity').Entity) {
|
|
1345
1243
|
this.loadedSkinEntityIds.delete(entity.id.toString())
|
|
1346
1244
|
delete this.currentSkinUrls[entity.id.toString()]
|
|
1347
|
-
this.motionCache.delete(entity.id.toString())
|
|
1348
1245
|
}
|
|
1349
1246
|
|
|
1350
1247
|
updateMap(mapNumber: string | number, data: string) {
|