2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2021-05-05 18:36:54 +02:00
mcl_sponges = { }
mcl_sponges.registered_sponges = { }
function mcl_sponges . register_sponge ( name , def )
if def.furnace_drying == nil then def.furnace_drying = true end
if not def.tiles then def.tiles = { " mcl_sponges_sponge_wet.png " } end
if not def.description then def.description = S ( " Logged Sponge " ) end
2021-05-05 21:19:20 +02:00
2021-05-05 18:36:54 +02:00
def.itemname = " mcl_sponges:sponge_ " .. name .. " _logged "
2021-05-05 21:19:20 +02:00
2021-05-05 18:36:54 +02:00
mcl_sponges.registered_sponges [ name ] = def
minetest.register_node ( def.itemname , {
description = def.description ,
_tt_help = def.help ,
_doc_items_longdesc = def.longdesc ,
is_ground_content = false ,
tiles = { " mcl_sponges_sponge_wet.png " } ,
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
groups = { handy = 1 , hoey = 1 , building_block = 1 , sponge_logged = 1 } ,
2021-05-05 21:19:20 +02:00
on_place = function ( 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 )
local new_stack = mcl_util.call_on_rightclick ( itemstack , player , pointed_thing )
if new_stack then
return new_stack
end
local name = placer : get_player_name ( )
if minetest.is_protected ( pointed_thing.above , name ) then
return itemstack
end
if def.on_place then
local new_item = def.on_place ( itemstack , placer , pointed_thing )
if new_item then return new_item end
end
return minetest.item_place_node ( itemstack , placer , pointed_thing )
end ,
2021-05-05 18:36:54 +02:00
_mcl_blast_resistance = 0.6 ,
_mcl_hardness = 0.6 ,
} )
--drying sponge
if def.furnace_drying then
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_sponges:sponge " ,
recipe = def.itemname ,
cooktime = 10 ,
} )
end
end
2019-03-08 00:22:28 +01:00
2021-05-05 21:19:20 +02:00
function mcl_sponges . absorb ( pos )
2017-03-03 00:49:30 +01:00
local change = false
2021-05-05 21:29:01 +02:00
-- Count number of absorbed liquid by type vs other nodes
2017-11-30 17:36:08 +01:00
-- to determine the wet sponge type.
2021-05-05 21:20:51 +02:00
local out = { }
2017-03-03 00:49:30 +01:00
local p , n
2021-05-05 23:18:56 +02:00
local count = 0
2017-03-03 00:49:30 +01:00
for i =- 3 , 3 do
for j =- 3 , 3 do
for k =- 3 , 3 do
2021-05-05 23:18:56 +02:00
count = count + 1
2021-05-05 21:20:51 +02:00
pos = { x = pos.x + i , y = pos.y + j , z = pos.z + k }
node = minetest.get_node ( pos )
2021-05-05 23:06:04 +02:00
for name , def in pairs ( mcl_sponges.registered_sponges ) do
2021-05-05 21:29:01 +02:00
if minetest.get_item_group ( node.name , def.liquidgroup ) ~= 0 then
minetest.add_node ( pos , { name = " air " } )
change = true
2021-05-05 23:18:56 +02:00
if not out [ name ] then out [ name ] = 0 end
2021-05-05 21:29:01 +02:00
out [ name ] = out [ name ] + 1
break
2017-11-30 17:36:08 +01:00
end
2017-03-03 00:49:30 +01:00
end
end
end
end
2021-05-19 00:23:43 +02:00
--DEBUG
2021-05-05 23:18:56 +02:00
minetest.chat_send_all ( count )
2021-05-19 00:23:43 +02:00
-- The dominant liquid type wins. In case of a tie, normal water wins.
2017-11-30 17:36:08 +01:00
-- This slight bias is intentional.
local sponge_type
2021-05-05 23:18:56 +02:00
local biggest
for name , number in pairs ( out ) do
if biggest then
if biggest < number then
sponge_type = name
biggest = number
end
else
sponge_type = name
biggest = number
end
2017-11-30 17:36:08 +01:00
end
2021-05-05 23:36:40 +02:00
return change , mcl_sponges.registered_sponges [ sponge_type ] . itemname
2017-03-03 00:49:30 +01:00
end
2021-05-05 21:19:20 +02:00
2017-02-16 20:45:28 +01:00
minetest.register_node ( " mcl_sponges:sponge " , {
2019-03-08 00:22:28 +01:00
description = S ( " Sponge " ) ,
2020-02-19 04:54:17 +01:00
_tt_help = S ( " Removes water on contact " ) ,
2021-05-05 21:19:20 +02:00
_doc_items_longdesc = S ( " Sponges are blocks which remove certain liquid nodes around them when they are placed or come in contact with liquid, turning it into a wet sponge. " ) ,
2017-02-16 20:45:28 +01:00
is_ground_content = false ,
tiles = { " mcl_sponges_sponge.png " } ,
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
2021-05-05 21:19:20 +02:00
groups = { handy = 1 , hoey = 1 , building_block = 1 , sponge_dry = 1 } ,
2017-03-03 00:19:13 +01:00
on_place = function ( itemstack , placer , pointed_thing )
2017-02-16 20:45:28 +01:00
local pn = placer : get_player_name ( )
2021-05-05 18:36:54 +02:00
2017-02-16 20:45:28 +01:00
if pointed_thing.type ~= " node " then
return itemstack
end
2017-03-02 16:09:13 +01:00
-- Use pointed node's on_rightclick function first, if present
2021-05-05 18:36:54 +02:00
local new_stack = mcl_util.call_on_rightclick ( itemstack , player , pointed_thing )
if new_stack then
return new_stack
2017-03-02 16:09:13 +01:00
end
2017-02-16 20:45:28 +01:00
if minetest.is_protected ( pointed_thing.above , pn ) then
return itemstack
end
2017-03-03 00:49:30 +01:00
2017-03-03 00:19:13 +01:00
local pos = pointed_thing.above
2017-03-03 00:49:30 +01:00
local on_water = false
2021-05-19 00:23:43 +02:00
if minetest.get_item_group ( minetest.get_node ( pos ) . name , " liquid " ) ~= 0 then
2017-02-16 20:45:28 +01:00
on_water = true
end
2017-03-03 00:49:30 +01:00
local water_found = minetest.find_node_near ( pos , 1 , " group:water " )
2021-05-29 16:12:33 +02:00
if water_found then
2017-03-03 00:49:30 +01:00
on_water = true
2017-02-16 20:45:28 +01:00
end
2017-03-03 00:49:30 +01:00
if on_water then
-- Absorb water
2017-03-03 00:51:22 +01:00
-- FIXME: pos is not always the right placement position because of pointed_thing
2021-05-05 21:19:20 +02:00
local absorbed , wet_sponge = mcl_sponges.absorb ( pos )
2017-11-30 17:36:08 +01:00
if absorbed then
minetest.item_place_node ( ItemStack ( wet_sponge ) , placer , pointed_thing )
2020-07-10 16:08:40 +02:00
if not minetest.is_creative_enabled ( placer : get_player_name ( ) ) then
2017-03-03 00:49:30 +01:00
itemstack : take_item ( )
2017-02-16 20:45:28 +01:00
end
2017-03-03 00:49:30 +01:00
return itemstack
2017-02-16 20:45:28 +01:00
end
2017-03-03 00:19:13 +01:00
end
2017-03-03 00:49:30 +01:00
return minetest.item_place_node ( itemstack , placer , pointed_thing )
2017-02-22 16:03:59 +01:00
end ,
2020-04-17 21:40:13 +02:00
_mcl_blast_resistance = 0.6 ,
2017-02-27 01:45:25 +01:00
_mcl_hardness = 0.6 ,
2017-02-16 20:45:28 +01:00
} )
2021-04-07 09:56:00 +02: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 )
2021-05-05 18:36:54 +02:00
local new_stack = mcl_util.call_on_rightclick ( itemstack , player , pointed_thing )
if new_stack then
return new_stack
2021-04-07 09:56:00 +02:00
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 16:37:16 +02: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 09:56:00 +02: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
2021-05-05 18:36:54 +02:00
--[[if minetest.get_modpath("mclx_core") then
2017-11-30 17:46:47 +01:00
minetest.register_node ( " mcl_sponges:sponge_wet_river_water " , {
2019-03-08 00:22:28 +01:00
description = S ( " Riverwaterlogged Sponge " ) ,
2020-02-19 04:54:17 +01:00
_tt_help = S ( " Can be dried in furnace " ) ,
2019-03-08 00:22:28 +01: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 17:46:47 +01: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 09:56:00 +02:00
on_place = place_wet_sponge ,
2020-04-17 21:40:13 +02:00
_mcl_blast_resistance = 0.6 ,
2017-11-30 17:46:47 +01:00
_mcl_hardness = 0.6 ,
} )
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_sponges:sponge " ,
recipe = " mcl_sponges:sponge_wet_river_water " ,
cooktime = 10 ,
} )
2021-05-05 18:36:54 +02:00
end ] ]
2017-11-30 17:36:08 +01:00
2021-05-05 18:36:54 +02:00
mcl_sponges.register_sponge ( " water " , {
description = S ( " Waterlogged Sponge " ) ,
2021-05-05 21:19:20 +02:00
help = S ( " Can be dried in furnace " ) ,
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. " ) ,
tiles = { " mcl_sponges_sponge_wet.png " } ,
liquidgroup = " legacity_water " ,
furnace_drying = true ,
on_place = function ( itemstack , placer , pointed_thing )
if mcl_worlds.pos_to_dimension ( pointed_thing.above ) == " nether " then
minetest.item_place_node ( ItemStack ( " mcl_sponges:sponge " ) , placer , pointed_thing )
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
if not minetest.is_creative_enabled ( name ) then
itemstack : take_item ( )
end
return itemstack
end
end ,
} )
mcl_sponges.register_sponge ( " riverwater " , {
description = S ( " Riverwaterlogged Sponge " ) ,
help = S ( " Can be dried in furnace " ) ,
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. " ) ,
2021-05-05 18:36:54 +02:00
tiles = { " mcl_sponges_sponge_wet.png " } ,
2021-05-05 21:19:20 +02:00
liquidgroup = " extra_water " ,
2021-05-05 18:36:54 +02:00
furnace_drying = true ,
} )
2017-03-03 00:49:30 +01:00
minetest.register_abm ( {
label = " Sponge water absorbtion " ,
nodenames = { " mcl_sponges:sponge " } ,
2021-05-05 23:36:40 +02:00
neighbors = { " group:water " } , -- FIXME
2017-03-03 00:49:30 +01:00
interval = 1 ,
chance = 1 ,
action = function ( pos )
2021-05-05 23:18:56 +02:00
local absorbed , wet_sponge = mcl_sponges.absorb ( pos )
2017-11-30 17:36:08 +01:00
if absorbed then
minetest.add_node ( pos , { name = wet_sponge } )
2017-03-03 00:49:30 +01:00
end
end ,
} )
2021-05-05 21:19:20 +02:00
minetest.register_alias ( " mcl_sponges:sponge_wet " , " mcl_sponges:sponge_water_logged " )
minetest.register_alias ( " mcl_sponges:sponge_wet_river_water " , " mcl_sponges:sponge_riverwater_logged " )