Skip to content

Commit 2e41f00

Browse files
committedDec 24, 2013
Mark the region with an entity cube.
1 parent 2fcea5a commit 2e41f00

File tree

4 files changed

+79
-41
lines changed

4 files changed

+79
-41
lines changed
 

‎worldedit/serialization.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ end
183183
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
184184
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
185185
worldedit.deserialize = function(originpos, value)
186-
--make area stay loaded --wip: not very performant
186+
--make area stay loaded
187187
local pos1, pos2 = worldedit.allocate(originpos, value)
188188
local manip = minetest.get_voxel_manip()
189189
manip:read_from_map(pos1, pos2)

‎worldedit_commands/mark.lua

+75-39
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
worldedit.marker1 = {}
22
worldedit.marker2 = {}
3-
worldedit.marker = {}
4-
5-
--wip: use this as a huge entity to make a full worldedit region box
6-
minetest.register_entity(":worldedit:region_cube", {
7-
initial_properties = {
8-
visual = "upright_sprite",
9-
visual_size = {x=1.1, y=1.1},
10-
textures = {"worldedit_pos1.png"},
11-
visual_size = {x=10, y=10},
12-
physical = false,
13-
},
14-
on_step = function(self, dtime)
15-
if self.active == nil then
16-
self.object:remove()
17-
end
18-
end,
19-
on_punch = function(self, hitter)
20-
--wip: remove the entire region marker
21-
end,
22-
})
3+
worldedit.marker_region = {}
234

245
--marks worldedit region position 1
256
worldedit.mark_pos1 = function(name)
@@ -37,11 +18,11 @@ worldedit.mark_pos1 = function(name)
3718
if pos1 ~= nil then
3819
--add marker
3920
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
40-
worldedit.marker1[name]:get_luaentity().active = true
41-
if pos2 ~= nil then --region defined
42-
worldedit.mark_region(pos1, pos2)
21+
if worldedit.marker1[name] ~= nil then
22+
worldedit.marker1[name]:get_luaentity().name = name
4323
end
4424
end
25+
worldedit.mark_region(name)
4526
end
4627

4728
--marks worldedit region position 2
@@ -60,23 +41,58 @@ worldedit.mark_pos2 = function(name)
6041
if pos2 ~= nil then
6142
--add marker
6243
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
63-
worldedit.marker2[name]:get_luaentity().active = true
64-
if pos1 ~= nil then --region defined
65-
worldedit.mark_region(pos1, pos2)
44+
if worldedit.marker2[name] ~= nil then
45+
worldedit.marker2[name]:get_luaentity().name = name
6646
end
6747
end
48+
worldedit.mark_region(name)
6849
end
6950

70-
worldedit.mark_region = function(pos1, pos2)
71-
--make area stay loaded
72-
local manip = minetest.get_voxel_manip()
73-
manip:read_from_map(pos1, pos2)
51+
worldedit.mark_region = function(name)
52+
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
7453

75-
if worldedit.marker[name] ~= nil then --marker already exists
76-
--wip: remove markers
54+
if worldedit.marker_region[name] ~= nil then --marker already exists
55+
--wip: make the area stay loaded somehow
56+
for _, entity in ipairs(worldedit.marker_region[name]) do
57+
entity:remove()
58+
end
59+
worldedit.marker_region[name] = nil
7760
end
7861
if pos1 ~= nil and pos2 ~= nil then
79-
--wip: place markers
62+
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
63+
local thickness = 0.2
64+
local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
65+
66+
--make area stay loaded
67+
local manip = minetest.get_voxel_manip()
68+
manip:read_from_map(pos1, pos2)
69+
70+
local markers = {}
71+
72+
--XY plane markers
73+
for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
74+
local marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")
75+
marker:set_properties({
76+
visual_size={x=sizex * 2, y=sizey * 2},
77+
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
78+
})
79+
marker:get_luaentity().name = name
80+
table.insert(markers, marker)
81+
end
82+
83+
--YZ plane markers
84+
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
85+
local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")
86+
marker:set_properties({
87+
visual_size={x=sizez * 2, y=sizey * 2},
88+
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
89+
})
90+
marker:setyaw(math.pi / 2)
91+
marker:get_luaentity().name = name
92+
table.insert(markers, marker)
93+
end
94+
95+
worldedit.marker_region[name] = markers
8096
end
8197
end
8298

@@ -91,14 +107,13 @@ minetest.register_entity(":worldedit:pos1", {
91107
physical = false,
92108
},
93109
on_step = function(self, dtime)
94-
if self.active == nil then
110+
if worldedit.marker1[self.name] == nil then
95111
self.object:remove()
96112
end
97113
end,
98114
on_punch = function(self, hitter)
99115
self.object:remove()
100-
local name = hitter:get_player_name()
101-
worldedit.marker1[name] = nil
116+
worldedit.marker1[self.name] = nil
102117
end,
103118
})
104119

@@ -113,13 +128,34 @@ minetest.register_entity(":worldedit:pos2", {
113128
physical = false,
114129
},
115130
on_step = function(self, dtime)
116-
if self.active == nil then
131+
if worldedit.marker2[self.name] == nil then
117132
self.object:remove()
118133
end
119134
end,
120135
on_punch = function(self, hitter)
121136
self.object:remove()
122-
local name = hitter:get_player_name()
123-
worldedit.marker2[name] = nil
137+
worldedit.marker2[self.name] = nil
138+
end,
139+
})
140+
141+
minetest.register_entity(":worldedit:region_cube", {
142+
initial_properties = {
143+
visual = "upright_sprite",
144+
visual_size = {x=1.1, y=1.1},
145+
textures = {"worldedit_cube.png"},
146+
visual_size = {x=10, y=10},
147+
physical = false,
148+
},
149+
on_step = function(self, dtime)
150+
if worldedit.marker_region[self.name] == nil then
151+
self.object:remove()
152+
return
153+
end
154+
end,
155+
on_punch = function(self, hitter)
156+
for _, entity in ipairs(worldedit.marker_region[self.name]) do
157+
entity:remove()
158+
end
159+
worldedit.marker_region[self.name] = nil
124160
end,
125161
})
147 Bytes
Loading

‎worldedit_gui/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
worldedit = worldedit or {}
22

3+
--wip: simply add a button to the player inventory if unified_inventory AND inventory++ are both not installed
4+
35
--[[
46
Example:
57
@@ -129,7 +131,7 @@ end
129131
worldedit.register_gui_function("worldedit_gui", {
130132
name = "WorldEdit GUI",
131133
get_formspec = function(name)
132-
--create a form with all the buttons arranged in a grid --wip: show only buttons that the player has privs for
134+
--create a form with all the buttons arranged in a grid
133135
local buttons, x, y, index = {}, 0, 1, 0
134136
local width, height = 3, 0.8
135137
local columns = 5

0 commit comments

Comments
 (0)
Please sign in to comment.