implement entity model rendering
(cherry picked from commit a0e5d51290cf521d511f90e23445206a14c4a772)
This commit is contained in:
@@ -5,6 +5,8 @@ window.World = class {
|
||||
constructor(minecraft) {
|
||||
this.minecraft = minecraft;
|
||||
|
||||
this.entities = [];
|
||||
|
||||
this.group = new THREE.Object3D();
|
||||
this.group.matrixAutoUpdate = false;
|
||||
|
||||
@@ -500,4 +502,31 @@ window.World = class {
|
||||
}
|
||||
return Math.floor(level * 11);
|
||||
}
|
||||
|
||||
addEntity(entity) {
|
||||
this.entities.push(entity);
|
||||
this.group.add(entity.group);
|
||||
|
||||
let tessellator = new Tessellator();
|
||||
|
||||
// Rebuild entity model
|
||||
let worldRenderer = this.minecraft.worldRenderer;
|
||||
let renderer = worldRenderer.entityRenderManager.getEntityRendererByEntity(entity);
|
||||
renderer.rebuild(tessellator, entity);
|
||||
}
|
||||
|
||||
removeEntityById(id) {
|
||||
let entity = this.getEntityById(id);
|
||||
this.entities.remove(entity);
|
||||
this.group.remove(entity.group);
|
||||
}
|
||||
|
||||
getEntityById(id) {
|
||||
for (let entity of this.entities) {
|
||||
if (entity.id === id) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user