forked from VoxeLibre/VoxeLibre
Remove "wet" metadata altogether
This commit is contained in:
parent
ebf6cf32e8
commit
b5afa34469
|
@ -30,7 +30,7 @@ local function get_moisture_level(pos)
|
||||||
local ndef = minetest.registered_nodes[minetest.get_node(n).name]
|
local ndef = minetest.registered_nodes[minetest.get_node(n).name]
|
||||||
local soil = ndef and ndef.groups.soil
|
local soil = ndef and ndef.groups.soil
|
||||||
if soil and soil >= 2 then
|
if soil and soil >= 2 then
|
||||||
local m = (soil > 2 or (soil == 2 and minetest.get_meta(n):get_int("wet") > 0)) and 3 or 1
|
local m = soil > 2 and 3 or 1
|
||||||
-- corners have less weight
|
-- corners have less weight
|
||||||
if x ~= 0 or z ~= 0 then m = m * 0.25 end
|
if x ~= 0 or z ~= 0 then m = m * 0.25 end
|
||||||
totalm = totalm + m
|
totalm = totalm + m
|
||||||
|
|
|
@ -50,55 +50,48 @@ minetest.register_abm({
|
||||||
local above_node = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0))
|
local above_node = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0))
|
||||||
if above_node and minetest.get_item_group(above_node.name, "solid") ~= 0 then
|
if above_node and minetest.get_item_group(above_node.name, "solid") ~= 0 then
|
||||||
node.name = "mcl_core:dirt"
|
node.name = "mcl_core:dirt"
|
||||||
minetest.set_node(pos, node) -- also removes "wet" metadata
|
minetest.set_node(pos, node)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local raining = mcl_weather and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos)
|
-- in rain, become wet, do not decay
|
||||||
local has_water, fully_loaded = false, true
|
if mcl_weather and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
||||||
if not raining then
|
if node.name == "mcl_farming:soil" then
|
||||||
-- Check an area of 9×2×9 around the node for nodename (9×9 on same level and 9×9 above)
|
node.name = "mcl_farming:soil_wet"
|
||||||
|
minetest.set_node(pos, node)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check an area of 9x2x9 around the node for nodename (9x9 on same level and 9x9 above)
|
||||||
-- include "ignore" to detect unloaded blocks
|
-- include "ignore" to detect unloaded blocks
|
||||||
local nodes, counts = minetest.find_nodes_in_area(vector.offset(pos, -4, 0, -4), vector.offset(pos, 4, 1, 4), {"group:water", "ignore"})
|
local nodes, counts = minetest.find_nodes_in_area(vector.offset(pos, -4, 0, -4), vector.offset(pos, 4, 1, 4), {"group:water", "ignore"})
|
||||||
local ignore = counts.ignore or 0
|
local ignore = counts.ignore or 0
|
||||||
has_water, fully_loaded = #nodes - ignore > 0, ignore == 0
|
local has_water, fully_loaded = #nodes > ignore, ignore == 0
|
||||||
end
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
-- Hydrate by rain or water, do not decay
|
||||||
local wet = meta:get_int("wet") or (node.name == "mcl_farming:soil" and 0 or 7)
|
if has_water then
|
||||||
-- Hydrate by rain or water
|
|
||||||
if raining or has_water then
|
|
||||||
if node.name == "mcl_farming:soil" then
|
if node.name == "mcl_farming:soil" then
|
||||||
node.name = "mcl_farming:soil_wet"
|
node.name = "mcl_farming:soil_wet"
|
||||||
minetest.set_node(pos, node) -- resets wetness
|
minetest.set_node(pos, node)
|
||||||
meta:set_int("wet", 7)
|
|
||||||
meta:mark_as_private("wet")
|
|
||||||
elseif wet < 7 then
|
|
||||||
meta:set_int("wet", 7)
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- No decay near unloaded areas (ignore) since these might include water.
|
-- No decay near unloaded areas (ignore) since these might include water.
|
||||||
if not fully_loaded then return end
|
if not fully_loaded then return end
|
||||||
|
|
||||||
-- Decay: make farmland dry or turn back to dirt
|
-- Decay: make wet farmland dry up
|
||||||
if wet > 1 then
|
if node.name == "mcl_farming:soil_wet" then
|
||||||
if node.name == "mcl_farming:soil_wet" then -- change visual appearance to dry
|
|
||||||
node.name = "mcl_farming:soil"
|
node.name = "mcl_farming:soil"
|
||||||
minetest.set_node(pos, node)
|
minetest.set_node(pos, node)
|
||||||
meta:set_int("wet", wet - 1)
|
|
||||||
meta:mark_as_private("wet") -- after set_int
|
|
||||||
else
|
|
||||||
meta:set_int("wet", wet - 1)
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Revert to dirt if wetness is 0, and no plant above
|
-- Revert to dirt if wetness is 0, and no plant above
|
||||||
local nn = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0))
|
local above = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0))
|
||||||
local nn_def = nn and minetest.registered_nodes[nn.name]
|
if minetest.get_item_group(above.name, "plant") == 0 then
|
||||||
if nn_def and (nn_def.groups.plant or 0) > 0 then return end
|
|
||||||
node.name = "mcl_core:dirt"
|
node.name = "mcl_core:dirt"
|
||||||
minetest.set_node(pos, node) -- also removes "wet" metadata
|
minetest.set_node(pos, node)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue