Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Laser test
- --[[
- minimumPotency=0.5:
- The minimum potency a laser can have. Raising this prevents computers spamming a large number of lasers in a short amount of time.
- maximumPotency=5:
- The maximum potency a laser can have.
- cost=10:
- The “energy” cost per potency for a laser. By default a computer will gain 10 energy points each tick (read about the cost system for more information).
- damage=4:
- The damage done to an entity for each potency. Players and most mobs have 20 health, meaning a fully charged laser can kill an unarmoured creature with one hit.
- --]]
- local posR = { x = 0, y=0, z=5 }
- -- Shots per potency
- local shotCount = 1
- local modules = peripheral.find("manipulator")
- if not modules then
- error("Cannot find manipulator", 0)
- end
- function scan(target)
- return modules.getBlockMeta(target.x, target.y, target.z)
- end
- local function fire(target, potency)
- potency = math.min(5,math.max(.5,potency))
- local delay = math.max(potency * .1 + .1, .1)
- local x, y, z = target.x, target.y, target.z
- local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
- local yaw = math.atan2(-x, z)
- modules.fire(math.deg(yaw), math.deg(pitch), potency)
- sleep(delay)
- end
- local function keyPress(k)
- while true do
- local e,p = os.pullEvent("key")
- if p == k then
- e,p = os.pullEvent("key_up")
- if p == k then
- break
- end
- end
- end
- end
- local function display(blockData)
- local x,y = term.getCursorPos()
- term.setCursorPos(1,1)
- term.clearLine()
- term.write("Target: "..blockData.name)
- term.setCursorPos(x,y)
- end
- settings.load("log")
- while true do
- term.setCursorPos(1,1)
- term.clear()
- print("Press [S] to start")
- keyPress(keys.s)
- local blockData = scan(posR)
- print("Target:", blockData.name)
- if blockData.name == "minecraft:air" then
- print("Please place a block on target position")
- print("at X:", posR.x, "Y:", posR.y, "Z:", posR.z)
- print("Then, press any key")
- os.pullEvent("key")
- os.pullEvent("key_up")
- else
- term.setCursorPos(1,2)
- term.clear()
- local maxPower = 0
- local newBlockData
- for power=0.5,5,0.1 do
- maxPower = power
- term.write(string.format(" fire potency: %s shots: ", power))
- display(blockData)
- for i=1,shotCount do --test de 5 tirs
- term.write("*")
- fire(posR, power)
- newBlockData = scan(posR)
- if newBlockData.name ~= blockData.name then
- break
- end
- end
- print("")
- if newBlockData.name ~= blockData.name then
- print("Target diff.\nBefore:", blockData.name, "\nAfter:", newBlockData.name)
- display(blockData)
- break
- end
- end
- settings.set(blockData.name, newBlockData.name ~= blockData.name and maxPower or math.huge)
- settings.save("log")
- print("Test over, press any key")
- os.pullEvent("key")
- os.pullEvent("key_up")
- if commands then
- print("Replace block", blockData.name, "? Y/N")
- local x,y,confirm = term.getCursorPos()
- repeat
- term.setCursorPos(x,y)
- term.clearLine()
- confirm = string.lower(read())
- until confirm == "y" or confirm == "n"
- if confirm == "y" then
- local ax,ay,az = commands.getBlockPosition()
- commands.setblock(ax+posR.x, ay+posR.y+1, az+posR.z, blockData.name)
- end
- end
- end
- sleep(.2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement