implement entity model rendering

(cherry picked from commit a0e5d51290cf521d511f90e23445206a14c4a772)
This commit is contained in:
LabyStudio
2022-04-13 12:52:51 +02:00
parent fd071f296a
commit 4644b050c6
16 changed files with 454 additions and 5 deletions
@@ -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;
}
}