working display
This commit is contained in:
parent
4938c09b27
commit
1e116e3a16
@ -7,8 +7,8 @@ minetest.register_entity("pick_and_place:display", {
|
||||
physical = false,
|
||||
static_save = false,
|
||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=10, y=10},
|
||||
visual = "cube",
|
||||
visual_size = {x=1, y=1, z=1},
|
||||
glow = 10
|
||||
},
|
||||
on_step = function(self)
|
||||
|
1
init.lua
1
init.lua
@ -3,6 +3,7 @@ pick_and_place = {}
|
||||
|
||||
local MP = minetest.get_modpath("pick_and_place")
|
||||
dofile(MP .. "/common.lua")
|
||||
dofile(MP .. "/pointed.lua")
|
||||
dofile(MP .. "/serialize.lua")
|
||||
dofile(MP .. "/entity.lua")
|
||||
dofile(MP .. "/node.lua")
|
||||
|
12
pointed.lua
Normal file
12
pointed.lua
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
--- returns the pointed position
|
||||
function pick_and_place.get_pointed_position(player, distance)
|
||||
distance = distance or 10
|
||||
local ppos = player:get_pos()
|
||||
local eye_height = player:get_properties().eye_height
|
||||
ppos = vector.add(ppos, {x=0, y=eye_height, z=0})
|
||||
local look_dir = player:get_look_dir()
|
||||
|
||||
local pos = vector.add(ppos, vector.multiply(look_dir, distance))
|
||||
return vector.round(pos)
|
||||
end
|
69
preview.lua
69
preview.lua
@ -2,16 +2,8 @@
|
||||
-- playername => key
|
||||
local active_preview = {}
|
||||
|
||||
local function add_preview_entity(texture, key, visual_size, pos, rotation)
|
||||
local ent = pick_and_place.add_entity(pos, key)
|
||||
ent:set_properties({
|
||||
visual_size = visual_size,
|
||||
textures = {texture}
|
||||
})
|
||||
ent:set_rotation(rotation)
|
||||
end
|
||||
|
||||
function pick_and_place.show_preview(playername, texture, color, pos1, pos2)
|
||||
pos2 = pos2 or pos1
|
||||
texture = texture .. "^[colorize:" .. color
|
||||
|
||||
local key =
|
||||
@ -27,51 +19,22 @@ function pick_and_place.show_preview(playername, texture, color, pos1, pos2)
|
||||
pick_and_place.clear_preview(playername)
|
||||
active_preview[playername] = key
|
||||
|
||||
local size = vector.subtract(pos2, pos1)
|
||||
local half_size = vector.divide(size, 2) -- 8 .. n
|
||||
|
||||
-- z-
|
||||
add_preview_entity(texture, key,
|
||||
{x=size.x, y=size.y},
|
||||
vector.add(pos1, {x=half_size.x-0.5, y=half_size.y-0.5, z=-0.5}),
|
||||
{x=0, y=0, z=0}
|
||||
)
|
||||
|
||||
-- z+
|
||||
add_preview_entity(texture, key,
|
||||
{x=size.x, y=size.y},
|
||||
vector.add(pos1, {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(pos1, {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(pos1, {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(pos1, {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(pos1, {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 visual_size = vector.add(vector.subtract(pos2, pos1), 1)
|
||||
local offset = vector.divide(vector.subtract(pos2, pos1), 2)
|
||||
local origin = vector.subtract(pos1, offset)
|
||||
|
||||
local ent = pick_and_place.add_entity(origin, key)
|
||||
ent:set_properties({
|
||||
visual_size = visual_size,
|
||||
textures = {
|
||||
texture,
|
||||
texture,
|
||||
texture,
|
||||
texture,
|
||||
texture,
|
||||
texture
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
function pick_and_place.clear_preview(playername)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 5.0 KiB |
15
tool.lua
15
tool.lua
@ -7,13 +7,16 @@ minetest.register_tool("pick_and_place:placer", {
|
||||
on_use = function(itemstack, player)
|
||||
print("on_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
end,
|
||||
on_focus = function(itemstack, player)
|
||||
print("on_focus: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
on_secondary_use = function(itemstack, player)
|
||||
print("on_secondary_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
end,
|
||||
on_step = function(itemstack, player)
|
||||
print("on_step: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
on_step = function(_, player)
|
||||
local playername = player:get_player_name()
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#00ff00", pointed_pos, vector.add(pointed_pos, {x=1, y=2, z=3}))
|
||||
end,
|
||||
on_blur = function(itemstack, player)
|
||||
print("on_blur: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
on_deselect = function(_, player)
|
||||
local playername = player:get_player_name()
|
||||
pick_and_place.clear_preview(playername)
|
||||
end
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user