add set and go mine
This commit is contained in:
parent
002e9931ab
commit
8e63d4bb31
47
api.lua
47
api.lua
|
@ -39,6 +39,28 @@ local function load_home()
|
|||
end
|
||||
load_home()
|
||||
|
||||
|
||||
-- load_mine
|
||||
local function load_mine()
|
||||
local input = io.open(unified_inventory.mine_filename, "r")
|
||||
if input then
|
||||
while true do
|
||||
local x = input:read("*n")
|
||||
if x == nil then
|
||||
break
|
||||
end
|
||||
local y = input:read("*n")
|
||||
local z = input:read("*n")
|
||||
local name = input:read("*l")
|
||||
unified_inventory.minepos[name:sub(2)] = {x = x, y = y, z = z}
|
||||
end
|
||||
io.close(input)
|
||||
else
|
||||
unified_inventory.minepos = {}
|
||||
end
|
||||
end
|
||||
load_mine()
|
||||
|
||||
function unified_inventory.set_home(player, pos)
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.home_pos[player_name] = pos
|
||||
|
@ -62,6 +84,31 @@ function unified_inventory.go_home(player)
|
|||
end
|
||||
end
|
||||
|
||||
-- set_mine
|
||||
function unified_inventory.set_mine(player, pos)
|
||||
local player_name=player:get_player_name()
|
||||
unified_inventory.minepos[player_name] = pos
|
||||
-- save the mine data from the table to the file
|
||||
local output = io.open(unified_inventory.mine_filename, "w")
|
||||
for k, v in pairs(unified_inventory.minepos) do
|
||||
if v ~= nil then
|
||||
output:write(math.floor(v.x).." "
|
||||
..math.floor(v.y).." "
|
||||
..math.floor(v.z).." "
|
||||
..k.."\n")
|
||||
end
|
||||
end
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
-- go_mine
|
||||
function unified_inventory.go_mine(player)
|
||||
local pos = unified_inventory.minepos[player:get_player_name()]
|
||||
if pos ~= nil then
|
||||
player:setpos(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- register_craft
|
||||
function unified_inventory.register_craft(options)
|
||||
if not options.output then
|
||||
|
|
2
init.lua
2
init.lua
|
@ -24,6 +24,8 @@ unified_inventory.buttons = {}
|
|||
unified_inventory.home_pos = {}
|
||||
unified_inventory.home_filename =
|
||||
worldpath.."/unified_inventory_home.home"
|
||||
unified_inventory.mine_filename =
|
||||
worldpath.."/unified_inventory_mine.mine"
|
||||
|
||||
-- Default inventory page
|
||||
unified_inventory.default = "craft"
|
||||
|
|
27
register.lua
27
register.lua
|
@ -56,6 +56,33 @@ unified_inventory.register_button("home_gui_go", {
|
|||
unified_inventory.go_home(player)
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("mine_gui_set", {
|
||||
type = "image",
|
||||
image = "ui_setmine.png",
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
unified_inventory.set_mine(player, player:getpos())
|
||||
local mine = unified_inventory.minepos[player_name]
|
||||
if mine ~= nil then
|
||||
minetest.sound_play("dingdong",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.chat_send_player(player_name,
|
||||
"Mine position set to: "
|
||||
..minetest.pos_to_string(mine))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("mine_gui_go", {
|
||||
type = "image",
|
||||
image = "ui_gomine.png",
|
||||
action = function(player)
|
||||
minetest.sound_play("teleport",
|
||||
{to_player=player:get_player_name(), gain = 1.0})
|
||||
unified_inventory.go_mine(player)
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("misc_set_day", {
|
||||
type = "image",
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in New Issue