mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2025-01-07 15:49:32 +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 modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
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_detached_movement)
|
||||
assert(movement.handle_cart_enter)
|
||||
assert(movement.handle_cart_leave)
|
||||
|
||||
-- Constants
|
||||
local max_step_distance = 0.5
|
||||
local MINECART_MAX_HP = 4
|
||||
local TWO_OVER_PI = 2 / math.pi
|
||||
|
||||
|
@ -40,7 +39,7 @@ local function detach_driver(self)
|
|||
|
||||
minetest.log("action", driver_name.." left a minecart")
|
||||
|
||||
-- Update cart informatino
|
||||
-- Update cart information
|
||||
self._driver = nil
|
||||
self._start_pos = nil
|
||||
local player_meta = mcl_playerinfo.get_mod_meta(driver_name, modname)
|
||||
|
@ -75,8 +74,8 @@ function mod.kill_cart(staticdata, killer)
|
|||
|
||||
-- Leave nodes
|
||||
if staticdata.attached_at then
|
||||
handle_cart_leave(self, staticdata.attached_at, staticdata.dir )
|
||||
else
|
||||
movement.handle_cart_leave(staticdata, staticdata.attached_at, staticdata.dir )
|
||||
--else
|
||||
--mcl_log("TODO: handle detatched minecart death")
|
||||
end
|
||||
|
||||
|
@ -332,11 +331,10 @@ function DEFAULT_CART_DEF:on_step(dtime)
|
|||
end
|
||||
|
||||
-- Controls
|
||||
local ctrl, player = nil, nil
|
||||
if self._driver then
|
||||
player = minetest.get_player_by_name(self._driver)
|
||||
local player = minetest.get_player_by_name(self._driver)
|
||||
if player then
|
||||
ctrl = player:get_player_control()
|
||||
local ctrl = player:get_player_control()
|
||||
-- player detach
|
||||
if ctrl.sneak then
|
||||
detach_driver(self)
|
||||
|
@ -385,9 +383,7 @@ local create_minecart = mod.create_minecart
|
|||
|
||||
-- Place a minecart at pointed_thing
|
||||
function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||
if not pointed_thing.type == "node" then
|
||||
return
|
||||
end
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
|
||||
local look_4dir = math.round(placer:get_look_horizontal() * TWO_OVER_PI) % 4
|
||||
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 cart_dir = look_dir
|
||||
|
||||
local railpos, node
|
||||
local railpos
|
||||
if mcl_minecarts.is_rail(pointed_thing.under) then
|
||||
railpos = pointed_thing.under
|
||||
elseif mcl_minecarts.is_rail(pointed_thing.above) then
|
||||
|
@ -404,11 +400,10 @@ function mod.place_minecart(itemstack, pointed_thing, placer)
|
|||
end
|
||||
if railpos then
|
||||
spawn_pos = railpos
|
||||
node = minetest.get_node(railpos)
|
||||
|
||||
-- Try two orientations, and select the second if the first is at an angle
|
||||
cart_dir1 = mcl_minecarts.get_rail_direction(railpos, look_dir)
|
||||
cart_dir2 = mcl_minecarts.get_rail_direction(railpos, -look_dir)
|
||||
local cart_dir1 = 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
|
||||
cart_dir = cart_dir1
|
||||
else
|
||||
|
@ -548,7 +543,6 @@ function mod.register_minecart(def)
|
|||
minetest.register_craft(craft)
|
||||
end
|
||||
end
|
||||
local register_minecart = mod.register_minecart
|
||||
|
||||
dofile(modpath.."/carts/minecart.lua")
|
||||
dofile(modpath.."/carts/with_chest.lua")
|
||||
|
@ -636,9 +630,9 @@ minetest.register_globalstep(function(dtime)
|
|||
local start_time
|
||||
if DEBUG then start_time = minetest.get_us_time() end
|
||||
|
||||
for uuid,staticdata in mod.carts() do
|
||||
local pos = mod.get_cart_position(staticdata)
|
||||
for _,staticdata in mod.carts() do
|
||||
--[[
|
||||
local pos = mod.get_cart_position(staticdata)
|
||||
local le = mcl_util.get_luaentity_from_uuid(staticdata.uuid)
|
||||
print("cart# "..uuid..
|
||||
",velocity="..tostring(staticdata.velocity)..
|
||||
|
@ -692,4 +686,3 @@ minetest.register_on_joinplayer(function(player)
|
|||
end, player_name, cart_uuid)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local S = minetest.get_translator(modname)
|
||||
local mcl_log = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
||||
local mod = mcl_minecarts
|
||||
|
||||
-- Imports
|
||||
|
@ -40,7 +39,6 @@ function mod.attach_driver(cart, player)
|
|||
staticdata.last_player = player_name
|
||||
|
||||
-- Update player information
|
||||
local uuid = staticdata.uuid
|
||||
mcl_player.player_attached[player_name] = true
|
||||
--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 modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
-- Minecart with Chest
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
local submod = {}
|
||||
local ENABLE_TRAINS = core.settings:get_bool("mcl_minecarts_enable_trains",true)
|
||||
|
||||
-- Constants
|
||||
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
|
||||
|
||||
-- Imports
|
||||
|
@ -25,10 +22,7 @@ local train_length = mod.train_length
|
|||
local update_train = mod.update_train
|
||||
local reverse_train = mod.reverse_train
|
||||
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_position = mod.get_cart_position
|
||||
|
||||
|
||||
local function reverse_direction(staticdata)
|
||||
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)
|
||||
handle_cart_enter_exit(staticdata, pos, next_dir, "on_leave" )
|
||||
end
|
||||
submod.handle_cart_leave = handle_cart_leave
|
||||
local function handle_cart_node_watches(staticdata, dtime)
|
||||
local watches = staticdata.node_watches or {}
|
||||
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))
|
||||
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
|
||||
|
||||
-- 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
|
||||
ctrl.impulse = nil
|
||||
|
||||
local old_v_0 = v_0
|
||||
local new_v_0 = v_0 + impulse
|
||||
if new_v_0 > SPEED_MAX then
|
||||
new_v_0 = SPEED_MAX
|
||||
|
@ -541,8 +535,7 @@ function submod.do_movement( staticdata, dtime )
|
|||
end
|
||||
end
|
||||
|
||||
local _half_pi = math.pi * 0.5
|
||||
function submod.do_detached_movement(self, dtime)
|
||||
function submod.do_detached_movement(self)
|
||||
local staticdata = self._staticdata
|
||||
|
||||
-- Make sure the object is still valid before trying to move it
|
||||
|
@ -622,7 +615,7 @@ function submod.do_detached_movement(self, dtime)
|
|||
end
|
||||
|
||||
-- Reset pitch if still not attached
|
||||
local rot = self.object:get_rotation()
|
||||
rot = self.object:get_rotation()
|
||||
rot.x = 0
|
||||
self.object:set_rotation(rot)
|
||||
end
|
||||
|
|
|
@ -9,7 +9,6 @@ mod.RAIL_GROUPS = {
|
|||
|
||||
-- Inport functions and constants from elsewhere
|
||||
local table_merge = mcl_util.table_merge
|
||||
local check_connection_rules = mod.check_connection_rules
|
||||
local update_rail_connections = mod.update_rail_connections
|
||||
local minetest_fourdir_to_dir = minetest.fourdir_to_dir
|
||||
local minetest_dir_to_fourdir = minetest.dir_to_fourdir
|
||||
|
@ -104,7 +103,6 @@ local BASE_DEF = {
|
|||
stack_max = 64,
|
||||
sounds = mcl_sounds.node_sound_metal_defaults(),
|
||||
is_ground_content = true,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
collision_box = {
|
||||
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),{
|
||||
_mcl_minecarts = {
|
||||
get_next_dir = rail_dir_sloped,
|
||||
railtype = "sloped",
|
||||
suffix = "_sloped",
|
||||
},
|
||||
mesecons = make_mesecons(base_name, "_sloped", def.mesecons),
|
||||
tiles = { tiles[1] },
|
||||
_mcl_minecarts = {
|
||||
railtype = "sloped",
|
||||
},
|
||||
}))
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
|
||||
-- Imports
|
||||
|
@ -42,7 +40,7 @@ local train_cars = mod.train_cars
|
|||
|
||||
function mod.train_length(cart)
|
||||
local count = 0
|
||||
for cart in train_cars(cart) do
|
||||
for _ in train_cars(cart) do
|
||||
count = count + 1
|
||||
end
|
||||
return count
|
||||
|
@ -103,14 +101,12 @@ function mod.update_train(staticdata)
|
|||
-- Set the entire train to the average velocity
|
||||
local behind = nil
|
||||
for c in train_cars(staticdata) do
|
||||
local e = 0
|
||||
local separation
|
||||
local cart_velocity = velocity
|
||||
if not c.connected_at then
|
||||
break_train_at(c)
|
||||
elseif behind then
|
||||
separation = distance_between_cars(behind, c)
|
||||
local e = 0
|
||||
if not separation then
|
||||
break_train_at(c)
|
||||
elseif separation > 1.6 then
|
||||
|
@ -144,4 +140,3 @@ function mod.reverse_train(cart)
|
|||
c.behind,c.ahead = c.ahead,c.behind
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue