-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprotection.lua
217 lines (192 loc) · 5.66 KB
/
protection.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
215
216
--[[
Minecart
========
Copyright (C) 2019-2023 Joachim Stolberg
MIT
See license.txt for more information
]]--
local S = minecart.S
local RANGE = 8
local IsNodeUnderObservation = {}
-- Register all nodes, which should be protected by the "minecart:landmark"
function minecart.register_protected_node(name)
IsNodeUnderObservation[name] = true
end
local function landmark_found(pos, name, range)
local pos1 = {x=pos.x-range, y=pos.y-range, z=pos.z-range}
local pos2 = {x=pos.x+range, y=pos.y+range, z=pos.z+range}
for _,npos in ipairs(minetest.find_nodes_in_area(pos1, pos2, {"minecart:landmark"})) do
if minetest.get_meta(npos):get_string("owner") ~= name then
return true
end
end
return false
end
local function is_protected(pos, name, range)
if minetest.check_player_privs(name, "minecart")
or not landmark_found(pos, name, range) then
return false
end
return true
end
local old_is_protected = minetest.is_protected
function minetest.is_protected(pos, name)
if pos and name then
local node = minetest.get_node(pos)
if IsNodeUnderObservation[node.name] and is_protected(pos, name, RANGE) then
return true
end
end
return old_is_protected(pos, name)
end
minetest.register_node("minecart:landmark", {
description = S("Minecart Landmark"),
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-3/16, -8/16, -3/16, 3/16, 4/16, 3/16},
{-2/16, 4/16, -3/16, 2/16, 5/16, 3/16},
},
},
tiles = {
'default_mossycobble.png',
'default_mossycobble.png',
'default_mossycobble.png',
'default_mossycobble.png',
'default_mossycobble.png^minecart_protect.png',
'default_mossycobble.png^minecart_protect.png',
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
if is_protected(pos, placer:get_player_name(), RANGE+3) then
minetest.remove_node(pos)
return true
end
end,
can_dig = function(pos, digger)
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == digger:get_player_name() then
return true
end
if minetest.check_player_privs(digger:get_player_name(), "minecart") then
return true
end
minetest.chat_send_player(digger:get_player_name(),
S("[minecart] Area is protected!").." (owner: "..meta:get_string("owner")..")")
return false
end,
on_punch = function(pos, node, puncher, pointed_thing)
minecart.set_land_marker(pos, RANGE, 20)
end,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = minecart.CLIP,
groups = {cracky = 3, stone = 1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "minecart:landmark 6",
recipe = {
{"", "default:mossycobble", ""},
{"", "default:mossycobble", ""},
{"", "default:mossycobble", ""},
},
})
minetest.register_node("minecart:ballast", {
description = "Minecart Ballast",
tiles = {"minecart_ballast.png"},
groups = {crumbly = 1, cracky = 3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("minecart:ballast_slope", {
description = "Minecart Ballast Slope",
tiles = {"minecart_ballast.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, -8/16, -8/16, 8/16, -4/16, 8/16},
{-8/16, -4/16, -4/16, 8/16, 0/16, 8/16},
{-8/16, 0/16, 0/16, 8/16, 4/16, 8/16},
{-8/16, 4/16, 4/16, 8/16, 8/16, 8/16},
},
},
selection_box = {
type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = minecart.CLIP,
groups = {crumbly = 1, cracky = 3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("minecart:ballast_ramp", {
description = "Minecart Ballast Ramp",
tiles = {"minecart_ballast.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
{-8/16, -4/16, -4/16, 8/16, 12/16, 8/16},
{-8/16, 0/16, 0/16, 8/16, 16/16, 8/16},
{-8/16, 4/16, 4/16, 8/16, 20/16, 8/16},
},
},
selection_box = {
type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
},
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = minecart.CLIP,
groups = {crumbly = 1, cracky = 3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "minecart:ballast 6",
recipe = {
{"", "", ""},
{"default:cobble", "default:stone", "default:cobble"},
{"default:cobble", "default:stone", "default:cobble"},
},
})
minetest.register_craft({
output = "minecart:ballast_slope 6",
recipe = {
{"", "", "default:cobble"},
{"", "default:stone", "default:cobble"},
{"default:cobble", "default:stone", "default:cobble"},
},
})
minetest.register_craft({
output = "minecart:ballast_ramp 2",
recipe = {
{"", "", ""},
{"minecart:ballast_slope", "", ""},
{"minecart:ballast", "", ""},
},
})
minetest.register_privilege("minecart", {
description = S("Allow to dig/place rails in Minecart Landmark areas"),
give_to_singleplayer = false,
give_to_admin = true,
})
minecart.register_protected_node("carts:rail")
minecart.register_protected_node("carts:powerrail")
minecart.register_protected_node("carts:brakerail")
minecart.register_protected_node("minecart:buffer")
minecart.register_protected_node("minecart:ballast")
minecart.register_protected_node("minecart:ballast_slope")
minecart.register_protected_node("minecart:ballast_ramp")
minecart.register_protected_node("minecart:speed1")
minecart.register_protected_node("minecart:speed2")
minecart.register_protected_node("minecart:speed4")
minecart.register_protected_node("minecart:speed8")