Update backpacks with kingdoms_game version

This commit is contained in:
Elkien3 2017-10-19 08:27:38 -05:00
parent a7a9fa04fd
commit 88c3caedac

View File

@ -99,6 +99,8 @@ end
minetest.after(CLEANUP_PERIOD__S, cleanInventory) minetest.after(CLEANUP_PERIOD__S, cleanInventory)
dropbackpack = function(player) dropbackpack = function(player)
local player = player
minetest.after(.1, function(player)
local name = player:get_player_name() local name = player:get_player_name()
if player_backpack[name] then if player_backpack[name] then
local pos = player:getpos() local pos = player:getpos()
@ -107,9 +109,11 @@ dropbackpack = function(player)
pos.y = pos.y + 0.4 pos.y = pos.y + 0.4
pack.owner = nil pack.owner = nil
obj:set_detach() obj:set_detach()
obj:setpos(pos) local addnewentity = rezEntity(nil, pos, player, pack.contents)
if addnewentity then obj:remove() end
player_backpack[name] = nil player_backpack[name] = nil
end end
end, player)
end end
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
@ -280,11 +284,11 @@ minetest.register_entity(
loop = false loop = false
}) })
end, end,
on_step = function(self, dt) --[[on_step = function(self, dt)
if self.owner then if self.owner then
self.object:setpos(self.owner:getpos()) self.object:setpos(self.owner:getpos())
end end
end end--]]
--[[on_step = function(self, dt) --[[on_step = function(self, dt)
self.timer = self.timer - dt self.timer = self.timer - dt
if self.timer > 0.0 then return end if self.timer > 0.0 then return end
@ -380,7 +384,7 @@ minetest.register_entity(
end--]] end--]]
}) })
local function rezEntity(stack, pos, player) function rezEntity(stack, pos, player, contents)
local x = pos.x local x = pos.x
local y = math.floor(pos.y) local y = math.floor(pos.y)
local z = pos.z local z = pos.z
@ -396,14 +400,15 @@ local function rezEntity(stack, pos, player)
local obj = minetest.env:add_entity(pos, "backpack:bag_entity") local obj = minetest.env:add_entity(pos, "backpack:bag_entity")
if not obj then return stack end if not obj then return stack end
if stack then
local contentData = stack:get_metadata() local contentData = stack:get_metadata()
local contents = deserializeContents(contentData) contents = deserializeContents(contentData)
obj:set_hp(BAG_MAX_HP - BAG_MAX_HP * stack:get_wear() / 2^16)
end
if contents then if contents then
obj:get_luaentity().contents = contents obj:get_luaentity().contents = contents
end end
obj:set_hp(4)
obj:set_hp(BAG_MAX_HP - BAG_MAX_HP * stack:get_wear() / 2^16)
minetest.sound_play( minetest.sound_play(
DROP_BAG_SOUND, DROP_BAG_SOUND,
@ -421,7 +426,7 @@ end
minetest.register_tool( minetest.register_tool(
"backpack:backpack", "backpack:backpack",
{ {
description = "Backpack", description = "Backpack (WORK IN PROGRESS, USE AT YOUR OWN RISK)",
groups = { bag = BAG_WIDTH*BAG_HEIGHT, flammable = 1 }, groups = { bag = BAG_WIDTH*BAG_HEIGHT, flammable = 1 },
inventory_image = "inventory_plus_backpack.png", inventory_image = "inventory_plus_backpack.png",
wield_image = "inventory_plus_backpack.png", wield_image = "inventory_plus_backpack.png",