markings
This commit is contained in:
parent
a8cc954ff7
commit
534ff33dde
1
init.lua
1
init.lua
@ -1,3 +1,4 @@
|
||||
dofile(minetest.get_modpath("basic_machines").."/mark.lua") -- used for markings, borrowed and adapted from worldedit
|
||||
dofile(minetest.get_modpath("basic_machines").."/mover.lua")
|
||||
|
||||
minetest.after(1, function() -- if you want keypad to open doors
|
||||
|
97
mark.lua
Normal file
97
mark.lua
Normal file
@ -0,0 +1,97 @@
|
||||
-- rnd: code borrowed from machines, mark.lua
|
||||
|
||||
-- need for marking
|
||||
machines = {}; machines.pos1 = {}; machines.pos2 = {};
|
||||
machines.marker1 = {}
|
||||
machines.marker2 = {}
|
||||
machines.marker_region = {}
|
||||
|
||||
|
||||
|
||||
--marks machines region position 1
|
||||
machines.mark_pos1 = function(name)
|
||||
local pos1, pos2 = machines.pos1[name], machines.pos2[name]
|
||||
|
||||
if pos1 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos1)
|
||||
end
|
||||
if machines.marker1[name] ~= nil then --marker already exists
|
||||
machines.marker1[name]:remove() --remove marker
|
||||
machines.marker1[name] = nil
|
||||
end
|
||||
if pos1 ~= nil then
|
||||
--add marker
|
||||
machines.marker1[name] = minetest.add_entity(pos1, "machines:pos1")
|
||||
if machines.marker1[name] ~= nil then
|
||||
machines.marker1[name]:get_luaentity().name = name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--marks machines region position 2
|
||||
machines.mark_pos2 = function(name)
|
||||
local pos1, pos2 = machines.pos1[name], machines.pos2[name]
|
||||
|
||||
if pos2 ~= nil then
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos2, pos2)
|
||||
end
|
||||
if machines.marker2[name] ~= nil then --marker already exists
|
||||
machines.marker2[name]:remove() --remove marker
|
||||
machines.marker2[name] = nil
|
||||
end
|
||||
if pos2 ~= nil then
|
||||
--add marker
|
||||
machines.marker2[name] = minetest.add_entity(pos2, "machines:pos2")
|
||||
if machines.marker2[name] ~= nil then
|
||||
machines.marker2[name]:get_luaentity().name = name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_entity(":machines:pos1", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
visual_size = {x=1.1, y=1.1},
|
||||
textures = {"machines_pos1.png", "machines_pos1.png",
|
||||
"machines_pos1.png", "machines_pos1.png",
|
||||
"machines_pos1.png", "machines_pos1.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if machines.marker1[self.name] == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
machines.marker1[self.name] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity(":machines:pos2", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
visual_size = {x=1.1, y=1.1},
|
||||
textures = {"machines_pos2.png", "machines_pos2.png",
|
||||
"machines_pos2.png", "machines_pos2.png",
|
||||
"machines_pos2.png", "machines_pos2.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if machines.marker2[self.name] == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
machines.marker2[self.name] = nil
|
||||
end,
|
||||
})
|
16
mover.lua
16
mover.lua
@ -44,6 +44,9 @@ minetest.register_node("basic_machines:mover", {
|
||||
x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");
|
||||
x1=meta:get_int("x1");y1=meta:get_int("y1");z1=meta:get_int("z1");
|
||||
x2=meta:get_int("x2");y2=meta:get_int("y2");z2=meta:get_int("z2");
|
||||
machines.pos1[player:get_player_name()] = {x=pos.x+x1,y=pos.y+y1,z=pos.z+z1};machines.mark_pos1(player:get_player_name()) -- mark pos1
|
||||
machines.pos2[player:get_player_name()] = {x=pos.x+x2,y=pos.y+y2,z=pos.z+z2};machines.mark_pos2(player:get_player_name()) -- mark pos2
|
||||
|
||||
prefer = meta:get_string("prefer");mode = meta:get_string("mode");
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
@ -353,6 +356,7 @@ minetest.register_node("basic_machines:keypad", {
|
||||
local x0,y0,z0,pass,iter,mode;
|
||||
x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");iter=meta:get_int("iter") or 1;
|
||||
mode = meta:get_int("mode") or 1;
|
||||
machines.pos1[player:get_player_name()] = {x=pos.x+x0,y=pos.y+y0,z=pos.z+z0};machines.mark_pos1(player:get_player_name()) -- mark pos1
|
||||
|
||||
pass = meta:get_string("pass");
|
||||
local form =
|
||||
@ -399,6 +403,10 @@ minetest.register_node("basic_machines:detector", {
|
||||
local x0,y0,z0,x1,y1,z1,r,node,NOT;
|
||||
x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");
|
||||
x1=meta:get_int("x1");y1=meta:get_int("y1");z1=meta:get_int("z1");r=meta:get_int("r");
|
||||
|
||||
machines.pos1[player:get_player_name()] = {x=pos.x+x0,y=pos.y+y0,z=pos.z+z0};machines.mark_pos1(player:get_player_name()) -- mark pos1
|
||||
machines.pos2[player:get_player_name()] = {x=pos.x+x1,y=pos.y+y1,z=pos.z+z1};machines.mark_pos2(player:get_player_name()) -- mark pos2
|
||||
|
||||
node=meta:get_string("node") or "";
|
||||
NOT=meta:get_int("NOT");
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
@ -581,6 +589,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||
end
|
||||
|
||||
punchset[name].pos1 = {x=pos.x,y=pos.y,z=pos.z};punchset[name].state = 2;
|
||||
machines.pos1[name] = punchset[name].pos1;machines.mark_pos1(name) -- mark position
|
||||
minetest.chat_send_player(name, "MOVER: Start position for mover set. Punch again to set end position.")
|
||||
return
|
||||
end
|
||||
@ -593,6 +602,8 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||
end
|
||||
|
||||
punchset[name].pos2 = {x=pos.x,y=pos.y,z=pos.z}; punchset[name].state = 0;
|
||||
machines.pos2[name] = punchset[name].pos2;machines.mark_pos2(name) -- mark pos2
|
||||
|
||||
minetest.chat_send_player(name, "MOVER: End position for mover set.")
|
||||
local x = punchset[name].pos1.x-punchset[name].pos.x;
|
||||
local y = punchset[name].pos1.y-punchset[name].pos.y;
|
||||
@ -635,7 +646,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||
minetest.chat_send_player(name, "KEYPAD: Punch closer to keypad. reseting.")
|
||||
punchset[name].state = 0; return
|
||||
end
|
||||
|
||||
machines.pos1[name] = pos;machines.mark_pos1(name) -- mark pos1
|
||||
meta:set_int("x0",x);meta:set_int("y0",y);meta:set_int("z0",z);
|
||||
punchset[name].state = 0
|
||||
minetest.chat_send_player(name, "KEYPAD: Keypad target set with coordinates " .. x .. " " .. y .. " " .. z)
|
||||
@ -665,6 +676,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||
end
|
||||
minetest.chat_send_player(name, "DETECTOR: Now punch the target machine.")
|
||||
punchset[name].pos1 = {x=pos.x,y=pos.y,z=pos.z};
|
||||
machines.pos1[name] = pos;machines.mark_pos1(name) -- mark pos1
|
||||
punchset[name].state = 2
|
||||
return
|
||||
end
|
||||
@ -680,7 +692,7 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||
punchset[name].state = 0; return
|
||||
end
|
||||
minetest.chat_send_player(name, "DETECTOR: Setup complete.")
|
||||
|
||||
machines.pos2[name] = pos;machines.mark_pos2(name) -- mark pos2
|
||||
local x = punchset[name].pos1.x-punchset[name].pos.x;
|
||||
local y = punchset[name].pos1.y-punchset[name].pos.y;
|
||||
local z = punchset[name].pos1.z-punchset[name].pos.z;
|
||||
|
BIN
textures/machines_pos1.png
Normal file
BIN
textures/machines_pos1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 203 B |
BIN
textures/machines_pos2.png
Normal file
BIN
textures/machines_pos2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 B |
Loading…
x
Reference in New Issue
Block a user