View difference between Paste ID: bBBxyeV5 and hf9gSfZZ
SHOW: | | - or go back to the newest paste.
1
spawner = peripheral.wrap("front")
2
chest = peripheral.wrap("back")
3
rednet.open("right")
4
compId = 12
5
6
mobs = {}
7
--Mobs in chest definition!
8
function defineMobs()
9
  mobs = {}
10
  mobs[0] = {name = "Empty", slot = 0}
11
  --These only if you didnt name nets with anvil
12
  --mobs[1] = {name = "Wither skeleton", slot = 1}
13
  --mobs[2] = {name = "Blaze", slot = 2}
14
  --mobs[3] = {name = "Zombie", slot = 3}
15
  --mobs[4] = {name = "Enderman", slot = 4}
16
  --mobs[5] = {name = "Villager", slot = 5}
17
  --mobs[6] = {name = "Magma Cube", slot = 6}
18
  --mobs[7] = {name = "Pigman", slot = 7}
19
  for i=1,chest.getInventorySize() do
20
    chslot = chest.getStackInSlot(i)
21
    if (chslot) then
22
      mobs[i] = {name = chslot.name, slot = i}
23
    end
24
  end
25
end
26
--End mobs definition
27
defineMobs()
28
29
currentMob = mobs[0]
30
31
spawnerSide = "east"
32
chestSide = "west"
33
34
spawnerSafarySlotNum = 1
35
turtleTempSlotNum = 16
36
  
37
function getFromSpawner()
38
  if (spawner.getStackInSlot(spawnerSafarySlotNum)) then 
39
    return spawner.pushItemIntoSlot(spawnerSide,spawnerSafarySlotNum,1,turtleTempSlotNum)
40
  else
41
    return false
42
  end
43
end
44
45
function getFromChest(mob)
46
  if (chest.getStackInSlot(mob.slot)) then
47
    return chest.pushItemIntoSlot(chestSide,mob.slot,1,turtleTempSlotNum)
48
  else
49
    return false
50
  end
51
--  currentMob = mob
52
end
53
54
function putToSpawner()
55
  if (spawner.getStackInSlot(spawnerSafarySlotNum) == nil) then
56
    return spawner.pullItemIntoSlot(spawnerSide,turtleTempSlotNum,1,spawnerSafarySlotNum)
57
  else
58
    return false
59
  end
60
end
61
62
function putToChest()
63
  return chest.pullItemIntoSlot(chestSide,turtleTempSlotNum,1,currentMob.slot)
64
--  currentMob = mobs[0]
65
end
66
67
function fromChestToSpawner(mob)
68
  if (mob.slot ~= 0) then
69
    if (getFromChest(mob)) then 
70
      currentMob = mob
71
      if (putToSpawner()) then
72
        return true
73
      else
74
        print ("Unable to put safary net to spawner!")
75
        print ("Returning safary net to chest!")
76
        putToChest()
77
        currentMob = mobs[0]
78
        return false
79
      end
80
    else
81
      print ("Unable to take safary net from chest!")
82
      return false
83
    end
84
  else
85
    --print("Do something with empty request, maybe just emptying spawner")
86
    fromSpawnerToChest()
87
    return true
88
  end
89
end
90
91
function fromSpawnerToChest()
92
  if (currentMob.slot ~= 0) then
93
    if (getFromSpawner()) then
94
      print ("Succes getting safary net from spawner")
95
      putToChest()
96
      currentMob = mobs[0]
97
    else
98
      print ("Cant get from spawner!")
99
      return false
100
    end
101
  else
102
    print ("Current Mob data not defined, dont know where to put safary net!")
103
    return false
104
  end  
105
end
106
107
function refreshAndGetMobs()
108
  defineMobs()
109
  return mobs
110
end
111
112
function response(mess)
113
  rednet.send(compId,mess)
114
end
115
commands = {
116
  getAllMobs = function() return refreshAndGetMobs() end,
117
  getCurrentMob = function() return currentMob end,
118
  fromChestToSpawner = function(args) return fromChestToSpawner(args[1]) end,
119
  fromSpawnerToChest = function() return fromSpawnerToChest() end,
120
  getSpawnExact = function() return spawner.getSpawnExact() end,
121
  setSpawnExact = function(args) return spawner.setSpawnExact(args[1]) end,
122
  getTankInfo = function() return spawner.getTankInfo("unknown")[1] end
123
}
124
125
while true do
126
  message = {}
127
  message.sId, message.command, message.distance = rednet.receive()
128
  if (message["command"]["cname"] == "Test") then
129
    response(mobs)
130
  else
131
    print ("Executing "..message["command"]["cname"].." command with args ")
132
    response(commands[message["command"]["cname"]](message["command"]["args"]))
133
  end
134
end