mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-24 01:30:40 +01:00
Mark the region with an entity cube.
This commit is contained in:
parent
2fcea5a3c0
commit
2e41f0076d
@ -183,7 +183,7 @@ end
|
||||
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
|
||||
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
|
||||
worldedit.deserialize = function(originpos, value)
|
||||
--make area stay loaded --wip: not very performant
|
||||
--make area stay loaded
|
||||
local pos1, pos2 = worldedit.allocate(originpos, value)
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
@ -1,25 +1,6 @@
|
||||
worldedit.marker1 = {}
|
||||
worldedit.marker2 = {}
|
||||
worldedit.marker = {}
|
||||
|
||||
--wip: use this as a huge entity to make a full worldedit region box
|
||||
minetest.register_entity(":worldedit:region_cube", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=1.1, y=1.1},
|
||||
textures = {"worldedit_pos1.png"},
|
||||
visual_size = {x=10, y=10},
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
--wip: remove the entire region marker
|
||||
end,
|
||||
})
|
||||
worldedit.marker_region = {}
|
||||
|
||||
--marks worldedit region position 1
|
||||
worldedit.mark_pos1 = function(name)
|
||||
@ -37,11 +18,11 @@ worldedit.mark_pos1 = function(name)
|
||||
if pos1 ~= nil then
|
||||
--add marker
|
||||
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
|
||||
worldedit.marker1[name]:get_luaentity().active = true
|
||||
if pos2 ~= nil then --region defined
|
||||
worldedit.mark_region(pos1, pos2)
|
||||
if worldedit.marker1[name] ~= nil then
|
||||
worldedit.marker1[name]:get_luaentity().name = name
|
||||
end
|
||||
end
|
||||
worldedit.mark_region(name)
|
||||
end
|
||||
|
||||
--marks worldedit region position 2
|
||||
@ -60,23 +41,58 @@ worldedit.mark_pos2 = function(name)
|
||||
if pos2 ~= nil then
|
||||
--add marker
|
||||
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
|
||||
worldedit.marker2[name]:get_luaentity().active = true
|
||||
if pos1 ~= nil then --region defined
|
||||
worldedit.mark_region(pos1, pos2)
|
||||
if worldedit.marker2[name] ~= nil then
|
||||
worldedit.marker2[name]:get_luaentity().name = name
|
||||
end
|
||||
end
|
||||
worldedit.mark_region(name)
|
||||
end
|
||||
|
||||
worldedit.mark_region = function(pos1, pos2)
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
worldedit.mark_region = function(name)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
|
||||
if worldedit.marker[name] ~= nil then --marker already exists
|
||||
--wip: remove markers
|
||||
if worldedit.marker_region[name] ~= nil then --marker already exists
|
||||
--wip: make the area stay loaded somehow
|
||||
for _, entity in ipairs(worldedit.marker_region[name]) do
|
||||
entity:remove()
|
||||
end
|
||||
worldedit.marker_region[name] = nil
|
||||
end
|
||||
if pos1 ~= nil and pos2 ~= nil then
|
||||
--wip: place markers
|
||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
local thickness = 0.2
|
||||
local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
|
||||
|
||||
--make area stay loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
local markers = {}
|
||||
|
||||
--XY plane markers
|
||||
for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
|
||||
local marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")
|
||||
marker:set_properties({
|
||||
visual_size={x=sizex * 2, y=sizey * 2},
|
||||
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
|
||||
})
|
||||
marker:get_luaentity().name = name
|
||||
table.insert(markers, marker)
|
||||
end
|
||||
|
||||
--YZ plane markers
|
||||
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
|
||||
local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")
|
||||
marker:set_properties({
|
||||
visual_size={x=sizez * 2, y=sizey * 2},
|
||||
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
|
||||
})
|
||||
marker:setyaw(math.pi / 2)
|
||||
marker:get_luaentity().name = name
|
||||
table.insert(markers, marker)
|
||||
end
|
||||
|
||||
worldedit.marker_region[name] = markers
|
||||
end
|
||||
end
|
||||
|
||||
@ -91,14 +107,13 @@ minetest.register_entity(":worldedit:pos1", {
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
if worldedit.marker1[self.name] == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
local name = hitter:get_player_name()
|
||||
worldedit.marker1[name] = nil
|
||||
worldedit.marker1[self.name] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
@ -113,13 +128,34 @@ minetest.register_entity(":worldedit:pos2", {
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if self.active == nil then
|
||||
if worldedit.marker2[self.name] == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
local name = hitter:get_player_name()
|
||||
worldedit.marker2[name] = nil
|
||||
worldedit.marker2[self.name] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity(":worldedit:region_cube", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=1.1, y=1.1},
|
||||
textures = {"worldedit_cube.png"},
|
||||
visual_size = {x=10, y=10},
|
||||
physical = false,
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
if worldedit.marker_region[self.name] == nil then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
for _, entity in ipairs(worldedit.marker_region[self.name]) do
|
||||
entity:remove()
|
||||
end
|
||||
worldedit.marker_region[self.name] = nil
|
||||
end,
|
||||
})
|
BIN
worldedit_commands/textures/worldedit_cube.png
Normal file
BIN
worldedit_commands/textures/worldedit_cube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 147 B |
@ -1,5 +1,7 @@
|
||||
worldedit = worldedit or {}
|
||||
|
||||
--wip: simply add a button to the player inventory if unified_inventory AND inventory++ are both not installed
|
||||
|
||||
--[[
|
||||
Example:
|
||||
|
||||
@ -129,7 +131,7 @@ end
|
||||
worldedit.register_gui_function("worldedit_gui", {
|
||||
name = "WorldEdit GUI",
|
||||
get_formspec = function(name)
|
||||
--create a form with all the buttons arranged in a grid --wip: show only buttons that the player has privs for
|
||||
--create a form with all the buttons arranged in a grid
|
||||
local buttons, x, y, index = {}, 0, 1, 0
|
||||
local width, height = 3, 0.8
|
||||
local columns = 5
|
||||
|
Loading…
Reference in New Issue
Block a user