Remove pcall wrappers completely, add command to disable advtrains mainloop

master
orwell96 2020-04-27 16:02:28 +02:00
parent b59b0d587d
commit 5c2534cc35
8 changed files with 145 additions and 178 deletions

View File

@ -108,53 +108,49 @@ advtrains.atc_function = function(def, preset, suffix, rotation)
return { return {
after_place_node=apn_func, after_place_node=apn_func,
after_dig_node=function(pos) after_dig_node=function(pos)
return advtrains.pcall(function() advtrains.invalidate_all_paths(pos)
advtrains.invalidate_all_paths(pos) advtrains.ndb.clear(pos)
advtrains.ndb.clear(pos) local pts=minetest.pos_to_string(pos)
local pts=minetest.pos_to_string(pos) atc.controllers[pts]=nil
atc.controllers[pts]=nil
end)
end, end,
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, player)
return advtrains.pcall(function() if advtrains.is_protected(pos, player:get_player_name()) then
if advtrains.is_protected(pos, player:get_player_name()) then minetest.record_protection_violation(pos, player:get_player_name())
minetest.record_protection_violation(pos, player:get_player_name()) return
end
local meta=minetest.get_meta(pos)
if meta then
if not fields.save then
--[[--maybe only the dropdown changed
if fields.mode then
meta:set_string("mode", idxtrans[fields.mode])
if fields.mode=="digiline" then
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) )
else
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", fields.mode, meta:get_string("command")) )
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
end]]--
return return
end end
local meta=minetest.get_meta(pos) --meta:set_string("mode", idxtrans[fields.mode])
if meta then meta:set_string("command", fields.command)
if not fields.save then --meta:set_string("command_on", fields.command_on)
--maybe only the dropdown changed meta:set_string("channel", fields.channel)
if fields.mode then --if fields.mode=="digiline" then
meta:set_string("mode", idxtrans[fields.mode]) -- meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) )
if fields.mode=="digiline" then --else
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) ) meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", "-", meta:get_string("command")) )
else --end
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) ) meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) local pts=minetest.pos_to_string(pos)
end local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
return atc.controllers[pts]={command=fields.command}
end if #advtrains.occ.get_trains_at(pos) > 0 then
meta:set_string("mode", idxtrans[fields.mode]) atc.send_command(pos)
meta:set_string("command", fields.command)
meta:set_string("command_on", fields.command_on)
meta:set_string("channel", fields.channel)
if fields.mode=="digiline" then
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) )
else
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) )
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
local pts=minetest.pos_to_string(pos)
local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
atc.controllers[pts]={command=fields.command}
if #advtrains.occ.get_trains_at(pos) > 0 then
atc.send_command(pos)
end
end end
end) end
end, end,
advtrains = { advtrains = {
on_train_enter = function(pos, train_id) on_train_enter = function(pos, train_id)

View File

@ -13,76 +13,74 @@ minetest.register_tool("advtrains:copytool", {
-- The front of the train is used as the start of the new train and it proceeds backwards from -- The front of the train is used as the start of the new train and it proceeds backwards from
-- the direction of travel. -- the direction of travel.
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function() if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
return
end
local pname = placer:get_player_name()
local node=minetest.get_node_or_nil(pointed_thing.under)
if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, {default=true})) then
atprint("no track here, not placing.")
return itemstack
end
if not minetest.check_player_privs(placer, {train_operator = true }) then
minetest.chat_send_player(pname, "You don't have the train_operator privilege.")
return itemstack
end
if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
return itemstack
end
local tconns=advtrains.get_track_connections(node.name, node.param2)
local yaw = placer:get_look_horizontal()
local plconnid = advtrains.yawToClosestConn(yaw, tconns)
local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true})
if not prevpos then
minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!")
return
end
local meta = itemstack:get_meta()
if not meta then
minetest.chat_send_player(pname, attrans("The clipboard couldn't access the metadata. Paste failed."))
return return
end end
local clipboard = meta:get_string("clipboard") local pname = placer:get_player_name()
if (clipboard == "") then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
clipboard = minetest.deserialize(clipboard)
if (clipboard.wagons == nil) then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
local wagons = {} local node=minetest.get_node_or_nil(pointed_thing.under)
local n = 1 if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
for _, wagonProto in pairs(clipboard.wagons) do local nodename=node.name
local wagon = advtrains.create_wagon(wagonProto.type, pname) if(not advtrains.is_track_and_drives_on(nodename, {default=true})) then
advtrains.wagons[wagon].wagon_flipped = wagonProto.wagon_flipped atprint("no track here, not placing.")
wagons[n] = wagon return itemstack
n = n + 1 end
end if not minetest.check_player_privs(placer, {train_operator = true }) then
minetest.chat_send_player(pname, "You don't have the train_operator privilege.")
local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, wagons) return itemstack
local train = advtrains.trains[id] end
train.off_track = train.end_index<train.path_trk_b if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
if (train.off_track) then return itemstack
minetest.chat_send_player(pname, "Back of train would end up off track, cancelling.") end
advtrains.remove_train(id) local tconns=advtrains.get_track_connections(node.name, node.param2)
return local yaw = placer:get_look_horizontal()
end local plconnid = advtrains.yawToClosestConn(yaw, tconns)
train.text_outside = clipboard.text_outside
train.text_inside = clipboard.text_inside
train.routingcode = clipboard.routingcode
train.line = clipboard.line
local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true})
if not prevpos then
minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!")
return return
end) end
local meta = itemstack:get_meta()
if not meta then
minetest.chat_send_player(pname, attrans("The clipboard couldn't access the metadata. Paste failed."))
return
end
local clipboard = meta:get_string("clipboard")
if (clipboard == "") then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
clipboard = minetest.deserialize(clipboard)
if (clipboard.wagons == nil) then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
local wagons = {}
local n = 1
for _, wagonProto in pairs(clipboard.wagons) do
local wagon = advtrains.create_wagon(wagonProto.type, pname)
advtrains.wagons[wagon].wagon_flipped = wagonProto.wagon_flipped
wagons[n] = wagon
n = n + 1
end
local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, wagons)
local train = advtrains.trains[id]
train.off_track = train.end_index<train.path_trk_b
if (train.off_track) then
minetest.chat_send_player(pname, "Back of train would end up off track, cancelling.")
advtrains.remove_train(id)
return
end
train.text_outside = clipboard.text_outside
train.text_inside = clipboard.text_inside
train.routingcode = clipboard.routingcode
train.line = clipboard.line
return
end, end,
-- Copy: Take the pointed-at train and put it on the clipboard -- Copy: Take the pointed-at train and put it on the clipboard
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
@ -182,4 +180,4 @@ minetest.register_tool("advtrains:copytool", {
minetest.chat_send_player(user:get_player_name(), attrans("Train copied!")) minetest.chat_send_player(user:get_player_name(), attrans("Train copied!"))
return itemstack return itemstack
end end
}) })

