diff --git a/src/components/canvas/Canvas.tsx b/src/components/canvas/Canvas.tsx index 5371335..4633996 100644 --- a/src/components/canvas/Canvas.tsx +++ b/src/components/canvas/Canvas.tsx @@ -45,7 +45,7 @@ function Canvas() { const { settings } = useContext(SettingsContext); const { missingTexture } = useContext(TexturesContext); const { isDark } = useContext(ThemeContext); - const { tool, radius, setTool } = useContext(ToolContext); + const { tool, radius, selectedBlock, setTool } = useContext(ToolContext); const textures = useTextures(version); const blockData = useBlockData(version); @@ -125,8 +125,14 @@ function Canvas() { eraser: eraserTool, }; + // Switch to eraser tool if selected block is air when using pencil + if (tool === "pencil" && selectedBlock === "air") { + eraserTool.use(); + return; + } + tools[tool]?.use(); - }, [tool, moveTool, lassoTool, pencilTool, eraserTool, rectangleSelectTool]); + }, [tool, selectedBlock, moveTool, lassoTool, pencilTool, eraserTool, rectangleSelectTool]); const onMouseMove = useCallback( (e: React.MouseEvent) => { diff --git a/src/hooks/tools/usePencilTool.ts b/src/hooks/tools/usePencilTool.ts index ff9688b..cadb128 100644 --- a/src/hooks/tools/usePencilTool.ts +++ b/src/hooks/tools/usePencilTool.ts @@ -14,10 +14,7 @@ export function usePencilTool(mouseCoords: Position) { const radiusPosition = useRadiusPosition(mouseCoords); const use = () => { - // if (selectedBlock == "air") { - // eraseTool(); - // break; - // } + if (selectedBlock == "air") return; const radiusBlocks: Block[] = []; for (let x = 0; x < radius; x++) {