1 local absorb
= function(pos
)
3 -- Count number of absorbed river water vs other nodes
4 -- to determine the wet sponge type.
6 local non_river_water
= 0
11 p
= {x
=pos
.x
+i
, y
=pos
.y
+j
, z
=pos
.z
+k
}
12 n
= minetest
.get_node(p
)
13 if minetest
.get_item_group(n
.name
, "water") ~= 0 then
14 minetest
.add_node(p
, {name
="air"})
16 if n
.name
== "mclx_core:river_water_source" or n
.name
== "mclx_core:river_water_flowing" then
17 river_water
= river_water
+ 1
19 non_river_water
= non_river_water
+ 1
25 -- The dominant water type wins. In case of a tie, normal water wins.
26 -- This slight bias is intentional.
28 if river_water
> non_river_water
then
29 sponge_type
= "mcl_sponges:sponge_wet_river_water"
31 sponge_type
= "mcl_sponges:sponge_wet"
33 return change
, sponge_type
36 minetest
.register_node("mcl_sponges:sponge", {
37 description
= "Sponge",
38 _doc_items_longdesc
= "Sponges are blocks which remove water around them when they are placed or come in contact with water, turning it into a wet sponge.",
40 is_ground_content
= false,
41 tiles
= {"mcl_sponges_sponge.png"},
47 sounds
= mcl_sounds
.node_sound_dirt_defaults(),
48 groups
= {handy
=1, building_block
=1},
49 on_place
= function(itemstack
, placer
, pointed_thing
)
50 local pn
= placer
:get_player_name()
51 if pointed_thing
.type ~= "node" then
55 -- Use pointed node's on_rightclick function first, if present
56 local node
= minetest
.get_node(pointed_thing
.under
)
57 if placer
and not placer
:get_player_control().sneak
then
58 if minetest
.registered_nodes
[node
.name
] and minetest
.registered_nodes
[node
.name
].on_rightclick
then
59 return minetest
.registered_nodes
[node
.name
].on_rightclick(pointed_thing
.under
, node
, placer
, itemstack
) or itemstack
63 if minetest
.is_protected(pointed_thing
.above
, pn
) then
67 local pos
= pointed_thing
.above
68 local on_water
= false
69 if minetest
.get_item_group(minetest
.get_node(pos
).name
, "water") ~= 0 then
72 local water_found
= minetest
.find_node_near(pos
, 1, "group:water")
73 if water_found
~= nil then
78 -- FIXME: pos is not always the right placement position because of pointed_thing
79 local absorbed
, wet_sponge
= absorb(pos
)
81 minetest
.item_place_node(ItemStack(wet_sponge
), placer
, pointed_thing
)
82 if not minetest
.settings
:get_bool("creative_mode") then
88 return minetest
.item_place_node(itemstack
, placer
, pointed_thing
)
90 _mcl_blast_resistance
= 3,
94 minetest
.register_node("mcl_sponges:sponge_wet", {
95 description
= "Waterlogged Sponge",
96 _doc_items_longdesc
= "A waterlogged sponge can be dried in the furnace to turn it into (dry) sponge. When there's an empty bucket in the fuel slot of a furnace, the water will pour into the bucket.",
98 is_ground_content
= false,
99 tiles
= {"mcl_sponges_sponge_wet.png"},
103 buildable_to
= false,
105 sounds
= mcl_sounds
.node_sound_dirt_defaults(),
106 groups
= {handy
=1, building_block
=1},
107 _mcl_blast_resistance
= 3,
111 if minetest
.get_modpath("mclx_core") then
112 minetest
.register_node("mcl_sponges:sponge_wet_river_water", {
113 description
= "Riverwaterlogged Sponge",
114 _doc_items_longdesc
= "This is a sponge soaking wet with river water. It can be dried in the furnace to turn it into (dry) sponge. When there's an empty bucket in the fuel slot of the furnace, the river water will pour into the bucket." .. "\n" .. "A sponge becomes riverwaterlogged (instead of waterlogged) if it sucks up more river water than (normal) water.",
116 is_ground_content
= false,
117 tiles
= {"mcl_sponges_sponge_wet_river_water.png"},
121 buildable_to
= false,
123 sounds
= mcl_sounds
.node_sound_dirt_defaults(),
124 groups
= {handy
=1, building_block
=1},
125 _mcl_blast_resistance
= 3,
129 minetest
.register_craft({
131 output
= "mcl_sponges:sponge",
132 recipe
= "mcl_sponges:sponge_wet_river_water",
137 minetest
.register_craft({
139 output
= "mcl_sponges:sponge",
140 recipe
= "mcl_sponges:sponge_wet",
144 minetest
.register_abm({
145 label
= "Sponge water absorbtion",
146 nodenames
= { "mcl_sponges:sponge" },
147 neighbors
= { "group:water" },
150 action
= function(pos
)
151 local absorbed
, wet_sponge
= absorb(pos
)
153 minetest
.add_node(pos
, {name
= wet_sponge
})