diff --git a/README.md b/README.md index 99063eb..bf7c4cd 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,17 @@ ## Water-removing sponges for Minetest. made by Benjie/Fiftysix - 27/8/18 +updated 22/12/20 [Forum topic](https://forum.minetest.net/viewtopic.php?f=9&t=20729) -Soggy sponges are quite rare, found deep in the sea where it is dark (below -11). -These can be cooked into dry sponges, and then placed near a liquid to remove an area of it. They will hold the water away until they are removed. -They turn in to soggy sponges when used, so to use them again, they have to be cooked. +Soggy sponges can rarely be found deep in the sea where the darkness begins. +These can be cooked into dry sponges, and then placed near a liquid to remove an area of it +They will hold the water away until they are removed. +This will cause them to become soggy, so to use them again they have to be cooked. ### How it works: -* sponges create a 9x9 area of air-like nodes that water can't flow through (checks for protection) -* if sponges have cleared more than 3 nodes of liquid, they become soggy sponges -* removing a sponge or soggy sponge will turn a 9x9 area of air-like nodes back into air. +* Sponges create a 9x9 area of air-like nodes that water can't flow through (checks for protection). +* If sponges have cleared more than 3 nodes of liquid, they become soggy sponges. +* Removing a sponge or soggy sponge will turn a 9x9 area of air-like nodes back into air, as long as they are not in the area of another sponge. *(Air-like nodes can be removed in protection by removing a sponge outside the protection, they are not meant to be permanent)* diff --git a/init.lua b/init.lua index 33e4ae9..36aeec0 100644 --- a/init.lua +++ b/init.lua @@ -3,105 +3,142 @@ - water removal for survival made by Benjie/Fiftysix - 27/8/18 +updated 22/12/20 -soggy sponges can be found quite rare, deep in the sea where it is dark -these can be cooked into dry sponges, and then placed near a liquid to remove an area of it -they will hold the water away until they are removed. -to use them again, they have to be cooked. +Soggy sponges can rarely be found deep in the sea where the darkness begins. +These can be cooked into dry sponges, and then placed near a liquid to remove an area of it +They will hold the water away until they are removed. +This will cause them to become soggy, so to use them again they have to be cooked. -sponges create a 9x9 area of air-like nodes that water can't flow through (checks for protection) -if sponges have cleared more than 3 nodes of liquid, they become soggy sponges +Sponges create a 9x9 area of air-like nodes that water can't flow through (checks for protection) +If sponges have cleared more than 3 nodes of liquid, they become soggy sponges removing a sponge or soggy sponge will turn a 9x9 area of air-like nodes back into air (air-like nodes can be removed in protection by removing a sponge outside the protection, they are not meant to be permanent) ]]-- -local area = 4 +local area = 4 -- The "radius" (of the cube) to clear water +local keep_dry = 3 -- The maximum amount of water cleared where the sponge doesn't turn soggy + +local modname = minetest.get_current_modname() +-- called by after_destruct() local destruct = function(pos) -- removing the air-like nodes + + -- find all sponges that intersect with this sponge's area + local sponge_info = minetest.find_nodes_in_area( + {x=pos.x-area*2, y=pos.y-area*2, z=pos.z-area*2}, {x=pos.x+area*2, y=pos.y+area*2, z=pos.z+area*2}, + {modname..":soggy_sponge", modname..":sponge"}, true + ) + local sponges = {} + for _, p in pairs(sponge_info) do + local node = minetest.get_node(p) + if node.param1 == 1 or node.name == modname..":sponge" then + table.insert(sponges, p) + end + end + for x = pos.x-area, pos.x+area do for y = pos.y-area, pos.y+area do for z = pos.z-area, pos.z+area do local n = minetest.get_node({x=x, y=y, z=z}).name - if n == "sponge:liquid_stop" then - minetest.remove_node({x=x, y=y, z=z}) + if n == modname..":liquid_stop" then + + -- check if position intersects with another sponge + local intersect = false + for _, s_pos in pairs(sponges) do + if math.abs(s_pos.x-x) <= area and math.abs(s_pos.y-y) <= area and math.abs(s_pos.z-z) <= area then + intersect = true + break + end + end + + if not intersect then + minetest.remove_node({x=x, y=y, z=z}) + end end end end end end +-- called by after_place_node() +local construct = function(pos, placer, itemstack, pointed_thing) + local playername = placer:get_player_name() -minetest.register_node("sponge:liquid_stop", { -- air-like node + if not minetest.is_protected(pos, playername) then + local count = 0 + + for x = pos.x-area, pos.x+area do + for y = pos.y-area, pos.y+area do + for z = pos.z-area, pos.z+area do + + local n = minetest.get_node({x=x, y=y, z=z}).name + local def = minetest.registered_nodes[n] + if def ~= nil and (n == "air" or def["drawtype"] == "liquid" or def["drawtype"] == "flowingliquid") then + local p = {x=x, y=y, z=z} + if not minetest.is_protected(p, playername) then + if n ~= "air" then + count = count + 1 -- counting liquids + end + minetest.set_node(p, {name=modname..":liquid_stop"}) + end + end + end + end + end + + if count > keep_dry then -- turns soggy if it removed more than `keep_dry` nodes + minetest.swap_node(pos, {name=modname..":soggy_sponge", param1=1}) + end + end +end + + +minetest.register_node(modname..":liquid_stop", { -- air-like node description = "liquid blocker for sponges", drawtype = "airlike", drop = {max_items=0, items={}}, groups = {not_in_creative_inventory=1}, pointable = false, walkable = false, + floodable = false, sunlight_propagates = true, paramtype = "light", buildable_to = true, }) -minetest.register_node("sponge:sponge", { -- dry sponge +minetest.register_node(modname..":sponge", { -- dry sponge description = "Sponge", tiles = {"sponge_sponge.png"}, groups = {crumbly=3}, sounds = default.node_sound_dirt_defaults(), - after_place_node = function(pos, placer, itemstack, pointed_thing) - local name = placer:get_player_name() - - if not minetest.is_protected(pos, name) then - local count = 0 - for x = pos.x-area, pos.x+area do - for y = pos.y-area, pos.y+area do - for z = pos.z-area, pos.z+area do - local n = minetest.get_node({x=x, y=y, z=z}).name - local d = minetest.registered_nodes[n] - if d ~= nil and (n == "air" or d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then - local p = {x=x, y=y, z=z} - if not minetest.is_protected(p, name) then - if n ~= "air" then - count = count + 1 -- counting liquids - end - minetest.set_node(p, {name="sponge:liquid_stop"}) - end - end - end - end - end - - if count > 3 then -- turns soggy if it removed more than 3 nodes - minetest.set_node(pos, {name="sponge:soggy_sponge"}) - end - end - end, + after_place_node = construct, - after_dig_node = destruct + after_destruct = destruct, }) -minetest.register_node("sponge:soggy_sponge", { -- soggy sponge +minetest.register_node(modname..":soggy_sponge", { -- soggy sponge description = "Soggy sponge", tiles = {"sponge_soggy_sponge.png"}, groups = {crumbly=3}, sounds = default.node_sound_dirt_defaults(), - on_destruct = destruct + after_destruct = destruct, }) minetest.register_craft({ -- cooking soggy sponge back into dry sponge type = "cooking", - recipe = "sponge:soggy_sponge", - output = "sponge:sponge", + recipe = modname..":soggy_sponge", + output = modname..":sponge", cooktime = 2, }) minetest.register_decoration({ -- sponges are found deep in the sea - name = "sponge:sponges", + name = modname..":sponges", deco_type = "simple", place_on = {"default:sand"}, spawn_by = "default:water_source", @@ -109,5 +146,5 @@ minetest.register_decoration({ -- sponges are found deep in the sea fill_ratio = 0.0003, y_max = -12, flags = "force_placement", - decoration = "sponge:soggy_sponge", + decoration = modname..":soggy_sponge", }) diff --git a/textures/sponge_soggy_sponge.png b/textures/sponge_soggy_sponge.png index d579c80..5122dcf 100644 Binary files a/textures/sponge_soggy_sponge.png and b/textures/sponge_soggy_sponge.png differ diff --git a/textures/sponge_sponge.png b/textures/sponge_sponge.png index ef8443e..ccc3504 100644 Binary files a/textures/sponge_sponge.png and b/textures/sponge_sponge.png differ diff --git a/textures/sponge_sponge.xcf b/textures/sponge_sponge.xcf index bd0eb68..f10b85a 100644 Binary files a/textures/sponge_sponge.xcf and b/textures/sponge_sponge.xcf differ