From 7adeb5cb7117ec9f1bdfae9d63fb6a9223034782 Mon Sep 17 00:00:00 2001 From: Benjie Fiftysix Date: Tue, 22 Dec 2020 01:12:06 +0000 Subject: [PATCH] fixed bug, updated textures --- README.md | 14 ++-- init.lua | 129 ++++++++++++++++++++----------- textures/sponge_soggy_sponge.png | Bin 388 -> 1173 bytes textures/sponge_sponge.png | Bin 363 -> 1239 bytes textures/sponge_sponge.xcf | Bin 1713 -> 3036 bytes 5 files changed, 91 insertions(+), 52 deletions(-) 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 d579c8015bed8051e8108db92cdc5a0e0a4e3585..5122dcf7e6016bd0d92f4d618fa1892319c56625 100644 GIT binary patch delta 1118 zcmV-k1flzc1CEX>4Tx04R}tkv&MmKpe$iQ$>-AgGHn` zWT;LSMMWI73Pq?8YK2xEOfLO`CJjl7i=*ILaPVWX>fqw6tAnc`2!4P#IXWr2NQwVT z3N2zhIPS;0dyl(!fKV?p&FUBjG~G5+iMW`_u8Li+2w?y~1b<^Pvy3@OO2T)1-6O!) zyBN>%KlkV8RdW^t0wVD&GfbO!gLrz=HaPDShgnfpiO-2gO}ZfQBi9v=-#8as7IZLMN=c5B95w>PWeK{W0mt3XRTai&3p0}hI0DKGS_JiA%R6KL4pVc zRg_SMjTo&uDSsAHv>*5JM_j)|E`?krFmf!Q0u8e32mgcL-CFs{2`?!W2RdII=VKV? z+65Xl$N4^XoW=l354hX`2A>SslwB!EQ^@Cm z_cQvYEYN=o^sITkHTQA)0Hmp_V-Ae7f{d=a_-w$z762tC z%Y8#^ky|H!0&Yn}K~y-)Ez(S?<-VGnC9KKbdhlN-QLx3ISC& zADuDmEr0y^yE>cMlhBo4jO#nzBtR(LjFC*(8n$HV%D^MkIH%0>i@L6G3hc?E2#?rP z`kgQb`cpQ0L6s#r;?~erGqr#SesZn{KHn5o%lK+g z9Kwn}cw7vD?%1$r=&H!HcK?%&OzR0}Hip>K76X6ZJzbkvw~Vn4(S&K58o@EW8W0$# z9Z(+e2xNBkpo&PvwO@Y~_n8Ng?sLta9nWU~1ORKGYaONE kIrzx6k91v&wTAxy{3AVU$Wd7O0000907*qoM6N<$g3g-&8~^|S delta 328 zcmV-O0k{5@34{ZXBRBvCVoOIv0RI30001*5eDeSR010qNS#tmYE+YT{E+YYWr9XB6 z000McNliru;s_fLBqj)ns1TFt0VjU|>`6pHR5;6ZQZWvLFc5R2jGzjUnGStQU)H&A zWPmvcA+onaYA{F065aWdJNtb5ykB4ZPpC%3)InnaTTbz1nsIL%c*s%k`B)D*dosSl zg=$2oMl928!2DSAF?HKij9p9}V(PX>cI128oG2+3N3b7ia2orGcI}7yKx=>dKs#Lt zsCA^~?E`|LLXpy5mvi2B%3T0pJ*}+tkuR-DMasoMOwD0R>fv?ox+a~hBrYd)DhxZb z$lm=>pQd#s7hX9~y^@6<;VDpQoy3&;PBF)xo-PSU%zEKqByv`VY2g($#wRD*0*iAa ajDLdwy!+T_2ZaCt002ovPDBK*LSTXf1&F)= diff --git a/textures/sponge_sponge.png b/textures/sponge_sponge.png index ef8443e56af30a3ebc6e08c34bfc0c198b02ddda..ccc350465347cb24a3a0968f5c237af4925393f5 100644 GIT binary patch delta 1168 zcmV;B1aJH60@n$U8Gi-<001BJ|6u?C0fT8nLr_UWLm+T+Z)Rz1WdHyuk$sUpNW(xJ z#a~lJk&1&wq&Q@#P8LN)9JLBXs1Ry}Rvk<({emV9Ns5c3;979-W3lSs;;gHKs~`w| zfH*liDY{6B|4RxjVmvtR$GdxvyLW(4FEh>R7zZ@nHdBeXn19Kxie0Y=VE{k`V=}Xh zIY~;wcYNI=z}LGN&+Gj4P0EeG-VIC+yMrk z4B3=jD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