configure and pick tool
This commit is contained in:
parent
cc995a8700
commit
8811c38660
@ -18,7 +18,3 @@ function pick_and_place.sort_pos(pos1, pos2)
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
|
||||
function pick_and_place.rotate_size(size, rotation)
|
||||
end
|
@ -4,12 +4,10 @@ local pos1 = {}
|
||||
|
||||
minetest.register_tool("pick_and_place:configure", {
|
||||
description = "Placement configuration tool",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#00ff00",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#ffffff",
|
||||
stack_max = 1,
|
||||
range = 0,
|
||||
on_use = function(itemstack, player)
|
||||
print("on_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
on_use = function(_, player)
|
||||
local playername = player:get_player_name()
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
|
||||
@ -35,10 +33,10 @@ minetest.register_tool("pick_and_place:configure", {
|
||||
|
||||
if pos1[playername] then
|
||||
-- first position already selected
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#0000ff", pointed_pos, pos1[playername])
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#ffffff", pointed_pos, pos1[playername])
|
||||
else
|
||||
-- nothing selected yet
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#00ff00", pointed_pos)
|
||||
pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#ffffff", pointed_pos)
|
||||
end
|
||||
end,
|
||||
on_deselect = function(_, player)
|
||||
|
16
create_tool.lua
Normal file
16
create_tool.lua
Normal file
@ -0,0 +1,16 @@
|
||||
function pick_and_place.create_tool(pos1, 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))
|
||||
|
||||
-- serialize schematic
|
||||
local schematic = pick_and_place.serialize(pos1, pos2)
|
||||
tool_meta:set_string("schematic", schematic)
|
||||
|
||||
local desc = string.format("Placement tool (%d bytes, size: %s)", #schematic, minetest.pos_to_string(size))
|
||||
tool_meta:set_string("description", desc)
|
||||
|
||||
return tool
|
||||
end
|
@ -14,17 +14,7 @@ local function on_rightclick(pos, _, _, itemstack)
|
||||
local pos1 = vector.add(pos, rel_pos1)
|
||||
local pos2 = vector.add(pos, rel_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))
|
||||
|
||||
-- serialize schematic
|
||||
local schematic = pick_and_place.serialize(pos1, pos2)
|
||||
tool_meta:set_string("schematic", schematic)
|
||||
|
||||
return tool
|
||||
return pick_and_place.create_tool(pos1, pos2)
|
||||
end
|
||||
|
||||
|
||||
@ -36,6 +26,7 @@ minetest.register_node("pick_and_place:handle", {
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
on_rightclick = on_rightclick,
|
||||
drop = "",
|
||||
groups = {
|
||||
oddly_breakable_by_hand = 3
|
||||
}
|
||||
|
2
init.lua
2
init.lua
@ -8,6 +8,8 @@ dofile(MP .. "/configure.lua")
|
||||
dofile(MP .. "/serialize.lua")
|
||||
dofile(MP .. "/entity.lua")
|
||||
dofile(MP .. "/handle_node.lua")
|
||||
dofile(MP .. "/create_tool.lua")
|
||||
dofile(MP .. "/configure_tool.lua")
|
||||
dofile(MP .. "/pick_tool.lua")
|
||||
dofile(MP .. "/place_tool.lua")
|
||||
dofile(MP .. "/preview.lua")
|
||||
|
48
pick_tool.lua
Normal file
48
pick_tool.lua
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
-- playername -> pos (if pos1 selected)
|
||||
local pos1 = {}
|
||||
|
||||
minetest.register_tool("pick_and_place:pick", {
|
||||
description = "Pick tool",
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#00ff00",
|
||||
stack_max = 1,
|
||||
range = 0,
|
||||
on_use = function(_, player)
|
||||
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 create tool
|
||||
local p1, p2 = pick_and_place.sort_pos(pos1[playername], pointed_pos)
|
||||
|
||||
local tool = pick_and_place.create_tool(p1, p2)
|
||||
pos1[playername] = nil
|
||||
return tool
|
||||
else
|
||||
-- first position selected
|
||||
pos1[playername] = pointed_pos
|
||||
end
|
||||
end,
|
||||
on_secondary_use = function(_, player)
|
||||
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", "#00ff00", 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
|
||||
})
|
@ -3,18 +3,15 @@ minetest.register_tool("pick_and_place:place", {
|
||||
inventory_image = "pick_and_place_plus.png^[colorize:#0000ff",
|
||||
stack_max = 1,
|
||||
range = 0,
|
||||
groups = {
|
||||
not_in_creative_inventory = 1
|
||||
},
|
||||
on_use = function(itemstack, player)
|
||||
print("on_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
local meta = itemstack:get_meta()
|
||||
local schematic = meta:get_string("schematic")
|
||||
pick_and_place.deserialize(pointed_pos, schematic)
|
||||
end,
|
||||
on_secondary_use = function(itemstack, player)
|
||||
print("on_secondary_use: " .. itemstack:get_name() .. ", " .. player:get_player_name())
|
||||
|
||||
end,
|
||||
on_step = function(itemstack, player)
|
||||
local playername = player:get_player_name()
|
||||
local pointed_pos = pick_and_place.get_pointed_position(player)
|
||||
|
@ -48,15 +48,6 @@ function pick_and_place.serialize(pos1, pos2)
|
||||
local compressed_data = minetest.compress(serialized_data, "deflate")
|
||||
local encoded_data = minetest.encode_base64(compressed_data)
|
||||
|
||||
-- TODO
|
||||
print(dump({
|
||||
fn = "pick_and_place.serialize",
|
||||
size = data.size,
|
||||
serialized_data_len = #serialized_data,
|
||||
compressed_data_len = #compressed_data,
|
||||
encoded_data_len = #encoded_data
|
||||
}))
|
||||
|
||||
return encoded_data
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user