Skip to content

Commit

Permalink
force crosshair cursor when block unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
j0code committed Mar 23, 2024
1 parent 54822e6 commit 8c320ce
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/gui/state/ingame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,20 @@ 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)
} else if (targetBlock?.type == "container") {
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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8c320ce

Please sign in to comment.