mirror of
https://github.com/t-affeldt/climate_api.git
synced 2025-07-02 16:30:42 +02:00
Complete rewrite
This commit is contained in:
65
ca_effects/particles.lua
Normal file
65
ca_effects/particles.lua
Normal file
@ -0,0 +1,65 @@
|
||||
if not climate_mod.settings.particles then return end
|
||||
|
||||
local function get_particle_texture(particles)
|
||||
if type(particles.textures) == "nil" or next(particles.textures) == nil then
|
||||
return particles.texture
|
||||
end
|
||||
return particles.textures[math.random(#particles.textures)]
|
||||
end
|
||||
|
||||
local function spawn_particles(player, particles)
|
||||
local ppos = player:getpos()
|
||||
local wind_x = climate_mod.state:get_int("wind_x")
|
||||
local wind_z = climate_mod.state:get_int("wind_z")
|
||||
local wind = vector.new(wind_x, 0, wind_z)
|
||||
local wind_pos = vector.multiply(wind, -1)
|
||||
local wind_speed = vector.length(wind)
|
||||
|
||||
local texture = get_particle_texture(particles)
|
||||
|
||||
local minp = vector.add(vector.add(ppos, particles.min_pos), wind_pos)
|
||||
local maxp = vector.add(vector.add(ppos, particles.max_pos), wind_pos)
|
||||
|
||||
local vel = vector.new({
|
||||
x = wind.x,
|
||||
y = -particles.falling_speed,
|
||||
z = wind.z
|
||||
})
|
||||
local acc = vector.new({x=0, y=0, z=0})
|
||||
|
||||
local exp = particles.exptime
|
||||
local vertical = math.abs(vector.normalize(vel).y) >= 0.6
|
||||
|
||||
minetest.add_particlespawner({
|
||||
amount = particles.amount,
|
||||
time = 0.5,
|
||||
minpos = minp,
|
||||
maxpos = maxp,
|
||||
minvel = vel,
|
||||
maxvel = vel,
|
||||
minacc = acc,
|
||||
maxacc = acc,
|
||||
minexptime = exp,
|
||||
maxexptime = exp,
|
||||
minsize = particles.size,
|
||||
maxsize = particles.size,
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = vertical,
|
||||
texture = texture,
|
||||
player = player:get_player_name()
|
||||
})
|
||||
end
|
||||
|
||||
local function handle_effect(player_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
minetest.chat_send_player(playername, "spam")
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
for weather, value in pairs(data) do
|
||||
spawn_particles(player, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:particles", handle_effect, "tick")
|
||||
climate_api.set_effect_cycle("climate_api:particles", climate_api.SHORT_CYCLE)
|
35
ca_effects/skybox.lua
Normal file
35
ca_effects/skybox.lua
Normal file
@ -0,0 +1,35 @@
|
||||
if not climate_mod.settings.skybox then return end
|
||||
if not minetest.get_modpath("skylayer") then return end
|
||||
|
||||
local SKYBOX_NAME = "climate_api:skybox"
|
||||
|
||||
local function set_skybox(player, sky)
|
||||
sky.name = SKYBOX_NAME
|
||||
skylayer.add_layer(player:get_player_name(), sky)
|
||||
end
|
||||
|
||||
local function remove_skybox(player)
|
||||
skylayer.remove_layer(player:get_player_name(), SKYBOX_NAME)
|
||||
end
|
||||
|
||||
local function handle_effect(player_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local sky = {}
|
||||
for weather, value in pairs(data) do
|
||||
climate_api.utility.merge_tables(sky, value)
|
||||
end
|
||||
set_skybox(player, sky)
|
||||
end
|
||||
end
|
||||
|
||||
local function remove_effect(player_data)
|
||||
for playername, data in ipairs(player_data) do
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
remove_skybox(player)
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:skybox", handle_effect, "tick")
|
||||
climate_api.register_effect("climate_api:skybox", remove_effect, "end")
|
||||
climate_api.set_effect_cycle("climate_api:skybox", climate_api.LONG_CYCLE)
|
14
ca_effects/sound.lua
Normal file
14
ca_effects/sound.lua
Normal file
@ -0,0 +1,14 @@
|
||||
if not climate_mod.settings.sound then return end
|
||||
|
||||
return
|
||||
|
||||
local function update_effect(player_data)
|
||||
for playername, data in pairs(player_data) do
|
||||
for weather, value in pairs(data) do
|
||||
climate_mod.effects.play_sound(player, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
climate_api.register_effect("climate_api:sound", update_effect, "change")
|
||||
climate_api.set_effect_cycle("climate_api:skybox", climate_api.LONG_CYCLE)
|
Reference in New Issue
Block a user