Skip to content

Commit

Permalink
Amulets of Thirst added
Browse files Browse the repository at this point in the history
Amulets of Thirst Added
~ Lower speed at which players use hydration points
~ Three versions Lesser, Normal, Greater
~ Only available as Dungeon Loot
Update register.hb_hng_drink() to register_food_drink()
Clean up Sound Effect
Clean up textures folder
Remove thirsty.config.players and store as player(meta)
  • Loading branch information
sirrobzeroone committed Sep 23, 2021
1 parent 17be020 commit e6fb470
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 97 deletions.
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Version: 0.10.2
**Code**
LGPL 2.1 (see included LICENSE file)

**Textures**
**Textures**
vessels_glass_bottle_full_cc_by_sa_3.png
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
modified from vessels_glass_bottle.png
Expand All @@ -21,11 +21,17 @@ thirsty_wooden_bowl_cc0.png +.xcf
thirsty_bronze_canteen_cc0.png +.xcf
thirsty_steel_canteen_cc0.png
thirsty_amulet_moisture_cc0.png +.xcf
thirsty_amulet_hydration_cc0.png +.xcf
thirsty_amulet_hydration_cc0.png +.xcf
Public Domain CC0 1.0 Universal
Sirrobzeroone

All other Images CC BY-SA 4.0 (see http://creativecommons.org/licenses/by-sa/4.0/)
All other Images CC BY-SA 4.0
(see http://creativecommons.org/licenses/by-sa/4.0/)

**Sounds**
thirsty_breviceps_drink-drinking-liquid.ogg
https://freesound.org/people/Breviceps/sounds/445970/
Public Domain CC0 1.0 Universal

Report bugs or request help on the forum topic.

Expand Down Expand Up @@ -83,7 +89,7 @@ Configure nodes that can be drunk from using a cup/glass etc assuming this was
not done as part of Tier 0 or if you wish to override max_hydration to be more
than the default value (normally 20):

** thirsty.register_drinkable_node(node_name,max_hydration)**
**thirsty.register_drinkable_node(node_name,max_hydration)**
**"item_name"** registered node name
**"max_hydration"** optional will default to thirsty.config.start (default 20)
max hydration can be set above 20 to encourage use of drinking fountains or
Expand Down Expand Up @@ -282,7 +288,7 @@ once and for all.

**Example**

thirsty.register_amulet_extractor("thirsty:extractor", 0.6)
thirsty.register_amulet_extractor("thirsty:amulet_of_moisture", 0.6)

**Amulet of Moisture** - Absorbs moisture from the surronding environment places it into a canteen or other water holding item. Must be held in Inventory.

Expand All @@ -294,7 +300,7 @@ once and for all.

**Example**

thirsty.register_amulet_supplier("thirsty:injector", 0.5)
thirsty.register_amulet_supplier("thirsty:amulet_of_hydration", 0.5)

**Amulet of Hydration** - Feeds water from a Canteen or other water holding
item directly into the player to keep them always hydrated. Must be held in Inventory.
Expand All @@ -303,20 +309,31 @@ The above two Amulets can be used in combination with each other plus a
canteen. However this does permenantly fill 3 inventory slots the delibrate
downside to offset the significant bonus.

**Lesser Amulet of Thirst - Coming Soon**
**Amulets of Thirst** - Three versions lesser,normal and greater each will slower the rate at which
a player becomes thirsty. Normal thirst factor is 1, however a "cursed" version could be created
which makes a player become thirsty faster.

* thirsty.set_thirst_factor(player, factor) : how fast does the given player get thirsty (default is 1.0)
* thirsty.get_thirst_factor(player) : returns the current thirst factor of a player
thirsty.register_amulet_thirst(item_name, thirst_factor)

**Amulet of Thirst - Coming Soon**
**"item_name"** Registered item name
**"thirst_factor"** Float value that represents the speed at which a player uses hydration points

**Greater Amulet of Thirst - Coming Soon**
**Example**

minetest.register_craftitem("thirsty:greater_amulet_thirst", {
description = "Greater Amulet of Thirst",
inventory_image = "thirsty_amulet_of_thirst_greater_cc0.png",
})

## *Additional Functions*
thirsty.register_amulet_thirst("thirsty:lesser_amulet_thirst",0.85)

**thirsty.get_hydro(player) : returns the current hydration of a player**
*Note: Included Amulets of Thirst have no craft recipes and are only avaliable as
*dungeon loot with more powerful versions only found in deeper dungeons.


## *Additional Functions*

*thirsty.get_hydro(player) : returns the current hydration of a player*

"player" refers to a player object, i.e. with a get_player_name() method.

Expand Down
33 changes: 26 additions & 7 deletions components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,34 +270,53 @@ if thirsty.config.register_amulets and
minetest.registered_items[E.mese_crystal] and
minetest.registered_items[E.bucket_water] then

minetest.register_craftitem('thirsty:injector', {
description = 'Amulet of Hydration',
minetest.register_craftitem("thirsty:amulet_of_hydration", {
description = "Amulet of Hydration",
inventory_image = "thirsty_amulet_hydration_cc0.png",
})
minetest.register_craft({
output = "thirsty:injector",
output = "thirsty:amulet_of_hydration",
recipe = {
{E.diamond ,E.mese_crystal,E.diamond},
{E.mese_crystal,E.bucket_water,E.mese_crystal},
{E.diamond ,E.mese_crystal,E.diamond}
}
})

thirsty.register_amulet_supplier("thirsty:injector", 0.5)
thirsty.register_amulet_supplier("thirsty:amulet_of_hydration", 0.5)

minetest.register_craftitem('thirsty:extractor', {
minetest.register_craftitem("thirsty:amulet_of_moisture", {
description = "Amulet of Moisture",
inventory_image = "thirsty_amulet_moisture_cc0.png",
})
minetest.register_craft({
output = "thirsty:extractor",
output = "thirsty:amulet_of_moisture",
recipe = {
{E.mese_crystal,E.diamond ,E.mese_crystal},
{E.diamond ,E.bucket_water,E.diamond },
{E.mese_crystal,E.diamond ,E.mese_crystal}
}
})

thirsty.register_amulet_extractor("thirsty:extractor", 0.6)
thirsty.register_amulet_extractor("thirsty:amulet_of_moisture", 0.6)

minetest.register_craftitem("thirsty:lesser_amulet_thirst", {
description = "Lesser Amulet of Thirst",
inventory_image = "thirsty_amulet_of_thirst_lesser_cc0.png",
})

minetest.register_craftitem("thirsty:amulet_thirst", {
description = "Amulet of Thirst",
inventory_image = "thirsty_amulet_of_thirst_cc0.png",
})

minetest.register_craftitem("thirsty:greater_amulet_thirst", {
description = "Greater Amulet of Thirst",
inventory_image = "thirsty_amulet_of_thirst_greater_cc0.png",
})

thirsty.register_amulet_thirst("thirsty:lesser_amulet_thirst",0.85)
thirsty.register_amulet_thirst("thirsty:amulet_thirst",0.70)
thirsty.register_amulet_thirst("thirsty:greater_amulet_thirst",0.55)

end
4 changes: 2 additions & 2 deletions components_external_nodes_items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ across the whole mod.
local E = thirsty.ext_nodes_items

-- item and node mod aliases, change these as needed.
-- if item dosen't exist as either Ing or Aug item
-- it wont register.
-- if item dosen't exist as either Ingredient or Augumented
-- item it wont register.

-- Basic Water, change here or register
-- using thirsty.register_hydrate_node()
Expand Down
97 changes: 58 additions & 39 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@
-- See init.lua for license --
------------------------------------------------------------

--[[ notes/ideas
move settings from conf to node/item defs were appropriate tool
Tier 0 nodes what to do? check for node liquid and drinkable?
Tier 1 function to register "Drinking containers" Tier 1
Tier 2 function to register "Hydro storing"
]]--

--------------------------
-- Tier 0 API Functions --
--------------------------
-- regen_from_node is a table defining, for each node type, the
-- amount of hydro per second a player drinks by standing in it.
-- Default is 0.5 of a hydration per second
function thirsty.register_hydrate_node(node_name,drink_cup,regen)

function thirsty.register_hydrate_node(node_name,drink_cup,regen)
local drink_cup = drink_cup or true
local regen = regen or 0.5

Expand Down Expand Up @@ -90,17 +82,15 @@ end
--------------------------
-- Tier 2 API Functions --
--------------------------
function thirsty.drink(player, value, max, empty_vessel)
-- if max is not specified, assume 20
if not max then
max = 20
end
function thirsty.drink(player, value, max_hyd, empty_vessel)
local max_hyd = max_hyd or 20
local value = value or 2
local pmeta = player:get_meta()
local hydro = pmeta:get_float("thirsty_hydro")
-- test whether we're not *above* max;
-- test whether we're not *above* max_hyd;
-- this function should not remove any overhydration
if hydro < max then
hydro = math.min(hydro + value, max)
if hydro < max_hyd then
hydro = math.min(hydro + value, max_hyd)
--print("Drinking by "..value.." to "..hydro)
pmeta:set_float("thirsty_hydro", hydro)
minetest.sound_play("thirsty_breviceps_drink-drinking-liquid", { to_player = player:get_player_name(), gain = 2.0, })
Expand Down Expand Up @@ -221,16 +211,23 @@ function thirsty.register_amulet_supplier(item_name,value)
thirsty.config.injection_for_item[item_name] = value
end

function thirsty.register_amulet_thirst(item_name,value)
thirsty.config.thirst_adjust_item[item_name] = value
end

function thirsty.get_thirst_factor(player)
local name = player:get_player_name()
local pl = thirsty.players[name]
local pmeta = player:get_meta()
local pl = minetest.deserialize(pmeta:get_string("thirsty_values"))
return pl.thirst_factor
end

function thirsty.set_thirst_factor(player, factor)
local name = player:get_player_name()
local pl = thirsty.players[name]
local pmeta = player:get_meta()
local pl = minetest.deserialize(pmeta:get_string("thirsty_values"))
pl.thirst_factor = factor
pmeta:set_string("thirsty_values",minetest.serialize(pl))
end


Expand Down Expand Up @@ -259,28 +256,33 @@ function thirsty.on_joinplayer(player)
pmeta:set_float("thirsty_hydro", thirsty.config.start)
end

-- default entry for joining players
if not thirsty.players[name] then
local pos = player:get_pos()
thirsty.players[name] = {
last_pos = math.floor(pos.x) .. ':' .. math.floor(pos.z),
time_in_pos = 0.0,
-- default entry for joining players
if pmeta:get_string("thirsty_values") == "" then
local pos = player:get_pos()
pmeta:set_string("thirsty_values", minetest.serialize({
last_pos = math.floor(pos.x) .. ':' .. math.floor(pos.z),
time_in_pos = 0.0,
pending_dmg = 0.0,
thirst_factor = 1.0,
}
end
thirst_factor = 1.0
}))
end

thirsty.hud_init(player)
end


function thirsty.on_dieplayer(player)
local name = player:get_player_name()
local pl = thirsty.players[name]
-- reset after death
local pos = player:get_pos()
local pmeta = player:get_meta()

pmeta:set_float("thirsty_hydro", thirsty.config.start)
pl.pending_dmg = 0.0
pl.thirst_factor = 1.0
pmeta:set_string("thirsty_values", minetest.serialize({
last_pos = math.floor(pos.x) .. ':' .. math.floor(pos.z),
time_in_pos = 0.0,
pending_dmg = 0.0,
thirst_factor = 1.0
}))
end


Expand All @@ -291,17 +293,17 @@ function thirsty.main_loop(dtime)
-- time for thirst
thirsty.time_next_tick = thirsty.time_next_tick + thirsty.config.tick_time
for _,player in ipairs(minetest.get_connected_players()) do

if player:get_hp() <= 0 then
-- dead players don't get thirsty, or full for that matter :-P
-- dead players don't get thirsty, or full for that matter :-P
if player:get_hp() <= 0 then
break
end

local name = player:get_player_name()
local pos = player:get_pos()
local pl = thirsty.players[name]
local pmeta = player:get_meta()
local hydro = pmeta:get_float("thirsty_hydro")
local pl = minetest.deserialize(pmeta:get_string("thirsty_values"))

-- how long have we been standing "here"?
-- (the node coordinates in X and Z should be enough)
Expand Down Expand Up @@ -343,19 +345,24 @@ function thirsty.main_loop(dtime)
local pl_inv = player:get_inventory()
local extractor_max = 0.0
local injector_max = 0.0
local amulet_thirst = false
local container_not_full = nil
local container_not_empty = nil
local inv_main = player:get_inventory():get_list('main')

for i, itemstack in ipairs(inv_main) do
local name = itemstack:get_name()
local injector_this = thirsty.config.injection_for_item[name]
-- Amulets Hydration/Moisture
local injector_this = thirsty.config.injection_for_item[name]
if injector_this and injector_this > injector_max then
injector_max = injector_this
end

local extractor_this = thirsty.config.extraction_for_item[name]
if extractor_this and extractor_this > extractor_max then
extractor_max = extractor_this
end

if thirsty.config.container_capacity[name] then
local wear = itemstack:get_wear()
-- can be both!
Expand All @@ -366,7 +373,17 @@ function thirsty.main_loop(dtime)
container_not_empty = { i, itemstack }
end
end
-- Amulets of Thirst
local is_thirst_amulet = thirsty.config.thirst_adjust_item[name]
if is_thirst_amulet then
amulet_thirst = true
pl.thirst_factor = thirsty.config.thirst_adjust_item[name]
end
end

if amulet_thirst ~= true and pl.thirst_factor ~= 1.0 then
pl.thirst_factor = 1.0
end

if extractor_max > 0.0 and container_not_full then
local i = container_not_full[1]
Expand Down Expand Up @@ -403,7 +420,8 @@ function thirsty.main_loop(dtime)

if drink_per_second > 0 and pl_standing then
-- Drinking from the ground won't give you more than max
thirsty.drink(player, drink_per_second * thirsty.config.tick_time, 20)
thirsty.drink(player, (drink_per_second * thirsty.config.tick_time)*2, 20)
pl.time_in_pos = 0.0
--print("Raising hydration by "..(drink_per_second*thirsty.config.tick_time).." to "..PPA.get_value(player, 'thirsty_hydro'))
else
if not pl_afk then
Expand Down Expand Up @@ -438,6 +456,7 @@ function thirsty.main_loop(dtime)
pl.pending_dmg = 0.0
end
end
pmeta:set_string("thirsty_values",minetest.serialize(pl))
end -- for players

-- check fountains for expiration
Expand All @@ -455,9 +474,9 @@ end


function thirsty.drink_handler(player, itemstack, node)
local pl = thirsty.players[player:get_player_name()]
local pmeta = player:get_meta()
local hydro = pmeta:get_float("thirsty_hydro")
local pl = minetest.deserialize(pmeta:get_string("thirsty_values"))
local old_hydro = hydro

-- selectors, always true, to make the following code easier
Expand Down
4 changes: 2 additions & 2 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ else
local name = player:get_player_name()
local pmeta = player:get_meta()

thirsty.players[name].hud_id = player:hud_add({
thirsty_hud = player:hud_add({
hud_elem_type = "statbar",
position = { x=0.5, y=1 },
text = "thirsty_drop_100_24_cc0.png",
Expand All @@ -69,7 +69,7 @@ else
end
function thirsty.hud_update(player, value)
local name = player:get_player_name()
local hud_id = thirsty.players[name].hud_id
local hud_id = thirsty_hud
player:hud_change(hud_id, 'number', thirsty.hud_clamp(value))
end
end
Loading

0 comments on commit e6fb470

Please sign in to comment.