commit | author | age
|
82cba9
|
1 |
|
354ee6
|
2 |
local S = technic.getter |
S |
3 |
|
14b30b
|
4 |
local function deploy_node(inv, slot_name, pos, node, machine_node) |
e65c8b
|
5 |
if node.param2 > 3 then return end |
14b30b
|
6 |
if node.name ~= "air" then |
S |
7 |
if node.name == "ignore" or |
|
8 |
node.name == "default:lava_source" or |
|
9 |
node.name == "default:lava_flowing" or |
|
10 |
node.name == "default:water_source" or |
|
11 |
node.name == "default:water_flowing" then |
|
12 |
return |
|
13 |
end |
|
14 |
local drops = minetest.get_node_drops(node.name, "") |
|
15 |
local remove_to = false |
|
16 |
for i, item in ipairs(drops) do |
|
17 |
if not inv:room_for_item(slot_name, item) then |
|
18 |
remove_to = i - 1 |
|
19 |
break |
|
20 |
end |
|
21 |
inv:add_item(slot_name, item) |
|
22 |
end |
|
23 |
if remove_to then |
|
24 |
for i = 1, remove_to do |
186f9b
|
25 |
inv:remove_item(slot_name, drops[i]) |
14b30b
|
26 |
end |
S |
27 |
else |
|
28 |
minetest.remove_node(pos) |
|
29 |
end |
|
30 |
return |
|
31 |
end |
|
32 |
if not inv:is_empty(slot_name) then |
|
33 |
local stack = inv:get_list(slot_name)[1] |
|
34 |
local def = stack:get_definition() |
|
35 |
if def.type == "node" then |
|
36 |
minetest.set_node(pos, { |
|
37 |
name = stack:get_name(), |
|
38 |
param2 = machine_node.param2 |
|
39 |
}) |
|
40 |
stack:take_item() |
|
41 |
inv:set_stack(slot_name, 1, stack) |
|
42 |
elseif def.type == "craft" then |
|
43 |
if def.on_place then |
|
44 |
-- Use pcall to avoid nil placer errors. |
|
45 |
-- TODO: Do without pcall. |
|
46 |
local ok, stk = pcall(def.on_place, stack, nil, { |
018b24
|
47 |
-- Fake pointed_thing |
VE |
48 |
type = "node", |
14b30b
|
49 |
above = pos, |
S |
50 |
under = {x=pos.x, y=pos.y-1, z=pos.z}, |
018b24
|
51 |
}) |
14b30b
|
52 |
if ok then |
S |
53 |
inv:set_stack(slot_name, 1, stk or stack) |
|
54 |
return |
018b24
|
55 |
end |
VE |
56 |
end |
14b30b
|
57 |
minetest.item_place_object(stack, nil, { |
S |
58 |
-- Fake pointed_thing |
|
59 |
type = "node", |
|
60 |
above = pos, |
|
61 |
under = pos, |
|
62 |
}) |
|
63 |
inv:set_stack(slot_name, 1, nil) |
018b24
|
64 |
end |
VE |
65 |
end |
|
66 |
end |
|
67 |
|
82cba9
|
68 |
minetest.register_craft({ |
R |
69 |
type = "shapeless", |
|
70 |
output = 'technic:constructor_mk1_off 1', |
|
71 |
recipe = {'technic:nodebreaker_off', 'technic:deployer_off'}, |
|
72 |
|
|
73 |
}) |
|
74 |
minetest.register_craft({ |
|
75 |
type = "shapeless", |
|
76 |
output = 'technic:constructor_mk2_off 1', |
|
77 |
recipe = {'technic:constructor_mk1_off', 'technic:constructor_mk1_off'}, |
|
78 |
|
|
79 |
}) |
|
80 |
|
|
81 |
minetest.register_craft({ |
|
82 |
type = "shapeless", |
|
83 |
output = 'technic:constructor_mk3_off 1', |
|
84 |
recipe = {'technic:constructor_mk2_off', 'technic:constructor_mk2_off'}, |
|
85 |
|
|
86 |
}) |
|
87 |
|
14b30b
|
88 |
local function make_on(mark, length) |
S |
89 |
return function(pos, node) |
ee0765
|
90 |
local meta = minetest.get_meta(pos) |
82cba9
|
91 |
local inv = meta:get_inventory() |
14b30b
|
92 |
local dir = vector.new() |
S |
93 |
if node.param2 == 3 then dir.x = 1 end |
|
94 |
if node.param2 == 2 then dir.z = 1 end |
|
95 |
if node.param2 == 1 then dir.x = -1 end |
|
96 |
if node.param2 == 0 then dir.z = -1 end |
82cba9
|
97 |
|
14b30b
|
98 |
local place_pos = vector.new(pos) |
82cba9
|
99 |
|
14b30b
|
100 |
if node.name == "technic:constructor_mk"..mark.."_off" then |
S |
101 |
technic.swap_node(pos, "technic:constructor_mk"..mark.."_on") |
0fcc7a
|
102 |
minetest.check_for_falling(pos) |
14b30b
|
103 |
for i = 1, length do |
S |
104 |
place_pos = vector.add(place_pos, dir) |
|
105 |
local place_node = minetest.get_node(place_pos) |
|
106 |
deploy_node(inv, "slot"..i, place_pos, place_node, node) |
|
107 |
end |
|
108 |
end |
82cba9
|
109 |
end |
R |
110 |
end |
|
111 |
|
14b30b
|
112 |
local function make_off(mark) |
S |
113 |
return function(pos, node) |
|
114 |
if node.name == "technic:constructor_mk"..mark.."_on" then |
|
115 |
technic.swap_node(pos,"technic:constructor_mk"..mark.."_off") |
0fcc7a
|
116 |
minetest.check_for_falling(pos) |
14b30b
|
117 |
end |
82cba9
|
118 |
end |
R |
119 |
end |
|
120 |
|
bb05ff
|
121 |
local function allow_inventory_put(pos, listname, index, stack, player) |
C |
122 |
if stack and minetest.get_item_group(stack:get_name(), "technic_constructor") == 1 then |
|
123 |
return 0 |
|
124 |
end |
|
125 |
return technic.machine_inventory_put(pos, listname, index, stack, player) |
|
126 |
end |
82cba9
|
127 |
|
14b30b
|
128 |
local function make_constructor(mark, length) |
S |
129 |
minetest.register_node("technic:constructor_mk"..mark.."_off", { |
|
130 |
description = S("Constructor Mk%d"):format(mark), |
|
131 |
tiles = {"technic_constructor_mk"..mark.."_top_off.png", |
|
132 |
"technic_constructor_mk"..mark.."_bottom_off.png", |
|
133 |
"technic_constructor_mk"..mark.."_side2_off.png", |
|
134 |
"technic_constructor_mk"..mark.."_side1_off.png", |
|
135 |
"technic_constructor_back.png", |
|
136 |
"technic_constructor_front_off.png"}, |
|
137 |
paramtype2 = "facedir", |
bb05ff
|
138 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
C |
139 |
mesecon = 2, technic_constructor = 1}, |
14b30b
|
140 |
mesecons = {effector = {action_on = make_on(mark, length)}}, |
S |
141 |
sounds = default.node_sound_stone_defaults(), |
|
142 |
on_construct = function(pos) |
|
143 |
local meta = minetest.get_meta(pos) |
|
144 |
local formspec = "size[8,9;]".. |
|
145 |
"label[0,0;"..S("Constructor Mk%d"):format(mark).."]".. |
|
146 |
"list[current_player;main;0,5;8,4;]" |
|
147 |
for i = 1, length do |
|
148 |
formspec = formspec |
|
149 |
.."label[5,"..(i - 1)..";"..S("Slot %d"):format(i).."]" |
|
150 |
.."list[current_name;slot"..i |
|
151 |
..";6,"..(i - 1)..";1,1;]" |
|
152 |
end |
|
153 |
meta:set_string("formspec", formspec) |
|
154 |
meta:set_string("infotext", S("Constructor Mk%d"):format(mark)) |
|
155 |
local inv = meta:get_inventory() |
|
156 |
for i = 1, length do |
|
157 |
inv:set_size("slot"..i, 1) |
|
158 |
end |
|
159 |
end, |
|
160 |
can_dig = function(pos, player) |
|
161 |
local meta = minetest.get_meta(pos) |
|
162 |
local inv = meta:get_inventory() |
|
163 |
for i = 1, length do |
|
164 |
if not inv:is_empty("slot"..i) then |
|
165 |
return false |
|
166 |
end |
|
167 |
end |
|
168 |
return true |
|
169 |
end, |
bb05ff
|
170 |
allow_metadata_inventory_put = allow_inventory_put, |
14b30b
|
171 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
S |
172 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
e65c8b
|
173 |
on_rotate = screwdriver.rotate_simple |
14b30b
|
174 |
}) |
82cba9
|
175 |
|
14b30b
|
176 |
minetest.register_node("technic:constructor_mk"..mark.."_on", { |
S |
177 |
tiles = {"technic_constructor_mk"..mark.."_top_on.png", |
|
178 |
"technic_constructor_mk"..mark.."_bottom_on.png", |
|
179 |
"technic_constructor_mk"..mark.."_side2_on.png", |
|
180 |
"technic_constructor_mk"..mark.."_side1_on.png", |
|
181 |
"technic_constructor_back.png", |
|
182 |
"technic_constructor_front_on.png"}, |
|
183 |
paramtype2 = "facedir", |
|
184 |
drop = "technic:constructor_mk"..mark.."_off", |
|
185 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
bb05ff
|
186 |
mesecon=2, not_in_creative_inventory=1, technic_constructor=1}, |
14b30b
|
187 |
mesecons= {effector = {action_off = make_off(mark)}}, |
S |
188 |
sounds = default.node_sound_stone_defaults(), |
bb05ff
|
189 |
allow_metadata_inventory_put = allow_inventory_put, |
14b30b
|
190 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
S |
191 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
e65c8b
|
192 |
on_rotate = false |
14b30b
|
193 |
}) |
82cba9
|
194 |
end |
R |
195 |
|
14b30b
|
196 |
make_constructor(1, 1) |
S |
197 |
make_constructor(2, 2) |
|
198 |
make_constructor(3, 4) |
82cba9
|
199 |
|