Compare commits

...

14 Commits

Author SHA1 Message Date
AFCMS 6cb54ceeea Merge branch 'master' into sponge-API 2021-06-04 19:11:51 +02:00
AFCMS 77c62f4d43 Merge branch 'master' into sponge-API 2021-05-27 09:16:16 +02:00
AFCMS f798698b4c fixes in comments, debug messages and groups 2021-05-19 00:23:43 +02:00
AFCMS e8bc475388 Merge branch 'master' into sponge-API 2021-05-19 00:19:48 +02:00
AFCMS b733f520b2 Merge branch 'master' into sponge-API 2021-05-10 09:38:51 +02:00
AFCMS 7187ca67e7 Merge branch 'master' into sponge-API 2021-05-08 12:33:17 +02:00
AFCMS 4f0a3b625b Merge branch 'master' into sponge-API 2021-05-08 10:04:01 +02:00
AFCMS d94fc9e696 fix crash 2021-05-05 23:36:40 +02:00
AFCMS 75689afdb4 WIP 2021-05-05 23:18:56 +02:00
AFCMS 14c19c915f fix crash 2021-05-05 23:06:04 +02:00
AFCMS 451a59c8a8 WIP liquid count 2021-05-05 21:29:01 +02:00
AFCMS de8ce5b68e start support of multiple absorbsion 2021-05-05 21:20:51 +02:00
AFCMS 58f989ca74 working sponges 2021-05-05 21:19:20 +02:00
AFCMS 717da6dd7c basic WIP API for sponges 2021-05-05 18:36:54 +02:00
3 changed files with 151 additions and 67 deletions

View File

@ -95,7 +95,7 @@ S("• When water is directly below lava, the water turns into stone."),
liquid_range = 7, liquid_range = 7,
post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C}, post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C},
stack_max = 64, stack_max = 64,
groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1}, groups = { water=3, legacity_water=1, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1},
_mcl_blast_resistance = 100, _mcl_blast_resistance = 100,
-- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode
_mcl_hardness = -1, _mcl_hardness = -1,

View File

@ -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")

View File

@ -13,6 +13,8 @@ source._doc_items_entry_name = S("River Water")
-- Auto-expose entry only in valleys mapgen -- Auto-expose entry only in valleys mapgen
source._doc_items_hidden = minetest.get_mapgen_setting("mg_name") ~= "valleys" source._doc_items_hidden = minetest.get_mapgen_setting("mg_name") ~= "valleys"
source.post_effect_color = {a=192, r=0x2c, g=0x88, b=0x8c} source.post_effect_color = {a=192, r=0x2c, g=0x88, b=0x8c}
source.groups["legacity_water"] = nil
source.groups["extra_water"] = 1
source.tiles = { source.tiles = {
{name="default_river_water_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=5.0}} {name="default_river_water_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=5.0}}
} }
@ -33,6 +35,8 @@ flowing.liquid_alternative_source = "mclx_core:river_water_source"
flowing.liquid_renewable = false flowing.liquid_renewable = false
flowing.tiles = {"default_river_water_flowing_animated.png^[verticalframe:64:0"} flowing.tiles = {"default_river_water_flowing_animated.png^[verticalframe:64:0"}
flowing.post_effect_color = {a=192, r=0x2c, g=0x88, b=0x8c} flowing.post_effect_color = {a=192, r=0x2c, g=0x88, b=0x8c}
flowing.groups["legacity_water"] = nil
flowing.groups["extra_water"] = 1
flowing.special_tiles = { flowing.special_tiles = {
{ {
image="default_river_water_flowing_animated.png", image="default_river_water_flowing_animated.png",