mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2025-01-08 16:19:37 +01:00
Export handle_cart_leave from movement, resolve luacheck and lua-language-server findings, fix typo
This commit is contained in:
parent
e5822ecc35
commit
24ca1b20a8
9 changed files with 18 additions and 48 deletions
|
@ -1,7 +1,6 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
local modpath = minetest.get_modpath(modname)
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
local S = minetest.get_translator(modname)
|
|
||||||
|
|
||||||
local mcl_log,DEBUG = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
local mcl_log,DEBUG = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
||||||
|
|
||||||
|
@ -17,9 +16,9 @@ local movement = dofile(modpath.."/movement.lua")
|
||||||
assert(movement.do_movement)
|
assert(movement.do_movement)
|
||||||
assert(movement.do_detached_movement)
|
assert(movement.do_detached_movement)
|
||||||
assert(movement.handle_cart_enter)
|
assert(movement.handle_cart_enter)
|
||||||
|
assert(movement.handle_cart_leave)
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
local max_step_distance = 0.5
|
|
||||||
local MINECART_MAX_HP = 4
|
local MINECART_MAX_HP = 4
|
||||||
local TWO_OVER_PI = 2 / math.pi
|
local TWO_OVER_PI = 2 / math.pi
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ local function detach_driver(self)
|
||||||
|
|
||||||
minetest.log("action", driver_name.." left a minecart")
|
minetest.log("action", driver_name.." left a minecart")
|
||||||
|
|
||||||
-- Update cart informatino
|
-- Update cart information
|
||||||
self._driver = nil
|
self._driver = nil
|
||||||
self._start_pos = nil
|
self._start_pos = nil
|
||||||
local player_meta = mcl_playerinfo.get_mod_meta(driver_name, modname)
|
local player_meta = mcl_playerinfo.get_mod_meta(driver_name, modname)
|
||||||
|
@ -75,8 +74,8 @@ function mod.kill_cart(staticdata, killer)
|
||||||
|
|
||||||
-- Leave nodes
|
-- Leave nodes
|
||||||
if staticdata.attached_at then
|
if staticdata.attached_at then
|
||||||
handle_cart_leave(self, staticdata.attached_at, staticdata.dir )
|
movement.handle_cart_leave(staticdata, staticdata.attached_at, staticdata.dir )
|
||||||
else
|
--else
|
||||||
--mcl_log("TODO: handle detatched minecart death")
|
--mcl_log("TODO: handle detatched minecart death")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -332,11 +331,10 @@ function DEFAULT_CART_DEF:on_step(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Controls
|
-- Controls
|
||||||
local ctrl, player = nil, nil
|
|
||||||
if self._driver then
|
if self._driver then
|
||||||
player = minetest.get_player_by_name(self._driver)
|
local player = minetest.get_player_by_name(self._driver)
|
||||||
if player then
|
if player then
|
||||||
ctrl = player:get_player_control()
|
local ctrl = player:get_player_control()
|
||||||
-- player detach
|
-- player detach
|
||||||
if ctrl.sneak then
|
if ctrl.sneak then
|
||||||
detach_driver(self)
|
detach_driver(self)
|
||||||
|
@ -385,9 +383,7 @@ local create_minecart = mod.create_minecart
|
||||||
|
|
||||||
-- Place a minecart at pointed_thing
|
-- Place a minecart at pointed_thing
|
||||||
function mod.place_minecart(itemstack, pointed_thing, placer)
|
function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||||
if not pointed_thing.type == "node" then
|
if pointed_thing.type ~= "node" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local look_4dir = math.round(placer:get_look_horizontal() * TWO_OVER_PI) % 4
|
local look_4dir = math.round(placer:get_look_horizontal() * TWO_OVER_PI) % 4
|
||||||
local look_dir = core.fourdir_to_dir(look_4dir)
|
local look_dir = core.fourdir_to_dir(look_4dir)
|
||||||
|
@ -396,7 +392,7 @@ function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||||
local spawn_pos = pointed_thing.above
|
local spawn_pos = pointed_thing.above
|
||||||
local cart_dir = look_dir
|
local cart_dir = look_dir
|
||||||
|
|
||||||
local railpos, node
|
local railpos
|
||||||
if mcl_minecarts.is_rail(pointed_thing.under) then
|
if mcl_minecarts.is_rail(pointed_thing.under) then
|
||||||
railpos = pointed_thing.under
|
railpos = pointed_thing.under
|
||||||
elseif mcl_minecarts.is_rail(pointed_thing.above) then
|
elseif mcl_minecarts.is_rail(pointed_thing.above) then
|
||||||
|
@ -404,11 +400,10 @@ function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||||
end
|
end
|
||||||
if railpos then
|
if railpos then
|
||||||
spawn_pos = railpos
|
spawn_pos = railpos
|
||||||
node = minetest.get_node(railpos)
|
|
||||||
|
|
||||||
-- Try two orientations, and select the second if the first is at an angle
|
-- Try two orientations, and select the second if the first is at an angle
|
||||||
cart_dir1 = mcl_minecarts.get_rail_direction(railpos, look_dir)
|
local cart_dir1 = mcl_minecarts.get_rail_direction(railpos, look_dir)
|
||||||
cart_dir2 = mcl_minecarts.get_rail_direction(railpos, -look_dir)
|
local cart_dir2 = mcl_minecarts.get_rail_direction(railpos, -look_dir)
|
||||||
if vector.length(cart_dir1) <= 1 then
|
if vector.length(cart_dir1) <= 1 then
|
||||||
cart_dir = cart_dir1
|
cart_dir = cart_dir1
|
||||||
else
|
else
|
||||||
|
@ -548,7 +543,6 @@ function mod.register_minecart(def)
|
||||||
minetest.register_craft(craft)
|
minetest.register_craft(craft)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local register_minecart = mod.register_minecart
|
|
||||||
|
|
||||||
dofile(modpath.."/carts/minecart.lua")
|
dofile(modpath.."/carts/minecart.lua")
|
||||||
dofile(modpath.."/carts/with_chest.lua")
|
dofile(modpath.."/carts/with_chest.lua")
|
||||||
|
@ -636,9 +630,9 @@ minetest.register_globalstep(function(dtime)
|
||||||
local start_time
|
local start_time
|
||||||
if DEBUG then start_time = minetest.get_us_time() end
|
if DEBUG then start_time = minetest.get_us_time() end
|
||||||
|
|
||||||
for uuid,staticdata in mod.carts() do
|
for _,staticdata in mod.carts() do
|
||||||
local pos = mod.get_cart_position(staticdata)
|
|
||||||
--[[
|
--[[
|
||||||
|
local pos = mod.get_cart_position(staticdata)
|
||||||
local le = mcl_util.get_luaentity_from_uuid(staticdata.uuid)
|
local le = mcl_util.get_luaentity_from_uuid(staticdata.uuid)
|
||||||
print("cart# "..uuid..
|
print("cart# "..uuid..
|
||||||
",velocity="..tostring(staticdata.velocity)..
|
",velocity="..tostring(staticdata.velocity)..
|
||||||
|
@ -692,4 +686,3 @@ minetest.register_on_joinplayer(function(player)
|
||||||
end, player_name, cart_uuid)
|
end, player_name, cart_uuid)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
local mcl_log = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
|
|
||||||
-- Imports
|
-- Imports
|
||||||
|
@ -40,7 +39,6 @@ function mod.attach_driver(cart, player)
|
||||||
staticdata.last_player = player_name
|
staticdata.last_player = player_name
|
||||||
|
|
||||||
-- Update player information
|
-- Update player information
|
||||||
local uuid = staticdata.uuid
|
|
||||||
mcl_player.player_attached[player_name] = true
|
mcl_player.player_attached[player_name] = true
|
||||||
--minetest.log("action", player_name.." entered minecart #"..tostring(uuid).." at "..tostring(cart._start_pos))
|
--minetest.log("action", player_name.." entered minecart #"..tostring(uuid).." at "..tostring(cart._start_pos))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
-- Minecart with Chest
|
-- Minecart with Chest
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
local S = minetest.get_translator(modname)
|
|
||||||
local submod = {}
|
local submod = {}
|
||||||
local ENABLE_TRAINS = core.settings:get_bool("mcl_minecarts_enable_trains",true)
|
local ENABLE_TRAINS = core.settings:get_bool("mcl_minecarts_enable_trains",true)
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
local mcl_debug,DEBUG = mcl_util.make_mcl_logger("mcl_logging_minecart_debug", "Minecart Debug")
|
local mcl_debug,DEBUG = mcl_util.make_mcl_logger("mcl_logging_minecart_debug", "Minecart Debug")
|
||||||
--DEBUG = false
|
|
||||||
--mcl_debug,DEBUG = function(msg) print(msg) end,true
|
--mcl_debug,DEBUG = function(msg) print(msg) end,true
|
||||||
|
|
||||||
-- Imports
|
-- Imports
|
||||||
|
@ -25,10 +22,7 @@ local train_length = mod.train_length
|
||||||
local update_train = mod.update_train
|
local update_train = mod.update_train
|
||||||
local reverse_train = mod.reverse_train
|
local reverse_train = mod.reverse_train
|
||||||
local link_cart_ahead = mod.link_cart_ahead
|
local link_cart_ahead = mod.link_cart_ahead
|
||||||
local update_cart_orientation = mod.update_cart_orientation
|
|
||||||
local get_cart_data = mod.get_cart_data
|
local get_cart_data = mod.get_cart_data
|
||||||
local get_cart_position = mod.get_cart_position
|
|
||||||
|
|
||||||
|
|
||||||
local function reverse_direction(staticdata)
|
local function reverse_direction(staticdata)
|
||||||
if staticdata.behind or staticdata.ahead then
|
if staticdata.behind or staticdata.ahead then
|
||||||
|
@ -101,6 +95,7 @@ local function handle_cart_leave(staticdata, pos, next_dir)
|
||||||
set_metadata_cart_status(pos, staticdata.uuid, nil)
|
set_metadata_cart_status(pos, staticdata.uuid, nil)
|
||||||
handle_cart_enter_exit(staticdata, pos, next_dir, "on_leave" )
|
handle_cart_enter_exit(staticdata, pos, next_dir, "on_leave" )
|
||||||
end
|
end
|
||||||
|
submod.handle_cart_leave = handle_cart_leave
|
||||||
local function handle_cart_node_watches(staticdata, dtime)
|
local function handle_cart_node_watches(staticdata, dtime)
|
||||||
local watches = staticdata.node_watches or {}
|
local watches = staticdata.node_watches or {}
|
||||||
local new_watches = {}
|
local new_watches = {}
|
||||||
|
@ -165,7 +160,7 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir)
|
||||||
meta:set_string("_mcl_minecarts_carts",minetest.serialize(carts))
|
meta:set_string("_mcl_minecarts_carts",minetest.serialize(carts))
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(vector.add(pos,next_dir))
|
meta = minetest.get_meta(vector.add(pos,next_dir))
|
||||||
if not cart_uuid then return end
|
if not cart_uuid then return end
|
||||||
|
|
||||||
-- Don't collide with the train car in front of you
|
-- Don't collide with the train car in front of you
|
||||||
|
@ -331,7 +326,6 @@ local function do_movement_step(staticdata, dtime)
|
||||||
local impulse = ctrl.impulse
|
local impulse = ctrl.impulse
|
||||||
ctrl.impulse = nil
|
ctrl.impulse = nil
|
||||||
|
|
||||||
local old_v_0 = v_0
|
|
||||||
local new_v_0 = v_0 + impulse
|
local new_v_0 = v_0 + impulse
|
||||||
if new_v_0 > SPEED_MAX then
|
if new_v_0 > SPEED_MAX then
|
||||||
new_v_0 = SPEED_MAX
|
new_v_0 = SPEED_MAX
|
||||||
|
@ -541,8 +535,7 @@ function submod.do_movement( staticdata, dtime )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local _half_pi = math.pi * 0.5
|
function submod.do_detached_movement(self)
|
||||||
function submod.do_detached_movement(self, dtime)
|
|
||||||
local staticdata = self._staticdata
|
local staticdata = self._staticdata
|
||||||
|
|
||||||
-- Make sure the object is still valid before trying to move it
|
-- Make sure the object is still valid before trying to move it
|
||||||
|
@ -622,7 +615,7 @@ function submod.do_detached_movement(self, dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reset pitch if still not attached
|
-- Reset pitch if still not attached
|
||||||
local rot = self.object:get_rotation()
|
rot = self.object:get_rotation()
|
||||||
rot.x = 0
|
rot.x = 0
|
||||||
self.object:set_rotation(rot)
|
self.object:set_rotation(rot)
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,6 @@ mod.RAIL_GROUPS = {
|
||||||
|
|
||||||
-- Inport functions and constants from elsewhere
|
-- Inport functions and constants from elsewhere
|
||||||
local table_merge = mcl_util.table_merge
|
local table_merge = mcl_util.table_merge
|
||||||
local check_connection_rules = mod.check_connection_rules
|
|
||||||
local update_rail_connections = mod.update_rail_connections
|
local update_rail_connections = mod.update_rail_connections
|
||||||
local minetest_fourdir_to_dir = minetest.fourdir_to_dir
|
local minetest_fourdir_to_dir = minetest.fourdir_to_dir
|
||||||
local minetest_dir_to_fourdir = minetest.dir_to_fourdir
|
local minetest_dir_to_fourdir = minetest.dir_to_fourdir
|
||||||
|
@ -104,7 +103,6 @@ local BASE_DEF = {
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
sounds = mcl_sounds.node_sound_metal_defaults(),
|
sounds = mcl_sounds.node_sound_metal_defaults(),
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
paramtype = "light",
|
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
collision_box = {
|
collision_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
|
@ -284,13 +282,11 @@ function mod.register_straight_rail(base_name, tiles, def)
|
||||||
mod.register_rail_sloped(base_name.."_sloped", table_merge(table.copy(sloped_def),{
|
mod.register_rail_sloped(base_name.."_sloped", table_merge(table.copy(sloped_def),{
|
||||||
_mcl_minecarts = {
|
_mcl_minecarts = {
|
||||||
get_next_dir = rail_dir_sloped,
|
get_next_dir = rail_dir_sloped,
|
||||||
|
railtype = "sloped",
|
||||||
suffix = "_sloped",
|
suffix = "_sloped",
|
||||||
},
|
},
|
||||||
mesecons = make_mesecons(base_name, "_sloped", def.mesecons),
|
mesecons = make_mesecons(base_name, "_sloped", def.mesecons),
|
||||||
tiles = { tiles[1] },
|
tiles = { tiles[1] },
|
||||||
_mcl_minecarts = {
|
|
||||||
railtype = "sloped",
|
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
local modname = minetest.get_current_modname()
|
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local mod = mcl_minecarts
|
local mod = mcl_minecarts
|
||||||
|
|
||||||
-- Imports
|
-- Imports
|
||||||
|
@ -42,7 +40,7 @@ local train_cars = mod.train_cars
|
||||||
|
|
||||||
function mod.train_length(cart)
|
function mod.train_length(cart)
|
||||||
local count = 0
|
local count = 0
|
||||||
for cart in train_cars(cart) do
|
for _ in train_cars(cart) do
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
|
@ -103,14 +101,12 @@ function mod.update_train(staticdata)
|
||||||
-- Set the entire train to the average velocity
|
-- Set the entire train to the average velocity
|
||||||
local behind = nil
|
local behind = nil
|
||||||
for c in train_cars(staticdata) do
|
for c in train_cars(staticdata) do
|
||||||
local e = 0
|
|
||||||
local separation
|
local separation
|
||||||
local cart_velocity = velocity
|
local cart_velocity = velocity
|
||||||
if not c.connected_at then
|
if not c.connected_at then
|
||||||
break_train_at(c)
|
break_train_at(c)
|
||||||
elseif behind then
|
elseif behind then
|
||||||
separation = distance_between_cars(behind, c)
|
separation = distance_between_cars(behind, c)
|
||||||
local e = 0
|
|
||||||
if not separation then
|
if not separation then
|
||||||
break_train_at(c)
|
break_train_at(c)
|
||||||
elseif separation > 1.6 then
|
elseif separation > 1.6 then
|
||||||
|
@ -144,4 +140,3 @@ function mod.reverse_train(cart)
|
||||||
c.behind,c.ahead = c.ahead,c.behind
|
c.behind,c.ahead = c.ahead,c.behind
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue