Support for other mods defining bucket with own water

master
daretmavi 2021-01-13 23:06:55 +01:00
parent 4377686ce0
commit 482c95df25
2 changed files with 47 additions and 24 deletions

View File

@ -1,5 +1,5 @@
--------------------------------------------------
Ver. 5.0 [10.01.2021] DEVEL
Ver. 5.0 [13.01.2021]
Added settings:
bucket_use_clasic_recipe - use clasic recipe for bucket if true
@ -7,7 +7,12 @@ Added settings:
Some code cleanup
giving_back = "bucket:bucket_empty" in register_full_bucket as fallback
Support for other mods defining bucket with own water
- all materials are supported
- like for water_life muddy water
- no special bucket water with reduces flowing is implemented (yet)
Bucket images are a little bit lighter
--------------------------------------------------
Ver. 4.1 [20.12.2020]

View File

@ -79,8 +79,6 @@ if not use_clasic_recipe then
end
end
minetest.log(dump(craft_ingreds))
-- according to source (liquid type) assign bucket with "bucket" liquid
-- with this you can override the mod setting
bucket.giving_back={
@ -108,7 +106,6 @@ local function replace_recipe_material(recipe_def, new_mat)
end
end
end
minetest.log(dump(recipe_mat))
return recipe_mat
end
@ -142,11 +139,14 @@ local function check_protection(pos, name, text)
return false
end
-- ============================================================================
-- Register a new liquid
-- source = name of the source node
-- flowing = name of the flowing node
-- itemname = name of the new bucket item (or nil if liquid is not takeable)
-- inventory_image = texture of the new bucket item (ignored if itemname == nil)
-- - this new bucket mod version defines is as table, e.g. {empty = "bucket_uni.png", materials = craft_ingreds, fill = "bucket_uni_lava.png"}
-- - if only one image is defined, then thi imege is used for liquid and bucket materials are from this mod
-- name = text description of the bucket item
-- groups = (optional) groups of the bucket item, for example {water_bucket = 1}
-- force_renew = (optional) bool. Force the liquid source to renew if it has a
@ -215,12 +215,9 @@ local function register_full_bucket(source, flowing, itemname, inventory_image,
})
end
-- Function to register new liquid in bucket
function bucket.register_liquid(source, flowing, itemname, inventory_image, name,
groups, force_renew, giving_back)
-- for compatibility - if not defined, then default empty bucket is used
if giving_back == nil then
giving_back = "bucket:bucket_empty"
end
bucket.liquids[source] = {
source = source,
@ -231,28 +228,49 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
bucket.liquids[flowing] = bucket.liquids[source]
if itemname ~= nil then
-- if only one image is defined (like from other mod)
local inv_images
if type(inventory_image) == "string" then
register_full_bucket(source, flowing, itemname, inventory_image, name,
groups, force_renew, giving_back)
-- if only one image is defined (like from other mod)
-- material are from predefined craft_ingreds
-- fill/liquid image ist taken from the inventory_image
inv_images = {empty = "bucket_uni.png", materials = craft_ingreds, fill = "bucket_uni_fill.png"}
else
-- if more images in table are defined = more materials
bucket.liquids[source].itemname = {}
for mat_name, mat in pairs(inventory_image["materials"]) do
local Mat_name = mat_name:gsub("^%l", string.upper)
local bucket_name = S(Mat_name.." "..name)
local bucket_itemname = itemname.."_"..mat_name
giving_back = bucket.empty.."_"..mat_name
bucket.liquids[source].itemname[mat_name]=bucket_itemname
local bucket_inv_image = mat[2].."^[resize:16x16".."^[colorize:#fff:30^bucket_uni.png^"..inventory_image["fill"].."^[noalpha^[makealpha:0,255,0"
register_full_bucket(source, flowing, bucket_itemname, bucket_inv_image, bucket_name,
groups, force_renew, giving_back)
-- suplied materials and images are used - has to be like in this mod defined
inv_images = inventory_image
end
bucket.liquids[source].itemname = {} -- all buckets for defined source
-- loop for all materials in inv_images
for mat_name, mat in pairs(inv_images["materials"]) do
local Mat_name = mat_name:gsub("^%l", string.upper)
local bucket_name = S(Mat_name.." "..name)
local bucket_itemname = itemname.."_"..mat_name
giving_back = bucket.empty.."_"..mat_name
bucket.liquids[source].itemname[mat_name]=bucket_itemname
-- different image creation ist defined for all material, or only liquid it in inventory_image
local bucket_inv_image
if type(inventory_image) == "string" then
-- inly one image was delivered - inventory_image = liquid
-- like from other mods
local bucket_fill_image = "("..inventory_image.."^[resize:16x16".."^[colorize:#fff:30^"..inv_images["fill"].."^[noalpha^[makealpha:0,255,0)"
bucket_inv_image = mat[2].."^[resize:16x16".."^[colorize:#fff:30^bucket_uni.png".."^[noalpha^[makealpha:0,255,0^"..bucket_fill_image
else
-- all images for bucket are defined
-- definition in this mod
bucket_inv_image = mat[2].."^[resize:16x16".."^[colorize:#fff:30^bucket_uni.png^"..inv_images["fill"].."^[noalpha^[makealpha:0,255,0"
end
register_full_bucket(source, flowing, bucket_itemname, bucket_inv_image, bucket_name,
groups, force_renew, giving_back)
end
end
end
-- ============================================================================
-- Register Empty buckets
for mat_name, mat in pairs(craft_ingreds) do