-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
119 lines (113 loc) · 3.69 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
minetest.register_node("barrier:barrier", {
description = "Barrier",
drawtype = "airlike",
tiles = {""},
alpha = 0,
paramtype = "light",
light_source = 0,
use_texture_alpha = true,
sunlight_propagates = true,
walkable = true,
pointable = false,
buildable_to = true,
drop = "",
groups = {
invisible = 1,
level = 1,
not_in_creative_inventory = 1
},
on_construct = function(pos) end,
can_dig = function(pos, player)
local wielded_item = player:get_wielded_item():get_name()
return wielded_item == "barrier:barrier_item"
end,
sounds = {
footstep = {name = "", gain = 0},
dig = {name = "default_dig_cracky", gain = 1},
dug = {name = "default_break_glass", gain = 1},
place = {name = "", gain = 0},
},
on_blast = function() end
})
minetest.register_tool("barrier:barrier_item", {
description = "Barrier",
inventory_image = "barrier_barrier.png",
liquids_pointable = true,
tool_capabilities = {
full_punch_interval = 0.9,
groupcaps={
invisible = {times={[1]=0.25}, uses=0, maxlevel=1},
cracky = {times={[0]=5.0}, uses=0, maxlevel=0},
snappy = {times={[0]=5.0}, uses=0, maxlevel=0},
crumbly = {times={[0]=5.0}, uses=0, maxlevel=0},
choppy = {times={[0]=5.0}, uses=0, maxlevel=0},
fleshy = {times={[0]=5.0}, uses=0, maxlevel=0},
oddly_breakable_by_hand = {times={[0]=5.0}, uses=0, maxlevel=0},
},
},
pointabilities = {
nodes = {
["barrier:barrier"] = true,
}
},
on_place = function(itemstack, placer, pointed_thing)
-- if the pointed_thing is not a node, return the itemstack
if pointed_thing.type ~= "node" then
return itemstack
end
local pos = pointed_thing.above
local node = minetest.get_node(pos)
-- if the node is not air, return the itemstack
if node.name ~= "air" then
return itemstack
end
minetest.set_node(pos, {name = "barrier:barrier"})
minetest.add_particle({
pos = pos,
velocity = {x = 0, y = 0, z = 0},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = 1.05,
size = 8,
collisiondetection = false,
vertical = false,
texture = "barrier_barrier.png",
glow = 5,
playername = placer:get_player_name()
})
return itemstack
end,
})
local function show_barriers(nodes, player)
if not nodes or #nodes == 0 then return end
for n = 1, #nodes do
minetest.add_particle({
pos = nodes[n],
velocity = {x = 0, y = 0, z = 0},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = 1.05,
size = 8,
collisiondetection = false,
vertical = false,
texture = "barrier_barrier.png",
glow = 5,
playername = player:get_player_name()
})
end
end
local function cyclic_update()
for _, player in ipairs(minetest.get_connected_players()) do
local wielded_item = player:get_wielded_item():get_name()
if wielded_item == "barrier:barrier_item" then
local pos = player:get_pos()
local radius = 10
local nodes = minetest.find_nodes_in_area(
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
{x = pos.x + radius, y = pos.y + radius, z = pos.z + radius},
{"barrier:barrier"}
)
show_barriers(nodes, player)
end
end
minetest.after(1, cyclic_update)
end
minetest.after(1, cyclic_update)