-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
174 lines (151 loc) · 5.17 KB
/
init.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
pushbox = {}
pushbox.GOAL_NODE = 'default:mese';
minetest.register_node("pushbox:glass", {
description = "Glass cover",
drawtype = "glasslike_framed_optional",
tiles = {"default_obsidian_glass.png"},
paramtype = "light",
is_ground_content = false,
sunlight_propagates = true,
sounds = default.node_sound_glass_defaults(),
groups = {cracky=3,oddly_breakable_by_hand=3},
})
pushbox.push_crate = function( pos, node, puncher, allow_diagonal, allow_pull, dir )
if( not( pos ) or not( node ) or not( puncher )) then
return;
end
-- only punching with a normal stick is supposed to work
local wielded = puncher:get_wielded_item();
if( wielded:get_name() ~= "") then
minetest.chat_send_player( name, 'You need empty hands in order to handle this crate!');
return;
end
local name = puncher:get_player_name();
local ppos = puncher:getpos();
if( ppos.y ~= pos.y-0.5 ) then
minetest.chat_send_player( name, 'You need to be on the same ground level as the crate in order to be strong enough to move it.');
return;
end
local xr = pos.x - ppos.x;
local zr = pos.z - ppos.z;
if( math.abs( xr ) > 1.5 or math.abs( zr ) > 1.5) then
minetest.chat_send_player( name, 'You are too far away to handle the crate!');
return;
end
if( not( allow_diagonal ) and math.abs( xr ) > 0.5 and math.abs( zr ) > 0.5 ) then
minetest.chat_send_player( name, 'The crate cannot be moved diagonally.');
return;
end
local tpos = {x=pos.x, y=pos.y, z=pos.z};
if( math.abs( xr ) > 0.5 ) then
if( xr < 0 ) then
tpos.x = tpos.x - (1.0*dir);
else
tpos.x = tpos.x + (1.0*dir);
end
end
if( math.abs( zr ) > 0.5 ) then
if( zr < 0 ) then
tpos.z = tpos.z - (1.0*dir);
else
tpos.z = tpos.z + (1.0*dir);
end
end
local tnode = minetest.get_node( tpos );
local target_is_liquid = false;
if( tnode and tnode.name and tnode.name ~= 'air') then
if( tnode and tnode.name
and minetest.registered_nodes[ tnode.name ]
and minetest.registered_nodes[ tnode.name ].groups
and minetest.registered_nodes[ tnode.name ].groups.liquid
and minetest.registered_nodes[ tnode.name ].groups.liquid > 0 ) then
target_is_liquid = true;
else
minetest.chat_send_player( name, 'You push and push, but there is no space for the crate.');
return;
end
end
local node_below = minetest.get_node( {x=tpos.x, y=tpos.y-1, z=tpos.z});
if( not( node_below ) or not( node_below.name ) or node_below.name == 'air') then
-- TODO: start falling down
return;
end
if( minetest.registered_nodes[ node_below.name ]
and minetest.registered_nodes[ node_below.name ].groups
and minetest.registered_nodes[ node_below.name ].groups.liquid
and minetest.registered_nodes[ node_below.name ].groups.liquid > 0 ) then
-- sink one down
tpos.y = tpos.y - 1;
end
-- the goal is marked by mese; indicate if the box is located on a goal marker
if( node.name == 'pushbox:box_on_goal' or node.name == 'pushbox:box' ) then
if( node_below.name == pushbox.GOAL_NODE ) then
node.name = 'pushbox:box_on_goal';
-- TODO: check if ALL boxes are on their goal marker
else
node.name = 'pushbox:box';
end
end
minetest.set_node( pos, {name='air'});
-- TODO: update the old position
minetest.add_node( tpos, node );
-- let the player follow the chest
pos.y = pos.y-0.5;
-- puncher:moveto( pos, true );
end
-- TODO: use after_place_node to make sure that placed crates light up if needed
-- TODO: add a reset button for the boxes (store where each came from?)
-- TODO: read the game format files
minetest.register_node("pushbox:box", {
description = "Pushable Crate",
tiles = {"darkage_box.png"},
groups = {cracky=2, falling_node=1},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher)
return pushbox.push_crate( pos, node, puncher, false, false, 1 );
end,
})
minetest.register_node("pushbox:box_on_goal", {
description = "Pushable Crate on goal",
tiles = {"darkage_box.png^default_mese_crystal.png"},
groups = {cracky=2, falling_node=1},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher)
return pushbox.push_crate( pos, node, puncher, false, false, 1 );
end,
paramtype = "light",
light_source = 15,
})
minetest.register_node("pushbox:box_small", {
description = "Moveable Crate",
tiles = {"darkage_box.png^default_stick.png"},
groups = {cracky=2, falling_node=1},
on_punch = function(pos, node, puncher)
return pushbox.push_crate( pos, node, puncher, true, false, 1 );
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return pushbox.push_crate( pos, node, clicker, true, true, -1 );
end,
drawtype = "nodebox",
paramtype = "light",
groups = {cracky=2, falling_node=1},
sounds = default.node_sound_wood_defaults(),
-- the bale is slightly smaller than a full node
node_box = {
type = "fixed",
fixed = {
{-0.45, -0.45,-0.45, 0.45, 0.45, 0.45},
{-0.40, -0.55,-0.40, -0.35, -0.45,-0.30},
{ 0.35, -0.55, 0.30, 0.40, -0.45, 0.40},
{-0.40, -0.55, 0.30, -0.35, -0.45, 0.40},
{ 0.35, -0.55,-0.40, 0.40, -0.45,-0.30},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.45, -0.45,-0.45, 0.45, 0.45, 0.45},
}
},
is_ground_content = false,
})