Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------
- -- Mob Spawner for Turtle --
- -- --
- -- https://youtu.be/cPGYSG19Y2U -- --
- ----------------------------------
- spawner = peripheral.wrap("front")
- chest = peripheral.wrap("back")
- rednet.open("right")
- compId = 12
- mobs = {}
- --Mobs in chest definition!
- function defineMobs()
- mobs = {}
- mobs[0] = {name = "Empty", slot = 0}
- --These only if you didnt name nets with anvil
- --mobs[1] = {name = "Wither skeleton", slot = 1}
- --mobs[2] = {name = "Blaze", slot = 2}
- --mobs[3] = {name = "Zombie", slot = 3}
- --mobs[4] = {name = "Enderman", slot = 4}
- --mobs[5] = {name = "Villager", slot = 5}
- --mobs[6] = {name = "Magma Cube", slot = 6}
- --mobs[7] = {name = "Pigman", slot = 7}
- for i=1,chest.getInventorySize() do
- chslot = chest.getStackInSlot(i)
- if (chslot) then
- mobs[i] = {name = chslot.name, slot = i}
- end
- end
- end
- --End mobs definition
- defineMobs()
- currentMob = mobs[0]
- spawnerSide = "east"
- chestSide = "west"
- spawnerSafarySlotNum = 1
- turtleTempSlotNum = 16
- function getFromSpawner()
- if (spawner.getStackInSlot(spawnerSafarySlotNum)) then
- return spawner.pushItemIntoSlot(spawnerSide,spawnerSafarySlotNum,1,turtleTempSlotNum)
- else
- return false
- end
- end
- function getFromChest(mob)
- if (chest.getStackInSlot(mob.slot)) then
- return chest.pushItemIntoSlot(chestSide,mob.slot,1,turtleTempSlotNum)
- else
- return false
- end
- -- currentMob = mob
- end
- function putToSpawner()
- if (spawner.getStackInSlot(spawnerSafarySlotNum) == nil) then
- return spawner.pullItemIntoSlot(spawnerSide,turtleTempSlotNum,1,spawnerSafarySlotNum)
- else
- return false
- end
- end
- function putToChest()
- return chest.pullItemIntoSlot(chestSide,turtleTempSlotNum,1,currentMob.slot)
- -- currentMob = mobs[0]
- end
- function fromChestToSpawner(mob)
- if (mob.slot ~= 0) then
- if (getFromChest(mob)) then
- currentMob = mob
- if (putToSpawner()) then
- return true
- else
- print ("Unable to put safary net to spawner!")
- print ("Returning safary net to chest!")
- putToChest()
- currentMob = mobs[0]
- return false
- end
- else
- print ("Unable to take safary net from chest!")
- return false
- end
- else
- --print("Do something with empty request, maybe just emptying spawner")
- fromSpawnerToChest()
- return true
- end
- end
- function fromSpawnerToChest()
- if (currentMob.slot ~= 0) then
- if (getFromSpawner()) then
- print ("Succes getting safary net from spawner")
- putToChest()
- currentMob = mobs[0]
- else
- print ("Cant get from spawner!")
- return false
- end
- else
- print ("Current Mob data not defined, dont know where to put safary net!")
- return false
- end
- end
- function refreshAndGetMobs()
- defineMobs()
- return mobs
- end
- function response(mess)
- rednet.send(compId,mess)
- end
- commands = {
- getAllMobs = function() return refreshAndGetMobs() end,
- getCurrentMob = function() return currentMob end,
- fromChestToSpawner = function(args) return fromChestToSpawner(args[1]) end,
- fromSpawnerToChest = function() return fromSpawnerToChest() end,
- getSpawnExact = function() return spawner.getSpawnExact() end,
- setSpawnExact = function(args) return spawner.setSpawnExact(args[1]) end,
- getTankInfo = function() return spawner.getTankInfo("unknown")[1] end
- }
- while true do
- message = {}
- message.sId, message.command, message.distance = rednet.receive()
- if (message["command"]["cname"] == "Test") then
- response(mobs)
- else
- print ("Executing "..message["command"]["cname"].." command with args ")
- response(commands[message["command"]["cname"]](message["command"]["args"]))
- end
- end
- elseif message=="remove" then
- event, ID, message, dist = os.pullEvent("rednet_message")
- if type(message)=="number" then
- testSpawner()
- print("Removing mob in slot "..message)
- chest.push("up", message-1, 1)
- turtle.drop()
- rednet.send(1, "done")
- else
- print("No mob selected")
- end
- end
- sleep(0.01)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement