diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index 2c3905982..6731c05fc 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -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 @@ -468,7 +463,7 @@ local function register_minecart_craftitem(itemstring, def) stack_max = 1, _mcl_dropper_on_drop = dropper_place_minecart, on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then + if pointed_thing.type ~= "node" then return end @@ -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,11 +630,11 @@ 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.. + print("cart# "..staticdata.uuid.. ",velocity="..tostring(staticdata.velocity).. ",pos="..tostring(pos).. ",le="..tostring(le).. @@ -692,4 +686,3 @@ minetest.register_on_joinplayer(function(player) end, player_name, cart_uuid) end end) - diff --git a/mods/ENTITIES/mcl_minecarts/carts/minecart.lua b/mods/ENTITIES/mcl_minecarts/carts/minecart.lua index a155c94b5..6ec4f791c 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/minecart.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/minecart.lua @@ -40,9 +40,8 @@ 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)) + mcl_log(player_name.." entered minecart #"..tostring(staticdata.uuid).." at "..tostring(cart._start_pos)) -- Attach the player object to the minecart player:set_attach(cart.object, "", vector.new(1,-1.75,-2), vector.new(0,0,0)) diff --git a/mods/ENTITIES/mcl_minecarts/carts/with_chest.lua b/mods/ENTITIES/mcl_minecarts/carts/with_chest.lua index 1f141eade..757be3607 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/with_chest.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/with_chest.lua @@ -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 diff --git a/mods/ENTITIES/mcl_minecarts/carts/with_commandblock.lua b/mods/ENTITIES/mcl_minecarts/carts/with_commandblock.lua index 0dc05d490..6f1186a9b 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/with_commandblock.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/with_commandblock.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua b/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua index 9e6defdad..5487d7bb3 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua @@ -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) @@ -30,7 +29,7 @@ local function hopper_take_item(self, dtime) if objs then mcl_log("there is an itemstring. Number of objs: ".. #objs) - for k, v in pairs(objs) do + for _, v in pairs(objs) do local ent = v:get_luaentity() if ent and not ent._removed and ent.itemstring and ent.itemstring ~= "" then @@ -88,7 +87,6 @@ local function hopper_take_item(self, dtime) mcl_log("We have more than enough space. Now holds: " .. new_stack_size) inv:set_stack("main", i, stack) - items_remaining = 0 ent.object:get_luaentity().itemstring = "" ent.object:remove() diff --git a/mods/ENTITIES/mcl_minecarts/carts/with_tnt.lua b/mods/ENTITIES/mcl_minecarts/carts/with_tnt.lua index 8b0c7d869..a902ae167 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/with_tnt.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/with_tnt.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 0b04824bc..234148b3d 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -212,8 +212,8 @@ local function get_rail_connections(pos, opt) -- Check for sloped rail one block down local below_neighbor = vector.offset(neighbor, 0, -1, 0) - local node = force_get_node(below_neighbor) - local nodedef = minetest.registered_nodes[node.name] + node = force_get_node(below_neighbor) + nodedef = minetest.registered_nodes[node.name] if mcl_minecarts.is_rail(below_neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then local rev_dir = vector.direction(dir, vector.zero()) if ignore_neighbor_connections or is_connection(below_neighbor, rev_dir) then @@ -229,7 +229,7 @@ local function apply_connection_rules(node, nodedef, pos, rules, connections) -- Select the best allowed connection local rule = nil local score = 0 - for k,r in pairs(rules) do + for _,r in pairs(rules) do if check_connection_rule(pos, connections, r) then if r.score > score then --print("Best rule so far is "..dump(r)) @@ -351,7 +351,6 @@ local function update_rail_connections(pos, opt) if opt and opt.convert_neighbors == false then return end -- Check if the open end of this rail runs into a corner or a tee and convert that node into a tee or a cross - local neighbors = {} for i=1,#CONNECTIONS do local dir = CONNECTIONS[i] if is_connection(pos, dir) then @@ -367,11 +366,6 @@ local function update_rail_connections(pos, opt) end mod.update_rail_connections = update_rail_connections -local north = vector.new(0,0,1) -local south = vector.new(0,0,-1) -local east = vector.new(1,0,0) -local west = vector.new(-1,0,0) - local function is_ahead_slope(pos, dir) local ahead = vector.add(pos,dir) if mcl_minecarts.is_rail(ahead) then return false end @@ -518,7 +512,5 @@ function mod.reverse_cart_direction(staticdata) staticdata.distance = 1 - (staticdata.distance or 0) -- recalculate direction - local next_dir,_ = mod:get_rail_direction(staticdata.connected_at, next_dir) - staticdata.dir = next_dir + staticdata.dir = mod:get_rail_direction(staticdata.connected_at, next_dir) end - diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index ce449a89b..92cc88c28 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -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 @@ -80,7 +74,7 @@ local function handle_cart_enter_exit(staticdata, pos, next_dir, event) if luaentity then local hook = luaentity["_mcl_minecarts_"..event] if hook then hook(luaentity, pos, staticdata) end - else + --else --minetest.log("warning", "TODO: change _mcl_minecarts_"..event.." calling so it is not dependent on the existence of a luaentity") end end @@ -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 = {} @@ -150,7 +145,7 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir) local carts = minetest.deserialize(meta:get_string("_mcl_minecarts_carts")) or {} local cart_uuid = nil local dirty = false - for uuid,v in pairs(carts) do + for uuid,_ in pairs(carts) do -- Clean up dead carts local data = get_cart_data(uuid) if not data or not data.connected_at then @@ -165,7 +160,6 @@ 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)) if not cart_uuid then return end -- Don't collide with the train car in front of you @@ -331,7 +325,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 +534,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 +614,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 diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index 2356c7b5f..c4b3c9a4c 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -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 diff --git a/mods/ENTITIES/mcl_minecarts/rails/activator.lua b/mods/ENTITIES/mcl_minecarts/rails/activator.lua index 605ba4a2f..6658c32e7 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/activator.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/activator.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/rails/detector.lua b/mods/ENTITIES/mcl_minecarts/rails/detector.lua index 443cecf07..6d4e9b3c5 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/detector.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/detector.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/rails/normal.lua b/mods/ENTITIES/mcl_minecarts/rails/normal.lua index 58ff60758..698e0898b 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/normal.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/normal.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/rails/powered.lua b/mods/ENTITIES/mcl_minecarts/rails/powered.lua index e76aff2c7..f249799bb 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/powered.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/powered.lua @@ -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) diff --git a/mods/ENTITIES/mcl_minecarts/train.lua b/mods/ENTITIES/mcl_minecarts/train.lua index c21cbb0eb..ebd81a0d2 100644 --- a/mods/ENTITIES/mcl_minecarts/train.lua +++ b/mods/ENTITIES/mcl_minecarts/train.lua @@ -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 -