update bones

master
Brett O'Donnell 2012-09-21 19:31:48 +09:30
parent f9d563ce76
commit 09144b2a9b
2 changed files with 68 additions and 16 deletions

View File

@ -25,15 +25,19 @@ bones.replaceable_node_types = {
"air"
}
bones.inventory_take = function(pos, listname, index, count, player)
bones.allow_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not bones.privilege(meta, player) then
minetest.log("action", player:get_player_name()..
" tried to access bones belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return
return 0
end
return stack:get_count()
end
bones.on_inventory_take = function(pos, listname, index, stack, player)
local fresh = meta:get_int("fresh") or 1
if fresh > 0 then
fresh = "fresh"
@ -42,7 +46,6 @@ bones.inventory_take = function(pos, listname, index, count, player)
end
minetest.log("action", player:get_player_name()..
" picks from "..meta:get_string("owner").."'s "..fresh.." bones at "..minetest.pos_to_string(pos))
--return minetest.node_metadata_inventory_take_allow_all(pos, listname, index, count, player)
end
bones.privilege=function(meta, player)
@ -61,11 +64,13 @@ end
bones.action=function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local fresh = meta:get_int("fresh") or 0
local bonetime = meta:get_float("bonetime") or 0
if fresh > 0 and worldtime_get() - bonetime > bones.age_after then
local name = meta:get_string("owner") or ""
meta:set_string("infotext", name .. "'s old bones")
meta:set_int("fresh", -1)
if fresh > 0 then
local bonetime = meta:get_float("bonetime") or 0
if worldtime_get() - bonetime > bones.age_after then
local name = meta:get_string("owner") or ""
meta:set_string("infotext", name .. "'s old bones")
meta:set_int("fresh", -1)
end
end
end
@ -130,6 +135,51 @@ bones.settle_type = function(nodename)
return false
end
bones.on_punch = function(pos, node, player)
if node == nil or node.name ~= "bones:bones" then
return
end
local meta = minetest.env:get_meta(pos)
local fresh = meta:get_int("fresh") or 0
if fresh == 0 then
return
end
local name = player:get_player_name()
if name ~= meta:get_string("owner") then
return
end
local meta = minetest.env:get_meta(pos)
local bones_inv = meta:get_inventory()
if ( bones_inv == nil ) then
return
end
local player_inv = player:get_inventory()
if ( player_inv == nil ) then
minetest.log("error", 'Bones: Unable to get player '..name..' inventory')
return
end
for i=1,32 do
local stack = bones_inv:get_stack("main", i)
if stack ~= nil and not stack:is_empty() then
local leftover = player_inv:add_item("main", stack)
bones_inv:set_stack("main", i, nil)
if leftover ~= nil and not leftover:is_empty() then
bones_inv:set_stack("main", i, leftover)
else
bones_inv:set_stack("main", i, nil)
end
end
end
minetest.log("action", name.." unloaded his fresh bones at "..minetest.pos_to_string(pos))
end
bones.settle_bones = function(pos)
local nextpos = pos;
local node

View File

@ -1,5 +1,5 @@
---
--Bones 1.01
--Bones 1.02
--Copyright (C) 2012 Bad_Command
--
--This library is free software; you can redistribute it and/or
@ -18,7 +18,7 @@
----
bones = {}
bones.version = 1.01
bones.version = 1.02
-- config.lua contains configuration parameters
dofile(minetest.get_modpath("bones").."/config.lua")
@ -27,7 +27,7 @@ dofile(minetest.get_modpath("bones").."/bones.lua")
minetest.register_node("bones:bones", {
description = "Old Bones",
tiles ={"bones_top.png", "bones_bottom.png", "bones_side.png",
tile_images ={"bones_top.png", "bones_bottom.png", "bones_side.png",
"bones_side.png", "bones_rear.png", "bones_front.png"},
paramtype2 = "facedir",
groups = {crumbly=2},
@ -44,13 +44,14 @@ minetest.register_node("bones:bones", {
local inv = meta:get_inventory()
return inv == nil or inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
return 0
end,
on_metadata_inventory_offer = function(pos, listname, index, stack, player)
return stack
allow_metadata_inventory_move = function(pos, listname, index, stack, player)
return 0
end,
on_metadata_inventory_take = bones.inventory_take,
allow_metadata_inventory_take = bones.allow_inventory_take,
on_metadata_inventory_take = bones.inventory_take
})
minetest.register_abm(
@ -61,4 +62,5 @@ minetest.register_abm(
})
minetest.register_on_dieplayer(bones.on_dieplayer)
minetest.register_on_punchnode(bones.on_punch)