Browse Source

prepare for unified_hunger patch

master
poikilos 5 years ago
parent
commit
2e4651cbf4
  1. 12
      Bucket_Game-base/clarify-food-api-vs-200327/mods/LICENSE
  2. 23
      Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/oldcoder.txt
  3. 63
      Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/LICENSE
  4. 372
      Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/hunger.lua
  5. 237
      Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/oldcoder.txt
  6. 12
      Bucket_Game-branches/clarify-food-api-vs-200327/mods/LICENSE
  7. 23
      Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/oldcoder.txt
  8. 63
      Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/LICENSE
  9. 372
      Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/hunger.lua
  10. 237
      Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/oldcoder.txt

12
Bucket_Game-base/clarify-food-api-vs-200327/mods/LICENSE

@ -0,0 +1,12 @@
For license information, see the following files, where they exist, in
each modpack or mod:
oldcoder.txt
LICENSE
LICENSE.txt
license.txt
README.md
README.txt
readme.txt
and/or files with similar names.

23
Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/oldcoder.txt

@ -0,0 +1,23 @@
Name: coderfood
Source: New modpack based on various mods and/or modpacks
License: See "license-modpack.txt"
----------------------------------------------------------------------
1. The "food" and "food_basic" mods were extracted from the following
modpack:
https://github.com/rubenwardy/food.git
modpack-level documentation files were moved into a new subdirectory
of the "food" mod named "rwfooddoc".
----------------------------------------------------------------------
2. Additions to that starting point:
2a. Added the OldCoder mod "coderfruit".
2b. Added Milan's forks of the mods "hbhunger" and "hudbars".
2c. Added the files "00README" and "oldcoder.txt" (this file).

63
Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/LICENSE

@ -0,0 +1,63 @@
Unified Foods Licenses
----------------------------------------------------------------------
1. OldCoder Unified Foods includes a food registration system and a
hunger system.
----------------------------------------------------------------------
2. The food registration system is original code. The license for the
code in question is:
(c) 2015-2020 and CC BY-NC-SA 4.0 International: OldCoder (Robert Kir-
aly)
----------------------------------------------------------------------
3. The hunger system is descended from a MT mod named "hbhunger". The
license for "hbhunger" code is LGPL v2.1. The license for "hbhunger"
textures is MIT.
One "hbhunger" sound file is used:
better_hunger_eat_generic.ogg
The license for that file is CC BY 3.0 with attribution to:
https://freesound.org/people/xtrgamr/sounds/253619/
----------------------------------------------------------------------
4. The licenses for other files are as follows:
* ufoods_*.png: WTFPL except for "ufoods_glass_*".
* ufoods_glass_*.png: These textures are presently based on a version
of "mobs_glass_milk.png" that is licensed as follows:
The MIT License (MIT)
Copyright (c) 2014 Krupnov Pavel and 2016 TenPlus1
* farming_*.png: See "farming" mod license file.
* mobs_*.png: See "mobs" mod license file.
* mtfoods_*.png:
License: (c) 2014-2020 and CC BY-NC-SA 4.0 International: Philip Rob-
inson.
* misc_baked_potato.png: WTFPL.
* coderfruit_*.png:
License: (c) 2019 and CC BY-NC-SA 4.0 International: OldCoder (Robert
Kiraly).
* moono_*.png:
License: (c) 2015-2020 and CC BY-SA 4.0 International: Moono.
* dessert_*.png and food_*.png:
License: (c) 2013-2010 and CC-BY-SA 3.0 Rubenwardy.
(end of document)

372
Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/hunger.lua

