tools
This commit is contained in:
parent
63ad7a2923
commit
a512f79a97
4
init.lua
4
init.lua
@ -30,4 +30,8 @@ end
|
|||||||
|
|
||||||
if minetest.settings:get_bool("building_lib.enable_example_buildings") then
|
if minetest.settings:get_bool("building_lib.enable_example_buildings") then
|
||||||
dofile(MP .. "/example_buildings.lua")
|
dofile(MP .. "/example_buildings.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.settings:get_bool("building_lib.enable_tools") then
|
||||||
|
dofile(MP .. "/tools.lua")
|
||||||
end
|
end
|
@ -68,4 +68,9 @@ building_lib.register_condition("on_flat_surface", {
|
|||||||
|
|
||||||
* `/building_place <building_name>`
|
* `/building_place <building_name>`
|
||||||
* `/building_check <building_name>`
|
* `/building_check <building_name>`
|
||||||
* `/building_info`
|
* `/building_info`
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
|
* Code: `MIT`
|
||||||
|
* Textures: `CC-BY-SA-3.0`
|
@ -1,2 +1,5 @@
|
|||||||
# Example buildings for testing
|
# Example buildings for testing
|
||||||
building_lib.enable_example_buildings (Enables the example buildings) bool false
|
building_lib.enable_example_buildings (Enables the example buildings) bool false
|
||||||
|
|
||||||
|
# Tools for manual placement
|
||||||
|
building_lib.enable_tools (Enables the admin tools) bool false
|
BIN
textures/building_lib_place.png
Normal file
BIN
textures/building_lib_place.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 630 B |
BIN
textures/building_lib_remove.png
Normal file
BIN
textures/building_lib_remove.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 629 B |
101
tools.lua
Normal file
101
tools.lua
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
local formname = "building_lib_placer_configure"
|
||||||
|
|
||||||
|
local function get_building_list()
|
||||||
|
local building_list = {}
|
||||||
|
for name in pairs(building_lib.buildings) do
|
||||||
|
table.insert(building_list, name)
|
||||||
|
end
|
||||||
|
return building_list
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_formspec(itemstack)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local building_list = get_building_list()
|
||||||
|
|
||||||
|
local selected_buildingname = meta:get_string("buildingname")
|
||||||
|
if not selected_buildingname or selected_buildingname == "" then
|
||||||
|
selected_buildingname = building_list[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
local selected_building = 1
|
||||||
|
local textlist = ""
|
||||||
|
|
||||||
|
for i, buildingname in ipairs(building_list) do
|
||||||
|
if selected_buildingname == buildingname then
|
||||||
|
selected_building = i
|
||||||
|
end
|
||||||
|
|
||||||
|
textlist = textlist .. buildingname
|
||||||
|
if i < #building_list then
|
||||||
|
textlist = textlist .. ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return "size[8,7;]" ..
|
||||||
|
"textlist[0,0.1;8,6;buildingname;" .. textlist .. ";" .. selected_building .. "]" ..
|
||||||
|
"button_exit[0.1,6.5;8,1;back;Back]"
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, f, fields)
|
||||||
|
if not minetest.check_player_privs(player, { mapblock_lib = true }) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if formname ~= f then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if fields.quit then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields.buildingname then
|
||||||
|
local parts = fields.buildingname:split(":")
|
||||||
|
if parts[1] == "CHG" then
|
||||||
|
local itemstack = player:get_wielded_item()
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
|
||||||
|
local selected = tonumber(parts[2])
|
||||||
|
local building_list = get_building_list()
|
||||||
|
|
||||||
|
local buildingname = building_list[selected]
|
||||||
|
if not buildingname then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
meta:set_string("buildingname", buildingname)
|
||||||
|
meta:set_string("description", "Selected building: '" .. buildingname .. "'")
|
||||||
|
player:set_wielded_item(itemstack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_tool("building_lib:place", {
|
||||||
|
description = "building_lib placer",
|
||||||
|
inventory_image = "building_lib_place.png",
|
||||||
|
stack_max = 1,
|
||||||
|
range = 0,
|
||||||
|
on_secondary_use = function(itemstack, player)
|
||||||
|
minetest.show_formspec(player:get_player_name(), formname, get_formspec(itemstack))
|
||||||
|
end,
|
||||||
|
on_use = function(itemstack, player)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local buildingname = meta:get_string("buildingname")
|
||||||
|
local building_def = building_lib.buildings[buildingname]
|
||||||
|
if not building_def then
|
||||||
|
minetest.chat_send_player(
|
||||||
|
player:get_player_name(),
|
||||||
|
"Placer unconfigured or selected building not found"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
print(dump(building_def))
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("building_lib:remove", {
|
||||||
|
description = "building_lib remover",
|
||||||
|
inventory_image = "building_lib_remove.png",
|
||||||
|
stack_max = 1,
|
||||||
|
range = 0,
|
||||||
|
on_use = function()
|
||||||
|
end
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user