commit | author | age
|
ee0765
|
1 |
-- Technic CNC v1.0 by kpoppel |
S |
2 |
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck |
|
3 |
|
|
4 |
-- Idea: |
|
5 |
-- Somehow have a tabbed/paged panel if the number of shapes should expand |
|
6 |
-- beyond what is available in the panel today. |
|
7 |
-- I could imagine some form of API allowing modders to come with their own node |
|
8 |
-- box definitions and easily stuff it in the this machine for production. |
|
9 |
|
be2f30
|
10 |
local S = technic.getter |
ee0765
|
11 |
|
83c649
|
12 |
|
S |
13 |
minetest.register_craft({ |
|
14 |
output = 'technic:cnc', |
|
15 |
recipe = { |
|
16 |
{'default:glass', 'technic:diamond_drill_head', 'default:glass'}, |
44cb8d
|
17 |
{'technic:control_logic_unit', 'technic:machine_casing', 'basic_materials:motor'}, |
83c649
|
18 |
{'technic:carbon_steel_ingot', 'technic:lv_cable', 'technic:carbon_steel_ingot'}, |
S |
19 |
}, |
|
20 |
}) |
|
21 |
|
|
22 |
|
ee0765
|
23 |
local shape = {} |
S |
24 |
local onesize_products = { |
|
25 |
slope = 2, |
|
26 |
slope_edge = 1, |
|
27 |
slope_inner_edge = 1, |
|
28 |
pyramid = 2, |
|
29 |
spike = 1, |
|
30 |
cylinder = 2, |
cf7591
|
31 |
oblate_spheroid = 1, |
ee0765
|
32 |
sphere = 1, |
S |
33 |
stick = 8, |
|
34 |
slope_upsdown = 2, |
|
35 |
slope_edge_upsdown = 1, |
|
36 |
slope_inner_edge_upsdown = 1, |
|
37 |
cylinder_horizontal = 2, |
|
38 |
slope_lying = 2, |
|
39 |
onecurvededge = 1, |
|
40 |
twocurvededge = 1, |
|
41 |
} |
|
42 |
local twosize_products = { |
|
43 |
element_straight = 4, |
|
44 |
element_end = 2, |
|
45 |
element_cross = 1, |
|
46 |
element_t = 1, |
|
47 |
element_edge = 2, |
|
48 |
} |
|
49 |
|
|
50 |
local cnc_formspec = |
fb9338
|
51 |
"size[9,11;]".. |
39c41a
|
52 |
"label[1,0;"..S("Choose Milling Program:").."]".. |
ee0765
|
53 |
"image_button[1,0.5;1,1;technic_cnc_slope.png;slope; ]".. |
S |
54 |
"image_button[2,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]".. |
|
55 |
"image_button[3,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]".. |
|
56 |
"image_button[4,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]".. |
|
57 |
"image_button[5,0.5;1,1;technic_cnc_spike.png;spike; ]".. |
|
58 |
"image_button[6,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]".. |
cf7591
|
59 |
"image_button[7,0.5;1,1;technic_cnc_oblate_spheroid.png;oblate_spheroid; ]".. |
ee0765
|
60 |
"image_button[8,0.5;1,1;technic_cnc_stick.png;stick; ]".. |
S |
61 |
|
|
62 |
"image_button[1,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdown; ]".. |
|
63 |
"image_button[2,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_edge_upsdown; ]".. |
|
64 |
"image_button[3,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_inner_edge_upsdown; ]".. |
|
65 |
"image_button[4,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]".. |
cf7591
|
66 |
"image_button[5,1.5;1,1;technic_cnc_sphere.png;sphere; ]".. |
ee0765
|
67 |
|
S |
68 |
"image_button[1,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]".. |
|
69 |
"image_button[2,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]".. |
|
70 |
"image_button[3,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]".. |
|
71 |
|
39c41a
|
72 |
"label[1,3.5;"..S("Slim Elements half / normal height:").."]".. |
ee0765
|
73 |
|
S |
74 |
"image_button[1,4;1,0.5;technic_cnc_full.png;full; ]".. |
|
75 |
"image_button[1,4.5;1,0.5;technic_cnc_half.png;half; ]".. |
|
76 |
"image_button[2,4;1,1;technic_cnc_element_straight.png;element_straight; ]".. |
|
77 |
"image_button[3,4;1,1;technic_cnc_element_end.png;element_end; ]".. |
|
78 |
"image_button[4,4;1,1;technic_cnc_element_cross.png;element_cross; ]".. |
|
79 |
"image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]".. |
|
80 |
"image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]".. |
|
81 |
|
39c41a
|
82 |
"label[0, 5.5;"..S("In:").."]".. |
ee0765
|
83 |
"list[current_name;src;0.5,5.5;1,1;]".. |
39c41a
|
84 |
"label[4, 5.5;"..S("Out:").."]".. |
ee0765
|
85 |
"list[current_name;dst;5,5.5;4,1;]".. |
S |
86 |
|
54b6d9
|
87 |
"list[current_player;main;0,7;8,4;]".. |
d732c8
|
88 |
"listring[current_name;dst]".. |
E |
89 |
"listring[current_player;main]".. |
|
90 |
"listring[current_name;src]".. |
|
91 |
"listring[current_player;main]" |
ee0765
|
92 |
|
S |
93 |
local size = 1; |
|
94 |
|
|
95 |
-- The form handler is declared here because we need it in both the inactive and active modes |
|
96 |
-- in order to be able to change programs wile it is running. |
|
97 |
local function form_handler(pos, formname, fields, sender) |
|
98 |
-- REGISTER MILLING PROGRAMS AND OUTPUTS: |
|
99 |
------------------------------------------ |
|
100 |
-- Program for half/full size |
|
101 |
if fields["full"] then |
|
102 |
size = 1 |
|
103 |
return |
|
104 |
end |
|
105 |
|
|
106 |
if fields["half"] then |
|
107 |
size = 2 |
|
108 |
return |
|
109 |
end |
|
110 |
|
|
111 |
-- Resolve the node name and the number of items to make |
|
112 |
local meta = minetest.get_meta(pos) |
|
113 |
local inv = meta:get_inventory() |
|
114 |
local inputstack = inv:get_stack("src", 1) |
|
115 |
local inputname = inputstack:get_name() |
|
116 |
local multiplier = 0 |
|
117 |
for k, _ in pairs(fields) do |
|
118 |
-- Set a multipier for the half/full size capable blocks |
|
119 |
if twosize_products[k] ~= nil then |
|
120 |
multiplier = size * twosize_products[k] |
|
121 |
else |
|
122 |
multiplier = onesize_products[k] |
|
123 |
end |
|
124 |
|
|
125 |
if onesize_products[k] ~= nil or twosize_products[k] ~= nil then |
|
126 |
meta:set_float( "cnc_multiplier", multiplier) |
|
127 |
meta:set_string("cnc_user", sender:get_player_name()) |
|
128 |
end |
|
129 |
|
|
130 |
if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then |
|
131 |
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) |
|
132 |
--print(inputname .. "_technic_cnc_" .. k) |
|
133 |
break |
|
134 |
end |
|
135 |
|
|
136 |
if twosize_products[k] ~= nil and size==1 then |
|
137 |
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") |
|
138 |
--print(inputname .. "_technic_cnc_" .. k .. "_double") |
|
139 |
break |
|
140 |
end |
|
141 |
end |
|
142 |
return |
|
143 |
end |
|
144 |
|
563a4c
|
145 |
-- Action code performing the transformation |
N |
146 |
local run = function(pos, node) |
|
147 |
local meta = minetest.get_meta(pos) |
|
148 |
local inv = meta:get_inventory() |
|
149 |
local eu_input = meta:get_int("LV_EU_input") |
|
150 |
local machine_name = S("%s CNC Machine"):format("LV") |
|
151 |
local machine_node = "technic:cnc" |
|
152 |
local demand = 450 |
|
153 |
|
|
154 |
local result = meta:get_string("cnc_product") |
54b6d9
|
155 |
if inv:is_empty("src") or |
563a4c
|
156 |
(not minetest.registered_nodes[result]) or |
N |
157 |
(not inv:room_for_item("dst", result)) then |
|
158 |
technic.swap_node(pos, machine_node) |
|
159 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
|
160 |
meta:set_string("cnc_product", "") |
|
161 |
meta:set_int("LV_EU_demand", 0) |
|
162 |
return |
|
163 |
end |
|
164 |
|
|
165 |
if eu_input < demand then |
|
166 |
technic.swap_node(pos, machine_node) |
|
167 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) |
|
168 |
elseif eu_input >= demand then |
|
169 |
technic.swap_node(pos, machine_node.."_active") |
|
170 |
meta:set_string("infotext", S("%s Active"):format(machine_name)) |
|
171 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
|
172 |
if meta:get_int("src_time") >= 3 then -- 3 ticks per output |
|
173 |
meta:set_int("src_time", 0) |
|
174 |
srcstack = inv:get_stack("src", 1) |
|
175 |
srcstack:take_item() |
|
176 |
inv:set_stack("src", 1, srcstack) |
|
177 |
inv:add_item("dst", result.." "..meta:get_int("cnc_multiplier")) |
|
178 |
end |
|
179 |
end |
|
180 |
meta:set_int("LV_EU_demand", demand) |
|
181 |
end |
|
182 |
|
ee0765
|
183 |
-- The actual block inactive state |
S |
184 |
minetest.register_node("technic:cnc", { |
7c4b70
|
185 |
description = S("%s CNC Machine"):format("LV"), |
ee0765
|
186 |
tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", |
S |
187 |
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, |
83c649
|
188 |
groups = {cracky=2, technic_machine=1, technic_lv=1}, |
S |
189 |
connect_sides = {"bottom", "back", "left", "right"}, |
ee0765
|
190 |
paramtype2 = "facedir", |
S |
191 |
legacy_facedir_simple = true, |
|
192 |
on_construct = function(pos) |
|
193 |
local meta = minetest.get_meta(pos) |
7c4b70
|
194 |
meta:set_string("infotext", S("%s CNC Machine"):format("LV")) |
ee0765
|
195 |
meta:set_float("technic_power_machine", 1) |
S |
196 |
meta:set_string("formspec", cnc_formspec) |
|
197 |
local inv = meta:get_inventory() |
|
198 |
inv:set_size("src", 1) |
|
199 |
inv:set_size("dst", 4) |
|
200 |
end, |
0809dd
|
201 |
can_dig = technic.machine_can_dig, |
S |
202 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
203 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
204 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
205 |
on_receive_fields = form_handler, |
563a4c
|
206 |
technic_run = run, |
ee0765
|
207 |
}) |
S |
208 |
|
|
209 |
-- Active state block |
|
210 |
minetest.register_node("technic:cnc_active", { |
7c4b70
|
211 |
description = S("%s CNC Machine"):format("LV"), |
ee0765
|
212 |
tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png", |
S |
213 |
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, |
83c649
|
214 |
groups = {cracky=2, technic_machine=1, technic_lv=1, not_in_creative_inventory=1}, |
S |
215 |
connect_sides = {"bottom", "back", "left", "right"}, |
ee0765
|
216 |
paramtype2 = "facedir", |
f50417
|
217 |
drop = "technic:cnc", |
ee0765
|
218 |
legacy_facedir_simple = true, |
0809dd
|
219 |
can_dig = technic.machine_can_dig, |
S |
220 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
221 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
222 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
223 |
on_receive_fields = form_handler, |
563a4c
|
224 |
technic_run = run, |
N |
225 |
technic_disabled_machine_name = "technic:cnc", |
ee0765
|
226 |
}) |
S |
227 |
|
|
228 |
technic.register_machine("LV", "technic:cnc", technic.receiver) |
|
229 |
technic.register_machine("LV", "technic:cnc_active", technic.receiver) |
|
230 |
|