@ -0,0 +1,372 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath (modname)
local enable_wonder = minetest.setting_getbool ("enable_wonder")
unified_hunger = {}
-- HUD statbar values
unified_hunger.hunger = {}
unified_hunger.hunger_out = {}
-- HUD item ids
local hunger_hud = {}
if minetest.setting_getbool ("enable_damage") then
unified_hunger.enable_damage = true
else
unified_hunger.enable_damage = false
end
HUNGER_HUD_TICK = 0.5 -- 0.1
--Some hunger settings
unified_hunger.exhaustion = {} -- Exhaustion is experimental!
-- time in seconds after that 1 hunger point is taken
local HUNGER_TICK_DEFAULT = 180
if enable_wonder then
HUNGER_TICK_DEFAULT = 90
end
HUNGER_HUNGER_TICK = tonumber (minetest.setting_get ("hunger_tick")) or HUNGER_TICK_DEFAULT
if HUNGER_HUNGER_TICK < 10 then HUNGER_HUNGER_TICK = 10 end
HUNGER_EXHAUST_DIG = 1.5 -- exhaustion increased this value after digged node
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
--[[load custom settings
local set = io.open(minetest.get_modpath("unified_hunger").."/unified_hunger.conf", "r")
if set then
dofile(minetest.get_modpath("unified_hunger").."/unified_hunger.conf")
set:close()
end--]]
local function custom_hud(player)
hb.init_hudbar(player, "satiation", unified_hunger.get_hunger(player))
end
-- Keep these for backwards compatibility
function unified_hunger.save_hunger(player)
unified_hunger.set_hunger(player)
end
function unified_hunger.load_hunger(player)
unified_hunger.get_hunger(player)
end
-- Poison player
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 unified_hunger.item_eat (hunger_change,
replace_with_item, poisen, heal, msg)
return function (itemstack, user, pointed_thing)
if itemstack:take_item() ~= nil and user ~= nil then
local name = user:get_player_name()
local h = tonumber(unified_hunger.hunger[name])
local hp = user:get_hp()
minetest.sound_play("unified_hunger_eat_generic", {
object = user,
max_hear_distance = 10,
gain = 1.0
})
-- Saturation
if h < 30 and hunger_change then
h = h + hunger_change
if h > 30 then h = 30 end
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(user)
end
-- Healing
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
if replace_with_item then
if itemstack:is_empty() then
itemstack:add_item(replace_with_item)
else
local inv = user:get_inventory()
if inv:room_for_item("main", {name = replace_with_item}) then
inv:add_item("main", replace_with_item)
else
local pos = user:getpos()
pos.y = math.floor(pos.y + 0.5)
core.add_item(pos, replace_with_item)
end
end
end
if msg ~= nil then
local mt = type (msg)
local send = nil
if mt == "string" then
send = msg
elseif mt == "table" then
send = msg [math.random (#msg)]
end
minetest.chat_send_player (name, send)
end
end
return itemstack
end
end
unified_hunger.overwrite = function (name, satiate, heal, poison,
replace, msg)
if not unified_hunger.enable_damage then
poison = nil
end
name = minetest.registered_aliases [name] or name
if minetest.registered_items [name] ~= nil then
minetest.override_item (name, {
on_use = unified_hunger.item_eat (satiate,
replace, poison, heal, msg)
})
end
end
local overwrite = unified_hunger.overwrite
-- ===================================================================
-- player-action based hunger changes
function unified_hunger.handle_node_actions(pos, oldnode, player, ext)
if not player or not player:is_player() then
return
end
local name = player:get_player_name()
local exhaus = unified_hunger.exhaustion[name]
if exhaus == nil then return end
local new = HUNGER_EXHAUST_PLACE
-- placenode event
if not ext then
new = HUNGER_EXHAUST_DIG
end
-- assume its send by main timer when movement detected
if not pos and not oldnode then
new = HUNGER_EXHAUST_MOVE
end
exhaus = exhaus + new
if exhaus > HUNGER_EXHAUST_LVL then
exhaus = 0
local h = tonumber(unified_hunger.hunger[name])
h = h - 1
if h < 0 then h = 0 end
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(player)
end
unified_hunger.exhaustion[name] = exhaus
end
--minetest.register_on_placenode(unified_hunger.handle_node_actions)
minetest.register_on_dignode(unified_hunger.handle_node_actions)
-- register satiation hudbar
hb.register_hudbar(
"satiation", 0xFFFFFF, "Satiation",
{
icon = "unified_hunger_icon.png",
bgicon = "unified_hunger_bgicon.png",
bar = "unified_hunger_bar.png"
},
20, 30, false
)
-- update hud elemtents if value has changed
local function update_hud(player)
local name = player:get_player_name()
local h_out = tonumber(unified_hunger.hunger_out[name])
local h = tonumber(unified_hunger.hunger[name])
if h_out ~= h then
unified_hunger.hunger_out[name] = h
hb.change_hudbar(player, "satiation", h)
end
end
unified_hunger.get_hunger = function(player)
local inv = player:get_inventory()
if not inv then return nil end
local hgp = inv:get_stack("hunger", 1):get_count()
if hgp == 0 then
hgp = 21
inv:set_stack("hunger", 1, ItemStack({name = ":", count = hgp}))
else
hgp = hgp
end
return hgp - 1
end
unified_hunger.set_hunger = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local value = unified_hunger.hunger[name]
if not inv or not value then return nil end
if value > 30 then value = 30 end
if value < 0 then value = 0 end
inv:set_stack("hunger", 1, ItemStack({name = ":", count = value + 1}))
return true
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local inv = player:get_inventory()
inv:set_size("hunger", 1)
unified_hunger.hunger[name] = unified_hunger.get_hunger(player)
unified_hunger.hunger_out[name] = unified_hunger.hunger[name]
unified_hunger.exhaustion[name] = 0
custom_hud(player)
unified_hunger.set_hunger(player)
end)
minetest.register_on_respawnplayer(function(player)
-- reset hunger (and save)
local name = player:get_player_name()
unified_hunger.hunger[name] = 20
unified_hunger.set_hunger(player)
unified_hunger.exhaustion[name] = 0
end)
-- ===================================================================
local param_starve = {
description = "Be hungry" ,
params = "" ,
privs = {} ,
func = function (plname, params)
local player = minetest.env:get_player_by_name (plname)
unified_hunger.hunger [plname] = 5
unified_hunger.set_hunger (player)
minetest.chat_send_player (plname, "O.K. you're hungry")
end
}
minetest.register_chatcommand ("starve", param_starve)
-- ===================================================================
minetest.register_privilege ("satiate", {
description = "satiate administration" ,
give_to_singleplayer = false ,
})
local param_satiate = {
description = "Be satiated" ,
params = "" ,
privs = { satiate=true } ,
func = function (plname, params)
local player = minetest.env:get_player_by_name (plname)
unified_hunger.hunger [plname] = 20
unified_hunger.set_hunger (player)
minetest.chat_send_player (plname, "O.K. you're satiated")
end
}
minetest.register_chatcommand ("satiate", param_satiate)
-- ===================================================================
if unified_hunger.enable_damage then
local main_timer = 0
local timer = 0
local timer2 = 0
minetest.register_globalstep(function(dtime)
main_timer = main_timer + dtime
timer = timer + dtime
timer2 = timer2 + dtime
if main_timer > HUNGER_HUD_TICK
or timer > 4
or timer2 > HUNGER_HUNGER_TICK then
if main_timer > HUNGER_HUD_TICK then
main_timer = 0
end
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local h = tonumber(unified_hunger.hunger[name])
local hp = player:get_hp()
if timer > 4 then
-- heal player by 1 hp if not dead and satiation is > 15
if h > 15
and hp > 0
and player:get_breath() > 0 then
player:set_hp(hp + 1)
-- or damage player by 1 hp if satiation is < 2
elseif h <= 1 then
if hp - 1 >= 0 then
player:set_hp(hp - 1)
end
end
end
-- lower satiation by 1 point after xx seconds
if timer2 > HUNGER_HUNGER_TICK then
if h > 0 then
h = h - 1
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(player)
end
end
-- update hud elements
update_hud(player)
-- Determine if player is walking
local controls = player:get_player_control()
if controls.up
or controls.down
or controls.left
or controls.right then
unified_hunger.handle_node_actions(nil, nil, player)
end
end
end
if timer > 4 then
timer = 0
end
if timer2 > HUNGER_HUNGER_TICK then
timer2 = 0
end
end)
end -- end if damage enabled

237
Bucket_Game-base/clarify-food-api-vs-200327/mods/coderfood/unified_foods/oldcoder.txt

@ -0,0 +1,237 @@
Name: unified_foods
Source: Original mod except for some "hbhunger" code
License: See "LICENSE"
----------------------------------------------------------------------
1. "unified_foods" is a largely original mod that provides a combined
food registration and hunger system.
The hunger system is based on a fork of "hbhunger".
This mod supersedes the following mods, though it doesn't replace all
of the foods defined in the mods:
food, food_basic, dessert, hbhunger, extra, mtfoods
----------------------------------------------------------------------
2. Overview of features.
2.1. Unified Foods supports satiation, healing, poison, and replace-
ment items as "hbhunger" did. It also offers numerous extra features.
----------------------------------------------------------------------
2.2. You don't need to explicitly hook foods any longer to support
basic operation.
Unified Foods intercepts calls to "minetest.item_eat". This means that
satiation and replacement items are supported automatically for normal
foods out of the box.
You can still hook foods to modify existing parameters or to set new
ones. However, this is optional.
----------------------------------------------------------------------
2.3. Unified Foods can merge similar items.
If there are, for example, three types of hamburgers, Unified Foods
retains all of the items or nodes, but it optionally assigns a similar
image and food parameters to all of them.
No permanent conversion is done. Just a temporary merge to promote the
sense of smoother operation. However, permanent conversion could be
added as another feature.
----------------------------------------------------------------------
2.4. Eating a particular food can optionally produce a specified mes-
sage to the user. Lists of messages are supported. If a list is speci-
fied, a random message is chosen from the list.
----------------------------------------------------------------------
2.5. "hbhunger" had a bug which prevented it from properly registering
items that didn't set "on_use". Unified Foods supports items of that
type. This means that, for example, you can make arbitrary items eata-
ble.
----------------------------------------------------------------------
2.6. Eating works whether or not damage is enabled.
If hunger is enabled and damage is disabled, the hunger time loop is
stopped and poison does no damage at the Unified Foods level.
----------------------------------------------------------------------
2.7. Two new commands "/starve" and "/satiate" have been added.
"/starve" makes the user hungry. "/satiate" makes him or her satiated
instead. These commands are useful for debugging purposes.
----------------------------------------------------------------------
2.8. It's easy to add juices to Unified Foods.
You can create a new juice, including merges with existing objects,
crafting recipes, and aliases, using just one simple statement. For
example, this statement:
reg_juice ("apple",
{ color = "#FFC929" } , { "mtfoods:apple_juice" })
sets up and/or performs all of these steps:
* Create a glass of juice named "food:apple_juice"
* Alias the glass to "mtfoods:apple_juice" if that item exists
* Set "mtfoods:apple_juice" to new juice's image and satiation
* Add a crafting recipe for new juice
* Create aliases "apple_juice" and "applejuice"
* If the player drinks the juice, replace it with empty glass
If a juice is a uniform color, the API is able to create an appropri-
ate juice image at runtime. So, it's possible to have numerous juices
without the need for numerous image files.
However, juice image files may be specified as well. This allows spe-
cial cases such as rainbow juice or worm juice to be handled.
----------------------------------------------------------------------
2.9. Unified Foods allows craft-item foods to be placed. Two modes are
supported:
Craft-items may be placed as static 2D sprites that always face the
caller.
This often looks better than the "plantlike" or "torchlike" drawing
modes that MT "_games" usually use when 2D objects are placed.
Or craft-items may be placed as dynamic 2D sprites that work the same
way but are "alive". For example, placed hamburgers may attempt to run
away from hungry players.
Craft-items may also be placed in "plantlike" or "torchlike" mode if a
world developer prefers this.
The mode in which craft-items are to be placed can be specified glob-
ally in "world.conf" or on a per-item basis in the mod source code for
individual items.
For more detailed documentation, see the comments preceding "register_
food" in "foodcore.lua".
----------------------------------------------------------------------
3. This mod requires only "default" and "hud", but "bucket" and "farm-
ing" are strongly recommended.
----------------------------------------------------------------------
4. This mod replaces the complicated API used by "food" v2 with an API
that's easier to use.
In particular, in Unified Foods, one subroutine call, in one place, is
typically enough to set up a food. Two calls, if a juice variation of
the food is desired.
Additionally, this mod restores some of the foods that were discarded
in "food" v2.
Historical note: The last pre-v2 commit to "food" was:
22be9b83c3087e15eea8878c5aef9be0f12d6158
----------------------------------------------------------------------
5. Unified Foods creates food and utensils in the "food:" namespace.
Most of these objects are original items that fall back to existing
items where possible.
For example, if "farming" is installed, "food:bread" becomes an alias
for "farming:bread". Otherwise, it's defined as a new and independent
item.
----------------------------------------------------------------------
6. If "drawtype" is set to "sprite" or "mob" for an item, "vsize" may
set, as well, to scale the size of the item up or down.
vsize = 0.50 will, for example, scale the item to half size. vsize =
2.00 will scale it to twice normal size.
The code adjusts collision boxes and vertical positions for items ap-
propriately.
----------------------------------------------------------------------
Appendix A. Partial list of objects supported.
Fruits:
Apple, Banana, Cherry, Orange, Pineapple, and Strawberry. Plus the
associated juices.
----------------------------------------------------------------------
Misc.:
Hamburger. Hamburger juice. Rainbow and worm juices. OBOE (Open Blade
of Exile) potions in multiple colors. Taco.
Raw and cooked pasta. A couple of types of breakfast cereal. Dog
treats.
Glass of Romulan Ale. Glass of Ginger Ale. Bottle of apple cider.
----------------------------------------------------------------------
Vegetables:
Onion, onion rings, onion slices.
Potato, potato juice, baked potato, potato slices, french fries, pota-
to chips.
Carrot, corn, rhubarb, and tomato. Plus most of the associated juices.
----------------------------------------------------------------------
Dairy:
Glass or bucket of milk. Butter. Cheese.
----------------------------------------------------------------------
Chocolate:
Cocoa bean, chocolate powder, dark chocolate, milk chocolate, and cup
or mug of chocolate milk.
----------------------------------------------------------------------
Coffee:
Raw coffee beans, roasted coffee beans, and cup or mug of coffee.
----------------------------------------------------------------------
Dessert:
Snackcake, blueberry muffin, raw tart base, tart base, and strawberry
tart.
Banana split, shortbread, cream, strawberry shortcake, and cupcake.
Moono desserts: Butterscotch Dillybar, Butterscotch Sundae, Heart on a
Stick, Strawberry Bar, Strawberry Icecream, and Strawberry Star.
There are also some cakes, but we encourage people to use the cakes
and pies from the "cakepie" mod instead. The cakes in this mod are
provided primarily for legacy support purposes.
----------------------------------------------------------------------
End of file.

12
Bucket_Game-branches/clarify-food-api-vs-200327/mods/LICENSE

@ -0,0 +1,12 @@
For license information, see the following files, where they exist, in
each modpack or mod:
oldcoder.txt
LICENSE
LICENSE.txt
license.txt
README.md
README.txt
readme.txt
and/or files with similar names.

23
Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/oldcoder.txt

@ -0,0 +1,23 @@
Name: coderfood
Source: New modpack based on various mods and/or modpacks
License: See "license-modpack.txt"
----------------------------------------------------------------------
1. The "food" and "food_basic" mods were extracted from the following
modpack:
https://github.com/rubenwardy/food.git
modpack-level documentation files were moved into a new subdirectory
of the "food" mod named "rwfooddoc".
----------------------------------------------------------------------
2. Additions to that starting point:
2a. Added the OldCoder mod "coderfruit".
2b. Added Milan's forks of the mods "hbhunger" and "hudbars".
2c. Added the files "00README" and "oldcoder.txt" (this file).

63
Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/LICENSE

@ -0,0 +1,63 @@
Unified Foods Licenses
----------------------------------------------------------------------
1. OldCoder Unified Foods includes a food registration system and a
hunger system.
----------------------------------------------------------------------
2. The food registration system is original code. The license for the
code in question is:
(c) 2015-2020 and CC BY-NC-SA 4.0 International: OldCoder (Robert Kir-
aly)
----------------------------------------------------------------------
3. The hunger system is descended from a MT mod named "hbhunger". The
license for "hbhunger" code is LGPL v2.1. The license for "hbhunger"
textures is MIT.
One "hbhunger" sound file is used:
better_hunger_eat_generic.ogg
The license for that file is CC BY 3.0 with attribution to:
https://freesound.org/people/xtrgamr/sounds/253619/
----------------------------------------------------------------------
4. The licenses for other files are as follows:
* ufoods_*.png: WTFPL except for "ufoods_glass_*".
* ufoods_glass_*.png: These textures are presently based on a version
of "mobs_glass_milk.png" that is licensed as follows:
The MIT License (MIT)
Copyright (c) 2014 Krupnov Pavel and 2016 TenPlus1
* farming_*.png: See "farming" mod license file.
* mobs_*.png: See "mobs" mod license file.
* mtfoods_*.png:
License: (c) 2014-2020 and CC BY-NC-SA 4.0 International: Philip Rob-
inson.
* misc_baked_potato.png: WTFPL.
* coderfruit_*.png:
License: (c) 2019 and CC BY-NC-SA 4.0 International: OldCoder (Robert
Kiraly).
* moono_*.png:
License: (c) 2015-2020 and CC BY-SA 4.0 International: Moono.
* dessert_*.png and food_*.png:
License: (c) 2013-2010 and CC-BY-SA 3.0 Rubenwardy.
(end of document)

372
Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/hunger.lua

@ -0,0 +1,372 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath (modname)
local enable_wonder = minetest.setting_getbool ("enable_wonder")
unified_hunger = {}
-- HUD statbar values
unified_hunger.hunger = {}
unified_hunger.hunger_out = {}
-- HUD item ids
local hunger_hud = {}
if minetest.setting_getbool ("enable_damage") then
unified_hunger.enable_damage = true
else
unified_hunger.enable_damage = false
end
HUNGER_HUD_TICK = 0.5 -- 0.1
--Some hunger settings
unified_hunger.exhaustion = {} -- Exhaustion is experimental!
-- time in seconds after that 1 hunger point is taken
local HUNGER_TICK_DEFAULT = 180
if enable_wonder then
HUNGER_TICK_DEFAULT = 90
end
HUNGER_HUNGER_TICK = tonumber (minetest.setting_get ("hunger_tick")) or HUNGER_TICK_DEFAULT
if HUNGER_HUNGER_TICK < 10 then HUNGER_HUNGER_TICK = 10 end
HUNGER_EXHAUST_DIG = 1.5 -- exhaustion increased this value after digged node
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
--[[load custom settings
local set = io.open(minetest.get_modpath("unified_hunger").."/unified_hunger.conf", "r")
if set then
dofile(minetest.get_modpath("unified_hunger").."/unified_hunger.conf")
set:close()
end--]]
local function custom_hud(player)
hb.init_hudbar(player, "satiation", unified_hunger.get_hunger(player))
end
-- Keep these for backwards compatibility
function unified_hunger.save_hunger(player)
unified_hunger.set_hunger(player)
end
function unified_hunger.load_hunger(player)
unified_hunger.get_hunger(player)
end
-- Poison player
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 unified_hunger.item_eat (hunger_change,
replace_with_item, poisen, heal, msg)
return function (itemstack, user, pointed_thing)
if itemstack:take_item() ~= nil and user ~= nil then
local name = user:get_player_name()
local h = tonumber(unified_hunger.hunger[name])
local hp = user:get_hp()
minetest.sound_play("unified_hunger_eat_generic", {
object = user,
max_hear_distance = 10,
gain = 1.0
})
-- Saturation
if h < 30 and hunger_change then
h = h + hunger_change
if h > 30 then h = 30 end
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(user)
end
-- Healing
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
if replace_with_item then
if itemstack:is_empty() then
itemstack:add_item(replace_with_item)
else
local inv = user:get_inventory()
if inv:room_for_item("main", {name = replace_with_item}) then
inv:add_item("main", replace_with_item)
else
local pos = user:getpos()
pos.y = math.floor(pos.y + 0.5)
core.add_item(pos, replace_with_item)
end
end
end
if msg ~= nil then
local mt = type (msg)
local send = nil
if mt == "string" then
send = msg
elseif mt == "table" then
send = msg [math.random (#msg)]
end
minetest.chat_send_player (name, send)
end
end
return itemstack
end
end
unified_hunger.overwrite = function (name, satiate, heal, poison,
replace, msg)
if not unified_hunger.enable_damage then
poison = nil
end
name = minetest.registered_aliases [name] or name
if minetest.registered_items [name] ~= nil then
minetest.override_item (name, {
on_use = unified_hunger.item_eat (satiate,
replace, poison, heal, msg)
})
end
end
local overwrite = unified_hunger.overwrite
-- ===================================================================
-- player-action based hunger changes
function unified_hunger.handle_node_actions(pos, oldnode, player, ext)
if not player or not player:is_player() then
return
end
local name = player:get_player_name()
local exhaus = unified_hunger.exhaustion[name]
if exhaus == nil then return end
local new = HUNGER_EXHAUST_PLACE
-- placenode event
if not ext then
new = HUNGER_EXHAUST_DIG
end
-- assume its send by main timer when movement detected
if not pos and not oldnode then
new = HUNGER_EXHAUST_MOVE
end
exhaus = exhaus + new
if exhaus > HUNGER_EXHAUST_LVL then
exhaus = 0
local h = tonumber(unified_hunger.hunger[name])
h = h - 1
if h < 0 then h = 0 end
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(player)
end
unified_hunger.exhaustion[name] = exhaus
end
--minetest.register_on_placenode(unified_hunger.handle_node_actions)
minetest.register_on_dignode(unified_hunger.handle_node_actions)
-- register satiation hudbar
hb.register_hudbar(
"satiation", 0xFFFFFF, "Satiation",
{
icon = "unified_hunger_icon.png",
bgicon = "unified_hunger_bgicon.png",
bar = "unified_hunger_bar.png"
},
20, 30, false
)
-- update hud elemtents if value has changed
local function update_hud(player)
local name = player:get_player_name()
local h_out = tonumber(unified_hunger.hunger_out[name])
local h = tonumber(unified_hunger.hunger[name])
if h_out ~= h then
unified_hunger.hunger_out[name] = h
hb.change_hudbar(player, "satiation", h)
end
end
unified_hunger.get_hunger = function(player)
local inv = player:get_inventory()
if not inv then return nil end
local hgp = inv:get_stack("hunger", 1):get_count()
if hgp == 0 then
hgp = 21
inv:set_stack("hunger", 1, ItemStack({name = ":", count = hgp}))
else
hgp = hgp
end
return hgp - 1
end
unified_hunger.set_hunger = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local value = unified_hunger.hunger[name]
if not inv or not value then return nil end
if value > 30 then value = 30 end
if value < 0 then value = 0 end
inv:set_stack("hunger", 1, ItemStack({name = ":", count = value + 1}))
return true
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local inv = player:get_inventory()
inv:set_size("hunger", 1)
unified_hunger.hunger[name] = unified_hunger.get_hunger(player)
unified_hunger.hunger_out[name] = unified_hunger.hunger[name]
unified_hunger.exhaustion[name] = 0
custom_hud(player)
unified_hunger.set_hunger(player)
end)
minetest.register_on_respawnplayer(function(player)
-- reset hunger (and save)
local name = player:get_player_name()
unified_hunger.hunger[name] = 20
unified_hunger.set_hunger(player)
unified_hunger.exhaustion[name] = 0
end)
-- ===================================================================
local param_starve = {
description = "Be hungry" ,
params = "" ,
privs = {} ,
func = function (plname, params)
local player = minetest.env:get_player_by_name (plname)
unified_hunger.hunger [plname] = 5
unified_hunger.set_hunger (player)
minetest.chat_send_player (plname, "O.K. you're hungry")
end
}
minetest.register_chatcommand ("starve", param_starve)
-- ===================================================================
minetest.register_privilege ("satiate", {
description = "satiate administration" ,
give_to_singleplayer = false ,
})
local param_satiate = {
description = "Be satiated" ,
params = "" ,
privs = { satiate=true } ,
func = function (plname, params)
local player = minetest.env:get_player_by_name (plname)
unified_hunger.hunger [plname] = 20
unified_hunger.set_hunger (player)
minetest.chat_send_player (plname, "O.K. you're satiated")
end
}
minetest.register_chatcommand ("satiate", param_satiate)
-- ===================================================================
if unified_hunger.enable_damage then
local main_timer = 0
local timer = 0
local timer2 = 0
minetest.register_globalstep(function(dtime)
main_timer = main_timer + dtime
timer = timer + dtime
timer2 = timer2 + dtime
if main_timer > HUNGER_HUD_TICK
or timer > 4
or timer2 > HUNGER_HUNGER_TICK then
if main_timer > HUNGER_HUD_TICK then
main_timer = 0
end
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local h = tonumber(unified_hunger.hunger[name])
local hp = player:get_hp()
if timer > 4 then
-- heal player by 1 hp if not dead and satiation is > 15
if h > 15
and hp > 0
and player:get_breath() > 0 then
player:set_hp(hp + 1)
-- or damage player by 1 hp if satiation is < 2
elseif h <= 1 then
if hp - 1 >= 0 then
player:set_hp(hp - 1)
end
end
end
-- lower satiation by 1 point after xx seconds
if timer2 > HUNGER_HUNGER_TICK then
if h > 0 then
h = h - 1
unified_hunger.hunger[name] = h
unified_hunger.set_hunger(player)
end
end
-- update hud elements
update_hud(player)
-- Determine if player is walking
local controls = player:get_player_control()
if controls.up
or controls.down
or controls.left
or controls.right then
unified_hunger.handle_node_actions(nil, nil, player)
end
end
end
if timer > 4 then
timer = 0
end
if timer2 > HUNGER_HUNGER_TICK then
timer2 = 0
end
end)
end -- end if damage enabled

237
Bucket_Game-branches/clarify-food-api-vs-200327/mods/coderfood/unified_foods/oldcoder.txt

@ -0,0 +1,237 @@
Name: unified_foods
Source: Original mod except for some "hbhunger" code
License: See "LICENSE"
----------------------------------------------------------------------
1. "unified_foods" is a largely original mod that provides a combined
food registration and hunger system.
The hunger system is based on a fork of "hbhunger".
This mod supersedes the following mods, though it doesn't replace all
of the foods defined in the mods:
food, food_basic, dessert, hbhunger, extra, mtfoods
----------------------------------------------------------------------
2. Overview of features.
2.1. Unified Foods supports satiation, healing, poison, and replace-
ment items as "hbhunger" did. It also offers numerous extra features.
----------------------------------------------------------------------
2.2. You don't need to explicitly hook foods any longer to support
basic operation.
Unified Foods intercepts calls to "minetest.item_eat". This means that
satiation and replacement items are supported automatically for normal
foods out of the box.
You can still hook foods to modify existing parameters or to set new
ones. However, this is optional.
----------------------------------------------------------------------
2.3. Unified Foods can merge similar items.
If there are, for example, three types of hamburgers, Unified Foods
retains all of the items or nodes, but it optionally assigns a similar
image and food parameters to all of them.
No permanent conversion is done. Just a temporary merge to promote the
sense of smoother operation. However, permanent conversion could be
added as another feature.
----------------------------------------------------------------------
2.4. Eating a particular food can optionally produce a specified mes-
sage to the user. Lists of messages are supported. If a list is speci-
fied, a random message is chosen from the list.
----------------------------------------------------------------------
2.5. "hbhunger" had a bug which prevented it from properly registering
items that didn't set "on_use". Unified Foods supports items of that
type. This means that, for example, you can make arbitrary items eata-
ble.
----------------------------------------------------------------------
2.6. Eating works whether or not damage is enabled.
If hunger is enabled and damage is disabled, the hunger time loop is
stopped and poison does no damage at the Unified Foods level.
----------------------------------------------------------------------
2.7. Two new commands "/starve" and "/satiate" have been added.
"/starve" makes the user hungry. "/satiate" makes him or her satiated
instead. These commands are useful for debugging purposes.
----------------------------------------------------------------------
2.8. It's easy to add juices to Unified Foods.
You can create a new juice, including merges with existing objects,
crafting recipes, and aliases, using just one simple statement. For
example, this statement:
reg_juice ("apple",
{ color = "#FFC929" } , { "mtfoods:apple_juice" })
sets up and/or performs all of these steps:
* Create a glass of juice named "food:apple_juice"
* Alias the glass to "mtfoods:apple_juice" if that item exists
* Set "mtfoods:apple_juice" to new juice's image and satiation
* Add a crafting recipe for new juice
* Create aliases "apple_juice" and "applejuice"
* If the player drinks the juice, replace it with empty glass
If a juice is a uniform color, the API is able to create an appropri-
ate juice image at runtime. So, it's possible to have numerous juices
without the need for numerous image files.
However, juice image files may be specified as well. This allows spe-
cial cases such as rainbow juice or worm juice to be handled.
----------------------------------------------------------------------
2.9. Unified Foods allows craft-item foods to be placed. Two modes are
supported:
Craft-items may be placed as static 2D sprites that always face the
caller.
This often looks better than the "plantlike" or "torchlike" drawing
modes that MT "_games" usually use when 2D objects are placed.
Or craft-items may be placed as dynamic 2D sprites that work the same
way but are "alive". For example, placed hamburgers may attempt to run
away from hungry players.
Craft-items may also be placed in "plantlike" or "torchlike" mode if a
world developer prefers this.
The mode in which craft-items are to be placed can be specified glob-
ally in "world.conf" or on a per-item basis in the mod source code for
individual items.
For more detailed documentation, see the comments preceding "register_
food" in "foodcore.lua".
----------------------------------------------------------------------
3. This mod requires only "default" and "hud", but "bucket" and "farm-
ing" are strongly recommended.
----------------------------------------------------------------------
4. This mod replaces the complicated API used by "food" v2 with an API
that's easier to use.
In particular, in Unified Foods, one subroutine call, in one place, is
typically enough to set up a food. Two calls, if a juice variation of
the food is desired.
Additionally, this mod restores some of the foods that were discarded
in "food" v2.
Historical note: The last pre-v2 commit to "food" was:
22be9b83c3087e15eea8878c5aef9be0f12d6158
----------------------------------------------------------------------
5. Unified Foods creates food and utensils in the "food:" namespace.
Most of these objects are original items that fall back to existing
items where possible.
For example, if "farming" is installed, "food:bread" becomes an alias
for "farming:bread". Otherwise, it's defined as a new and independent
item.
----------------------------------------------------------------------
6. If "drawtype" is set to "sprite" or "mob" for an item, "vsize" may
set, as well, to scale the size of the item up or down.
vsize = 0.50 will, for example, scale the item to half size. vsize =
2.00 will scale it to twice normal size.
The code adjusts collision boxes and vertical positions for items ap-
propriately.
----------------------------------------------------------------------
Appendix A. Partial list of objects supported.
Fruits:
Apple, Banana, Cherry, Orange, Pineapple, and Strawberry. Plus the
associated juices.
----------------------------------------------------------------------
Misc.:
Hamburger. Hamburger juice. Rainbow and worm juices. OBOE (Open Blade
of Exile) potions in multiple colors. Taco.
Raw and cooked pasta. A couple of types of breakfast cereal. Dog
treats.
Glass of Romulan Ale. Glass of Ginger Ale. Bottle of apple cider.
----------------------------------------------------------------------
Vegetables:
Onion, onion rings, onion slices.
Potato, potato juice, baked potato, potato slices, french fries, pota-
to chips.
Carrot, corn, rhubarb, and tomato. Plus most of the associated juices.
----------------------------------------------------------------------
Dairy:
Glass or bucket of milk. Butter. Cheese.
----------------------------------------------------------------------
Chocolate:
Cocoa bean, chocolate powder, dark chocolate, milk chocolate, and cup
or mug of chocolate milk.
----------------------------------------------------------------------
Coffee:
Raw coffee beans, roasted coffee beans, and cup or mug of coffee.
----------------------------------------------------------------------
Dessert:
Snackcake, blueberry muffin, raw tart base, tart base, and strawberry
tart.
Banana split, shortbread, cream, strawberry shortcake, and cupcake.
Moono desserts: Butterscotch Dillybar, Butterscotch Sundae, Heart on a
Stick, Strawberry Bar, Strawberry Icecream, and Strawberry Star.
There are also some cakes, but we encourage people to use the cakes
and pies from the "cakepie" mod instead. The cakes in this mod are
provided primarily for legacy support purposes.
----------------------------------------------------------------------
End of file.
Loading…
Cancel
Save