Version 0.41.3
[MineClone/MineClone2/MineClone2-Fixes.git] / mods / ITEMS / mcl_sponges / init.lua
blob531e74c99c578a9e24fe4225e4fe81cecbe86853
1 local absorb = function(pos)
2 local change = false
3 -- Count number of absorbed river water vs other nodes
4 -- to determine the wet sponge type.
5 local river_water = 0
6 local non_river_water = 0
7 local p, n
8 for i=-3,3 do
9 for j=-3,3 do
10 for k=-3,3 do
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"})
15 change = true
16 if n.name == "mclx_core:river_water_source" or n.name == "mclx_core:river_water_flowing" then
17 river_water = river_water + 1
18 else
19 non_river_water = non_river_water + 1
20 end
21 end
22 end
23 end
24 end
25 -- The dominant water type wins. In case of a tie, normal water wins.
26 -- This slight bias is intentional.
27 local sponge_type
28 if river_water > non_river_water then
29 sponge_type = "mcl_sponges:sponge_wet_river_water"
30 else
31 sponge_type = "mcl_sponges:sponge_wet"
32 end
33 return change, sponge_type
34 end
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.",
39 drawtype = "normal",
40 is_ground_content = false,
41 tiles = {"mcl_sponges_sponge.png"},
42 walkable = true,
43 pointable = true,
44 diggable = true,
45 buildable_to = false,
46 stack_max = 64,
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
52 return itemstack
53 end
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
60 end
61 end
63 if minetest.is_protected(pointed_thing.above, pn) then
64 return itemstack
65 end
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
70 on_water = true
71 end
72 local water_found = minetest.find_node_near(pos, 1, "group:water")
73 if water_found ~= nil then
74 on_water = true
75 end
76 if on_water then
77 -- Absorb water
78 -- FIXME: pos is not always the right placement position because of pointed_thing
79 local absorbed, wet_sponge = absorb(pos)
80 if absorbed then
81 minetest.item_place_node(ItemStack(wet_sponge), placer, pointed_thing)
82 if not minetest.settings:get_bool("creative_mode") then
83 itemstack:take_item()
84 end
85 return itemstack
86 end
87 end
88 return minetest.item_place_node(itemstack, placer, pointed_thing)
89 end,
90 _mcl_blast_resistance = 3,
91 _mcl_hardness = 0.6,
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.",
97 drawtype = "normal",
98 is_ground_content = false,
99 tiles = {"mcl_sponges_sponge_wet.png"},
100 walkable = true,
101 pointable = true,
102 diggable = true,
103 buildable_to = false,
104 stack_max = 64,
105 sounds = mcl_sounds.node_sound_dirt_defaults(),
106 groups = {handy=1, building_block=1},
107 _mcl_blast_resistance = 3,
108 _mcl_hardness = 0.6,
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.",
115 drawtype = "normal",
116 is_ground_content = false,
117 tiles = {"mcl_sponges_sponge_wet_river_water.png"},
118 walkable = true,
119 pointable = true,
120 diggable = true,
121 buildable_to = false,
122 stack_max = 64,
123 sounds = mcl_sounds.node_sound_dirt_defaults(),
124 groups = {handy=1, building_block=1},
125 _mcl_blast_resistance = 3,
126 _mcl_hardness = 0.6,
129 minetest.register_craft({
130 type = "cooking",
131 output = "mcl_sponges:sponge",
132 recipe = "mcl_sponges:sponge_wet_river_water",
133 cooktime = 10,
137 minetest.register_craft({
138 type = "cooking",
139 output = "mcl_sponges:sponge",
140 recipe = "mcl_sponges:sponge_wet",
141 cooktime = 10,
144 minetest.register_abm({
145 label = "Sponge water absorbtion",
146 nodenames = { "mcl_sponges:sponge" },
147 neighbors = { "group:water" },
148 interval = 1,
149 chance = 1,
150 action = function(pos)
151 local absorbed, wet_sponge = absorb(pos)
152 if absorbed then
153 minetest.add_node(pos, {name = wet_sponge})
155 end,