From 9a9fab87f7ebe1ba36bae17cd2764278f39c806a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 3 Mar 2017 00:49:30 +0100 Subject: [PATCH] Sponges now regularily absorb water --- mods/ITEMS/mcl_sponges/init.lua | 88 ++++++++++++++++----------------- mods/MISC/mcl_wip/init.lua | 1 - 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/mods/ITEMS/mcl_sponges/init.lua b/mods/ITEMS/mcl_sponges/init.lua index baf3ef1a09..3ddcd3eac0 100644 --- a/mods/ITEMS/mcl_sponges/init.lua +++ b/mods/ITEMS/mcl_sponges/init.lua @@ -1,3 +1,21 @@ +local absorb = function(pos) + local change = false + local p, n + for i=-3,3 do + for j=-3,3 do + for k=-3,3 do + p = {x=pos.x+i, y=pos.y+j, z=pos.z+k} + n = minetest.get_node(p) + if minetest.get_item_group(n.name, "water") ~= 0 then + minetest.add_node(p, {name="air"}) + change = true + end + end + end + end + return change +end + minetest.register_node("mcl_sponges:sponge", { description = "Sponge", drawtype = "normal", @@ -28,57 +46,27 @@ minetest.register_node("mcl_sponges:sponge", { if minetest.is_protected(pointed_thing.above, pn) then return itemstack end - local change = false - local on_water = false + local pos = pointed_thing.above - local nn = minetest.get_node(pointed_thing.above).name - if minetest.get_item_group(nn, "water") ~= 0 then + local on_water = false + if minetest.get_item_group(minetest.get_node(pos).name, "water") ~= 0 then on_water = true end - for i=-1,1 do - local p = {x=pos.x+i, y=pos.y, z=pos.z} - local n = minetest.get_node(p) - if minetest.get_item_group(n.name, "water") ~= 0 then - on_water = true - end + local water_found = minetest.find_node_near(pos, 1, "group:water") + if water_found ~= nil then + on_water = true end - for i=-1,1 do - local p = {x=pos.x, y=pos.y+i, z=pos.z} - local n = minetest.get_node(p) - if minetest.get_item_group(n.name, "water") ~= 0 then - on_water = true - end - end - for i=-1,1 do - local p = {x=pos.x, y=pos.y, z=pos.z+i} - local n = minetest.get_node(p) - if minetest.get_item_group(n.name, "water") ~= 0 then - on_water = true - end - end - local p, n - if on_water == true then - for i=-3,3 do - for j=-3,3 do - for k=-3,3 do - p = {x=pos.x+i, y=pos.y+j, z=pos.z+k} - n = minetest.get_node(p) - if minetest.get_item_group(n.name, "water") ~= 0 then - minetest.add_node(p, {name="air"}) - change = true - end - end + if on_water then + -- Absorb water + if absorb(pos) then + minetest.item_place_node(ItemStack("mcl_sponges:sponge_wet"), placer, pointed_thing) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() end + return itemstack end end - p = {x=pos.x, y=pos.y, z=pos.z} - n = minetest.get_node(p) - if change == true then - minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge_wet"}) - else - minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge"}) - end - return itemstack + return minetest.item_place_node(itemstack, placer, pointed_thing) end, _mcl_blast_resistance = 3, _mcl_hardness = 0.6, @@ -108,3 +96,15 @@ minetest.register_craft({ cooktime = 10, }) +minetest.register_abm({ + label = "Sponge water absorbtion", + nodenames = { "mcl_sponges:sponge" }, + neighbors = { "group:water" }, + interval = 1, + chance = 1, + action = function(pos) + if absorb(pos) then + minetest.add_node(pos, {name = "mcl_sponges:sponge_wet"}) + end + end, +}) diff --git a/mods/MISC/mcl_wip/init.lua b/mods/MISC/mcl_wip/init.lua index 559a73be79..db2e8d1efb 100644 --- a/mods/MISC/mcl_wip/init.lua +++ b/mods/MISC/mcl_wip/init.lua @@ -26,7 +26,6 @@ local wip_items = { "mcl_mobitems:rotten_flesh", "mcl_mobitems:spider_eye", "mcl_minecarts:golden_rail", - "mcl_sponges:sponge", "mcl_mushrooms:mushroom_red", "mcl_mushrooms:mushroom_brown", "gemalde:node_1",