Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Gorzoid

Members
  • Content Count

    111
  • Joined

  • Last visited

  • Days Won

    22

Posts posted by Gorzoid

  1. Updated original code so it will stop to empty the inventory if inventory is full then continue where it left off. It also only ever dropped off the first slot so that would obviously be a big issue in a farm with over 32 plant crops, and 43x43 is alot bigger than that.

  2. You need to put the code into an eeprom and then the eeprom into the drone, either when your assembling it, or after by putting the drone and the eeprom into a crafting bench.

    To put the code into the eeprom, start up a computer as normal, when it has fully loaded, swap out the lua eeprom for a blank one. Then type "edit /dev/eeprom" and copy paste the code into the editor via the Insert key. Then save the code and exit, the eeprom will now have the code. Craft it with the drone to insert it.

  3. This was a fun challenge, tried to make it simple, with almost no need to change the code while also being complex enough to expand into big farms. I made this with sugarcane in mind because I am pretty sure they work exactly the same.

    
    local WAIT_TIME = 60 -- time to wait between cycles
    
    local drone = component.proxy(component.list("drone")())
    local nav = component.proxy(component.list("navigation")())
    
    local vector
    vector = {
    	__add = function(vec1,vec2)
    		local vec3 = vector {}
    		for i = 1,#vec1  do
    			vec3[i] = vec1[i] + vec2[i]
    		end
    		return vec3
    	end,
    	__sub = function(vec1,vec2)
    		local vec3 = vector {}
    		for i = 1,#vec1  do
    			vec3[i] = vec1[i] - vec2[i]
    		end
    		return vec3
    	end,
    	__unm = function(vec1)
    		local vec2 = vector {}
    		for i = 1,#vec1  do
    			vec2[i] = vec1[i]
    		end
    		return vec2
    	end,
    	unpack = function(tbl)
    		return table.unpack(tbl)
    	end
    }
    vector.__index = vector
    
    setmetatable(vector,
    	{
    		__call = function(mt,arg1,...)
    			return setmetatable(type(arg1) == "table" and arg1 or {arg1,...},vector)
    		end
    	}
    )
    local plants = {}
    local charger = vector {0,0,0}
    local chest = charger
    
    do
    	local list = nav.findWaypoints(16) -- Change to increase waypoint search radius, probably uses more power idk
    	
    	for i = 1,#list do
    		local wp = list[i]
    		local direction,length = wp.label:match("^plant:([2-5]):([0-9]+)$") 
    		if direction then
    			direction = tonumber(direction)
    			local axis,negate = direction > 3 and 1 or 3, (direction % 2)*2 - 1
    			for i = 0,negate*(length-1),negate do
    				local pos = {table.unpack(wp.position)}
    				pos[axis] = pos[axis] + i
    				pos[2] = pos[2] + 3 -- Crop height
    				plants[#plants+1] = vector(pos)
    			end
    		end
    		if wp.label:find"chest" then
    			chest = vector(wp.position)
    		end
    		if wp.label:find"charger" then
    			WAIT_TIME = tonumber(wp.label:match("%[([0-9]+)%]")) or WAIT_TIME -- if charger waypoint label contains [number] the waittime will become that number
    			charger = vector(wp.position)
    		end
    	end
    end
    
    local pos = vector {0,0,0}
    
    local function move(vec,halt)
    
    	drone.move(vec:unpack())
    	
    	if(halt) then
    		local speed = drone.getVelocity()
    		while(true) do
    			computer.pullSignal(0.1)
    			local tmpspeed = drone.getVelocity() 
    			if tmpspeed < speed and tmpspeed < 2 then break end
    			speed = tmpspeed
    		end
    		computer.pullSignal(0.5)
    	end
    	
    	pos = pos + vec
    end
    
    local invSize = drone.inventorySize()
    local currSlot = 1
    
    while true do
    	for i = 1,#plants do
    		move(plants[i] - pos,true)
    		if drone.detect(0) then 
    			drone.swing(0)
    			move(vector{0,-1,0},true)
    			drone.swing(0)
    		end
    		
    		if drone.count(currSlot) == 64 then
    			currSlot = currSlot + 1
    			if currSlot > invSize then
    				move(chest - pos,true)
    				for i = 1,invSize do
    					drone.select(i)
    					drone.drop(0)
    				end
    				currSlot = 1
    			end
    		end
    		
    	end
    	move(chest - pos,true)
    	for i = 1,currSlot do
    		drone.select(i)
    		drone.drop(0)
    	end
    	currSlot = 1
    	move(charger - pos)
    	computer.pullSignal(WAIT_TIME)
    end

     

    If you want to set up a farm you need atleast these two things:

    1. A drone with a navigation upgrade and atleast one inventory upgrade.
    2. A waypoint block to mark out where the crops are.

    The waypoint labels are what configure the drone, when it starts up it will search for all waypoints in a 16 block radius. There are three tags for the waypoint labels: plant, chest and charger. chest and/or charger are not required if your drone starts up above the chest and/or beside a charging face of the charger, look at the first attached image as an example. If you don't have the drone spawning on one of them you will need a waypoint to mark out where it is, using the label chest or charger. The plant waypoint is a bit more complicated, it uses a format of:

    plant:direction:length

    Where direction is the sides index that the line of crops extends and length is the number of crops in that direction. Use the sides api to get the correct direction. As an example my farm had 3 sugarcane crops extending south/positive z direction. So my label, was plant:3:3. You can see in the second picture what that looked like.

    Hope this works, I actually never knew drones could break/place blocks until now.

    2017-02-25_18.18.13.png

    2017-02-25_18.32.41.png

  4. On 2/19/2017 at 9:02 PM, Michiyo said:

    For a computer you have to do

    
    local component = require("component")

    In the lua interpreter you don't have to require stuff like you do in scripts

    For a microcontroller... well you don't get require there so you'll have to do it lower level and I'm not sure how that works :P

    In eeprom code the component table is never removed from global table so it's fine to use, and his original code should work on a microcontroller since he doesn't use any of the component api additions added by openos.

  5. Nice work, I think the largest tape drive can store a few MB so you can store quite alot with this, albeit very slowly.

    Suggestions:

    1. "if var == true then" is the exact same as "if var then", just as "if var == false then" is the same as "if not var then"
    2. You may want to try mount this file to a /dev/tape_drive file. This would mean you could do let's say "cp /dev/tape_drive /home/myfile.txt" to read from tapedrive, or "cp /home/myfile.txt /dev/tape_drive" to write to tapedrive. Check out OpenOS' devfs.lua for info on making fake files.
  6. sets the environment variable PATH to first argument. PATH is a ; divided list of paths that the shell uses to search for a program when you type a command. basically the same as in most operating systems these days

    Also this is all in the wiki

    Also also: this is in the wrong section, tutorials is meant for OP to give info, not ask for it, use support subforum next time.

  7. When I launch Minecraft with OpenComputers dev in eclipse OC spits alot of errors but does not crash, when I go into a world all items don't seem to work (can't put into computer).

    Some of the errors include:

    [18:39:50] [Client thread/INFO] [OpenComputers/OpenComputers]: Registering new assembler template 'Tablet (Creative)' from mod OpenComputers.
    [18:39:50] [Client thread/WARN] [OpenComputers/OpenComputers]: Failed registering assembler template.
    java.lang.ClassCastException: interface li.cil.oc.api.internal.Tablet

    Entire log: http://pastebin.com/YEteSicq

    I don't think it is my mods doing, since even if I comment out the 2 lines of code that run it will still break. If I build the mod it works fine with regular universal build. I didn't make an issue on github because I am not sure if this is just me messing up or if it's a problem with the dev build since I tried it on 3 versions.

  8. Check out CC forums, sadly even though alot of them use OpenComputers, they don't post their server on this forum too, while your at it, you may want to ask the owner if they can post it over here too.

  9. So really you just want an OC emulator? There is one or two on the forums.

     

    --Edit:

     

    If your talking about making a full baremetal OS that acts like OpenOS it would be very difficult especially if you don't know any low level languages.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.