mirror of
https://github.com/rubenwardy/diet.git
synced 2025-01-09 18:20:17 +01:00
Fix hud_hunger compatibility (#3)
* Fix hud_hunger compatibility Add hbhunger support * Indent with tabs other than spaces * Fix for the old hud support
This commit is contained in:
parent
7256464660
commit
938bf546c5
@ -1,3 +1,5 @@
|
|||||||
|
hbhunger?
|
||||||
|
hud?
|
||||||
hunger?
|
hunger?
|
||||||
default?
|
default?
|
||||||
animalmaterials?
|
animalmaterials?
|
||||||
|
78
init.lua
78
init.lua
@ -23,13 +23,28 @@ function diet.save()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function diet.item_eat(max)
|
-- Poison player
|
||||||
return function(itemstack, user, pointed_thing)
|
local function poisenp(tick, time, time_left, player)
|
||||||
|
time_left = time_left + tick
|
||||||
|
if time_left < time then
|
||||||
|
minetest.after(tick, poisenp, tick, time, time_left, player)
|
||||||
|
else
|
||||||
|
--reset hud image
|
||||||
|
end
|
||||||
|
if player:get_hp()-1 > 0 then
|
||||||
|
player:set_hp(player:get_hp()-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function diet.item_eat(max, replace_with_item, poisen, heal)
|
||||||
|
return function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
-- Process player data
|
-- Process player data
|
||||||
local name = user:get_player_name()
|
local name = user:get_player_name()
|
||||||
local player = diet.__player(name)
|
local player = diet.__player(name)
|
||||||
local item = itemstack:get_name()
|
local item = itemstack:get_name()
|
||||||
|
|
||||||
-- Get type
|
-- Get type
|
||||||
local ftype = ""
|
local ftype = ""
|
||||||
if (minetest.registered_items[item] and minetest.registered_items[item].groups) then
|
if (minetest.registered_items[item] and minetest.registered_items[item].groups) then
|
||||||
@ -44,7 +59,7 @@ function diet.item_eat(max)
|
|||||||
ftype = "drink"
|
ftype = "drink"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate points
|
-- Calculate points
|
||||||
local points = max
|
local points = max
|
||||||
if (#player.eaten>0) then
|
if (#player.eaten>0) then
|
||||||
@ -60,7 +75,7 @@ function diet.item_eat(max)
|
|||||||
end
|
end
|
||||||
local mult = same_food/10
|
local mult = same_food/10
|
||||||
points = points * 1-mult
|
points = points * 1-mult
|
||||||
|
|
||||||
if (mult > 0.9) then
|
if (mult > 0.9) then
|
||||||
local desc = item
|
local desc = item
|
||||||
if (minetest.registered_items[item] and minetest.registered_items[item].description) then
|
if (minetest.registered_items[item] and minetest.registered_items[item].description) then
|
||||||
@ -75,14 +90,44 @@ function diet.item_eat(max)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Increase health
|
-- Increase health
|
||||||
if minetest.get_modpath("hud") and hud then
|
if minetest.get_modpath("hbhunger") and hbhunger then
|
||||||
|
minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})
|
||||||
|
|
||||||
|
-- saturation
|
||||||
|
local h = tonumber(hbhunger.hunger[name])
|
||||||
|
h = h + points
|
||||||
|
if h > 30 then h = 30 end
|
||||||
|
hbhunger.hunger[name] = h
|
||||||
|
hbhunger.set_hunger(user)
|
||||||
|
|
||||||
|
-- healing
|
||||||
|
local hp = user:get_hp()
|
||||||
|
if hp < 20 and heal then
|
||||||
|
hp = hp + heal
|
||||||
|
if hp > 20 then hp = 20 end
|
||||||
|
user:set_hp(hp)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Poison
|
||||||
|
if poisen then
|
||||||
|
--set hud-img
|
||||||
|
poisenp(1.0, poisen, 0, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif minetest.get_modpath("hunger") and hunger then
|
||||||
|
local h = tonumber(hunger.players[name].lvl)
|
||||||
|
h = h + points
|
||||||
|
hunger.update_hunger(user, h)
|
||||||
|
|
||||||
|
elseif minetest.get_modpath("hud") and hud and hud.hunger then
|
||||||
local h = tonumber(hud.hunger[name])
|
local h = tonumber(hud.hunger[name])
|
||||||
h = h + points
|
h = h + points
|
||||||
if h>30 then h = 30 end
|
if h > 30 then h = 30 end
|
||||||
hud.hunger[name] = h
|
hud.hunger[name] = h
|
||||||
hud.save_hunger(user)
|
hud.save_hunger(user)
|
||||||
|
|
||||||
else
|
else
|
||||||
local hp = user:get_hp()
|
local hp = user:get_hp()
|
||||||
if (hp+points > 20) then
|
if (hp+points > 20) then
|
||||||
@ -92,17 +137,18 @@ function diet.item_eat(max)
|
|||||||
end
|
end
|
||||||
user:set_hp(hp)
|
user:set_hp(hp)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register
|
-- Register
|
||||||
diet.__register_eat(player,item,ftype)
|
diet.__register_eat(player,item,ftype)
|
||||||
|
|
||||||
diet.save()
|
diet.save()
|
||||||
|
|
||||||
-- Remove item
|
-- Remove item
|
||||||
|
itemstack:add_item(replace_with_item)
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function diet.__player(name)
|
function diet.__player(name)
|
||||||
if name == "" then
|
if name == "" then
|
||||||
@ -128,12 +174,12 @@ function diet.__register_eat(player,food,type)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function overwrite(name, amt)
|
local function overwrite(name, hunger_change, replace_with_item, poisen, heal)
|
||||||
local tab = minetest.registered_items[name]
|
local tab = minetest.registered_items[name]
|
||||||
if not tab then
|
if not tab then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
tab.on_use = diet.item_eat(amt)
|
tab.on_use = diet.item_eat(hunger_change, replace_with_item, poisen, heal)
|
||||||
end
|
end
|
||||||
|
|
||||||
diet.__init()
|
diet.__init()
|
||||||
@ -223,7 +269,7 @@ end
|
|||||||
if minetest.get_modpath("bushes_classic") then
|
if minetest.get_modpath("bushes_classic") then
|
||||||
-- bushes_classic mod, as found in the plantlife modpack
|
-- bushes_classic mod, as found in the plantlife modpack
|
||||||
local berries = {
|
local berries = {
|
||||||
"strawberry",
|
"strawberry",
|
||||||
"blackberry",
|
"blackberry",
|
||||||
"blueberry",
|
"blueberry",
|
||||||
"raspberry",
|
"raspberry",
|
||||||
@ -397,7 +443,7 @@ if minetest.get_modpath("kpgmobs") ~= nil then
|
|||||||
overwrite("kpgmobs:meat", 6)
|
overwrite("kpgmobs:meat", 6)
|
||||||
overwrite("kpgmobs:rat_cooked", 5)
|
overwrite("kpgmobs:rat_cooked", 5)
|
||||||
overwrite("kpgmobs:med_cooked", 4)
|
overwrite("kpgmobs:med_cooked", 4)
|
||||||
if minetest.get_modpath("bucket") then
|
if minetest.get_modpath("bucket") then
|
||||||
overwrite("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
|
overwrite("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user