View File

@ -32,7 +32,6 @@ minetest.register_entity("advtrains:discouple", {
end, end,
get_staticdata=function() return "DISCOUPLE" end, get_staticdata=function() return "DISCOUPLE" end,
on_punch=function(self, player) on_punch=function(self, player)
return advtrains.pcall(function()
local pname = player:get_player_name() local pname = player:get_player_name()
if pname and pname~="" and self.wagon then if pname and pname~="" and self.wagon then
if advtrains.safe_decouple_wagon(self.wagon.id, pname) then if advtrains.safe_decouple_wagon(self.wagon.id, pname) then
@ -41,10 +40,8 @@ minetest.register_entity("advtrains:discouple", {
minetest.add_entity(self.object:getpos(), "advtrains:lockmarker") minetest.add_entity(self.object:getpos(), "advtrains:lockmarker")
end end
end end
end)
end, end,
on_step=function(self, dtime) on_step=function(self, dtime)
return advtrains.pcall(function()
if not self.wagon then if not self.wagon then
self.object:remove() self.object:remove()
return return
@ -58,7 +55,6 @@ minetest.register_entity("advtrains:discouple", {
self.object:remove() self.object:remove()
return return
end end
end)
end, end,
}) })
@ -79,7 +75,6 @@ minetest.register_entity("advtrains:couple", {
is_couple=true, is_couple=true,
static_save = false, static_save = false,
on_activate=function(self, staticdata) on_activate=function(self, staticdata)
return advtrains.pcall(function()
if staticdata=="COUPLE" then if staticdata=="COUPLE" then
--couple entities have no right to exist further... --couple entities have no right to exist further...
atprint("Couple loaded from staticdata, destroying") atprint("Couple loaded from staticdata, destroying")
@ -87,11 +82,9 @@ minetest.register_entity("advtrains:couple", {
return return
end end
self.object:set_armor_groups({immmortal=1}) self.object:set_armor_groups({immmortal=1})
end)
end, end,
get_staticdata=function(self) return "COUPLE" end, get_staticdata=function(self) return "COUPLE" end,
on_rightclick=function(self, clicker) on_rightclick=function(self, clicker)
return advtrains.pcall(function()
if not self.train_id_1 or not self.train_id_2 then return end if not self.train_id_1 or not self.train_id_2 then return end
local pname=clicker local pname=clicker
@ -102,15 +95,12 @@ minetest.register_entity("advtrains:couple", {
else else
lockmarker(self.object) lockmarker(self.object)
end end
end)
end, end,
on_step=function(self, dtime) on_step=function(self, dtime)
return advtrains.pcall(function()
if advtrains.wagon_outside_range(self.object:getpos()) then if advtrains.wagon_outside_range(self.object:getpos()) then
self.object:remove() self.object:remove()
return return
end end
advtrains.atprint_context_tid=self.train_id_1
if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end
local train1=advtrains.trains[self.train_id_1] local train1=advtrains.trains[self.train_id_1]
@ -161,8 +151,6 @@ minetest.register_entity("advtrains:couple", {
end end
atprintbm("couple step", t) atprintbm("couple step", t)
advtrains.atprint_context_tid=nil advtrains.atprint_context_tid=nil
end)
end, end,
}) })
minetest.register_entity("advtrains:lockmarker", { minetest.register_entity("advtrains:lockmarker", {
@ -175,7 +163,6 @@ minetest.register_entity("advtrains:lockmarker", {
is_lockmarker=true, is_lockmarker=true,
static_save = false, static_save = false,
on_activate=function(self, staticdata) on_activate=function(self, staticdata)
return advtrains.pcall(function()
if staticdata=="COUPLE" then if staticdata=="COUPLE" then
--couple entities have no right to exist further... --couple entities have no right to exist further...
atprint("Couple loaded from staticdata, destroying") atprint("Couple loaded from staticdata, destroying")
@ -184,7 +171,6 @@ minetest.register_entity("advtrains:lockmarker", {
end end
self.object:set_armor_groups({immmortal=1}) self.object:set_armor_groups({immmortal=1})
self.life=5 self.life=5
end)
end, end,
get_staticdata=function(self) return "COUPLE" end, get_staticdata=function(self) return "COUPLE" end,
on_step=function(self, dtime) on_step=function(self, dtime)

View File

@ -61,26 +61,6 @@ local function reload_saves()
end) end)
end end
function advtrains.pcall(fun)
if no_action then return end
local succ, return1, return2, return3, return4=xpcall(fun, function(err)
atwarn("Lua Error occured: ", err)
atwarn(debug.traceback())
if advtrains.atprint_context_tid then
advtrains.path_print(advtrains.trains[advtrains.atprint_context_tid], atdebug)
atwarn(advtrains.trains[advtrains.atprint_context_tid].debug)
end
end)
if not succ then
error("pcall")
reload_saves()
else
return return1, return2, return3, return4
end
end
advtrains.modpath = minetest.get_modpath("advtrains") advtrains.modpath = minetest.get_modpath("advtrains")
--Advtrains dump (special treatment of pos and sigd) --Advtrains dump (special treatment of pos and sigd)
@ -569,7 +549,11 @@ advtrains.mainloop_runcnt=0
local t = 0 local t = 0
minetest.register_globalstep(function(dtime_mt) minetest.register_globalstep(function(dtime_mt)
return advtrains.pcall(function() if no_action then
-- the advtrains globalstep is skipped by command. Return immediately
return
end
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1 advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
--atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt) --atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
--call load once. see advtrains.load() comment --call load once. see advtrains.load() comment
@ -615,7 +599,6 @@ minetest.register_globalstep(function(dtime_mt)
save_timer=save_interval save_timer=save_interval
atprintbm("saving", t) atprintbm("saving", t)
end end
end)
end) end)
--if something goes wrong in these functions, there is no help. no pcall here. --if something goes wrong in these functions, there is no help. no pcall here.
@ -644,6 +627,11 @@ function advtrains.save(remove_players_from_wagons)
atwarn("Instructed to save() but load() was never called!") atwarn("Instructed to save() but load() was never called!")
return return
end end
if no_action then
atlog("[save] Saving requested externally, but Advtrains step is disabled. Not saving any data as state may be inconsistent.")
return
end
advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data() advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data()
if atlatc then if atlatc then
atlatc.save() atlatc.save()
@ -664,11 +652,9 @@ minetest.register_chatcommand("at_empty_seats",
description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description
privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run
func = function(name, param) func = function(name, param)
return advtrains.pcall(function()
atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!") atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!")
advtrains.save(true) advtrains.save(true)
reload_saves() reload_saves()
end)
end, end,
}) })
-- This chat command solves another problem: Trains getting randomly stuck. -- This chat command solves another problem: Trains getting randomly stuck.
@ -678,13 +664,36 @@ minetest.register_chatcommand("at_reroute",
description = "Delete all train routes, force them to recalculate", description = "Delete all train routes, force them to recalculate",
privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe. privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe.
func = function(name, param) func = function(name, param)
return advtrains.pcall(function()
advtrains.invalidate_all_paths() advtrains.invalidate_all_paths()
return true, "Successfully invalidated train routes" return true, "Successfully invalidated train routes"
end)
end, end,
}) })
minetest.register_chatcommand("at_disable_step",
{
params = "<yes/no>",
description = "Disable the advtrains globalstep temporarily",
privs = {server=true},
func = function(name, param)
if minetest.is_yes(param) then
-- disable everything, and turn off saving
no_action = true;
atwarn("The advtrains globalstep has been disabled. Trains are not moving, and no data is saved! Run '/at_disable_step no' to enable again!")
return true, "Disabled advtrains successfully"
elseif no_action then
atwarn("Re-enabling advtrains globalstep...")
reload_saves()
return true
else
return false, "Advtrains is already running normally!"
end
end,
})
advtrains.is_no_action = function()
return no_action
end
local tot=(os.clock()-lot)*1000 local tot=(os.clock()-lot)*1000
minetest.log("action", "[advtrains] Loaded in "..tot.."ms") minetest.log("action", "[advtrains] Loaded in "..tot.."ms")

View File

@ -282,7 +282,6 @@ function advtrains.get_rail_info_at(pos, drives_on)
end end
ndb.run_lbm = function(pos, node) ndb.run_lbm = function(pos, node)
return advtrains.pcall(function()
local cid=ndbget(pos.x, pos.y, pos.z) local cid=ndbget(pos.x, pos.y, pos.z)
if cid then if cid then
--if in database, detect changes and apply. --if in database, detect changes and apply.
@ -310,7 +309,6 @@ ndb.run_lbm = function(pos, node)
ndb.update(pos, node) ndb.update(pos, node)
end end
return false return false
end)
end end
@ -358,9 +356,7 @@ ndb.restore_all = function()
end end
minetest.register_on_dignode(function(pos, oldnode, digger) minetest.register_on_dignode(function(pos, oldnode, digger)
return advtrains.pcall(function()
ndb.clear(pos) ndb.clear(pos)
end)
end) end)
function ndb.get_nodes() function ndb.get_nodes()
@ -381,14 +377,12 @@ minetest.register_chatcommand("at_sync_ndb",
description = "Write node db back to map and find ghost nodes", -- Full description description = "Write node db back to map and find ghost nodes", -- Full description
privs = {train_operator=true}, privs = {train_operator=true},
func = function(name, param) func = function(name, param)
return advtrains.pcall(function()
if os.time() < ptime+30 then if os.time() < ptime+30 then
return false, "Please wait at least 30s from the previous execution of /at_restore_ndb!" return false, "Please wait at least 30s from the previous execution of /at_restore_ndb!"
end end
local text = ndb.restore_all() local text = ndb.restore_all()
ptime=os.time() ptime=os.time()
return true, text return true, text
end)
end, end,
}) })

View File

@ -275,8 +275,7 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname, def)
groups={advtrains_trackplacer=1, digtron_on_place=1}, groups={advtrains_trackplacer=1, digtron_on_place=1},
liquids_pointable = def.liquids_pointable, liquids_pointable = def.liquids_pointable,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function() local name = placer:get_player_name()
local name = placer:get_player_name()
if not name then if not name then
return itemstack, false return itemstack, false
end end
@ -303,7 +302,6 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname, def)
end end
end end
return itemstack, true return itemstack, true
end)
end, end,
}) })
end end
@ -317,7 +315,6 @@ minetest.register_craftitem("advtrains:trackworker",{
wield_image = "advtrains_trackworker.png", wield_image = "advtrains_trackworker.png",
stack_max = 1, stack_max = 1,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function()
local name = placer:get_player_name() local name = placer:get_player_name()
if not name then if not name then
return return
@ -382,10 +379,8 @@ minetest.register_craftitem("advtrains:trackworker",{
advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2})
end end
end end
end)
end, end,
on_use=function(itemstack, user, pointed_thing) on_use=function(itemstack, user, pointed_thing)
return advtrains.pcall(function()
local name = user:get_player_name() local name = user:get_player_name()
if not name then if not name then
return return
@ -430,7 +425,6 @@ minetest.register_craftitem("advtrains:trackworker",{
else else
atprint(name, dump(tp.tracks)) atprint(name, dump(tp.tracks))
end end
end)
end, end,
}) })

