added check for pipeworks' fake players

This commit is contained in:
TenPlus1 2019-02-27 14:34:17 +00:00
parent 4b5de2831c
commit ceca6bebff
2 changed files with 9 additions and 1 deletions

View File

@ -48,7 +48,7 @@ A global function is available for mods to change player stamina levels:
stamina.change(player, change)
This mod has added support for POVA and player_monoids for overrides to play
nicely.
nicely, it also has some pipeworks checks for fake players.
License:

View File

@ -29,6 +29,8 @@ SPRINT_DRAIN = 0.35 -- how fast to drain satation while sprinting (0-1)
local function get_int_attribute(player, key)
if not player.get_attribute then return nil end -- pipeworks fake player check
local level = player:get_attribute(key)
if level then
@ -41,6 +43,8 @@ end
local function stamina_update_level(player, level)
if not player.get_attribute then return nil end -- pipeworks fake player check
local old = get_int_attribute(player, "stamina:level")
if level == old then -- To suppress HUD update
@ -343,6 +347,10 @@ end
-- override core.do_item_eat() so we can redirect hp_change to stamina
core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
if user.is_fake_player then
return -- abort if called by fake player (eg. pipeworks-wielder)
end
local old_itemstack = itemstack
itemstack = stamina.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)