Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract attraction function #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions mods/sbz_meteorites/attractor.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
local elapsed = 0

local function attract_meteorite(pos, dtime, t, obj)
local magnitude = 256
if obj:is_player() then
local wielded_item = obj:get_wielded_item()
if wielded_item:is_empty() then return end
magnitude = wielded_item:get_definition().groups.attraction
if not magnitude then return end
magnitude = magnitude * wielded_item:get_count()
end
obj:add_velocity(t * dtime * sbz_api.get_attraction(obj:get_pos(), pos) * magnitude)
if elapsed > 1 then
minetest.add_particlespawner({
time = 1,
amount = math.floor(vector.distance(pos, obj:get_pos()) / 2),
exptime = 2,
size = { min = 2, max = 4 },
drag = 3,
pos = { min = pos, max = obj:get_pos() },
texture = "meteorite_trail_emitter.png" ..
(t < 0 and "^[colorize:#ffcccc:alpha" or "^[colorize:#888888:alpha"),
animation = { type = "vertical_frames", aspect_width = 4, aspect_height = 4, length = -1 },
glow = 7,
attract = {
kind = "line",
origin = vector.zero(),
origin_attached = obj,
direction = pos - obj:get_pos(),
strength = 3,
die_on_contact = false
}
})
end
end

local function attract_meteorites(pos, dtime, t)
elapsed = elapsed + dtime
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 200)) do
if (obj:is_player() and obj:get_wielded_item()) or (obj:get_luaentity() and obj:get_luaentity().name == "sbz_meteorites:meteorite") then
local magnitude = 256
if obj:is_player() then
local wielded_item = obj:get_wielded_item()
if wielded_item:is_empty() then return end
magnitude = wielded_item:get_definition().groups.attraction
if not magnitude then return end
magnitude = magnitude * wielded_item:get_count()
end
obj:add_velocity(t * dtime * sbz_api.get_attraction(obj:get_pos(), pos) * magnitude)
if elapsed > 1 then
minetest.add_particlespawner({
time = 1,
amount = math.floor(vector.distance(pos, obj:get_pos()) / 2),
exptime = 2,
size = { min = 2, max = 4 },
drag = 3,
pos = { min = pos, max = obj:get_pos() },
texture = "meteorite_trail_emitter.png" ..
(t < 0 and "^[colorize:#ffcccc:alpha" or "^[colorize:#888888:alpha"),
animation = { type = "vertical_frames", aspect_width = 4, aspect_height = 4, length = -1 },
glow = 7,
attract = {
kind = "line",
origin = vector.zero(),
origin_attached = obj,
direction = pos - obj:get_pos(),
strength = 3,
die_on_contact = false
}
})
end
attract_meteorite(pos, dtime, t, obj)
end
end
if elapsed > 1 then elapsed = 0 end
end
sbz_api.attract_meteorites = attract_meteorites
sbz_api.attract_meteorite = attract_meteorite

minetest.register_entity("sbz_meteorites:gravitational_attractor_entity", {
initial_properties = {
Expand Down
Loading