diff --git a/entity.lua b/entity.lua index 486e825..9497095 100644 --- a/entity.lua +++ b/entity.lua @@ -5,7 +5,7 @@ local active_entities = {} minetest.register_entity("building_lib:display", { initial_properties = { physical = false, - static_save = false, + static_save = false, collisionbox = {0, 0, 0, 0, 0, 0}, visual = "upright_sprite", visual_size = {x=10, y=10}, @@ -19,6 +19,32 @@ minetest.register_entity("building_lib:display", { end }) +minetest.register_entity("building_lib:cube_display", { + initial_properties = { + physical = false, + static_save = false, + collisionbox = {0, 0, 0, 0, 0, 0}, + visual = "cube", + backface_culling = false, + visual_size = {x=1, y=1, z=1}, + glow = 10 + }, + on_step = function(self) + if not active_entities[self.id] then + -- not valid anymore + self.object:remove() + end + end +}) + +function building_lib.add_cube_entity(pos, id) + active_entities[id] = true + local ent = minetest.add_entity(pos, "building_lib:cube_display") + local luaent = ent:get_luaentity() + luaent.id = id + return ent +end + function building_lib.add_entity(pos, id) active_entities[id] = true local ent = minetest.add_entity(pos, "building_lib:display") diff --git a/preview.lua b/preview.lua index 11d9907..2d4bdb5 100644 --- a/preview.lua +++ b/preview.lua @@ -2,15 +2,6 @@ -- playername => key local active_preview = {} -local function add_preview_entity(texture, key, visual_size, pos, rotation) - local ent = building_lib.add_entity(pos, key) - ent:set_properties({ - visual_size = visual_size, - textures = {texture} - }) - ent:set_rotation(rotation) -end - function building_lib.show_preview(playername, texture, color, building_def, mapblock_pos1, mapblock_pos2, rotation) texture = texture .. "^[colorize:" .. color @@ -35,47 +26,20 @@ function building_lib.show_preview(playername, texture, color, building_def, map local size = vector.multiply(size_mapblocks, 16) -- 16 .. n local half_size = vector.divide(size, 2) -- 8 .. n - -- z- - add_preview_entity(texture, key, - {x=size.x, y=size.y}, - vector.add(min, {x=half_size.x-0.5, y=half_size.y-0.5, z=-0.5}), - {x=0, y=0, z=0} - ) + local origin = vector.add(min, half_size) - -- z+ - add_preview_entity(texture, key, - {x=size.x, y=size.y}, - vector.add(min, {x=half_size.x-0.5, y=half_size.y-0.5, z=size.z-0.5}), - {x=0, y=0, z=0} - ) - - -- x- - add_preview_entity(texture, key, - {x=size.z, y=size.y}, - vector.add(min, {x=-0.5, y=half_size.y-0.5, z=half_size.z-0.5}), - {x=0, y=math.pi/2, z=0} - ) - - -- x+ - add_preview_entity(texture, key, - {x=size.z, y=size.y}, - vector.add(min, {x=size.x-0.5, y=half_size.y-0.5, z=half_size.z-0.5}), - {x=0, y=math.pi/2, z=0} - ) - - -- y- - add_preview_entity(texture, key, - {x=size.x, y=size.z}, - vector.add(min, {x=half_size.x-0.5, y=-0.5, z=half_size.z-0.5}), - {x=math.pi/2, y=0, z=0} - ) - - -- y+ - add_preview_entity(texture, key, - {x=size.x, y=size.z}, - vector.add(min, {x=half_size.x-0.5, y=size.y-0.5, z=half_size.z-0.5}), - {x=math.pi/2, y=0, z=0} - ) + local ent = building_lib.add_cube_entity(origin, key) + ent:set_properties({ + visual_size = size, + textures = { + texture, + texture, + texture, + texture, + texture, + texture + } + }) if building_def and building_def.markers then -- add markers @@ -96,15 +60,16 @@ function building_lib.show_preview(playername, texture, color, building_def, map z_rotation = z_rotation + math.pi/2 end - add_preview_entity( - marker.texture .. texture_modifier, - key, marker.size, - node_pos, { - x=marker.rotation.x, - y=marker.rotation.y, - z=z_rotation - } - ) + ent = building_lib.add_entity(node_pos, key) + ent:set_properties({ + visual_size = marker.size, + textures = {marker.texture .. texture_modifier} + }) + ent:set_rotation({ + x=marker.rotation.x, + y=marker.rotation.y, + z=z_rotation + }) end end end diff --git a/textures/building_lib_autoplace.png b/textures/building_lib_autoplace.png index 298fdb5..6a58233 100644 Binary files a/textures/building_lib_autoplace.png and b/textures/building_lib_autoplace.png differ diff --git a/textures/building_lib_place.png b/textures/building_lib_place.png index 9e93c60..336248e 100644 Binary files a/textures/building_lib_place.png and b/textures/building_lib_place.png differ diff --git a/textures/building_lib_remove.png b/textures/building_lib_remove.png index 970e996..8150a48 100644 Binary files a/textures/building_lib_remove.png and b/textures/building_lib_remove.png differ