Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Laser sentry based mob farm
- -- by SukaiPoppuGo
- --
- -- Config API
- --
- --------------------------------------------------
- -- Default settings file
- local SETTINGS_FILE = "mob_spawnerPosition"
- file = {}
- function file.get() return SETTINGS_FILE end
- function file.set(s) SETTINGS_FILE = s end
- --------------------------------------------------
- -- Display
- local screenW, screenH = term.getSize()
- local screenHalfW, screenHalfH = math.floor(screenW/2), math.floor(screenH/2)
- local screenHR, screenHalfHR = string.rep("-", screenW), string.rep("-", screenHalfW)
- --------------------------------------------------
- -- utils
- function string.ucfirst(sText)
- return string.upper(string.sub(sText,1,1))..string.sub(sText,2)
- end
- --------------------------------------------------
- -- function init
- -- Load settings file, or attempts to create it
- --
- -- return table mob_spawner Relative coordinates X, Y, Z
- function init()
- -- init modules
- local modules = peripheral.find("manipulator")
- if not modules then error("Cannot find manipulator", 0) end
- --------------------------------------------------
- -- Config mob_spawner relative position
- if not settings.load(SETTINGS_FILE) then
- term.setCursorPos(1, 1)
- term.clear()
- print(screenHR)
- print("Laser sentry - config wizard")
- print(screenHR)
- print("Mob spawner relative coordinates")
- print(screenHalfHR)
- -- auto config
- local selectedBlock = false
- if modules.hasModule("plethora:scanner") then
- print("Auto config")
- local map = modules.scan()
- print("scan result:", #map)
- term.clearLine()
- for i,block in ipairs(map) do
- if block.name == "minecraft:mob_spawner" then
- print(screenHalfHR)
- print("#"..i, block.name)
- print("X:", block.x, ", Y:", block.y, ", Z:", block.z)
- print("Dir:",
- ( block.z > 0 ) and "south" or ( block.z < 0 and "north" or "" ),
- ( block.x > 0 ) and "east" or ( block.x < 0 and "west" or "" ),
- ( block.y > 0 ) and "above (up)" or ( block.y < 0 and "below (down)" or "same height" )
- )
- term.write("Select this target Y/N ? ")
- repeat
- local e,p = os.pullEvent("key")
- if p == keys.n then
- print("> No.")
- print(screenHalfHR)
- elseif p == keys.y then
- print("> Yes.")
- selectedBlock = block
- end
- until p == keys.n or p == keys.y
- if selectedBlock then
- break
- end
- else
- local cursor = {term.getCursorPos()}
- term.setTextColor(colors.gray)
- term.clearLine()
- term.write(math.floor(i*100/#map).."% "..(block.name or "nil"))
- term.setTextColor(colors.white)
- term.setCursorPos(unpack(cursor))
- if i%math.floor(#map/50)==0 then sleep() end
- end
- end
- if not selectedBlock then
- printError("Mob spawner block not found.")
- print("May be out of range for block scanner.")
- end
- print(screenHalfHR)
- end
- -- manual config
- if not modules.hasModule("plethora:scanner") or not selectedBlock then
- print("Manual config")
- print("Input mob_spawner relative position\n(from the laser position)")
- selectedBlock = {}
- for i,axe in ipairs( {"x", "y", "z"} ) do
- local input
- repeat
- term.setTextColor(colors.lightGray)
- term.write("Relative "..string.upper(axe).." >")
- term.setTextColor(colors.white)
- input = tonumber( read() )
- until input
- term.setTextColor(colors.white)
- selectedBlock[ axe ] = input
- end
- print(screenHalfHR)
- end
- -- save config
- if selectedBlock then
- settings.set("mob_spawner.x", selectedBlock.x)
- settings.set("mob_spawner.y", selectedBlock.y)
- settings.set("mob_spawner.z", selectedBlock.z)
- settings.save(SETTINGS_FILE)
- assert(fs.exists(SETTINGS_FILE), string.format("Fails to save settings file \"%s\"", SETTINGS_FILE))
- print("Settings saved:", SETTINGS_FILE)
- end
- end
- local mob_spawner = {
- x = settings.get("mob_spawner.x", false),
- y = settings.get("mob_spawner.y", false),
- z = settings.get("mob_spawner.z", false),
- }
- assert(fs.exists(SETTINGS_FILE) and mob_spawner.x and mob_spawner.y and mob_spawner.z, string.format([[Warning!
- Your settings file "%s" may be corrupted. You should delete it and restart]], SETTINGS_FILE))
- assert(mob_spawner.x and mob_spawner.y and mob_spawner.z, string.format([[Warning!
- Setup Laser sentry require mob_spawner relative position.
- Install block scanner module, or create a settings file "%s" with each relative coordinates:
- {
- mob_spawner.x = number,
- mob_spawner.y = number,
- mob_spawner.z = number,
- }]], SETTINGS_FILE))
- print(string.rep("-", screenW))
- print("Laser sentry - config wizard terminated")
- print(string.rep("-", screenW))
- return mob_spawner
- end
- --------------------------------------------------
- -- Init Entity whitelist
- function getWhiteList()
- term.setCursorPos(1,1)
- term.clear()
- print(screenHR)
- print("Laser sentry - White list wizard")
- print(screenHR)
- os.loadAPI("api/EnumMob.lua")
- assert(EnumMob, "Require API EnumMob.lua\npastebin get mAraxgcc api/EnumMob.lua")
- local mobList = EnumMob
- local function completeMobName(sText)
- if sText == "" then
- return ""
- end
- sText = string.ucfirst(sText)
- return textutils.complete(sText, mobList)
- end
- local prevWhiteList = settings.get("mob_spawner.whiteList", {})
- local selectedMobs = prevWhiteList
- -- Whitelist display
- local displayList = window.create(
- term.current(),
- screenW - screenHalfW +1, 4, --pos
- screenHalfW, screenH -3, --size
- true)
- -- Whitelist display update
- function displayList.update()
- displayList.setCursorPos(1,1)
- displayList.setBackgroundColor(colors.gray)
- displayList.clear()
- displayList.blit(
- string.rep("\131", screenHalfW),
- string.rep("f", screenHalfW),
- string.rep("0", screenHalfW)
- )
- displayList.setCursorPos(1,2)
- displayList.blit(
- string.sub(" White list"..string.rep(" ", screenHalfW), 1, screenHalfW),
- string.rep("f", screenHalfW),
- string.rep("0", screenHalfW)
- )
- local y=4
- for name,keep in pairs(selectedMobs) do
- if keep == true then
- displayList.setCursorPos(2, y)
- displayList.write(name)
- y = y+1
- if y > screenH -5 then break end
- end
- end
- displayList.redraw()
- end
- -- Whitelist edit
- term.setCursorPos(1,4)
- print("Define a white list :")
- print("Write which mob's types\nshould be shot by laser")
- print(screenHalfHR)
- local cursor = {term.getCursorPos()}
- local confirmSave = false
- repeat -- back to edit or save/not save and exit
- repeat --adding several mobs in a list
- term.setCursorPos(1,8)
- term.clearLine()
- displayList.update()
- --Input mob types
- term.setCursorPos(1,8)
- term.write("> ")
- local input = string.ucfirst( read(nil, nil, completeMobName) )
- --Already in whitelist -> ask to remove
- if selectedMobs[ input ] == true then
- print("Already listed")
- print("Remove this mob ? Y/N")
- local confirm
- repeat
- local e,p = os.pullEvent("key")
- os.pullEvent("key_up") --clear char event
- if p == keys.y then
- selectedMobs[ input ] = false
- end
- until p == keys.n or p == keys.y
- term.setCursorPos(1,9)
- term.clearLine()
- term.setCursorPos(1,10)
- term.clearLine()
- --Add in whitelist
- elseif EnumMob[ input ] then
- selectedMobs[ input ] = true
- --Unreconized mobs
- elseif input ~= "" and not EnumMob[ input ] then
- print("isn't registered as mob")
- print("in database. Confirm: Y/N")
- local confirm = true
- repeat
- local e,p = os.pullEvent("key")
- os.pullEvent("key_up") --clear char event
- confirm = p == keys.y
- until p == keys.n or p == keys.y
- if confirm then
- selectedMobs[ input ] = true
- end
- term.setCursorPos(1,9)
- term.clearLine()
- term.setCursorPos(1,10)
- term.clearLine()
- end
- --Enter empty line to exit
- until #selectedMobs > 0 or input == ""
- --Saving confirmation
- term.setCursorPos(1,8)
- term.clearLine()
- displayList.update()
- term.setCursorPos(1,8)
- print("Save white list ? Y/N")
- print("Any key to resume")
- local e,p = os.pullEvent("key")
- os.pullEvent("key_up") --clear char event
- confirmSave = p == keys.y
- until p == keys.n or p == keys.y
- --clear display
- displayList.setVisible(false)
- displayList.redraw()
- for y=4, screenH do
- term.setCursorPos(1,y)
- term.clearLine()
- end
- term.setCursorPos(1,4)
- --Do not save
- if confirmSave then
- --Saving
- settings.set("mob_spawner.whiteList", selectedMobs)
- settings.save(SETTINGS_FILE)
- assert(fs.exists(SETTINGS_FILE), string.format([[Warning!
- Your settings file "%s" may be corrupted. You should delete it and restart]], SETTINGS_FILE))
- else
- print("Abort white list edition")
- print("Press any key")
- os.pullEvent("key")
- os.pullEvent("key_up") --clear char event
- selectedMobs = prevWhiteList
- end
- --Display list (final)
- term.write("whiteList = ")
- textutils.pagedPrint(textutils.serialize(selectedMobs))
- return selectedMobs
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement