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

Mob Farm Touchscreen

Started by dxtrxc23, 19 August 2015 - 04:44 PM
dxtrxc23 #1
Posted 19 August 2015 - 06:44 PM
Hi there/ community,
got a big problem for me bot mabye not for you.
Maybe you know Direwolf20, a guy capturing Modded Minecraft lets plays.
In season 6 of his lets play series he decided to do a computercraft controlled mob farm for different types of mobs + some extra options(turn off the light; open a door, etc.)
So i went throught the code + api and built/coded the exact same thing he did.
first thing i realised was:
Had Openperipheral any important update since maybe 1 year becasue i cant run some strings:
Example for my 1st problem:
i decided to test around a little bit and copied his test program that can access a chest through a peripheral proxy and get certain information like stack size of a chest slot and the id/durability/name/etc and print the result on the screen

c = peripheral.wrap("container_chest_0")
for i = 1,27 do
if c.getStackInSlot(i) then
data = c.getStackInSlot(i)
print(i..":"..data.captured)
end
end
here i get an error in line 5: attempt to concatenate string and nil

Here is the code for the main problem:
Button API: http://pastebin.com/7Spj9KBa
Mob Farm: http://pastebin.com/vL4zeCtx

some screen pics: http://www.directupload.net/file/d/4084/j8a527v5_png.htm http://www.directupload.net/file/d/4084/s84ks53g_png.htm


how the code work: direwolf20 created a program where you can control your mob farm + other function(turn off on lights, open close door) over touchscreen of an advanched monitor.
since i think openperiheral has changed and so the code dont work anymore because of some wrong string / codelines.
if screenshots or any other information is needed pls tell me.
the major thing im looking for is get his code working, but i also want to understand it(for example if openperipheral string was changed and why the old string is not working anymore)

im really lokking forward to your answers and will highly appreciate them.
thank you in advantage

best regards
lukas

ps: if you want to look into it here are the yt links to the videos:
setup: https://www.youtube.com/watch?v=BIeuH7y1V_o&index=103&list=PLaiPn4ewcbkFVpHSec5nvnY-HdU5Yptc_
main part + in action: https://www.youtube.com/watch?v=qBiWrSIKKew&index=104&list=PLaiPn4ewcbkFVpHSec5nvnY-HdU5Yptc_
finalizing: https://www.youtube.com/watch?v=ZkvG5roZtmw&index=105&list=PLaiPn4ewcbkFVpHSec5nvnY-HdU5Yptc_

if im not allowed to post outside links, pls tell me im new to this.
also im srry for my language mistakes but my native language is german :)/>
Lupus590 #2
Posted 19 August 2015 - 08:36 PM
check that data.captured is not nil before attempting to print it


c = peripheral.wrap("container_chest_0")
for i = 1,27 do
  if c.getStackInSlot(i) then
	data = c.getStackInSlot(i)
	if data.captured then
	  print(i..":"..data.captured)
	end
  end
end
Edited on 19 August 2015 - 06:37 PM
dxtrxc23 #3
Posted 19 August 2015 - 09:03 PM
tried ur code but;
the good thing is,it dont gives me an error.
bad thing: dont get the data i want like name of item durability etc

so the only thing i know is the current string for getStackInSlot()
if i call this string with data.captured it gives me an error.
so the goal/solutioen here is what i need to add, cause I comapered the the "old" getStackInSlot with the one you can find through m.listMethods() and there was another information added you need to call(its proxy?)
i dont know how to go on and i digged through the web cant find anything
pls its the goal, help me
thank you in advantage
Bomb Bloke #4
Posted 20 August 2015 - 01:49 AM
Perhaps try it like this:

local c = peripheral.wrap("container_chest_0")

for i = 1,27 do
	local data = c.getStackInSlot(i)
	if data then
		print("Slot "..i)
		for key, value in pairs(data) do print("data."..key..": "..tostring(value)) end
		print("\nPress any key...\n")
		os.pullEvent("key")
	end
end

This should tell you what information is available for each item in the container.
dxtrxc23 #5
Posted 20 August 2015 - 12:26 PM
ye ur right it tells me what information is available.

http://www.directupload.net/file/d/4085/igix7mb5_png.htm

but i/the mob farm control program need the information which mob is captured in the different slot/ safari net.
like i said before were there any changes to the getItemInSlot function.
cause maybe i need to call other things then only the slot.
HPWebcamAble #6
Posted 20 August 2015 - 09:27 PM
You cannot use ComputerCraft to figure out which mob is in a safari net.

The best alternative is to use a Vanilla anvil to rename each safari net to the name of the mob inside it
.getItemInSlot() should return the new name.
dxtrxc23 #7
Posted 21 August 2015 - 12:52 AM
thank you now if i run my test program it can give the name of the captured mob
http://www.directupload.net/file/d/4086/aazrvh2y_png.htm
thats a good starting point.
so i combined HPWebcamAble `s idea with Lupus590 `s idea and got a now a working test2 program that tells me which mob is captured in the safari net: http://www.directupload.net/file/d/4086/um424uha_png.htm
nice :)/> but this was only for the testing part.
my main idea was getting direwolf20s touchscreen mob spawner program working again.
so i implemented my result (code below) out of HPWebcamAble `s idea andLupus590 `s idea in the main program(from dw20).

c = peripheral.wrap("container_chest_1")
for i = 1,27 do
  if c.getStackInSlot(i) then
	    data = c.getStackInSlot(i)
	    if data.display_name then
		  print(i..":"..data.display_name)
	    end
  end
end
main program: http://pastebin.com/vL4zeCtx
so far i got this; its finally drawing some buttons on my screen but i got maybe the last error (http://www.directupload.net/file/d/4086/hhddqgn7_png.htm)
my code: http://pastebin.com/PMRce9A3

we are not far away from the end :)/>
thank you guys in adavtange; i really appreciate ur answer until now. they were gold for me ;)/>

best regards
Bomb Bloke #8
Posted 21 August 2015 - 03:04 AM
function getCurrMob()
 for i = 1,27 do
   if c.getStackInSlot(i) then
         data = c.getStackInSlot(i)
         if data.display_name then
           currMob = data.captured  -- What's this "data.captured" reference still doing here?
                       else
                         currMob = "None"  -- We'll never reach this line if there were no items in the container at all.
         end
   end
 end
end

Try it like this:

function getCurrMob()
	for i = 1,27 do
		local data = c.getStackInSlot(i)
		if data then
			currMob = data.captured
			return
		end
	end
	currMob = "None"
end
dxtrxc23 #9
Posted 21 August 2015 - 12:05 PM
dude you are awesoem :)/> thank you really much its working fluent and muc ore faster than the origianl.
but i got 1 last error: its always dispalying the same mob on the screen even if the mob is not inside the spawner.
http://www.directupload.net/file/d/4086/pusvkrw2_png.htm here you can see that the mob is always displayed.
http://www.directupload.net/file/d/4086/ze9cnhu8_png.htm in this screen pic you can see that i can spawn 5 mobs (enderman included) but the enderman is shown as current Mob which is false casue the spawner is empty.
here is the actual program with all of the changes, only the mob thing explained above need a fix.
http://pastebin.com/YxZNtaK5 i think its the function getCurrMob
bradford789 #10
Posted 21 August 2015 - 10:00 PM
Hello I was wondering if this code will work on the 1.6.4 version of Direwolfs mod pack and what mod pack are you playing that you have this working on.

I have been trying for a week to get his code to work and all i run into in nil errors or other errors that i get fixed and then more pop up that drove me crazy to the point where i gave up today and built a new mob spawner and was just working on creating a new program but ran into a issue creating the touchscreen so i went online and to research the problem and found your post. If this will work on 1.6.4 i will recreate the spawner and run your program or switch to 1.7.10 and use the mod pack that you are using.
dxtrxc23 #11
Posted 21 August 2015 - 10:13 PM
atm im using ftb infinity 1.10.1
the code is working; you can see that in the pictures above BUT i/we need to fix 1 last problem.
this problem is explained in my last post.
you can run the program with cc 1.7
pls guys help me out with the last mistake.
Bomb Bloke #12
Posted 21 August 2015 - 11:59 PM
Hrm, it looks like you should perhaps be checking a slot in "s", not in "c"?
dxtrxc23 #13
Posted 22 August 2015 - 12:39 AM
how do you mean that? in which function/line?
dont have anything to do with the currMob = "None" where maybe an else would be possible?
Bomb Bloke #14
Posted 22 August 2015 - 12:58 AM
Well, you want getCurrMob() to check what's in the spawner, right? But the wrapped peripheral it's dealing with - c - isn't the spawner (s).
dxtrxc23 #15
Posted 22 August 2015 - 01:07 AM
ye thats true but if i do that with s.getStackInSlot its returning into another error.
mobs line 97: slot id (2) must be less than 2
Bomb Bloke #16
Posted 22 August 2015 - 01:34 AM
Have a think about how many inventory slots the spawner has, and how many slots the loop is attempting to check.

Frankly you shouldn't need the loop at all, as I'd assume there's only one slot in the spawner you'll be sticking your nets into.
dxtrxc23 #17
Posted 22 August 2015 - 02:06 AM
the loop is checking a chest where the different types of mobs are stored.
so based on ur post i checked the code and i think there is a function missing.
a function that checks the inventory of the spawner

for clearness i ll post some screen caps
dxtrxc23 #18
Posted 22 August 2015 - 02:34 AM
http://www.directupload.net/file/d/4087/t4frek5f_png.htm the function getCurrMob belongs to the Chest where the safari nets are inside. im using the commans push/pull to get the item(safari net) remotely over a transvector interface into the auto spawner.
the spawner is also connected via networking cable http://www.directupload.net/file/d/4087/nqxpxr56_png.htm
like i said the function for chechin the autospawner "inventory is missing ?!"
HPWebcamAble #19
Posted 22 August 2015 - 02:54 AM
I think you might be misunderstanding:

To figure out what the 'curMob' is, you'd check the SPAWNER, not the CHEST

It seems that attempting to check 27 slots in the spawner throws an error, just have it look at the first slot. (Or are there 2? I don't know, just have it check the slot where safari nets go)
(Eg: getStackInSlot(1))
dxtrxc23 #20
Posted 22 August 2015 - 03:39 AM
seems like im misunderstanding smth and am a bit confused right now.


function getCurrMob()
	    for i = 1,27 do
			    local data = c.getStackInSlot(i)
			    if data then
					    currMob = data.display_name
					    return
			    end
	    end
	    currMob = "None"
end

i dont know right now if i sould change the for loop or only s.getStackInSlot :/
Bomb Bloke #21
Posted 22 August 2015 - 03:53 AM
Look, just do this:

function getCurrMob()
	    local data = s.getStackInSlot(1)
            currMob = data and data.display_name or "None"
end
dxtrxc23 #22
Posted 22 August 2015 - 04:15 AM
its working . cant thank you guys enough.
keep that pls

best reagards