|
|
@ -1,66 +1,131 @@
|
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
|
|
|
|
|
|
local absorb = function(pos)
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def.itemname = "mcl_sponges:sponge_"..name.."_logged"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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},
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mcl_sponges.absorb(pos)
|
|
|
|
local change = false
|
|
|
|
local change = false
|
|
|
|
-- Count number of absorbed river water vs other nodes
|
|
|
|
-- Count number of absorbed liquid by type vs other nodes
|
|
|
|
-- to determine the wet sponge type.
|
|
|
|
-- to determine the wet sponge type.
|
|
|
|
local river_water = 0
|
|
|
|
local out = {}
|
|
|
|
local non_river_water = 0
|
|
|
|
|
|
|
|
local p, n
|
|
|
|
local p, n
|
|
|
|
|
|
|
|
local count = 0
|
|
|
|
for i=-3,3 do
|
|
|
|
for i=-3,3 do
|
|
|
|
for j=-3,3 do
|
|
|
|
for j=-3,3 do
|
|
|
|
for k=-3,3 do
|
|
|
|
for k=-3,3 do
|
|
|
|
p = {x=pos.x+i, y=pos.y+j, z=pos.z+k}
|
|
|
|
count = count + 1
|
|
|
|
n = minetest.get_node(p)
|
|
|
|
pos = {x=pos.x+i, y=pos.y+j, z=pos.z+k}
|
|
|
|
if minetest.get_item_group(n.name, "water") ~= 0 then
|
|
|
|
node = minetest.get_node(pos)
|
|
|
|
minetest.add_node(p, {name="air"})
|
|
|
|
for name,def in pairs(mcl_sponges.registered_sponges) do
|
|
|
|
change = true
|
|
|
|
if minetest.get_item_group(node.name, def.liquidgroup) ~= 0 then
|
|
|
|
if n.name == "mclx_core:river_water_source" or n.name == "mclx_core:river_water_flowing" then
|
|
|
|
minetest.add_node(pos, {name="air"})
|
|
|
|
river_water = river_water + 1
|
|
|
|
change = true
|
|
|
|
else
|
|
|
|
if not out[name] then out[name] = 0 end
|
|
|
|
non_river_water = non_river_water + 1
|
|
|
|
out[name] = out[name]+1
|
|
|
|
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- The dominant water type wins. In case of a tie, normal water wins.
|
|
|
|
--DEBUG
|
|
|
|
|
|
|
|
minetest.chat_send_all(count)
|
|
|
|
|
|
|
|
-- The dominant liquid type wins. In case of a tie, normal water wins.
|
|
|
|
-- This slight bias is intentional.
|
|
|
|
-- This slight bias is intentional.
|
|
|
|
local sponge_type
|
|
|
|
local sponge_type
|
|
|
|
if river_water > non_river_water then
|
|
|
|
local biggest
|
|
|
|
sponge_type = "mcl_sponges:sponge_wet_river_water"
|
|
|
|
for name, number in pairs(out) do
|
|
|
|
else
|
|
|
|
if biggest then
|
|
|
|
sponge_type = "mcl_sponges:sponge_wet"
|
|
|
|
if biggest < number then
|
|
|
|
|
|
|
|
sponge_type = name
|
|
|
|
|
|
|
|
biggest = number
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sponge_type = name
|
|
|
|
|
|
|
|
biggest = number
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return change, sponge_type
|
|
|
|
return change, mcl_sponges.registered_sponges[sponge_type].itemname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("mcl_sponges:sponge", {
|
|
|
|
minetest.register_node("mcl_sponges:sponge", {
|
|
|
|
description = S("Sponge"),
|
|
|
|
description = S("Sponge"),
|
|
|
|
_tt_help = S("Removes water on contact"),
|
|
|
|
_tt_help = S("Removes water on contact"),
|
|
|
|
_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."),
|
|
|
|
_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."),
|
|
|
|
drawtype = "normal",
|
|
|
|
|
|
|
|
is_ground_content = false,
|
|
|
|
is_ground_content = false,
|
|
|
|
tiles = {"mcl_sponges_sponge.png"},
|
|
|
|
tiles = {"mcl_sponges_sponge.png"},
|
|
|
|
walkable = true,
|
|
|
|
|
|
|
|
pointable = true,
|
|
|
|
|
|
|
|
diggable = true,
|
|
|
|
|
|
|
|
buildable_to = false,
|
|
|
|
|
|
|
|
stack_max = 64,
|
|
|
|
|
|
|
|
sounds = mcl_sounds.node_sound_dirt_defaults(),
|
|
|
|
sounds = mcl_sounds.node_sound_dirt_defaults(),
|
|
|
|
groups = {handy=1, hoey=1, building_block=1},
|
|
|
|
groups = {handy=1, hoey=1, building_block=1, sponge_dry=1},
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
local pn = placer:get_player_name()
|
|
|
|
local pn = placer:get_player_name()
|
|
|
|
|
|
|
|
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return itemstack
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Use pointed node's on_rightclick function first, if present
|
|
|
|
-- 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 placer and not placer:get_player_control().sneak then
|
|
|
|
if new_stack then
|
|
|
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
|
|
|
return new_stack
|
|
|
|
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if minetest.is_protected(pointed_thing.above, pn) then
|
|
|
|
if minetest.is_protected(pointed_thing.above, pn) then
|
|
|
@ -69,7 +134,7 @@ minetest.register_node("mcl_sponges:sponge", {
|
|
|
|
|
|
|
|
|
|
|
|
local pos = pointed_thing.above
|
|
|
|
local pos = pointed_thing.above
|
|
|
|
local on_water = false
|
|
|
|
local on_water = false
|
|
|
|
if minetest.get_item_group(minetest.get_node(pos).name, "water") ~= 0 then
|
|
|
|
if minetest.get_item_group(minetest.get_node(pos).name, "liquid") ~= 0 then
|
|
|
|
on_water = true
|
|
|
|
on_water = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local water_found = minetest.find_node_near(pos, 1, "group:water")
|
|
|
|
local water_found = minetest.find_node_near(pos, 1, "group:water")
|
|
|
@ -79,7 +144,7 @@ minetest.register_node("mcl_sponges:sponge", {
|
|
|
|
if on_water then
|
|
|
|
if on_water then
|
|
|
|
-- Absorb water
|
|
|
|
-- Absorb water
|
|
|
|
-- FIXME: pos is not always the right placement position because of pointed_thing
|
|
|
|
-- FIXME: pos is not always the right placement position because of pointed_thing
|
|
|
|
local absorbed, wet_sponge = absorb(pos)
|
|
|
|
local absorbed, wet_sponge = mcl_sponges.absorb(pos)
|
|
|
|
if absorbed then
|
|
|
|
if absorbed then
|
|
|
|
minetest.item_place_node(ItemStack(wet_sponge), placer, pointed_thing)
|
|
|
|
minetest.item_place_node(ItemStack(wet_sponge), placer, pointed_thing)
|
|
|
|
if not minetest.is_creative_enabled(placer:get_player_name()) then
|
|
|
|
if not minetest.is_creative_enabled(placer:get_player_name()) then
|
|
|
@ -100,10 +165,9 @@ function place_wet_sponge(itemstack, placer, pointed_thing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Use pointed node's on_rightclick function first, if present
|
|
|
|
-- Use pointed node's on_rightclick function first, if present
|
|
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
|
|
if placer and not placer:get_player_control().sneak then
|
|
|
|
local new_stack = mcl_util.call_on_rightclick(itemstack, player, pointed_thing)
|
|
|
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
|
|
|
if new_stack then
|
|
|
|
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
|
|
|
return new_stack
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local name = placer:get_player_name()
|
|
|
|
local name = placer:get_player_name()
|
|
|
@ -136,26 +200,7 @@ function place_wet_sponge(itemstack, placer, pointed_thing)
|
|
|
|
return minetest.item_place_node(itemstack, placer, pointed_thing)
|
|
|
|
return minetest.item_place_node(itemstack, placer, pointed_thing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("mcl_sponges:sponge_wet", {
|
|
|
|
--[[if minetest.get_modpath("mclx_core") then
|
|
|
|
description = S("Waterlogged Sponge"),
|
|
|
|
|
|
|
|
_tt_help = S("Can be dried in furnace"),
|
|
|
|
|
|
|
|
_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."),
|
|
|
|
|
|
|
|
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(),
|
|
|
|
|
|
|
|
groups = {handy=1, hoey=1, building_block=1},
|
|
|
|
|
|
|
|
on_place = place_wet_sponge,
|
|
|
|
|
|
|
|
_mcl_blast_resistance = 0.6,
|
|
|
|
|
|
|
|
_mcl_hardness = 0.6,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if minetest.get_modpath("mclx_core") then
|
|
|
|
|
|
|
|
minetest.register_node("mcl_sponges:sponge_wet_river_water", {
|
|
|
|
minetest.register_node("mcl_sponges:sponge_wet_river_water", {
|
|
|
|
description = S("Riverwaterlogged Sponge"),
|
|
|
|
description = S("Riverwaterlogged Sponge"),
|
|
|
|
_tt_help = S("Can be dried in furnace"),
|
|
|
|
_tt_help = S("Can be dried in furnace"),
|
|
|
@ -181,25 +226,60 @@ if minetest.get_modpath("mclx_core") then
|
|
|
|
recipe = "mcl_sponges:sponge_wet_river_water",
|
|
|
|
recipe = "mcl_sponges:sponge_wet_river_water",
|
|
|
|
cooktime = 10,
|
|
|
|
cooktime = 10,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end]]
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
mcl_sponges.register_sponge("water", {
|
|
|
|
type = "cooking",
|
|
|
|
description = S("Waterlogged Sponge"),
|
|
|
|
output = "mcl_sponges:sponge",
|
|
|
|
help = S("Can be dried in furnace"),
|
|
|
|
recipe = "mcl_sponges:sponge_wet",
|
|
|
|
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."),
|
|
|
|
cooktime = 10,
|
|
|
|
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."),
|
|
|
|
|
|
|
|
tiles = {"mcl_sponges_sponge_wet.png"},
|
|
|
|
|
|
|
|
liquidgroup = "extra_water",
|
|
|
|
|
|
|
|
furnace_drying = true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_abm({
|
|
|
|
minetest.register_abm({
|
|
|
|
label = "Sponge water absorbtion",
|
|
|
|
label = "Sponge water absorbtion",
|
|
|
|
nodenames = { "mcl_sponges:sponge" },
|
|
|
|
nodenames = { "mcl_sponges:sponge" },
|
|
|
|
neighbors = { "group:water" },
|
|
|
|
neighbors = { "group:water" }, -- FIXME
|
|
|
|
interval = 1,
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos)
|
|
|
|
action = function(pos)
|
|
|
|
local absorbed, wet_sponge = absorb(pos)
|
|
|
|
local absorbed, wet_sponge = mcl_sponges.absorb(pos)
|
|
|
|
if absorbed then
|
|
|
|
if absorbed then
|
|
|
|
minetest.add_node(pos, {name = wet_sponge})
|
|
|
|
minetest.add_node(pos, {name = wet_sponge})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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")
|