-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
name = physics | ||
depends = dev_helpers, builtin, lord_equipment | ||
depends = dev_helpers, builtin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
minetest.mod(function(mod) | ||
require("lord_physics").init(mod) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = lord_physics | ||
depends = builtin, physics, lord_equipment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local ipairs | ||
= ipairs | ||
|
||
--- @type table<number,string>|string[] | ||
local PHYSICS_TYPES = { "jump", "speed", "gravity" } | ||
|
||
--- @param player Player | ||
local function collect_physics_from_armor(player) | ||
local physics = { speed = 1, gravity = 1, jump = 1 } | ||
for _, stack in equipment.for_player(player):items(equipment.Kind.ARMOR) do | ||
if stack:get_count() == 1 then | ||
local item_groups = stack:get_definition().groups | ||
for _, type in ipairs(PHYSICS_TYPES) do | ||
local value = item_groups["physics_" .. type] | ||
if value then | ||
physics[type] = (physics[type] or 1) + value | ||
end | ||
end | ||
end | ||
end | ||
|
||
return physics | ||
end | ||
|
||
--- @param player Player | ||
local function set_player_physics(player) | ||
local physics_o = collect_physics_from_armor(player) | ||
|
||
physics.for_player(player):set(physics_o) | ||
end | ||
|
||
|
||
return { | ||
init = function() | ||
equipment.on_load(equipment.Kind.ARMOR, function(player) | ||
set_player_physics(player) | ||
end) | ||
equipment.on_change(equipment.Kind.ARMOR, function(player) | ||
set_player_physics(player) | ||
end) | ||
end, | ||
} |