aboutsummaryrefslogtreecommitdiff
path: root/advtrains/copytool.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-04-27 16:02:28 +0200
committerorwell96 <orwell@bleipb.de>2021-02-10 16:36:24 +0100
commit5c2534cc35bc0fc47b53c8a992e3e71b15a60ec4 (patch)
tree5c72e9e541401126d5416b6d122893c300b88bea /advtrains/copytool.lua
parentb59b0d587d72f78c5923aa501038b93269bba271 (diff)
downloadadvtrains-5c2534cc35bc0fc47b53c8a992e3e71b15a60ec4.tar.gz
advtrains-5c2534cc35bc0fc47b53c8a992e3e71b15a60ec4.tar.bz2
advtrains-5c2534cc35bc0fc47b53c8a992e3e71b15a60ec4.zip
Remove pcall wrappers completely, add command to disable advtrains mainloop
Diffstat (limited to 'advtrains/copytool.lua')
-rw-r--r--advtrains/copytool.lua134
1 files changed, 66 insertions, 68 deletions
diff --git a/advtrains/copytool.lua b/advtrains/copytool.lua
index dc18081..0c1cdfe 100644
--- a/advtrains/copytool.lua
+++ b/advtrains/copytool.lua
@@ -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 direction of travel.
on_place = function(itemstack, placer, pointed_thing)
- return advtrains.pcall(function()
- 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."))
+ if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
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
+ 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
+ end
+ local clipboard = meta:get_string("clipboard")
+ if (clipboard == "") then
+ minetest.chat_send_player(pname, "The clipboard is empty.");
return
- end)
+ 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,
-- Copy: Take the pointed-at train and put it on the clipboard
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!"))
return itemstack
end
-}) \ No newline at end of file
+})