-
Notifications
You must be signed in to change notification settings - Fork 20
/
nodes_barrel.lua
214 lines (185 loc) · 8.61 KB
/
nodes_barrel.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---------------------------------------------------------------------
-- a barrel and a tub - plus a function that makes 'round' objects
---------------------------------------------------------------------
-- IMPORTANT NOTE: The barrel requires a lot of nodeboxes. That may be
-- too much for weak hardware!
---------------------------------------------------------------------
-- Functionality: right-click to open/close a barrel;
-- punch a barrel to change between vertical/horizontal
---------------------------------------------------------------------
-- Changelog:
-- 24.03.13 Can no longer be opended/closed on rightclick because that is now used for a formspec;
-- instead, it can be filled with liquids.
-- Filled barrels will always be closed, while empty barrels will always be open.
-- pipes: table with the following entries for each pipe-part:
-- f: radius factor; if 1, it will have a radius of half a nodebox and fill the entire nodebox
-- h1, h2: height at witch the nodebox shall start and end; usually -0.5 and 0.5 for a full nodebox
-- b: make a horizontal part/shelf
-- horizontal: if 1, then x and y coordinates will be swapped
-- TODO: option so that it works without nodeboxes
local S = cottages.S
barrel = {};
-- prepare formspec
barrel.on_construct = function( pos )
local meta = minetest.get_meta(pos);
local percent = math.random( 1, 100 ); -- TODO: show real filling
meta:set_string( 'formspec',
"size[8,9]"..
"image[2.6,2;2,3;default_sandstone.png^[lowpart:"..
(100-percent)..":default_desert_stone.png]".. -- TODO: better images
"label[2.2,0;"..S("Pour:").."]"..
"list[current_name;input;3,0.5;1,1;]"..
"label[5,3.3;"..S("Fill:").."]"..
"list[current_name;output;5,3.8;1,1;]"..
"list[current_player;main;0,5;8,4;]");
meta:set_string( 'liquid_type', '' ); -- which liquid is in the barrel?
meta:set_int( 'liquid_level', 0 ); -- how much of the liquid is in there?
local inv = meta:get_inventory()
inv:set_size("input", 1); -- to fill in new liquid
inv:set_size("output", 1); -- to extract liquid
end
-- can only be digged if there are no more vessels/buckets in any of the slots
-- TODO: allow digging of a filled barrel? this would disallow stacking of them
barrel.can_dig = function( pos, player )
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return ( inv:is_empty('input')
and inv:is_empty('output'));
end
-- the barrel received input; either a new liquid that is to be poured in or a vessel that is to be filled
barrel.on_metadata_inventory_put = function( pos, listname, index, stack, player )
end
-- right-click to open/close barrel; punch to switch between horizontal/vertical position
minetest.register_node("cottages:barrel", {
description = S("barrel (closed)"),
paramtype = "light",
drawtype = "mesh",
mesh = "cottages_barrel_closed.obj",
tiles = {"cottages_barrel.png" },
groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
},
drop = "cottages:barrel",
-- on_rightclick = function(pos, node, puncher)
-- minetest.add_node(pos, {name = "cottages:barrel_open", param2 = node.param2})
-- end,
-- TODO: on_rightclick is no longer available - maybe open if empty and closed if full?
on_punch = function(pos, node, puncher)
minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = node.param2})
end,
on_construct = function( pos )
return barrel.on_construct( pos );
end,
can_dig = function(pos,player)
return barrel.can_dig( pos, player );
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
return barrel.on_metadata_inventory_put( pos, listname, index, stack, player );
end,
is_ground_content = false,
})
-- this barrel is opened at the top
minetest.register_node("cottages:barrel_open", {
description = S("barrel (open)"),
paramtype = "light",
drawtype = "mesh",
mesh = "cottages_barrel.obj",
tiles = {"cottages_barrel.png" },
groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
},
drop = "cottages:barrel",
-- on_rightclick = function(pos, node, puncher)
-- minetest.add_node(pos, {name = "cottages:barrel", param2 = node.param2})
-- end,
on_punch = function(pos, node, puncher)
minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = node.param2})
end,
is_ground_content = false,
})
-- horizontal barrel
minetest.register_node("cottages:barrel_lying", {
description = S("barrel (closed), lying somewhere"),
paramtype = "light",
paramtype2 = "facedir",
drawtype = "mesh",
mesh = "cottages_barrel_closed_lying.obj",
tiles = {"cottages_barrel.png" },
groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
},
drop = "cottages:barrel",
on_rightclick = function(pos, node, puncher)
minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = node.param2})
end,
on_punch = function(pos, node, puncher)
if( node.param2 < 4 ) then
minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = (node.param2+1)})
else
minetest.add_node(pos, {name = "cottages:barrel", param2 = 0})
end
end,
is_ground_content = false,
})
-- horizontal barrel, open
minetest.register_node("cottages:barrel_lying_open", {
description = S("barrel (opened), lying somewhere"),
paramtype = "light",
paramtype2 = "facedir",
drawtype = "mesh",
mesh = "cottages_barrel_lying.obj",
tiles = {"cottages_barrel.png" },
groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
},
drop = "cottages:barrel",
on_rightclick = function(pos, node, puncher)
minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = node.param2})
end,
on_punch = function(pos, node, puncher)
if( node.param2 < 4 ) then
minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = (node.param2+1)})
else
minetest.add_node(pos, {name = "cottages:barrel_open", param2 = 0})
end
end,
is_ground_content = false,
})
-- let's hope "tub" is the correct english word for "bottich"
minetest.register_node("cottages:tub", {
description = S("tub"),
paramtype = "light",
drawtype = "mesh",
mesh = "cottages_tub.obj",
tiles = {"cottages_barrel.png" },
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5,-0.1, 0.5},
}},
collision_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5,-0.1, 0.5},
}},
groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
},
is_ground_content = false,
})
minetest.register_craft({
output = "cottages:barrel",
recipe = {
{cottages.craftitem_wood, "", cottages.craftitem_wood },
{cottages.craftitem_steel, "", cottages.craftitem_steel},
{cottages.craftitem_wood, cottages.craftitem_wood, cottages.craftitem_wood },
},
})
minetest.register_craft({
output = "cottages:tub 2",
recipe = {
{"cottages:barrel"},
},
})
minetest.register_craft({
output = "cottages:barrel",
recipe = {
{"cottages:tub"},
{"cottages:tub"},
},
})