make items darker in pause menu
This commit is contained in:
@@ -158,6 +158,9 @@ window.Minecraft = class {
|
|||||||
this.window.exitFocus();
|
this.window.exitFocus();
|
||||||
screen.setup(this, this.window.width, this.window.height);
|
screen.setup(this, this.window.width, this.window.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update items
|
||||||
|
this.itemRenderer.rebuildAllItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
onTick() {
|
onTick() {
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ window.BlockRenderer = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderGuiBlock(group, block, x, y, size) {
|
renderGuiBlock(group, block, x, y, size, brightness) {
|
||||||
this.tessellator.startDrawing();
|
this.tessellator.startDrawing();
|
||||||
|
|
||||||
let boundingBox = block.getBoundingBox(null, 0, 0, 0);
|
let boundingBox = block.getBoundingBox(null, 0, 0, 0);
|
||||||
@@ -269,6 +269,9 @@ window.BlockRenderer = class {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change brightness
|
||||||
|
this.tessellator.transformBrightness(brightness);
|
||||||
|
|
||||||
// Create mesh
|
// Create mesh
|
||||||
let mesh = this.tessellator.draw(group);
|
let mesh = this.tessellator.draw(group);
|
||||||
mesh.geometry.center();
|
mesh.geometry.center();
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ window.Tessellator = class {
|
|||||||
this.colors.push(this.blue);
|
this.colors.push(this.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transformBrightness(brightness) {
|
||||||
|
for (let i in this.colors) {
|
||||||
|
this.colors[i] *= brightness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
draw(group) {
|
draw(group) {
|
||||||
let geometry = new THREE.BufferGeometry();
|
let geometry = new THREE.BufferGeometry();
|
||||||
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
||||||
|
|||||||
@@ -53,21 +53,35 @@ window.ItemRenderer = class {
|
|||||||
if (typeof meta === "undefined") {
|
if (typeof meta === "undefined") {
|
||||||
let meta = {};
|
let meta = {};
|
||||||
|
|
||||||
|
// To make the items darker
|
||||||
|
let paused = this.minecraft.isPaused();
|
||||||
|
|
||||||
|
// Render item
|
||||||
let group = new THREE.Group();
|
let group = new THREE.Group();
|
||||||
this.minecraft.worldRenderer.blockRenderer.renderGuiBlock(group, block, x, y, 10);
|
this.minecraft.worldRenderer.blockRenderer.renderGuiBlock(group, block, x, y, 10, paused ? 0.5 : 1);
|
||||||
this.scene.add(group);
|
this.scene.add(group);
|
||||||
|
|
||||||
|
// Create meta
|
||||||
meta.group = group;
|
meta.group = group;
|
||||||
meta.typeId = block.getId();
|
meta.typeId = block.getId();
|
||||||
meta.x = x;
|
meta.x = x;
|
||||||
meta.y = y;
|
meta.y = y;
|
||||||
|
meta.dirty = false;
|
||||||
this.items[renderId] = meta;
|
this.items[renderId] = meta;
|
||||||
} else {
|
} else {
|
||||||
if (meta.typeId !== block.getId() || meta.x !== x || meta.y !== y) {
|
// Check if rendered item has changed
|
||||||
|
if (meta.dirty || meta.typeId !== block.getId() || meta.x !== x || meta.y !== y) {
|
||||||
|
// Rebuild item
|
||||||
this.scene.remove(meta.group);
|
this.scene.remove(meta.group);
|
||||||
delete this.items[renderId];
|
delete this.items[renderId];
|
||||||
this.renderItemInGui(renderId, block, x, y);
|
this.renderItemInGui(renderId, block, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rebuildAllItems() {
|
||||||
|
for (let i in this.items) {
|
||||||
|
this.items[i].dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user