implement video settings, implement slider and switch button, fix torch block light
This commit is contained in:
@@ -7,6 +7,8 @@ export default class GameSettings {
|
||||
this.thirdPersonView = 0;
|
||||
this.fov = 70;
|
||||
this.viewBobbing = true;
|
||||
this.ambientOcclusion = true;
|
||||
this.sensitivity = 100;
|
||||
}
|
||||
|
||||
load() {
|
||||
|
||||
@@ -56,7 +56,22 @@ export default class GameWindow {
|
||||
document.addEventListener('pointerlockchange', _ => this.onFocusChanged(), false);
|
||||
|
||||
// Mouse motion
|
||||
document.addEventListener('mousemove', event => this.onMouseMove(event), false);
|
||||
document.addEventListener('mousemove', event => {
|
||||
this.onMouseMove(event);
|
||||
|
||||
// Handle mouse move on screen
|
||||
if (!(minecraft.currentScreen === null)) {
|
||||
minecraft.currentScreen.mouseDragged(event.x / scope.scaleFactor, event.y / scope.scaleFactor, event.code);
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Mouse release
|
||||
document.addEventListener('mouseup', event => {
|
||||
// Handle mouse release on screen
|
||||
if (!(minecraft.currentScreen === null)) {
|
||||
minecraft.currentScreen.mouseReleased(event.x / scope.scaleFactor, event.y / scope.scaleFactor, event.code);
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Losing focus event
|
||||
this.canvas.addEventListener("mouseout", function () {
|
||||
|
||||
@@ -73,8 +73,9 @@ export default class PlayerEntity extends EntityLiving {
|
||||
}
|
||||
|
||||
turn(motionX, motionY) {
|
||||
this.rotationYaw = this.rotationYaw + motionX * 0.15;
|
||||
this.rotationPitch = this.rotationPitch - motionY * 0.15;
|
||||
let sensitivity = this.minecraft.settings.sensitivity / 500;
|
||||
this.rotationYaw = this.rotationYaw + motionX * sensitivity;
|
||||
this.rotationPitch = this.rotationPitch - motionY * sensitivity;
|
||||
|
||||
if (this.rotationPitch < -90.0) {
|
||||
this.rotationPitch = -90.0;
|
||||
|
||||
@@ -56,4 +56,20 @@ export default class GuiScreen extends Gui {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mouseReleased(mouseX, mouseY, mouseButton) {
|
||||
for (let i in this.buttonList) {
|
||||
let button = this.buttonList[i];
|
||||
|
||||
button.mouseReleased(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
mouseDragged(mouseX, mouseY, mouseButton) {
|
||||
for (let i in this.buttonList) {
|
||||
let button = this.buttonList[i];
|
||||
|
||||
button.mouseDragged(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,22 @@ export default class IngameOverlay extends Gui {
|
||||
// Render hotbar
|
||||
this.renderHotbar(stack, this.window.width / 2 - 91, this.window.height - 22);
|
||||
|
||||
let world = this.minecraft.world;
|
||||
let player = this.minecraft.player;
|
||||
|
||||
let x = Math.floor(player.x);
|
||||
let y = Math.floor(player.y);
|
||||
let z = Math.floor(player.z);
|
||||
|
||||
let fps = Math.floor(this.minecraft.fps);
|
||||
let lightUpdates = world.lightUpdateQueue.length;
|
||||
let chunkUpdates = this.minecraft.worldRenderer.chunkSectionUpdateQueue.length;
|
||||
let lightLevel = world.getTotalLightAt(x, y, z);
|
||||
|
||||
// Debug
|
||||
this.drawString(stack, Math.floor(this.minecraft.fps) + " fps," +
|
||||
" " + this.minecraft.world.lightUpdateQueue.length + " light updates," +
|
||||
" " + this.minecraft.worldRenderer.chunkSectionUpdateQueue.length + " chunk updates", 1, 1);
|
||||
this.drawString(stack, Math.floor(this.minecraft.player.x) + ", " + Math.floor(this.minecraft.player.y) + ", " + Math.floor(this.minecraft.player.z)
|
||||
+ " (" + Math.floor(Math.floor(this.minecraft.player.x) >> 4) + ", " + Math.floor(Math.floor(this.minecraft.player.y) >> 4) + ", " + Math.floor(Math.floor(this.minecraft.player.z) >> 4) + ")", 1, 1 + 9);
|
||||
this.drawString(stack, fps + " fps," + " " + lightUpdates + " light updates," + " " + chunkUpdates + " chunk updates", 1, 1);
|
||||
this.drawString(stack, x + ", " + y + ", " + z + " (" + (x >> 4) + ", " + (y >> 4) + ", " + (z >> 4) + ")", 1, 1 + 9);
|
||||
this.drawString(stack, "Light: " + lightLevel, 1, 1 + 9 + 10);
|
||||
}
|
||||
|
||||
renderCrosshair(stack, x, y) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import GuiScreen from "../GuiScreen.js";
|
||||
import GuiKeyButton from "../widgets/GuiKeyButton.js";
|
||||
import GuiButton from "../widgets/GuiButton.js";
|
||||
import GuiSliderButton from "../widgets/GuiSliderButton.js";
|
||||
|
||||
export default class GuiControls extends GuiScreen {
|
||||
|
||||
@@ -16,19 +17,22 @@ export default class GuiControls extends GuiScreen {
|
||||
let settings = this.minecraft.settings;
|
||||
|
||||
let scope = this;
|
||||
this.buttonList.push(new GuiSliderButton("Mouse Sensitivity", settings.sensitivity, 50, 150, this.width / 2 - 100, this.height / 2 - 55, 200, 20, function (value) {
|
||||
settings.sensitivity = value;
|
||||
}).setDisplayNameBuilder(function (name, value) {
|
||||
return name + ": " + value + "%";
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiKeyButton("Crouch", settings.crouching, this.width / 2 - 100, this.height / 2 - 30, 200, 20, function (key) {
|
||||
settings.crouching = key;
|
||||
scope.init();
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiKeyButton("Sprint", settings.sprinting, this.width / 2 - 100, this.height / 2 - 5, 200, 20, function (key) {
|
||||
settings.sprinting = key;
|
||||
scope.init();
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiKeyButton("Toggle Perspective", settings.togglePerspective, this.width / 2 - 100, this.height / 2 + 20, 200, 20, function (key) {
|
||||
settings.togglePerspective = key;
|
||||
scope.init();
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiButton("Done", this.width / 2 - 100, this.height / 2 + 70, 200, 20, function () {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import GuiButton from "../widgets/GuiButton.js";
|
||||
import GuiControls from "./GuiControls.js";
|
||||
import GuiScreen from "../GuiScreen.js";
|
||||
import GuiSettings from "./GuiSettings.js";
|
||||
|
||||
export default class GuiIngameMenu extends GuiScreen {
|
||||
|
||||
@@ -16,7 +17,11 @@ export default class GuiIngameMenu extends GuiScreen {
|
||||
scope.minecraft.displayScreen(null);
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiButton("Controls...", this.width / 2 - 100, this.height / 2 + 20, 200, 20, function () {
|
||||
this.buttonList.push(new GuiButton("Settings...", this.width / 2 - 100, this.height / 2 + 20, 98, 20, function () {
|
||||
scope.minecraft.displayScreen(new GuiSettings(scope));
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiButton("Controls...", this.width / 2 + 2, this.height / 2 + 20, 98, 20, function () {
|
||||
scope.minecraft.displayScreen(new GuiControls(scope));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import GuiScreen from "../GuiScreen.js";
|
||||
import GuiButton from "../widgets/GuiButton.js";
|
||||
import GuiSwitchButton from "../widgets/GuiSwitchButton.js";
|
||||
import GuiSliderButton from "../widgets/GuiSliderButton.js";
|
||||
|
||||
export default class GuiSettings extends GuiScreen {
|
||||
|
||||
constructor(previousScreen) {
|
||||
super();
|
||||
|
||||
this.previousScreen = previousScreen;
|
||||
}
|
||||
|
||||
init() {
|
||||
super.init();
|
||||
|
||||
let settings = this.minecraft.settings;
|
||||
|
||||
let scope = this;
|
||||
this.buttonList.push(new GuiSwitchButton("Ambient Occlusion", settings.ambientOcclusion, this.width / 2 - 100, this.height / 2 - 30, 200, 20, function (value) {
|
||||
settings.ambientOcclusion = value;
|
||||
scope.minecraft.worldRenderer.rebuildAll();
|
||||
}));
|
||||
this.buttonList.push(new GuiSwitchButton("View Bobbing", settings.viewBobbing, this.width / 2 - 100, this.height / 2 - 5, 200, 20, function (value) {
|
||||
settings.viewBobbing = value;
|
||||
}));
|
||||
this.buttonList.push(new GuiSliderButton("FOV", settings.fov, 50, 100, this.width / 2 - 100, this.height / 2 + 20, 200, 20, function (value) {
|
||||
settings.fov = value;
|
||||
}));
|
||||
|
||||
this.buttonList.push(new GuiButton("Done", this.width / 2 - 100, this.height / 2 + 70, 200, 20, function () {
|
||||
scope.minecraft.displayScreen(scope.previousScreen);
|
||||
}));
|
||||
}
|
||||
|
||||
drawScreen(stack, mouseX, mouseY, partialTicks) {
|
||||
// Background
|
||||
this.drawRect(stack, 0, 0, this.width, this.height, 'black', 0.6);
|
||||
|
||||
// Title
|
||||
this.drawCenteredString(stack, "Settings", this.width / 2, 50);
|
||||
|
||||
super.drawScreen(stack, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
onClose() {
|
||||
// Save settings
|
||||
this.minecraft.settings.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,29 +6,40 @@ export default class GuiButton extends Gui {
|
||||
super();
|
||||
|
||||
this.string = string;
|
||||
this.enabled = true;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
render(stack, mouseX, mouseY, partialTicks) {
|
||||
let textureGui = this.getTexture("gui/gui.png");
|
||||
|
||||
let mouseOver = this.isMouseOver(mouseX, mouseY);
|
||||
this.drawSprite(stack, textureGui, 0, 66 + (mouseOver ? 20 : 0), 200, 20, this.x, this.y, this.width, this.height);
|
||||
this.drawButton(stack, this.enabled, mouseOver, this.x, this.y, this.width, this.height);
|
||||
this.drawCenteredString(stack, this.string, this.x + this.width / 2, this.y + this.height / 2 - 4);
|
||||
}
|
||||
|
||||
onPress() {
|
||||
this.callback();
|
||||
if (this.enabled) {
|
||||
this.callback();
|
||||
}
|
||||
}
|
||||
|
||||
mouseClicked(mouseX, mouseY, mouseButton) {
|
||||
this.onPress();
|
||||
}
|
||||
|
||||
mouseReleased(mouseX, mouseY, mouseButton) {
|
||||
|
||||
}
|
||||
|
||||
mouseDragged(mouseX, mouseY, mouseButton) {
|
||||
|
||||
}
|
||||
|
||||
keyTyped(key) {
|
||||
|
||||
}
|
||||
@@ -37,4 +48,12 @@ export default class GuiButton extends Gui {
|
||||
return mouseX > this.x && mouseX < this.x + this.width && mouseY > this.y && mouseY < this.y + this.height;
|
||||
}
|
||||
|
||||
drawButton(stack, enabled, mouseOver, x, y, width, height) {
|
||||
let textureGui = this.getTexture("gui/gui.png");
|
||||
let spriteY = 66 + (enabled ? (mouseOver ? 20 : 0) : -20);
|
||||
|
||||
this.drawSprite(stack, textureGui, 0, spriteY, width / 2, 20, x, y, width / 2, height);
|
||||
this.drawSprite(stack, textureGui, 200 - width / 2, spriteY, width / 2, 20, x + width / 2, y, width / 2, height);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import GuiButton from "./GuiButton.js";
|
||||
import MathHelper from "../../../util/MathHelper.js";
|
||||
|
||||
export default class GuiSliderButton extends GuiButton {
|
||||
|
||||
constructor(name, value, min, max, x, y, width, height, callback) {
|
||||
super(name, x, y, width, height, _ => callback(this.value));
|
||||
|
||||
this.settingName = name;
|
||||
this.value = value;
|
||||
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
||||
this.enabled = false;
|
||||
this.dragging = false;
|
||||
|
||||
this.setDisplayNameBuilder((name, value) => {
|
||||
return name + ": " + value;
|
||||
})
|
||||
}
|
||||
|
||||
mouseClicked(mouseX, mouseY, mouseButton) {
|
||||
if (this.isMouseOver(mouseX, mouseY)) {
|
||||
this.dragging = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mouseDragged(mouseX, mouseY, mouseButton) {
|
||||
if (this.dragging) {
|
||||
let percent = (this.value - this.min) / (this.max - this.min);
|
||||
let offset = -4 + 8 * percent;
|
||||
this.value = Math.round(this.min + (mouseX + offset - this.x) / this.width * (this.max - this.min));
|
||||
this.value = MathHelper.clamp(this.value, this.min, this.max);
|
||||
|
||||
this.string = this.getDisplayName(this.settingName, this.value);
|
||||
this.callback();
|
||||
}
|
||||
}
|
||||
|
||||
mouseReleased(mouseX, mouseY, mouseButton) {
|
||||
this.dragging = false;
|
||||
}
|
||||
|
||||
render(stack, mouseX, mouseY, partialTicks) {
|
||||
let mouseOver = this.isMouseOver(mouseX, mouseY);
|
||||
let percent = (this.value - this.min) / (this.max - this.min);
|
||||
let offset = Math.round(percent * (this.width - 8));
|
||||
|
||||
this.drawButton(stack, this.enabled, mouseOver, this.x, this.y, this.width, this.height);
|
||||
this.drawButton(stack, true, false, this.x + offset, this.y, 8, this.height);
|
||||
this.drawCenteredString(stack, this.string, this.x + this.width / 2, this.y + this.height / 2 - 4);
|
||||
}
|
||||
|
||||
setDisplayNameBuilder(builder) {
|
||||
this.getDisplayName = builder;
|
||||
this.string = this.getDisplayName(this.settingName, this.value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import GuiButton from "./GuiButton.js";
|
||||
|
||||
export default class GuiSwitchButton extends GuiButton {
|
||||
|
||||
constructor(name, value, x, y, width, height, callback) {
|
||||
super(name, x, y, width, height, _ => callback(this.value));
|
||||
|
||||
this.settingName = name;
|
||||
this.value = value;
|
||||
|
||||
this.string = this.getDisplayName();
|
||||
}
|
||||
|
||||
onPress() {
|
||||
this.value = !this.value;
|
||||
this.string = this.getDisplayName();
|
||||
this.callback();
|
||||
}
|
||||
|
||||
getDisplayName() {
|
||||
return this.settingName + ": " + (this.value ? "ON" : "OFF");
|
||||
}
|
||||
}
|
||||
@@ -6,18 +6,16 @@ import Block from "../world/block/Block.js";
|
||||
|
||||
export default class BlockRenderer {
|
||||
|
||||
static CLASSIC_LIGHTNING = false;
|
||||
|
||||
constructor(worldRenderer) {
|
||||
this.worldRenderer = worldRenderer;
|
||||
this.tessellator = new Tessellator();
|
||||
this.tessellator.bindTexture(worldRenderer.textureTerrain);
|
||||
}
|
||||
|
||||
renderBlock(world, block, x, y, z) {
|
||||
renderBlock(world, block, ambientOcclusion, x, y, z) {
|
||||
switch (block.getRenderType()) {
|
||||
case BlockRenderType.BLOCK:
|
||||
this.renderSolidBlock(world, block, x, y, z);
|
||||
this.renderSolidBlock(world, block, ambientOcclusion, x, y, z);
|
||||
break;
|
||||
case BlockRenderType.TORCH:
|
||||
this.renderTorch(world, block, x, y, z);
|
||||
@@ -25,7 +23,7 @@ export default class BlockRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
renderSolidBlock(world, block, x, y, z) {
|
||||
renderSolidBlock(world, block, ambientOcclusion, x, y, z) {
|
||||
let boundingBox = block.getBoundingBox(world, x, y, z);
|
||||
|
||||
// Render all faces
|
||||
@@ -37,12 +35,12 @@ export default class BlockRenderer {
|
||||
if (world === null || block.shouldRenderFace(world, x, y, z, face)) {
|
||||
|
||||
// Render face
|
||||
this.renderFace(world, block, boundingBox, face, x, y, z);
|
||||
this.renderFace(world, block, boundingBox, face, ambientOcclusion, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderFace(world, block, boundingBox, face, x, y, z) {
|
||||
renderFace(world, block, boundingBox, face, ambientOcclusion, x, y, z) {
|
||||
// Vertex mappings
|
||||
let minX = x + boundingBox.minX;
|
||||
let minY = y + boundingBox.minY;
|
||||
@@ -63,7 +61,7 @@ export default class BlockRenderer {
|
||||
maxV = 1 - maxV;
|
||||
|
||||
// Classic lightning
|
||||
if (BlockRenderer.CLASSIC_LIGHTNING) {
|
||||
if (!ambientOcclusion) {
|
||||
let level = world === null ? 15 : world.getTotalLightAt(minX + face.x, minY + face.y, minZ + face.z);
|
||||
let brightness = 0.9 / 15.0 * level + 0.1;
|
||||
let color = brightness * face.getShading();
|
||||
@@ -71,51 +69,51 @@ export default class BlockRenderer {
|
||||
}
|
||||
|
||||
// Add face to tessellator
|
||||
this.addFace(world, face, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV);
|
||||
this.addFace(world, face, ambientOcclusion, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV);
|
||||
}
|
||||
|
||||
addFace(world, face, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV) {
|
||||
addFace(world, face, ambientOcclusion, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV) {
|
||||
if (face === EnumBlockFace.BOTTOM) {
|
||||
this.addBlockCorner(world, face, maxX, minY, maxZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, maxX, minY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, minX, minY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, minX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, maxZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, maxZ, minU, maxV);
|
||||
}
|
||||
if (face === EnumBlockFace.TOP) {
|
||||
this.addBlockCorner(world, face, minX, maxY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, maxZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, maxZ, maxU, maxV);
|
||||
}
|
||||
if (face === EnumBlockFace.NORTH) {
|
||||
this.addBlockCorner(world, face, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, minX, minY, minZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, maxX, minY, minZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, minZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, minZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, minZ, maxU, minV);
|
||||
}
|
||||
if (face === EnumBlockFace.SOUTH) {
|
||||
this.addBlockCorner(world, face, minX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, maxX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX, minY, maxZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, maxZ, maxU, maxV);
|
||||
}
|
||||
if (face === EnumBlockFace.WEST) {
|
||||
this.addBlockCorner(world, face, minX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX, minY, minZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, minX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, minX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, maxZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, minY, minZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, maxZ, minU, minV);
|
||||
}
|
||||
if (face === EnumBlockFace.EAST) {
|
||||
this.addBlockCorner(world, face, maxX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, maxX, minY, minZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, maxX, minY, maxZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, minZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, minY, maxZ, maxU, maxV);
|
||||
}
|
||||
}
|
||||
|
||||
addBlockCorner(world, face, x, y, z, u, v) {
|
||||
addBlockCorner(world, face, ambientOcclusion, x, y, z, u, v) {
|
||||
// Smooth lightning
|
||||
if (!BlockRenderer.CLASSIC_LIGHTNING) {
|
||||
if (ambientOcclusion) {
|
||||
this.setAverageColor(world, face, x, y, z);
|
||||
}
|
||||
|
||||
@@ -147,10 +145,10 @@ export default class BlockRenderer {
|
||||
for (let offsetY = -1; offsetY <= 0; offsetY++) {
|
||||
for (let offsetZ = -1; offsetZ <= 0; offsetZ++) {
|
||||
let typeId = world.getBlockAt(x + offsetX, y + offsetY, z + offsetZ);
|
||||
let block = typeId === 0 ? null : Block.getById(typeId);
|
||||
|
||||
// Does it contain air?
|
||||
if (typeId === 0 || !Block.getById(typeId).isSolid()) {
|
||||
|
||||
if (block === null || !block.isSolid()) {
|
||||
// Sum up the light levels
|
||||
totalLightLevel += world.getTotalLightAt(x + offsetX, y + offsetY, z + offsetZ);
|
||||
totalBlocks++;
|
||||
@@ -231,37 +229,37 @@ export default class BlockRenderer {
|
||||
this.tessellator.setColor(1, 1, 1);
|
||||
|
||||
// Add faces to tessellator
|
||||
this.addDistortFace(world, EnumBlockFace.NORTH, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.EAST, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.SOUTH, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.WEST, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addFace(world, EnumBlockFace.TOP, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV + 8 / 256);
|
||||
this.addDistortFace(world, EnumBlockFace.NORTH, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.EAST, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.SOUTH, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addDistortFace(world, EnumBlockFace.WEST, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ);
|
||||
this.addFace(world, EnumBlockFace.TOP, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV + 8 / 256);
|
||||
}
|
||||
|
||||
addDistortFace(world, face, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ) {
|
||||
addDistortFace(world, face, ambientOcclusion, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV, distortX, distortZ) {
|
||||
if (face === EnumBlockFace.NORTH) {
|
||||
this.addBlockCorner(world, face, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, minX + distortX, minY, minZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, maxX + distortX, minY, minZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX + distortX, minY, minZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX + distortX, minY, minZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, minZ, maxU, minV);
|
||||
}
|
||||
if (face === EnumBlockFace.SOUTH) {
|
||||
this.addBlockCorner(world, face, minX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, maxX + distortX, minY, maxZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX + distortX, minY, maxZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX + distortX, minY, maxZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX + distortX, minY, maxZ + distortZ, maxU, maxV);
|
||||
}
|
||||
if (face === EnumBlockFace.WEST) {
|
||||
this.addBlockCorner(world, face, minX + distortX, minY, maxZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, minX + distortX, minY, minZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, minX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, minX, maxY, maxZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX + distortX, minY, maxZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX + distortX, minY, minZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, minZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, minX, maxY, maxZ, minU, minV);
|
||||
}
|
||||
if (face === EnumBlockFace.EAST) {
|
||||
this.addBlockCorner(world, face, maxX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, maxX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, maxX + distortX, minY, minZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, maxX + distortX, minY, maxZ + distortZ, maxU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, maxZ, maxU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX, maxY, minZ, minU, minV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX + distortX, minY, minZ + distortZ, minU, maxV);
|
||||
this.addBlockCorner(world, face, ambientOcclusion, maxX + distortX, minY, maxZ + distortZ, maxU, maxV);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +267,7 @@ export default class BlockRenderer {
|
||||
this.tessellator.startDrawing();
|
||||
|
||||
// Render block
|
||||
this.renderBlock(null, block, 0, 0, 0);
|
||||
this.renderBlock(null, block, false, 0, 0, 0);
|
||||
|
||||
// Change brightness
|
||||
this.tessellator.transformBrightness(brightness);
|
||||
@@ -296,7 +294,7 @@ export default class BlockRenderer {
|
||||
this.tessellator.startDrawing();
|
||||
|
||||
// Render block
|
||||
this.renderBlock(null, block, 0, 0, 0);
|
||||
this.renderBlock(null, block, false, 0, 0, 0);
|
||||
|
||||
// Change brightness
|
||||
this.tessellator.transformBrightness(brightness);
|
||||
@@ -313,15 +311,16 @@ export default class BlockRenderer {
|
||||
|
||||
renderGuiBlock(group, block, x, y, size, brightness) {
|
||||
this.tessellator.startDrawing();
|
||||
this.tessellator.setColor(1, 1, 1);
|
||||
|
||||
let boundingBox = block.getBoundingBox(null, 0, 0, 0);
|
||||
|
||||
// Render block by type
|
||||
switch (block.getRenderType()) {
|
||||
case BlockRenderType.BLOCK:
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.TOP, 0, 0, 0);
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.NORTH, 0, 0, 0);
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.EAST, 0, 0, 0);
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.TOP, false, 0, 0, 0);
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.NORTH, false, 0, 0, 0);
|
||||
this.renderFace(null, block, boundingBox, EnumBlockFace.EAST, false, 0, 0, 0);
|
||||
break;
|
||||
default:
|
||||
this.renderGuiItem(block);
|
||||
@@ -379,6 +378,6 @@ export default class BlockRenderer {
|
||||
maxV = 1 - maxV;
|
||||
|
||||
// Render item
|
||||
this.addFace(null, EnumBlockFace.NORTH, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV);
|
||||
this.addFace(null, EnumBlockFace.NORTH, false, minX, minY, minZ, maxX, maxY, maxZ, minU, minV, maxU, maxV);
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ export default class WorldRenderer {
|
||||
this.webRenderer.render(this.scene, this.camera);
|
||||
|
||||
// Render overlay with a static FOV
|
||||
this.camera.fov = this.minecraft.settings.fov;
|
||||
this.camera.fov = 70;
|
||||
this.camera.updateProjectionMatrix();
|
||||
this.webRenderer.render(this.overlay, this.camera);
|
||||
}
|
||||
@@ -180,8 +180,9 @@ export default class WorldRenderer {
|
||||
orientCamera(partialTicks) {
|
||||
let player = this.minecraft.player;
|
||||
|
||||
let rotationY = -MathHelper.toRadians(player.rotationYaw + 180);
|
||||
let rotationX = -MathHelper.toRadians(player.rotationPitch);
|
||||
let rotationY = -MathHelper.toRadians(player.rotationYaw + 180);
|
||||
let rotationZ = 0;
|
||||
|
||||
// Position
|
||||
let x = player.prevX + (player.x - player.prevX) * partialTicks;
|
||||
@@ -209,19 +210,25 @@ export default class WorldRenderer {
|
||||
}
|
||||
|
||||
// Update rotation
|
||||
this.camera.rotation.y = rotationY;
|
||||
this.camera.rotation.x = rotationX;
|
||||
this.camera.rotation.y = rotationY;
|
||||
this.camera.rotation.z = rotationZ;
|
||||
|
||||
// Update camera positionWC
|
||||
// Update camera position
|
||||
this.camera.position.set(x, y + player.getEyeHeight(), z);
|
||||
|
||||
// Update frustum
|
||||
this.frustum.setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse));
|
||||
// Apply bobbing animation
|
||||
if (mode === 0 && this.minecraft.settings.viewBobbing) {
|
||||
this.bobbingAnimation(player, this.camera, partialTicks);
|
||||
}
|
||||
|
||||
// Update FOV
|
||||
this.camera.fov = this.minecraft.settings.fov + player.getFOVModifier();
|
||||
this.camera.updateProjectionMatrix();
|
||||
|
||||
// Update frustum
|
||||
this.frustum.setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse));
|
||||
|
||||
// Setup fog
|
||||
this.setupFog(x, z, player.isHeadInWater(), partialTicks);
|
||||
}
|
||||
@@ -595,18 +602,7 @@ export default class WorldRenderer {
|
||||
|
||||
// Bobbing animation
|
||||
if (this.minecraft.settings.viewBobbing) {
|
||||
let walked = -(player.prevDistanceWalked + (player.distanceWalked - player.prevDistanceWalked) * partialTicks);
|
||||
let yaw = player.prevCameraYaw + (player.cameraYaw - player.prevCameraYaw) * partialTicks;
|
||||
let pitch = player.prevCameraPitch + (player.cameraPitch - player.prevCameraPitch) * partialTicks;
|
||||
this.translate(
|
||||
stack,
|
||||
Math.sin(walked * 3.141593) * yaw * 0.5,
|
||||
-Math.abs(Math.cos(walked * Math.PI) * yaw),
|
||||
0.0
|
||||
);
|
||||
stack.rotateZ(MathHelper.toRadians(Math.sin(walked * Math.PI) * yaw * 3.0));
|
||||
stack.rotateX(MathHelper.toRadians(Math.abs(Math.cos(walked * Math.PI - 0.2) * yaw) * 5.0));
|
||||
stack.rotateX(MathHelper.toRadians(pitch));
|
||||
this.bobbingAnimation(player, stack, partialTicks);
|
||||
}
|
||||
|
||||
let factor = 0.8;
|
||||
@@ -705,4 +701,21 @@ export default class WorldRenderer {
|
||||
stack.translateY(y);
|
||||
stack.translateZ(z);
|
||||
}
|
||||
|
||||
bobbingAnimation(player, stack, partialTicks) {
|
||||
let walked = -(player.prevDistanceWalked + (player.distanceWalked - player.prevDistanceWalked) * partialTicks);
|
||||
let yaw = player.prevCameraYaw + (player.cameraYaw - player.prevCameraYaw) * partialTicks;
|
||||
let pitch = player.prevCameraPitch + (player.cameraPitch - player.prevCameraPitch) * partialTicks;
|
||||
|
||||
this.translate(
|
||||
stack,
|
||||
Math.sin(walked * 3.141593) * yaw * 0.5,
|
||||
-Math.abs(Math.cos(walked * Math.PI) * yaw),
|
||||
0.0
|
||||
);
|
||||
|
||||
stack.rotateZ(MathHelper.toRadians(Math.sin(walked * Math.PI) * yaw * 3.0));
|
||||
stack.rotateX(MathHelper.toRadians(Math.abs(Math.cos(walked * Math.PI - 0.2) * yaw) * 5.0));
|
||||
stack.rotateX(MathHelper.toRadians(pitch));
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,8 @@ export default class ChunkSection {
|
||||
this.isModified = false;
|
||||
this.group.clear();
|
||||
|
||||
let ambientOcclusion = this.world.minecraft.settings.ambientOcclusion;
|
||||
|
||||
// Start drawing chunk section
|
||||
let tessellator = renderer.blockRenderer.tessellator;
|
||||
tessellator.startDrawing();
|
||||
@@ -67,7 +69,7 @@ export default class ChunkSection {
|
||||
let absoluteZ = this.z * ChunkSection.SIZE + z;
|
||||
|
||||
let block = Block.getById(typeId);
|
||||
renderer.blockRenderer.renderBlock(this.world, block, absoluteX, absoluteY, absoluteZ);
|
||||
renderer.blockRenderer.renderBlock(this.world, block, ambientOcclusion, absoluteX, absoluteY, absoluteZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user