From a7b8bcf1c8ecf11e6a9d892cc5ef8a2ed96c309c Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 27 Apr 2023 13:19:37 +0200 Subject: [PATCH] Made placing safe. --- src/movescript.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/movescript.lua b/src/movescript.lua index e0314bc..60ba969 100644 --- a/src/movescript.lua +++ b/src/movescript.lua @@ -100,19 +100,35 @@ local function goLeft(options, settings) t.turnLeft() end +local function placeFunction(func, digFunction, detectFunction, settings, options) + settings = settings or movescript.defaultSettings + safe = settings.safe or movescript.defaultSettings.safe + destructive = settings.destructive or movescript.defaultSettings.destructive + local success = func(options.text) + if not safe then return end + while not success do + debug("Unable to place.", settings) + if destructive and detectFunction() then + debug("Detected a block in the way; attempting to remove it.", settings) + digFunction() + end + success = func(options.text) + end +end + local function place(options, settings) debug("Placing.", settings) - t.place(options.text) + placeFunction(t.place, t.dig, t.detect, settings, options) end local function placeUp(options, settings) debug("Placing up.", settings) - t.placeUp(options.text) + placeFunction(t.placeUp, t.digUp, t.detectUp, settings, options) end local function placeDown(options, settings) debug("Placing down.", settings) - t.placeDown(options.text) + placeFunction(t.placeDown, t.digDown, t.detectDown, settings, options) end local function attack(options, settings)