Route storage and cart command bugfixes

master
Joachim Stolberg 2020-06-27 12:49:27 +02:00
parent 523cff05f8
commit 24061b0b74
5 changed files with 19 additions and 11 deletions

View File

@ -114,4 +114,5 @@ History
2020-03-28 v1.04 cart unloading bugfix
2020-05-14 v1.05 API changed to be able to register carts
2020-06-14 v1.06 API changed and chat command added
2020-06-27 v1.07 Route storage and cart command bugfixes

View File

@ -13,7 +13,7 @@
minecart = {}
-- Version for compatibility checks, see readme.md/history
minecart.version = 1.06
minecart.version = 1.07
minecart.hopper_enabled = minetest.settings:get_bool("minecart_hopper_enabled") ~= false

View File

@ -14,7 +14,7 @@
-- 1) Entity IDs are volatile. For each server restart all carts get new IDs.
-- 2) Monitoring is performed for entities only. Stopped carts in form of
-- real nodes need no monitoring.
-- 3) But nodes at startions have to call 'node_at_station' to be "visible"
-- 3) But nodes at stations have to call 'node_at_station' to be "visible"
-- for the chat commands
@ -95,6 +95,7 @@ function minecart.start_cart(pos, myID)
if item and item.stopped then
item.stopped = false
item.start_pos = pos
item.start_time = nil
-- cart started from a buffer?
local start_key = lib.get_route_key(pos)
if start_key then
@ -147,6 +148,8 @@ local function monitoring()
end
item.last_pos, item.last_vel = pos, vel
else
-- should never happen
minetest.log("error", "[minecart] Cart of owner "..(item.owner or "nil").." got lost")
CartsOnRail[key] = nil
end
end
@ -208,7 +211,7 @@ minetest.register_chatcommand("mycart", {
end
-- Check all running carts
local state, cart_pos = get_cart_state(name, userID)
if state then
if state and cart_pos then
local pos = get_cart_pos(query_pos, cart_pos)
if type(pos) == "string" then
return true, "Cart #"..userID.." stopped at "..pos.." "

View File

@ -51,7 +51,7 @@ end
function minecart.stop_recording(self, pos, vel, puncher)
local dest_pos = lib.get_route_key(pos, self.driver)
if dest_pos then
if self.start_key ~= dest_pos then
if self.start_key and self.start_key ~= dest_pos then
local route = {
waypoints = self.waypoints,
dest_pos = dest_pos,

View File

@ -16,7 +16,7 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos
local S = minecart.S
local DAYS_VALID = (30 * 72) -- 30 real days
local DAYS_VALID = (180 * 72) -- 180 real days
local storage = minetest.get_mod_storage()
@ -45,7 +45,6 @@ for key,val in pairs(minetest.deserialize(storage:get_string("CartsOnRail")) or
end
minetest.register_on_shutdown(function()
data_maintenance()
storage:set_string("CartsOnRail", minetest.serialize(minecart.CartsOnRail))
end)
@ -66,14 +65,19 @@ local Routes = {}
local NEW_ROUTE = {waypoints = {}, junctions = {}}
function minecart.store_route(key, route)
Routes[key] = table.copy(route)
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
storage:set_string(key, minetest.serialize(Routes[key]))
if key and route then
Routes[key] = table.copy(route)
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
storage:set_string(key, minetest.serialize(Routes[key]))
end
end
function minecart.get_route(key)
Routes[key] = Routes[key] or minetest.deserialize(storage:get_string(key)) or NEW_ROUTE
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
if not Routes[key] then
Routes[key] = minetest.deserialize(storage:get_string(key)) or NEW_ROUTE
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
storage:set_string(key, minetest.serialize(Routes[key]))
end
return Routes[key]
end