diff --git a/src/gui/state/ingame.ts b/src/gui/state/ingame.ts index 31eabdd..3324c0a 100644 --- a/src/gui/state/ingame.ts +++ b/src/gui/state/ingame.ts @@ -152,10 +152,12 @@ export function draw(g: Graphics) { const targetBlock = world.getBlock(x, y, z) const inaccessible = z < frontZ && frontBlock?.full - if (floatingStack) { + if (!reachable) { + drawCrosshair(g, size, "#707070") + } else if (floatingStack) { g.ctx.translate(-size/2, -size/2) floatingStack.draw(g, size) - } else if (reachable && player.selectedItem.item.id != "tiny:air" && !inaccessible && targetBlock?.id == "tiny:air") { + } else if (player.selectedItem.item.id != "tiny:air" && !inaccessible && targetBlock?.id == "tiny:air") { g.ctx.translate(-size/2, -size/2) g.globalAlpha = 0.8 player.selectedItem.item.texture?.draw(g, size, size, true) @@ -163,14 +165,7 @@ export function draw(g: Graphics) { g.ctx.translate(-size/2, -size) cursors.openContainer.draw(g, size, size, true) } else { - g.strokeStyle = reachable ? "white" : "#707070" - g.lineWidth = 2 - g.ctx.beginPath() - g.ctx.moveTo(0, -size/3) - g.ctx.lineTo(0, size/3) - g.ctx.moveTo(-size/3, 0) - g.ctx.lineTo(size/3, 0) - g.ctx.stroke() + drawCrosshair(g, size, "white") } g.restore() @@ -334,6 +329,17 @@ function isBlockReachable(pos: Dim2) { .add(new Dim2(0, player.eyeHeight))) <= player.attributes.get("player.block_interaction_range", 0)! } +function drawCrosshair(g: Graphics, size: number, color: string) { + g.strokeStyle = color + g.lineWidth = 2 + g.ctx.beginPath() + g.ctx.moveTo(0, -size/3) + g.ctx.lineTo(0, size/3) + g.ctx.moveTo(-size/3, 0) + g.ctx.lineTo(size/3, 0) + g.ctx.stroke() +} + function openInventory() { const { x, y } = getMouseBlock() const block = world.getBlock(x, y, 0)