]> git.lizzy.rs Git - worldedit.git/blob - worldedit_commands/mark.lua
Rewrite spirals from scratch and fix upside-down pyramids. Use voxelmanip for markers...
[worldedit.git] / worldedit_commands / mark.lua
1 worldedit.marker1 = {}\r
2 worldedit.marker2 = {}\r
3 worldedit.marker = {}\r
4 \r
5 --wip: use this as a huge entity to make a full worldedit region box\r
6 minetest.register_entity(":worldedit:region_cube", {\r
7         initial_properties = {\r
8                 visual = "upright_sprite",\r
9                 visual_size = {x=1.1, y=1.1},\r
10                 textures = {"worldedit_pos1.png"},\r
11                 visual_size = {x=10, y=10},\r
12                 physical = false,\r
13         },\r
14         on_step = function(self, dtime)\r
15                 if self.active == nil then\r
16                         self.object:remove()\r
17                 end\r
18         end,\r
19         on_punch = function(self, hitter)\r
20                 --wip: remove the entire region marker\r
21         end,\r
22 })\r
23 \r
24 --marks worldedit region position 1\r
25 worldedit.mark_pos1 = function(name)\r
26         local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
27 \r
28         if pos1 ~= nil then\r
29                 --make area stay loaded\r
30                 local manip = minetest.get_voxel_manip()\r
31                 manip:read_from_map(pos1, pos1) --wip: see if this even works\r
32         end\r
33         if worldedit.marker1[name] ~= nil then --marker already exists\r
34                 worldedit.marker1[name]:remove() --remove marker\r
35                 worldedit.marker1[name] = nil\r
36         end\r
37         if pos1 ~= nil then\r
38                 --add marker\r
39                 worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")\r
40                 worldedit.marker1[name]:get_luaentity().active = true\r
41                 if pos2 ~= nil then --region defined\r
42                         worldedit.mark_region(pos1, pos2)\r
43                 end\r
44         end\r
45 end\r
46 \r
47 --marks worldedit region position 2\r
48 worldedit.mark_pos2 = function(name)\r
49         local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
50 \r
51         if pos2 ~= nil then\r
52                 --make area stay loaded\r
53                 local manip = minetest.get_voxel_manip()\r
54                 manip:read_from_map(pos2, pos2) --wip: see if this even works\r
55         end\r
56         if worldedit.marker2[name] ~= nil then --marker already exists\r
57                 worldedit.marker2[name]:remove() --remove marker\r
58                 worldedit.marker2[name] = nil\r
59         end\r
60         if pos2 ~= nil then\r
61                 --add marker\r
62                 worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")\r
63                 worldedit.marker2[name]:get_luaentity().active = true\r
64                 if pos1 ~= nil then --region defined\r
65                         worldedit.mark_region(pos1, pos2)\r
66                 end\r
67         end\r
68 end\r
69 \r
70 worldedit.mark_region = function(pos1, pos2)\r
71         --make area stay loaded\r
72         local manip = minetest.get_voxel_manip()\r
73         manip:read_from_map(pos1, pos2)\r
74 \r
75         if worldedit.marker[name] ~= nil then --marker already exists\r
76                 --wip: remove markers\r
77         end\r
78         if pos1 ~= nil and pos2 ~= nil then\r
79                 --wip: place markers\r
80         end\r
81 end\r
82 \r
83 minetest.register_entity(":worldedit:pos1", {\r
84         initial_properties = {\r
85                 visual = "cube",\r
86                 visual_size = {x=1.1, y=1.1},\r
87                 textures = {"worldedit_pos1.png", "worldedit_pos1.png",\r
88                         "worldedit_pos1.png", "worldedit_pos1.png",\r
89                         "worldedit_pos1.png", "worldedit_pos1.png"},\r
90                 collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},\r
91                 physical = false,\r
92         },\r
93         on_step = function(self, dtime)\r
94                 if self.active == nil then\r
95                         self.object:remove()\r
96                 end\r
97         end,\r
98         on_punch = function(self, hitter)\r
99                 self.object:remove()\r
100                 local name = hitter:get_player_name()\r
101                 worldedit.marker1[name] = nil\r
102         end,\r
103 })\r
104 \r
105 minetest.register_entity(":worldedit:pos2", {\r
106         initial_properties = {\r
107                 visual = "cube",\r
108                 visual_size = {x=1.1, y=1.1},\r
109                 textures = {"worldedit_pos2.png", "worldedit_pos2.png",\r
110                         "worldedit_pos2.png", "worldedit_pos2.png",\r
111                         "worldedit_pos2.png", "worldedit_pos2.png"},\r
112                 collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},\r
113                 physical = false,\r
114         },\r
115         on_step = function(self, dtime)\r
116                 if self.active == nil then\r
117                         self.object:remove()\r
118                 end\r
119         end,\r
120         on_punch = function(self, hitter)\r
121                 self.object:remove()\r
122                 local name = hitter:get_player_name()\r
123                 worldedit.marker2[name] = nil\r
124         end,\r
125 })