diff --git a/src/js/net/minecraft/client/Minecraft.js b/src/js/net/minecraft/client/Minecraft.js index f50aa1f..73221cb 100644 --- a/src/js/net/minecraft/client/Minecraft.js +++ b/src/js/net/minecraft/client/Minecraft.js @@ -23,7 +23,7 @@ window.Minecraft = class { this.pickedBlock = 1; // Create current screen and overlay - this.ingameOverlay = new IngameOverlay(); + this.ingameOverlay = new IngameOverlay(this.window); this.currentScreen = null; // Initialize diff --git a/src/js/net/minecraft/client/gui/Gui.js b/src/js/net/minecraft/client/gui/Gui.js index 1c62031..96f5f81 100644 --- a/src/js/net/minecraft/client/gui/Gui.js +++ b/src/js/net/minecraft/client/gui/Gui.js @@ -7,4 +7,20 @@ window.Gui = class { stack.globalAlpha = alpha; } + drawTexture(stack, texture, x, y, width, height, alpha = 1.0) { + this.drawSprite(stack, texture, 0, 0, 256, 256, x, y, width, height, alpha); + } + + drawSprite(stack, texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height, alpha = 1.0) { + stack.globalAlpha = alpha; + stack.drawImage(texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height); + stack.globalAlpha = 1.0; + } + + loadTexture(path) { + let img = new Image(); + img.src = path; + return img; + } + } \ No newline at end of file diff --git a/src/js/net/minecraft/client/gui/IngameOverlay.js b/src/js/net/minecraft/client/gui/IngameOverlay.js index af2119a..6344c60 100644 --- a/src/js/net/minecraft/client/gui/IngameOverlay.js +++ b/src/js/net/minecraft/client/gui/IngameOverlay.js @@ -1,7 +1,19 @@ window.IngameOverlay = class extends Gui { + constructor(window) { + super(); + this.window = window; + + this.textureCrosshair = this.loadTexture("icons.png"); + } + render(stack, mouseX, mouseY, partialTicks) { - this.drawRect(stack, 0, 0, 500, 500, '#0000FF'); + this.renderCrosshair(stack, this.window.width / 2, this.window.height / 2) + } + + renderCrosshair(stack, x, y) { + let size = 15 * 4; + this.drawSprite(stack, this.textureCrosshair, 0, 0, 15, 15, x - size / 2, y - size / 2, size, size, 0.6); } } \ No newline at end of file diff --git a/src/js/net/minecraft/client/render/WorldRenderer.js b/src/js/net/minecraft/client/render/WorldRenderer.js index 1e98505..4c67a6a 100644 --- a/src/js/net/minecraft/client/render/WorldRenderer.js +++ b/src/js/net/minecraft/client/render/WorldRenderer.js @@ -70,6 +70,7 @@ window.WorldRenderer = class { // Get context stack of 2d canvas this.stack2d = this.canvas2d.getContext('2d'); + this.stack2d.imageSmoothingEnabled = false; // Create texture from rendered graphics. this.frameBuffer = new THREE.Texture(this.canvas2d) @@ -110,6 +111,10 @@ window.WorldRenderer = class { let cameraChunkZ = Math.floor(player.z >> 4); this.renderChunks(cameraChunkX, cameraChunkZ); + // Clear frame buffer for 2d screen + this.stack2d.clearRect(0, 0, this.window.width, this.window.height); + this.frameBuffer.needsUpdate = true; + // Render in-game overlay let mouseX = this.minecraft.window.mouseX; let mouseY = this.minecraft.window.mouseY; diff --git a/src/resources/icons.png b/src/resources/icons.png new file mode 100644 index 0000000..d746b17 Binary files /dev/null and b/src/resources/icons.png differ