2021-05-29 14:12:33 +00:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-07 23:22:28 +00:00
2017-03-02 23:49:30 +00:00
local absorb = function ( pos )
local change = false
2017-11-30 16:36:08 +00:00
-- Count number of absorbed river water vs other nodes
-- to determine the wet sponge type.
local river_water = 0
local non_river_water = 0
2017-03-02 23:49:30 +00:00
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
2017-11-30 16:36:08 +00:00
if n.name == " mclx_core:river_water_source " or n.name == " mclx_core:river_water_flowing " then
river_water = river_water + 1
else
non_river_water = non_river_water + 1
end
2017-03-02 23:49:30 +00:00
end
end
end
end
2017-11-30 16:36:08 +00:00
-- The dominant water type wins. In case of a tie, normal water wins.
-- This slight bias is intentional.
local sponge_type
if river_water > non_river_water then
sponge_type = " mcl_sponges:sponge_wet_river_water "
else
sponge_type = " mcl_sponges:sponge_wet "
end
return change , sponge_type
2017-03-02 23:49:30 +00:00
end
2017-02-16 19:45:28 +00:00
minetest.register_node ( " mcl_sponges:sponge " , {
2019-03-07 23:22:28 +00:00
description = S ( " Sponge " ) ,
2020-02-19 03:54:17 +00:00
_tt_help = S ( " Removes water on contact " ) ,
2019-03-07 23:22:28 +00:00
_doc_items_longdesc = S ( " Sponges are blocks which remove water around them when they are placed or come in contact with water, turning it into a wet sponge. " ) ,
2017-02-16 19:45:28 +00:00
drawtype = " normal " ,
is_ground_content = false ,
tiles = { " mcl_sponges_sponge.png " } ,
walkable = true ,
pointable = true ,
diggable = true ,
buildable_to = false ,
stack_max = 64 ,
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
2021-04-12 13:09:48 +00:00
groups = { handy = 1 , hoey = 1 , building_block = 1 } ,
2017-03-02 23:19:13 +00:00
on_place = function ( itemstack , placer , pointed_thing )
2017-02-16 19:45:28 +00:00
local pn = placer : get_player_name ( )
if pointed_thing.type ~= " node " then
return itemstack
end
2017-03-02 15:09:13 +00:00
-- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node ( pointed_thing.under )
if placer and not placer : get_player_control ( ) . sneak then
if minetest.registered_nodes [ node.name ] and minetest.registered_nodes [ node.name ] . on_rightclick then
return minetest.registered_nodes [ node.name ] . on_rightclick ( pointed_thing.under , node , placer , itemstack ) or itemstack
end
end
2017-02-16 19:45:28 +00:00
if minetest.is_protected ( pointed_thing.above , pn ) then
return itemstack
end
2017-03-02 23:49:30 +00:00
2017-03-02 23:19:13 +00:00
local pos = pointed_thing.above
2017-03-02 23:49:30 +00:00
local on_water = false
if minetest.get_item_group ( minetest.get_node ( pos ) . name , " water " ) ~= 0 then
2017-02-16 19:45:28 +00:00
on_water = true
end
2017-03-02 23:49:30 +00:00
local water_found = minetest.find_node_near ( pos , 1 , " group:water " )
2021-05-29 14:12:33 +00:00
if water_found then
2017-03-02 23:49:30 +00:00
on_water = true
2017-02-16 19:45:28 +00:00
end
2017-03-02 23:49:30 +00:00
if on_water then
-- Absorb water
2017-03-02 23:51:22 +00:00
-- FIXME: pos is not always the right placement position because of pointed_thing
2017-11-30 16:36:08 +00:00
local absorbed , wet_sponge = absorb ( pos )
if absorbed then
minetest.item_place_node ( ItemStack ( wet_sponge ) , placer , pointed_thing )
2020-07-10 14:08:40 +00:00
if not minetest.is_creative_enabled ( placer : get_player_name ( ) ) then
2017-03-02 23:49:30 +00:00
itemstack : take_item ( )
2017-02-16 19:45:28 +00:00
end
2017-03-02 23:49:30 +00:00
return itemstack
2017-02-16 19:45:28 +00:00
end
2017-03-02 23:19:13 +00:00
end
2017-03-02 23:49:30 +00:00
return minetest.item_place_node ( itemstack , placer , pointed_thing )
2017-02-22 15:03:59 +00:00
end ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 0.6 ,
2017-02-27 00:45:25 +00:00
_mcl_hardness = 0.6 ,
2017-02-16 19:45:28 +00:00
} )
2021-04-07 07:56:00 +00:00
function place_wet_sponge ( itemstack , placer , pointed_thing )
if pointed_thing.type ~= " node " then
return itemstack
end
-- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node ( pointed_thing.under )
if placer and not placer : get_player_control ( ) . sneak then
if minetest.registered_nodes [ node.name ] and minetest.registered_nodes [ node.name ] . on_rightclick then
return minetest.registered_nodes [ node.name ] . on_rightclick ( pointed_thing.under , node , placer , itemstack ) or itemstack
end
end
local name = placer : get_player_name ( )
if minetest.is_protected ( pointed_thing.above , name ) then
return itemstack
end
if mcl_worlds.pos_to_dimension ( pointed_thing.above ) == " nether " then
minetest.item_place_node ( ItemStack ( " mcl_sponges:sponge " ) , placer , pointed_thing )
2021-04-28 14:37:16 +00:00
local pos = pointed_thing.above
for n = 0 , 25 do
minetest.add_particle ( {
pos = { x = pos.x + math.random ( - 1 , 1 ) * math.random ( ) / 2 , y = pos.y + 0.6 , z = pos.z + math.random ( - 1 , 1 ) * math.random ( ) / 2 } ,
velocity = { x = 0 , y = math.random ( ) , z = 0 } ,
acceleration = { x = 0 , y = 0 , z = 0 } ,
expirationtime = math.random ( ) ,
collisiondetection = false ,
vertical = false ,
size = math.random ( 2 , 5 ) ,
texture = " mcl_particles_sponge " .. math.random ( 1 , 5 ) .. " .png " ,
} )
end
2021-04-07 07:56:00 +00:00
if not minetest.is_creative_enabled ( name ) then
itemstack : take_item ( )
end
return itemstack
end
return minetest.item_place_node ( itemstack , placer , pointed_thing )
end
2017-02-16 19:45:28 +00:00
minetest.register_node ( " mcl_sponges:sponge_wet " , {
2019-03-07 23:22:28 +00:00
description = S ( " Waterlogged Sponge " ) ,
2020-02-19 03:54:17 +00:00
_tt_help = S ( " Can be dried in furnace " ) ,
2019-03-07 23:22:28 +00:00
_doc_items_longdesc = S ( " 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. " ) ,
2017-02-16 19:45:28 +00:00
drawtype = " normal " ,
is_ground_content = false ,
tiles = { " mcl_sponges_sponge_wet.png " } ,
walkable = true ,
pointable = true ,
diggable = true ,
buildable_to = false ,
stack_max = 64 ,
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
2021-04-12 13:09:48 +00:00
groups = { handy = 1 , hoey = 1 , building_block = 1 } ,
2021-04-07 07:56:00 +00:00
on_place = place_wet_sponge ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 0.6 ,
2017-02-27 00:45:25 +00:00
_mcl_hardness = 0.6 ,
2017-02-16 19:45:28 +00:00
} )
2017-11-30 16:46:47 +00:00
if minetest.get_modpath ( " mclx_core " ) then
minetest.register_node ( " mcl_sponges:sponge_wet_river_water " , {
2019-03-07 23:22:28 +00:00
description = S ( " Riverwaterlogged Sponge " ) ,
2020-02-19 03:54:17 +00:00
_tt_help = S ( " Can be dried in furnace " ) ,
2019-03-07 23:22:28 +00:00
_doc_items_longdesc = S ( " 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 " .. S ( " A sponge becomes riverwaterlogged (instead of waterlogged) if it sucks up more river water than (normal) water. " ) ,
2017-11-30 16:46:47 +00:00
drawtype = " normal " ,
is_ground_content = false ,
tiles = { " mcl_sponges_sponge_wet_river_water.png " } ,
walkable = true ,
pointable = true ,
diggable = true ,
buildable_to = false ,
stack_max = 64 ,
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
groups = { handy = 1 , building_block = 1 } ,
2021-04-07 07:56:00 +00:00
on_place = place_wet_sponge ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 0.6 ,
2017-11-30 16:46:47 +00:00
_mcl_hardness = 0.6 ,
} )
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_sponges:sponge " ,
recipe = " mcl_sponges:sponge_wet_river_water " ,
cooktime = 10 ,
} )
end
2017-11-30 16:36:08 +00:00
2017-02-16 19:45:28 +00:00
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_sponges:sponge " ,
recipe = " mcl_sponges:sponge_wet " ,
cooktime = 10 ,
} )
2017-03-02 23:49:30 +00:00
minetest.register_abm ( {
label = " Sponge water absorbtion " ,
nodenames = { " mcl_sponges:sponge " } ,
neighbors = { " group:water " } ,
interval = 1 ,
chance = 1 ,
action = function ( pos )
2017-11-30 16:36:08 +00:00
local absorbed , wet_sponge = absorb ( pos )
if absorbed then
minetest.add_node ( pos , { name = wet_sponge } )
2017-03-02 23:49:30 +00:00
end
end ,
} )