basic WIP API for sponges

This commit is contained in:
AFCMS 2021-05-05 18:36:54 +02:00
parent f5b2a5f5c1
commit 717da6dd7c
1 changed files with 52 additions and 11 deletions

View File

@ -1,4 +1,40 @@
local S = minetest.get_translator("mcl_sponges")
local math = math
mcl_sponges = {}
mcl_sponges.registered_sponges = {}
function mcl_sponges.register_sponge(name, def)
if def.furnace_drying == nil then def.furnace_drying = true end
if not def.tiles then def.tiles = {"mcl_sponges_sponge_wet.png"} end
if not def.description then def.description = S("Logged Sponge") end
def.itemname = "mcl_sponges:sponge_"..name.."_logged"
mcl_sponges.registered_sponges[name] = def
minetest.register_node(def.itemname, {
description = def.description,
_tt_help = def.help,
_doc_items_longdesc = def.longdesc,
is_ground_content = false,
tiles = {"mcl_sponges_sponge_wet.png"},
sounds = mcl_sounds.node_sound_dirt_defaults(),
groups = {handy=1, hoey=1, building_block=1, sponge_logged=1},
on_place = place_wet_sponge,
_mcl_blast_resistance = 0.6,
_mcl_hardness = 0.6,
})
--drying sponge
if def.furnace_drying then
minetest.register_craft({
type = "cooking",
output = "mcl_sponges:sponge",
recipe = def.itemname,
cooktime = 10,
})
end
end
local absorb = function(pos)
local change = false
@ -51,16 +87,15 @@ minetest.register_node("mcl_sponges:sponge", {
groups = {handy=1, hoey=1, building_block=1},
on_place = function(itemstack, placer, pointed_thing)
local pn = placer:get_player_name()
if pointed_thing.type ~= "node" then
return itemstack
end
-- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node(pointed_thing.under)
if placer and not placer:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end
local new_stack = mcl_util.call_on_rightclick(itemstack, player, pointed_thing)
if new_stack then
return new_stack
end
if minetest.is_protected(pointed_thing.above, pn) then
@ -100,10 +135,9 @@ function place_wet_sponge(itemstack, placer, pointed_thing)
end
-- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node(pointed_thing.under)
if placer and not placer:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end
local new_stack = mcl_util.call_on_rightclick(itemstack, player, pointed_thing)
if new_stack then
return new_stack
end
local name = placer:get_player_name()
@ -155,7 +189,7 @@ minetest.register_node("mcl_sponges:sponge_wet", {
_mcl_hardness = 0.6,
})
if minetest.get_modpath("mclx_core") then
--[[if minetest.get_modpath("mclx_core") then
minetest.register_node("mcl_sponges:sponge_wet_river_water", {
description = S("Riverwaterlogged Sponge"),
_tt_help = S("Can be dried in furnace"),
@ -181,7 +215,7 @@ if minetest.get_modpath("mclx_core") then
recipe = "mcl_sponges:sponge_wet_river_water",
cooktime = 10,
})
end
end]]
minetest.register_craft({
type = "cooking",
@ -190,6 +224,12 @@ minetest.register_craft({
cooktime = 10,
})
mcl_sponges.register_sponge("water", {
description = S("Waterlogged Sponge"),
tiles = {"mcl_sponges_sponge_wet.png"},
furnace_drying = true,
})
minetest.register_abm({
label = "Sponge water absorbtion",
nodenames = { "mcl_sponges:sponge" },
@ -203,3 +243,4 @@ minetest.register_abm({
end
end,
})
minetest.register_alias("mcl_sponges:sponge_wet", "mcl_sponges:sponge_water_logged")