From cfe72b9f47f1e7f1ef5cc875f1b872891499e8be Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 4 Jan 2018 23:28:53 +0800 Subject: [PATCH] Add chest check --- transport_client.lua | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/transport_client.lua b/transport_client.lua index bf6bad4..bb1bf17 100644 --- a/transport_client.lua +++ b/transport_client.lua @@ -1,4 +1,5 @@ local component=require("component") +local sides=require("sides") require("libevent") require("util") @@ -19,6 +20,10 @@ local route_ba_load = proxy("routing_switch","088") local route_ab_unload = proxy("routing_switch","08c") local route_ba_unload = proxy("routing_switch","c") +--- Internal Variables +local load_box_side +local unload_box_side + -- Value: 1 Green 2 Blinking Yello 3 Yello 4 Blinking Red 5 Red local green=1 @@ -94,12 +99,48 @@ local function checkDevice() checkRoutingTicket(out_ticket) + local function checkChest(device) + if(device.getInventorySize(sides.down)==nil) then + error("CheckChest: Failed to check chest. Cache Chest must exists.") + end + + for i=1,device.getInventorySize(sides.down),1 do + if(device.getStackInSlot(sides.down,i)~=nil) then + error("CheckChest: Failed to check chest. Cache Chest not empty.") + end + end + + local tsd + + local dr={sides.north,sides.south,sides.east,sides.west} + for k,v in pairs(dr) do + if(device.getInventorySize(v)~=nil) then + tsd=v + end + end + + if(tsd==nil) then + error("CheckChest: Failed to check chest. Normal Chest must exists.") + end + + for i=1,device.getInventorySize(tsd),1 do + if(device.getStackInSlot(tsd,i)~=nil) then + error("CheckChest: Failed to check chest. Normal Chest not empty.") + end + end + + return tsd + end + + load_box_side=checkChest(load_transposer) + unload_box_side=checkChest(unload_transposer) + print("Check device pass.") end local function resetDevice() print("Reseting Devices...") - + digital_controller.setEveryAspect(red) route_ab_load.setRoutingTable({})