-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrobot.lua
145 lines (132 loc) · 3.74 KB
/
robot.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
--[[
Signs Bot
=========
Copyright (C) 2019-2023 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Signs Bot: The Robot itself
]]--
local lib = signs_bot.lib
local enable_LBM = minetest.settings:get_bool("signs_bot_enable_LBM") == true
-- Called when robot is started
function signs_bot.place_robot(pos1, pos2, param2)
local node1 = tubelib2.get_node_lvm(pos1)
local node2 = tubelib2.get_node_lvm(pos2)
if lib.check_pos(pos1, node1, node2, param2) then
minetest.set_node(pos1, {name = "signs_bot:robot", param2 = param2})
end
end
-- Called when robot is removed
function signs_bot.remove_robot(mem)
local pos = mem.robot_pos
local node = tubelib2.get_node_lvm(pos)
if node.name == "signs_bot:robot" then
minetest.remove_node(pos)
local pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
node = tubelib2.get_node_lvm(pos1)
if node.name == "signs_bot:robot_foot" or node.name == "signs_bot:robot_leg" then
if node.name == "signs_bot:robot_foot" then
minetest.swap_node(pos1, mem.stored_node or {name = "air"})
else
minetest.remove_node(pos1)
end
pos1 = {x=pos.x, y=pos.y-2, z=pos.z}
node = tubelib2.get_node_lvm(pos1)
if node.name == "signs_bot:robot_foot" then
minetest.swap_node(pos1, mem.stored_node or {name = "air"})
end
else
minetest.swap_node(pos, mem.stored_node or {name = "air"})
end
end
end
minetest.register_node("signs_bot:robot", {
-- up, down, right, left, back, front
tiles = {
"signs_bot_robot_top.png",
"signs_bot_robot_bottom.png",
"signs_bot_robot_right.png",
"signs_bot_robot_left.png",
"signs_bot_robot_front.png",
"signs_bot_robot_back.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/16, 3/16, -5/16, 5/16, 8/16, 5/16},
{ -3/16, 2/16, -3/16, 3/16, 3/16, 3/16},
{ -6/16, -7/16, -6/16, 6/16, 2/16, 6/16},
{ -6/16, -8/16, -3/16, 6/16, -7/16, 3/16},
},
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = signs_bot.CLIP,
sunlight_propagates = true,
is_ground_content = false,
drop = "",
groups = {cracky=1, not_in_creative_inventory = 1,
plant = 1, -- prevents the transformation from wet soil to soil
},
sounds = default.node_sound_metal_defaults(),
})
minetest.register_node("signs_bot:robot_leg", {
tiles = {"signs_bot_robot.png^[transformR90]"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/8, -4/8, -1/8, 1/8, 4/8, 1/8},
},
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = signs_bot.CLIP,
sunlight_propagates = true,
is_ground_content = false,
drop = "",
groups = {cracky=1, not_in_creative_inventory = 1},
sounds = default.node_sound_metal_defaults(),
})
minetest.register_node("signs_bot:robot_foot", {
tiles = {"signs_bot_robot.png^[transformR90]"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/8, -4/8, -1/8, 1/8, 4/8, 1/8},
{ -2/8, -4/8, -2/8, 2/8, -3/8, 2/8},
},
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = signs_bot.CLIP,
sunlight_propagates = true,
is_ground_content = false,
drop = "",
groups = {cracky=1, not_in_creative_inventory = 1,
plant = 1, -- prevents the transformation from wet soil to soil
},
sounds = default.node_sound_metal_defaults(),
})
if enable_LBM then
minetest.register_lbm({
label = "[signs_bot] Remove lost robots",
name = "signs_bot:lost_robot_remove",
nodenames = {"signs_bot:robot"},
run_at_every_load = true,
action = function(pos, node)
local found = false
tubelib2.walk_over_all(function(npos, node, mem)
if node.name == "signs_bot:box" and mem.robot_pos and
vector.equals(pos, mem.robot_pos) then
found = true
end
end, "robot_pos")
if not found then
signs_bot.remove_robot({robot_pos = pos})
end
end
})
end