working selection
This commit is contained in:
parent
1e116e3a16
commit
e85e401f91
21
common.lua
21
common.lua
@ -1,3 +1,24 @@
|
||||
|
||||
--- sorts the position by ascending order
|
||||
-- @param pos1 @{node_pos} the first position
|
||||
-- @param pos2 @{node_pos} the second position
|
||||
-- @return @{node_pos} the lower position
|
||||
-- @return @{node_pos} the upper position
|
||||
function pick_and_place.sort_pos(pos1, pos2)
|
||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||
if pos1.x > pos2.x then
|
||||
pos2.x, pos1.x = pos1.x, pos2.x
|
||||
end
|
||||
if pos1.y > pos2.y then
|
||||
pos2.y, pos1.y = pos1.y, pos2.y
|
||||
end
|
||||
if pos1.z > pos2.z then
|
||||
pos2.z, pos1.z = pos1.z, pos2.z
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
|
||||
function pick_and_place.rotate_size(size, rotation)
|
||||
end
|
31
configure.lua
Normal file
31
configure.lua
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
local function get_outer_corners(pos1, pos2)
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
pos1 = vector.subtract(pos1, 1)
|
||||
pos2 = vector.add(pos2, 1)
|
||||
|
||||
return {
|
||||
{ x=pos1.x, y=pos1.y, z=pos1.z },
|
||||
{ x=pos1.x, y=pos1.y, z=pos2.z },
|
||||
{ x=pos1.x, y=pos2.y, z=pos1.z },
|
||||
{ x=pos1.x, y=pos2.y, z=pos2.z },
|
||||
{ x=pos2.x, y=pos1.y, z=pos1.z },
|
||||
{ x=pos2.x, y=pos1.y, z=pos2.z },
|
||||
{ x=pos2.x, y=pos2.y, z=pos1.z },
|
||||
{ x=pos2.x, y=pos2.y, z=pos2.z }
|
||||
}
|
||||
end
|
||||
|
||||
function pick_and_place.configure(pos1, pos2)
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
|
||||
for _, cpos in ipairs(get_outer_corners(pos1, pos2)) do
|
||||
local node = minetest.get_node(cpos)
|
||||
if node.name == "air" then
|
||||
minetest.set_node(cpos, { name = "pick_and_place:handle" })
|
||||
local meta = minetest.get_meta(cpos)
|
||||
meta:set_string("pos1", minetest.pos_to_string(pos1))
|
||||
meta:set_string("pos2", minetest.pos_to_string(pos2))
|
||||
end
|
||||
end
|
||||
end
|
48
configure_tool.lua
Normal file
48
configure_tool.lua
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
-- playername -> pos (if pos1 selected)
|
||||
local pos1 = {}
|
||||
|
||||
minetest.register_tool("pick_and_place:configure", {
|
||||
description = "Placement configuration tool",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#00ff00",
|
||||
stack_max = 1,
|
||||
range = 0,
|
||||
on_use = function(itemstack, player)
|
||||
print("on_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
local playername = player:get_player_name()
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
|
||||
if pos1[playername] then
|
||||
-- second position selected
|
||||
-- configure and unmark
|
||||
pick_and_place.configure(pos1[playername], pointed_pos)
|
||||
pos1[playername] = nil
|
||||
else
|
||||
-- first position selected
|
||||
pos1[playername] = pointed_pos
|
||||
end
|
||||
end,
|
||||
on_secondary_use = function(itemstack, player)
|
||||
print("on_secondary_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
local playername = player:get_player_name()
|
||||
pos1[playername] = nil
|
||||
end,
|
||||
on_step = function(_, player)
|
||||
local playername = player:get_player_name()
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
|
||||
if pos1[playername] then
|
||||
-- first position already selected
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#0000ff", pointed_pos, pos1[playername])
|
||||
else
|
||||
-- nothing selected yet
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#00ff00", pointed_pos)
|
||||
end
|
||||
end,
|
||||
on_deselect = function(_, player)
|
||||
local playername = player:get_player_name()
|
||||
pick_and_place.clear_preview(playername)
|
||||
end
|
||||
})
|
@ -8,6 +8,7 @@ minetest.register_entity("pick_and_place:display", {
|
||||
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
|
||||
},
|
||||
|
32
handle_node.lua
Normal file
32
handle_node.lua
Normal file
@ -0,0 +1,32 @@
|
||||
local function on_rightclick(pos, _, _, itemstack)
|
||||
if not itemstack:is_empty() then
|
||||
-- not an empty hand
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local pos1 = minetest.string_to_pos(meta:get_string("pos1"))
|
||||
local pos2 = minetest.string_to_pos(meta:get_string("pos2"))
|
||||
local size = vector.add(vector.subtract(pos2, pos1), 1)
|
||||
|
||||
|
||||
local tool = ItemStack("pick_and_place:place 1")
|
||||
local tool_meta = tool:get_meta()
|
||||
tool_meta:set_string("size", minetest.pos_to_string(size))
|
||||
|
||||
return tool
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("pick_and_place:handle", {
|
||||
description = "Pick and place handle",
|
||||
tiles = {"pick_and_place_plus.png"},
|
||||
drawtype = "allfaces",
|
||||
use_texture_alpha = "blend",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
on_rightclick = on_rightclick,
|
||||
groups = {
|
||||
oddly_breakable_by_hand = 3
|
||||
}
|
||||
})
|
6
init.lua
6
init.lua
@ -4,8 +4,10 @@ pick_and_place = {}
|
||||
local MP = minetest.get_modpath("pick_and_place")
|
||||
dofile(MP .. "/common.lua")
|
||||
dofile(MP .. "/pointed.lua")
|
||||
dofile(MP .. "/configure.lua")
|
||||
dofile(MP .. "/serialize.lua")
|
||||
dofile(MP .. "/entity.lua")
|
||||
dofile(MP .. "/node.lua")
|
||||
dofile(MP .. "/tool.lua")
|
||||
dofile(MP .. "/handle_node.lua")
|
||||
dofile(MP .. "/configure_tool.lua")
|
||||
dofile(MP .. "/place_tool.lua")
|
||||
dofile(MP .. "/preview.lua")
|
||||
|
25
node.lua
25
node.lua
@ -1,25 +0,0 @@
|
||||
|
||||
minetest.register_node("pick_and_place:handle", {
|
||||
description = "Pick and place handle",
|
||||
tiles = {"pick_and_place_plus.png"},
|
||||
drawtype = "allfaces",
|
||||
use_texture_alpha = "blend",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {
|
||||
oddly_breakable_by_hand = 3
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("pick_and_place:handle_configured", {
|
||||
description = "Pick and place handle (configured)",
|
||||
tiles = {"pick_and_place_plus.png^[colorize:#00ff00"},
|
||||
drawtype = "allfaces",
|
||||
use_texture_alpha = "blend",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {
|
||||
oddly_breakable_by_hand = 3,
|
||||
not_in_creative_inventory = 1
|
||||
}
|
||||
})
|
@ -1,19 +1,27 @@
|
||||
|
||||
minetest.register_tool("pick_and_place:placer", {
|
||||
minetest.register_tool("pick_and_place:place", {
|
||||
description = "Placement tool",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#00ff00",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#0000ff",
|
||||
stack_max = 1,
|
||||
range = 0,
|
||||
on_use = function(itemstack, player)
|
||||
print("on_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
|
||||
end,
|
||||
on_secondary_use = function(itemstack, player)
|
||||
print("on_secondary_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
end,
|
||||
on_step = function(_, player)
|
||||
on_step = function(itemstack, 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}))
|
||||
|
||||
local meta = itemstack:get_meta()
|
||||
local size = minetest.string_to_pos(meta:get_string("size"))
|
||||
|
||||
local pos2 = vector.add(pointed_pos, vector.subtract(size, 1))
|
||||
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#0000ff", pointed_pos, pos2)
|
||||
end,
|
||||
on_deselect = function(_, player)
|
||||
local playername = player:get_player_name()
|
@ -6,6 +6,8 @@ function pick_and_place.show_preview(playername, texture, color, pos1, pos2)
|
||||
pos2 = pos2 or pos1
|
||||
texture = texture .. "^[colorize:" .. color
|
||||
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
|
||||
local key =
|
||||
minetest.pos_to_string(pos1) .. "/" ..
|
||||
minetest.pos_to_string(pos2) .. "/" ..
|
||||
@ -21,7 +23,7 @@ function pick_and_place.show_preview(playername, texture, color, pos1, pos2)
|
||||
|
||||
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 origin = vector.subtract(pos2, offset)
|
||||
|
||||
local ent = pick_and_place.add_entity(origin, key)
|
||||
ent:set_properties({
|
||||
|
Loading…
x
Reference in New Issue
Block a user