forked from MineClone5/MineClone5
remix mcl_buckets API to be more self documented
This commit is contained in:
parent
6c3d4524a0
commit
752f74e554
|
@ -0,0 +1,21 @@
|
||||||
|
# mcl_buckets
|
||||||
|
Add an API to register buckets to mcl
|
||||||
|
|
||||||
|
## mcl_buckets.register_liquid(def)
|
||||||
|
|
||||||
|
Register a new liquid
|
||||||
|
Accept folowing params:
|
||||||
|
* source_place = a string or function.
|
||||||
|
* string: name of the node to place
|
||||||
|
* function(pos): will returns name of the node to place with pos being the placement position
|
||||||
|
* source_take = table of liquid source node names to take
|
||||||
|
* itemname = itemstring of the new bucket item (or nil if liquid is not takeable)
|
||||||
|
* inventory_image = texture of the new bucket item (ignored if itemname == nil)
|
||||||
|
* name = user-visible bucket description
|
||||||
|
* longdesc = long explanatory description (for help)
|
||||||
|
* usagehelp = short usage explanation (for help)
|
||||||
|
* tt_help = very short tooltip help
|
||||||
|
* extra_check(pos, placer) = optional function(pos) which can returns false to avoid placing the liquid. Placer is object/player who is placing the liquid, can be nil.
|
||||||
|
* groups = optional list of item groups
|
||||||
|
|
||||||
|
This function can be called from any mod (which depends on this one)
|
|
@ -45,43 +45,27 @@ local place_liquid = function(pos, itemstring)
|
||||||
minetest.add_node(pos, {name=itemstring, param2=fullness})
|
minetest.add_node(pos, {name=itemstring, param2=fullness})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register a new liquid
|
function mcl_buckets.register_liquid(def)
|
||||||
-- source_place = a string or function.
|
for i=1, #def.source_take do
|
||||||
-- * string: name of the node to place
|
mcl_buckets.liquids[def.source_take[i]] = {
|
||||||
-- * function(pos): will returns name of the node to place with pos being the placement position
|
source_place = def.source_place,
|
||||||
-- source_take = table of liquid source node names to take
|
source_take = def.source_take[i],
|
||||||
-- itemname = itemstring of the new bucket item (or nil if liquid is not takeable)
|
itemname = def.itemname,
|
||||||
-- inventory_image = texture of the new bucket item (ignored if itemname == nil)
|
|
||||||
-- name = user-visible bucket description
|
|
||||||
-- longdesc = long explanatory description (for help)
|
|
||||||
-- usagehelp = short usage explanation (for help)
|
|
||||||
-- tt_help = very short tooltip help
|
|
||||||
-- extra_check(pos, placer) = optional function(pos) which can returns false to avoid placing the liquid.
|
|
||||||
-- placer is object/player who is placing the liquid, can be nil
|
|
||||||
-- groups = optional list of item groups
|
|
||||||
--
|
|
||||||
-- This function can be called from any mod (which depends on this one)
|
|
||||||
function mcl_buckets.register_liquid(source_place, source_take, itemname, inventory_image, name, longdesc, usagehelp, tt_help, extra_check, groups)
|
|
||||||
for i=1, #source_take do
|
|
||||||
mcl_buckets.liquids[source_take[i]] = {
|
|
||||||
source_place = source_place,
|
|
||||||
source_take = source_take[i],
|
|
||||||
itemname = itemname,
|
|
||||||
}
|
}
|
||||||
if type(source_place) == "string" then
|
if type(def.source_place) == "string" then
|
||||||
mcl_buckets.liquids[source_place] = mcl_buckets.liquids[source_take[i]]
|
mcl_buckets.liquids[def.source_place] = mcl_buckets.liquids[def.source_take[i]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if itemname ~= nil then
|
if def.itemname ~= nil then
|
||||||
minetest.register_craftitem(itemname, {
|
minetest.register_craftitem(def.itemname, {
|
||||||
description = name,
|
description = def.name,
|
||||||
_doc_items_longdesc = longdesc,
|
_doc_items_longdesc = def.longdesc,
|
||||||
_doc_items_usagehelp = usagehelp,
|
_doc_items_usagehelp = def.usagehelp,
|
||||||
_tt_help = tt_help,
|
_tt_help = def.tt_help,
|
||||||
inventory_image = inventory_image,
|
inventory_image = def.inventory_image,
|
||||||
stack_max = 16,
|
stack_max = 16,
|
||||||
groups = groups,
|
groups = def.groups,
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
-- Must be pointing to node
|
-- Must be pointing to node
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
|
@ -99,10 +83,10 @@ function mcl_buckets.register_liquid(source_place, source_take, itemname, invent
|
||||||
end
|
end
|
||||||
|
|
||||||
local node_place
|
local node_place
|
||||||
if type(source_place) == "function" then
|
if type(def.source_place) == "function" then
|
||||||
node_place = source_place(place_pos)
|
node_place = def.source_place(place_pos)
|
||||||
else
|
else
|
||||||
node_place = source_place
|
node_place = def.source_place
|
||||||
end
|
end
|
||||||
-- Check if pointing to a buildable node
|
-- Check if pointing to a buildable node
|
||||||
local item = itemstack:get_name()
|
local item = itemstack:get_name()
|
||||||
|
@ -165,15 +149,15 @@ function mcl_buckets.register_liquid(source_place, source_take, itemname, invent
|
||||||
local iname = stack:get_name()
|
local iname = stack:get_name()
|
||||||
local buildable = minetest.registered_nodes[dropnode.name].buildable_to
|
local buildable = minetest.registered_nodes[dropnode.name].buildable_to
|
||||||
|
|
||||||
if extra_check and extra_check(droppos, nil) == false then
|
if def.extra_check and def.extra_check(droppos, nil) == false then
|
||||||
-- Fail placement of liquid
|
-- Fail placement of liquid
|
||||||
elseif buildable then
|
elseif buildable then
|
||||||
-- buildable; replace the node
|
-- buildable; replace the node
|
||||||
local node_place
|
local node_place
|
||||||
if type(source_place) == "function" then
|
if type(def.source_place) == "function" then
|
||||||
node_place = source_place(droppos)
|
node_place = def.source_place(droppos)
|
||||||
else
|
else
|
||||||
node_place = source_place
|
node_place = def.source_place
|
||||||
end
|
end
|
||||||
place_liquid(droppos, node_place)
|
place_liquid(droppos, node_place)
|
||||||
stack:set_name("mcl_buckets:bucket_empty")
|
stack:set_name("mcl_buckets:bucket_empty")
|
||||||
|
@ -294,8 +278,8 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
|
||||||
|
|
||||||
if mod_mcl_core then
|
if mod_mcl_core then
|
||||||
-- Lava bucket
|
-- Lava bucket
|
||||||
mcl_buckets.register_liquid(
|
mcl_buckets.register_liquid({
|
||||||
function(pos)
|
source_place = function(pos)
|
||||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
local dim = mcl_worlds.pos_to_dimension(pos)
|
||||||
if dim == "nether" then
|
if dim == "nether" then
|
||||||
return "mcl_nether:nether_lava_source"
|
return "mcl_nether:nether_lava_source"
|
||||||
|
@ -303,26 +287,26 @@ if mod_mcl_core then
|
||||||
return "mcl_core:lava_source"
|
return "mcl_core:lava_source"
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{"mcl_core:lava_source", "mcl_nether:nether_lava_source"},
|
source_take = {"mcl_core:lava_source", "mcl_nether:nether_lava_source"},
|
||||||
"mcl_buckets:bucket_lava",
|
itemname = "mcl_buckets:bucket_lava",
|
||||||
"bucket_lava.png",
|
inventory_image = "bucket_lava.png",
|
||||||
S("Lava Bucket"),
|
name = S("Lava Bucket"),
|
||||||
S("A bucket can be used to collect and release liquids. This one is filled with hot lava, safely contained inside. Use with caution."),
|
longdesc = S("A bucket can be used to collect and release liquids. This one is filled with hot lava, safely contained inside. Use with caution."),
|
||||||
S("Get in a safe distance and place the bucket to empty it and create a lava source at this spot. Don't burn yourself!"),
|
usagehelp = S("Get in a safe distance and place the bucket to empty it and create a lava source at this spot. Don't burn yourself!"),
|
||||||
S("Places a lava source")
|
tt_help = S("Places a lava source")
|
||||||
)
|
})
|
||||||
|
|
||||||
-- Water bucket
|
-- Water bucket
|
||||||
mcl_buckets.register_liquid(
|
mcl_buckets.register_liquid({
|
||||||
"mcl_core:water_source",
|
source_place = "mcl_core:water_source",
|
||||||
{"mcl_core:water_source"},
|
source_take = {"mcl_core:water_source"},
|
||||||
"mcl_buckets:bucket_water",
|
itemname = "mcl_buckets:bucket_water",
|
||||||
"bucket_water.png",
|
inventory_image = "bucket_water.png",
|
||||||
S("Water Bucket"),
|
name = S("Water Bucket"),
|
||||||
S("A bucket can be used to collect and release liquids. This one is filled with water."),
|
longdesc = S("A bucket can be used to collect and release liquids. This one is filled with water."),
|
||||||
S("Place it to empty the bucket and create a water source."),
|
usagehelp = S("Place it to empty the bucket and create a water source."),
|
||||||
S("Places a water source"),
|
tt_help = S("Places a water source"),
|
||||||
function(pos, placer)
|
extra_check = function(pos, placer)
|
||||||
-- Check protection
|
-- Check protection
|
||||||
local placer_name = ""
|
local placer_name = ""
|
||||||
if placer ~= nil then
|
if placer ~= nil then
|
||||||
|
@ -350,22 +334,22 @@ if mod_mcl_core then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{ water_bucket = 1 }
|
groups = { water_bucket = 1 },
|
||||||
)
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if mod_mclx_core then
|
if mod_mclx_core then
|
||||||
-- River water bucket
|
-- River water bucket
|
||||||
mcl_buckets.register_liquid(
|
mcl_buckets.register_liquid({
|
||||||
"mclx_core:river_water_source",
|
source_place = "mclx_core:river_water_source",
|
||||||
{"mclx_core:river_water_source"},
|
source_take = {"mclx_core:river_water_source"},
|
||||||
"mcl_buckets:bucket_river_water",
|
itemname = "mcl_buckets:bucket_river_water",
|
||||||
"bucket_river_water.png",
|
inventory_image = "bucket_river_water.png",
|
||||||
S("River Water Bucket"),
|
name = S("River Water Bucket"),
|
||||||
S("A bucket can be used to collect and release liquids. This one is filled with river water."),
|
longdesc = S("A bucket can be used to collect and release liquids. This one is filled with river water."),
|
||||||
S("Place it to empty the bucket and create a river water source."),
|
usagehelp = S("Place it to empty the bucket and create a river water source."),
|
||||||
S("Places a river water source"),
|
tt_help = S("Places a river water source"),
|
||||||
function(pos, placer)
|
extra_check = function(pos, placer)
|
||||||
-- Check protection
|
-- Check protection
|
||||||
local placer_name = ""
|
local placer_name = ""
|
||||||
if placer ~= nil then
|
if placer ~= nil then
|
||||||
|
@ -393,8 +377,8 @@ if mod_mclx_core then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{ water_bucket = 1 }
|
groups = { water_bucket = 1 },
|
||||||
)
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
|
Loading…
Reference in New Issue