Fill buckets, turn off fire during rain
This commit is contained in:
parent
09d54ba264
commit
ab58aec761
@ -82,6 +82,8 @@ This is the list of all groups used for nodes. Note: If no number/rating is spec
|
||||
* `unmagnetic`: Node is "unmagnetic", this means it can de-magnetize stuff
|
||||
* `locked`: Node is considered to be locked
|
||||
* `container`: Node has an inventory to store item(s)
|
||||
* `react_on_rain`: Node does something when it rains; the `rp_weather` mod will call `_rp_on_rain(pos, node)` in random intervals
|
||||
* `react_on_rain_hf`: Same as above, but callback is called with higher frequency
|
||||
* `interactive_node`: Node can be interacted with (excluding pure container nodes)
|
||||
* `no_spawn_allowed_on`: If set, players can not (initially) spawn on this block
|
||||
* `spawn_allowed_in`: If set, players can spawn into this block (note: this group is ignored for the 'air' and 'ignore' nodes)
|
||||
|
@ -142,7 +142,7 @@ minetest.register_node(
|
||||
stack_max = 10,
|
||||
wield_scale = {x=1,y=1,z=2},
|
||||
liquids_pointable = true,
|
||||
groups = { bucket = 1, tool = 1, dig_immediate = 3, attached_node = 1 },
|
||||
groups = { bucket = 1, tool = 1, dig_immediate = 3, attached_node = 1, react_on_rain = 1 },
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
|
||||
@ -198,6 +198,27 @@ minetest.register_node(
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
|
||||
_rp_on_rain = function(pos, node)
|
||||
-- Fill bucket with water when it rains.
|
||||
-- Before the bucket fills, it first increases a hidden "fullness"
|
||||
-- value. The rain callback must be called 3 times before the bucket
|
||||
-- fills with water. The fullness value is stored in param2.
|
||||
local p2 = node.param2
|
||||
if p2 < 64 then
|
||||
-- We increase param2 by 32 because this is the value at which
|
||||
-- facedir wraps around
|
||||
p2 = p2 + 32
|
||||
minetest.set_node(pos, {name=node.name, param2 = p2})
|
||||
minetest.log("verbose", "[rp_default] Bucket at "..minetest.pos_to_string(pos).." got its fullness increased in the rain (param2="..p2..")")
|
||||
else
|
||||
-- If param2 was 64 or greater, we know that the bucket
|
||||
-- was rained into 2 times before. Therefore, this must
|
||||
-- be now the 3rd time, so we add the water bucket node.
|
||||
p2 = p2 % 32
|
||||
minetest.set_node(pos, {name="rp_default:bucket_water", param2 = p2})
|
||||
minetest.log("action", "[rp_default] Bucket at "..minetest.pos_to_string(pos).." was filled with water by rain")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
name = rp_default
|
||||
depends = rp_sounds, rp_util, rp_formspec, rp_crafting, rp_item_drop
|
||||
optional_depends = rp_achievements
|
||||
optional_depends = rp_achievements, rp_weather
|
||||
description = Main Repixture content mod. Contains most of the basic building blocks and items, including tools, weapons, fertilizer, buckets, chest, furnace, signs, torches, ladders and fences. Also contains the core map generator.
|
||||
|
@ -2,6 +2,29 @@ local S = minetest.get_translator("rp_fire")
|
||||
|
||||
local LIGHT = 10
|
||||
|
||||
local burnout_effect = function(pos)
|
||||
-- Spawn burnout particle
|
||||
local ppos, vel
|
||||
local vel = vector.new(0, 0.6, 0)
|
||||
ppos = vector.add(pos, vector.new(0, -0.4, 0))
|
||||
vel = vector.new(math.random(-10, 10)*0.001, math.random(50, 70)*0.01, math.random(-10, 10)*0.001)
|
||||
local anim = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = -1 }
|
||||
minetest.add_particlespawner({
|
||||
amount = 1,
|
||||
time = 0.001,
|
||||
pos = ppos,
|
||||
vel = vel,
|
||||
exptime = 1,
|
||||
size = 5.75,
|
||||
texpool = {
|
||||
{name = "rp_default_torch_smoke_anim.png", animation = anim},
|
||||
{name = "rp_default_torch_smoke_anim.png^[transformFX", animation = anim},
|
||||
},
|
||||
})
|
||||
-- Sound
|
||||
minetest.sound_play({name="rp_default_torch_burnout", gain=0.2, max_hear_distance = 16}, {pos=pos}, true)
|
||||
end
|
||||
|
||||
minetest.register_node(
|
||||
"rp_fire:bonfire",
|
||||
{
|
||||
@ -48,8 +71,14 @@ minetest.register_node(
|
||||
floodable = true,
|
||||
light_source = LIGHT,
|
||||
use_texture_alpha = "clip",
|
||||
groups = {cracky = 3, bonfine = 2, attached_node = 1, not_in_creative_inventory = 1},
|
||||
groups = {cracky = 3, bonfine = 2, attached_node = 1, not_in_creative_inventory = 1, react_on_rain_hf = 1},
|
||||
walkable = false,
|
||||
drop = "rp_fire:bonfire",
|
||||
sounds = rp_sounds.node_sound_stone_defaults(),
|
||||
|
||||
_rp_on_rain = function(pos, node)
|
||||
minetest.set_node(pos, {name="rp_fire:bonfire", param2 = node.param2})
|
||||
burnout_effect(pos)
|
||||
minetest.log("action", "[rp_fire] Bonfire at "..minetest.pos_to_string(pos).." goes out in the rain")
|
||||
end,
|
||||
})
|
||||
|
@ -92,6 +92,30 @@ local function setweather_type(wtype, do_repeat)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the current weather
|
||||
function weather.get_weather()
|
||||
return weather.weather
|
||||
end
|
||||
|
||||
-- Returns true is position `pos` is in a place in which it could rain into
|
||||
function weather.is_node_rainable(pos)
|
||||
for i=0, 15 do
|
||||
local cpos = {x=pos.x, y=pos.y+i, z=pos.z}
|
||||
local node = minetest.get_node(cpos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def or def.walkable then
|
||||
return false
|
||||
end
|
||||
if i == 0 then
|
||||
local light = minetest.get_node_light(cpos, 0.5)
|
||||
if light < 15 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- Returns a number telling how many µs the weather was changed before.
|
||||
-- Returns nil if weather was not changed before
|
||||
function weather.weather_last_changed_before()
|
||||
@ -256,3 +280,41 @@ minetest.register_chatcommand(
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
sound_handles[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
local on_rain_abm = function(pos, node)
|
||||
if weather.get_weather() ~= "storm" then
|
||||
return
|
||||
end
|
||||
-- Don't call handlers for the first 5 seconds of rain
|
||||
local lwc = weather.weather_last_changed_before()
|
||||
if lwc ~= nil and lwc < 5000000 then
|
||||
return
|
||||
end
|
||||
if not weather.is_node_rainable({x=pos.x,y=pos.y+1,z=pos.z}) then
|
||||
return
|
||||
end
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if def._rp_on_rain then
|
||||
def._rp_on_rain(pos, node)
|
||||
else
|
||||
minetest.log("error", "[rp_weather] Node "..node.name.." has reacts_on_rain group but no _rp_on_rain handler!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_abm({
|
||||
label = "Call _rp_on_rain node handlers during rain (low frequency)",
|
||||
chance = 3,
|
||||
interval = 30.0,
|
||||
nodenames = { "group:react_on_rain" },
|
||||
action = on_rain_abm,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label = "Call _rp_on_rain node handlers during rain (high frequency)",
|
||||
chance = 2,
|
||||
interval = 5.0,
|
||||
nodenames = { "group:react_on_rain_hf" },
|
||||
action = on_rain_abm,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user