This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kain184's profile picture

direwolf 20 mobfarm push pull item help

Started by kain184, 13 January 2015 - 09:58 PM
kain184 #1
Posted 13 January 2015 - 10:58 PM
hello all trying to create a change to a build i made but cant quite grasp how to do it. im working to try and push and pull from invintories via networked peripherals but cant quite grasp how to do it i tried looking at direwolfs code from

os.loadAPI("button")
local m = peripheral.wrap("right")
local rsOut = {}
local c = peripheral.wrap("container_chest_0")
local a = peripheral.wrap("tt_magnet_0")
local s = peripheral.wrap("tile_mfr_machine_autospawner_name_0")
m.clear()
local mobArray = {}
local buttonColors = {}
local attractorStatus = ""
local page = 1
local pages = 0
local currMob = ""
  
function fillMainTable()
   getCurrMob()
   checkExact()
   getAttractorStatus()
   m.clear()
   button.clearTable()
   button.setTable("Lights", lights, "", 4, 17, 2, 4)
   button.setTable("Door", door, "", 20, 33, 2, 4)
   button.setTable("Grinders", grinders, "", 4, 17, 6, 8)
   button.setTable("DrawBridge", drawBridge, "", 20, 33, 6, 8)
   button.setTable("Attractor", attractorToggle, "", 4, 17, 10, 12)
   button.setTable(attractorStatus, togglePush, "", 20, 33, 10, 12)
   button.setTable("Mob Selector", mobSelect, "", 20, 33, 14, 16)
   button.setTable("Spawner", spawner, "", 4, 17, 14, 16)
   --button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
   print("Filled")
   button.screen()
   for i,j in pairs(buttonColors) do
	  if not rsOut[j] then button.toggleButton(i) end
   end
   button.toggleButton("Attractor")
   button.label(1, 19, "Current Mob: "..currMob)
   button.label(30, 19, "Exact: "..currExact)
end
function getAttractorStatus()
   if a.isPulling() then
	  attractorStatus = "Pulling"
   else
	  attractorStatus = "Pushing"
   end
end
function togglePush()
   button.flash(attractorStatus)
   a.setPulling(not a.isPulling())
   fillMainTable()
end
function fillTable()
   checkMobs()
   checkExact()
   getCurrMob()
   m.clear()
   button.clearTable()
   local totalrows = 0
   local npp = 12 --names per page
   local numNames = 0
   local col = 2
   local row = 12
   local countRow = 1
   local currName = 0
   for i,j in pairs(mobArray) do
	  totalrows = totalrows+1
   end
   pages = math.ceil(totalrows/npp)
   print(totalrows)
   for name,slot in pairs(mobArray) do
	   currName = currName + 1
	   if currName > npp*(page-1) and currName < npp*page+1 then
		 row = 4+(countRow)
		 button.setTable(string.sub(name, 0, 17), insertMob, slot, col, col+17 , row, row)
		 if col == 21 then
		   col = 2
		   countRow = countRow + 2
		 else
		   col = col+19
		 end
	   end
   end
   button.setTable("Next Page", nextPage, "", 27, 38, 1, 1)
   button.setTable("Prev Page", prevPage, "", 2, 13, 1, 1)
   button.setTable("Main Menu", goMainMenu, "", 15, 25, 1, 1)
   button.setTable("Exact: "..currExact, switchExact, "", 21, 38, 18, 19)
   button.setTable("Remove Mob", removeMob, "", 2, 19, 18, 19)
   button.screen()
   button.label(15,3, "Page: "..tostring(page).." of "..tostring(pages))
   button.label(12, 16, "Current Mob: "..currMob)
end	 
function getCurrMob()
   data = s.getStackInSlot(1)
   if data then
	  currMob = data.captured
   else
	  currMob = "None"
   end
end
function goMainMenu()
   fillMainTable()
--   refresh()
end
function checkExact()
   if s.getSpawnExact() then
	  currExact = "Yes"
   else
	  currExact = "No"
   end
end
function switchExact()
   s.setSpawnExact(not s.getSpawnExact())
   fillTable()
end
function nextPage()
   if page+1 <= pages then
	  page = page+1
   end
   fillTable()
   sleep(0.25)
end
function prevPage()
   if page-1 >= 1 then page = page-1 end
   fillTable()
   sleep(0.25)
end  
						  
function getMobs()
   mobArray = {}
   for i = 1,27  do
	  if c.getStackInSlot(i) then
		 data = c.getStackInSlot(i)
		 --print(i..":"..data.captured)
		 mobArray[data.captured] = i
	  end
   end
end
function findEmptySlot()
   for i = 1,27 do
	  if not c.getStackInSlot(i) then
		 return(i)
	  end
   end
end
function removeMob()
   local slot = findEmptySlot()
   c.pullItem("down", 1, 1, slot)
end
function insertMob(info)
   removeMob()
   c.pushItem("down", info, 1, 1)
   fillTable()
end
function checkMobs()
   getMobs()
   --fillTable()
