View difference between Paste ID: 1XuRMvrq and 2M3g5Q16
SHOW: | | - or go back to the newest paste.
1
--cc:Tweaked: AE2 Inscriber Automation
2
--pastebin get 2M3g5Q16 inscriber.lua
3
--inscriber
4
5
local sides = require("sides")
6
local inventory = require("inventory")
7
8
local SILICON_PRESS = 			"ae2:silicon_press"
9
local ENGINEERING_PRESS = 		"ae2:engineering_processor_press"
10
local LOGIC_PRESS = 			"ae2:logic_processor_press"
11
local CALCULATION_PRESS =   	"ae2:calculation_processor_press"
12
13
local LOGIC_CIRCUIT =			"ae2:printed_logic_processor"
14
local ENGINEERING_CIRCUIT = 	"ae2:printed_engineering_processor"
15
local CALCULATION_CIRCUIT = 	"ae2:printed_calculation_processor"
16
local SILICON_CIRCUIT = 		"ae2:printed_silicon"
17
18
local SILICON = 				"ftbic:silicon"
19
local DIAMOND = 				"minecraft:diamond"
20
local GOLD = 					"minecraft:gold_ingot"
21
local CERTUS_QUARTZ = 			"ae2:certus_quartz_crystal"
22
local REDSTONE = 				"minecraft:redstone"
23
24
local PRINTED_SILICON_RECIPE = 				{ SILICON_PRESS,		SILICON }
25
local PRINTED_ENGINEERING_CIRCUIT_RECIPE = 	{ ENGINEERING_PRESS, 	DIAMOND }
26
local PRINTED_LOGIC_CIRCUIT_RECIPE = 		{ LOGIC_PRESS,			GOLD }
27
local PRINTED_CALCULATION_CIRCUIT_RECIPE = 	{ CALCULATION_PRESS,	CERTUS_QUARTZ }
28
29
local LOGIC_PROCESSOR_RECIPE = 				{ LOGIC_CIRCUIT,		REDSTONE,	SILICON_CIRCUIT }
30
local CALCULATION_PROCESSOR_RECIPE = 		{ CALCULATION_CIRCUIT,	REDSTONE, 	SILICON_CIRCUIT }
31
local ENGINEERING_PROCESSOR_RECIPE = 		{ ENGINEERING_CIRCUIT, 	REDSTONE, 	SILICON_CIRCUIT }
32
33
local RECIPES = {
34
	PRINTED_SILICON_RECIPE,
35
	PRINTED_ENGINEERING_CIRCUIT_RECIPE,
36
	PRINTED_LOGIC_CIRCUIT_RECIPE,
37
	PRINTED_CALCULATION_CIRCUIT_RECIPE,
38
	LOGIC_PROCESSOR_RECIPE,
39
	CALCULATION_PROCESSOR_RECIPE,
40
	ENGINEERING_PROCESSOR_RECIPE
41
}
42
43
local chest 	= inventory.wrap(sides.left)
44
local inscriber = inventory.wrap(sides.right)
45
local slots 	= { 1,3,2 }
46
47
local function canMake(recipe,loaded,avail)
48
	for slot,ingredient in pairs(recipe) do
49
		local isLoaded = stacksEqual(ingredient, loaded[slots[slot]])
50
		if not isLoaded then
51
			if avail[ingredient] == nil then return false end
52
		end
53
	end
54
	return true
55
end
56
57
local function canMakeSomething()
58
	local loaded = inscriber.list()
59
	local avail = chest.counts()
60
	
61
	for _,recipe in pairs(RECIPES) do
62
		if canMake(recipe,loaded,avail) then return true, recipe end
63
	end
64
	return false
65
end
66
67
local function make(recipe)
68
	for n=1,3 do
69
		local inscriberSlot	= slots[n]
70
		local ingredient 	= recipe[n]
71
		local itemInSlot 	= inscriber.item(inscriberSlot)
72
		local isLoaded 		= stacksEqual(ingredient, itemInSlot)
73
		
74
		if not isLoaded then
75
			if itemInSlot ~= ingredient and itemInSlot ~= nil then repeat chest.pull(inscriber, inscriberSlot) until inscriber.item(inscriberSlot) == nil end
76
			if ingredient ~= nil then
77
				repeat 
78
					local found, slot = chest.find(ingredient)
79
					if not found then return end
80
				until chest.push(inscriber, slot, 1, inscriberSlot)
81
			end
82
		end
83
	end
84
end
85
86
local function takeProduct()
87
	chest.pull(inscriber, 4)
88
end
89
	
90
while true do
91
	local canMake, recipe = canMakeSomething()
92
	
93
	if canMake then
94
		repeat takeProduct() until not make(recipe)
95
	end
96
	takeProduct() 
97
end