View File

@ -127,7 +127,6 @@ function advtrains.tp_player_to_train(player)
end end
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
return advtrains.pcall(function()
advtrains.hud[player:get_player_name()] = nil advtrains.hud[player:get_player_name()] = nil
advtrains.hhud[player:get_player_name()] = nil advtrains.hhud[player:get_player_name()] = nil
--independent of this, cause all wagons of the train which are loaded to reattach their players --independent of this, cause all wagons of the train which are loaded to reattach their players
@ -137,12 +136,10 @@ minetest.register_on_joinplayer(function(player)
wagon:reattach_all() wagon:reattach_all()
end end
end end
end)
end) end)
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
return advtrains.pcall(function()
local pname=player:get_player_name() local pname=player:get_player_name()
local id=advtrains.player_to_train_mapping[pname] local id=advtrains.player_to_train_mapping[pname]
if id then if id then
@ -156,7 +153,6 @@ minetest.register_on_dieplayer(function(player)
end end
end end
end end
end)
end) end)
--[[ --[[
@ -421,7 +417,7 @@ function advtrains.train_step_b(id, train, dtime)
v_target_apply(v_targets, VLEVER_EMERG, braketar) v_target_apply(v_targets, VLEVER_EMERG, braketar)
end end
else else
v_target_apply(v_targets, VLEVER_BRAKE, braketar) v_target_apply(v_targets, VLEVER_ROLL, braketar)
end end
end end
end end

View File

@ -166,7 +166,6 @@ end
-- Remove the wagon -- Remove the wagon
function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
@ -223,7 +222,6 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
for _,item in ipairs(self.drops or {self.name}) do for _,item in ipairs(self.drops or {self.name}) do
inv:add_item("main", item) inv:add_item("main", item)
end end
end)
end end
function wagon:destroy() function wagon:destroy()
--some rules: --some rules:
@ -268,9 +266,13 @@ function wagon:is_driver_stand(seat)
end end
function wagon:on_step(dtime) function wagon:on_step(dtime)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
if advtrains.is_no_action() then
self.object:remove()
return
end
local t=os.clock() local t=os.clock()
local pos = self.object:getpos() local pos = self.object:getpos()
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
@ -595,11 +597,9 @@ function wagon:on_step(dtime)
self.old_acceleration_vector=accelerationvec self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw self.old_yaw=yaw
atprintbm("wagon step", t) atprintbm("wagon step", t)
end)
end end
function wagon:on_rightclick(clicker) function wagon:on_rightclick(clicker)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
if not clicker or not clicker:is_player() then if not clicker or not clicker:is_player() then
return return
@ -687,7 +687,6 @@ function wagon:on_rightclick(clicker)
self:show_get_on_form(pname) self:show_get_on_form(pname)
end end
end end
end)
end end
function wagon:get_on(clicker, seatno) function wagon:get_on(clicker, seatno)
@ -1101,7 +1100,6 @@ function wagon:handle_bordcom_fields(pname, formname, fields)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
return advtrains.pcall(function()
local uid=string.match(formname, "^advtrains_geton_(.+)$") local uid=string.match(formname, "^advtrains_geton_(.+)$")
if uid then if uid then
for _,wagon in pairs(minetest.luaentities) do for _,wagon in pairs(minetest.luaentities) do
@ -1185,7 +1183,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end end
end end
end)
end) end)
function wagon:seating_from_key_helper(pname, fields, no) function wagon:seating_from_key_helper(pname, fields, no)
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
@ -1389,7 +1386,6 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
groups = { not_in_creative_inventory = nincreative and 1 or 0}, groups = { not_in_creative_inventory = nincreative and 1 or 0},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function()
if not pointed_thing.type == "node" then if not pointed_thing.type == "node" then
return return
end end
@ -1427,8 +1423,6 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
end)
end, end,
}) })
end end