end
function initRS()
   rsOut[colors.white] = false
   rsOut[colors.orange] = true
   rsOut[colors.magenta] = false
   rsOut[colors.lightBlue] = true
   rsOut[colors.yellow] = false
   rsOut[colors.lime] = true
   buttonColors["Lights"] = colors.white
   buttonColors["Spawner"] = colors.orange
   buttonColors["Grinders"] = colors.magenta
   buttonColors["DrawBridge"] = colors.lightBlue
   buttonColors["Attractor"] = colors.yellow
   buttonColors["Door"] = colors.lime
end
function setRS()
   local colorOutput = 0
   for i,j in pairs(rsOut) do
	  if j then colorOutput = colorOutput + i end
end
rs.setBundledOutput("left", colorOutput)
end
function lights()
   button.toggleButton("Lights")
   rsOut[colors.white] = not rsOut[colors.white]
   setRS()
end
function door()
   button.toggleButton("Door")
   rsOut[colors.lime] = not rsOut[colors.lime]
   setRS()
end

function spawner()
   button.toggleButton("Spawner")
   rsOut[colors.orange] = not rsOut[colors.orange]
   setRS()
end
function grinders()
   button.toggleButton("Grinders")
   rsOut[colors.magenta] = not rsOut[colors.magenta]
   setRS()
end
function drawBridge()
   button.toggleButton("DrawBridge")
   rsOut[colors.lightBlue] = not rsOut[colors.lightBlue]
   setRS()
end
function attractorToggle()
   button.toggleButton("Attractor")
   rsOut[colors.yellow] = not rsOut[colors.yellow]
   setRS()
end
function mobSelect()
   fillTable()
--   refresh()
--   getClick()
end
function getClick()
   local event,side,x,y = os.pullEvent()
   if event=="monitor_touch" then
	 button.checkxy(x,y)
   end
end
function refresh()
   m.clear()
   print("Refreshed")
   button.screen()
end
initRS()
setRS()
fillMainTable()
--refresh()
while true do getClick() end


what i dont understand is he used open peripheral to connect the mob spawner and the chest and was able to push and pull from a distance over network cable. but i just cant quite figure out how he did it can any one explain it to me.
KingofGamesYami #2
Posted 13 January 2015 - 11:01 PM
The computer doesn't actually move the items: the peripheral does. Someone else will have to explain in more detail, I don't really use OpenP much.
Bomb Bloke #3
Posted 13 January 2015 - 11:33 PM
The computer doesn't actually move the items: the peripheral does. Someone else will have to explain in more detail, I don't really use OpenP much.

That pretty much sums it up fully, really. Nothing gets pushed/pulled through the network cable - the computer tells the peripheral what to do, and the peripheral does it.

For example, this line:

c.pullItem("down", 1, 1, slot)

… tells the chest to pull an item from underneath itself into its first slot. The position of the computer is irrelevant to this command.
kain184 #4
Posted 14 January 2015 - 01:27 AM
i know all that but from what i saw in the video ill have to find it and link it he did not have the chest and the mob spawner in the same area . he did it from a distance using open peripherals but i dont see how with what i have read which is exactly what you guys have been saying.
Bomb Bloke #5
Posted 14 January 2015 - 01:42 AM
The usual method is via network cables. Slap a wired modem on every peripheral you're using, and one on the computer. Cable everything together, then use (right-click) each peripheral's modem to "connect" it. As you do so, you'll see messages telling you their network names (eg something along the lines of "container_chest_0" for your chest), which are what you should be using to wrap the peripherals with.

This allows the computer to remotely transmit instructions to the peripherals, which they then carry out from where they're actually located.
kain184 #6
Posted 14 January 2015 - 03:47 AM
right which i do like so . c=peripheral.wrap("crystal_0") iron chests mod and d=peripheral.wrap("itemdropper_0") but how do i then tell the chest to send to the dropper over the peripheral because it will only take directions not names and each time i try any direction all it gives me is other inventory not found
Edited on 14 January 2015 - 02:48 AM
Lyqyd #7
Posted 14 January 2015 - 03:52 AM
Are they physically adjacent to each other? If so, use the cardinal direction (north, south, etc.), I believe. If not, it won't work until you place them adjacent to each other.
kain184 #8
Posted 14 January 2015 - 04:05 AM
i am special i just relized he used a transvector interface to move the items from a distance by having the chest next to it. i think i can make this work now thank you all i was on the right track i just forgot that one part
kain184 #9
Posted 15 January 2015 - 01:36 AM
alright new issue same topic i need to see all of the methods of a peripheral that i have wrapped so i can find the one i need. using open peripherals it allows you to connect to thermal expansion devices but you can only input and output on one side with the transvector interfaces i have set up i can only pull and push from a single side. so i need the method that will let me change the side from input to output. i try getmethod/listmethods but the terminal cuts off most of the commands. so i thought i would put it to a monitor. so i used

local x=1
for i,v in ipairs(peripheral.getMethods("tile_thermalexpansion_device_activator_name_3")) do
if x<39 then
x=x+1 mon.setCursorPos(x,1)
elseif not x<39 then
mon.setCursorPos(1,1)
end
  mon.write(i..". "..v) end
to try and make it write to the monitor but tab down each time it runs. but all it will display is numbers and it will not move down. can anyone tell me why.
edit nvm figured it out lol had the x and the y backwords
Edited on 15 January 2015 - 12:44 AM