From 2ec68d7855e56e13779c651cd7cb5f21fc826636 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Mon, 10 Dec 2018 22:41:02 +0100 Subject: Change get_inventory_formspec API - add invname parameter --- advtrains/api_doc.txt | 28 ++++++++++++++-------------- advtrains/wagons.lua | 19 +++++++++++++------ advtrains_train_industrial/init.lua | 8 ++++---- advtrains_train_steam/init.lua | 4 ++-- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt index e34b32a..60e4c79 100644 --- a/advtrains/api_doc.txt +++ b/advtrains/api_doc.txt @@ -98,11 +98,11 @@ advtrains.register_wagon(name, prototype, description, inventory_image) }, ^- List of assignments of type list_name=size. ^- For every entry, an inventory list is created with the specified size. - get_inventory_formspec = function(self, player_name) + get_inventory_formspec = function(self, player_name, inventory_name) return "" end, ^- Function that should return the formspec to be displayed when requests to open the wagon's inventory - ^- Use "list[detached:advtrains_wgn_"..self.unique_id..";;,;,;]" to display a wagon's inventory list. + ^- Use "list["..inventory_name..";;,;,;]" to display a wagon's inventory list. custom_on_step = function(self, dtime) end ^- optional: Execute custom code on every step @@ -151,27 +151,27 @@ minetest.register_node(nodename, { connect1 = 0, connect2 = 8, ^- These values tell the direction (horizontal) the rail ends are pointing to. 0 means +Z, then rotation values increase clockwise. For a translation of directions to positions see helpers.lua. - rely1=0, + rely1=0, rely2=0, - ^- the Y height of the rail end 1/2. A value of >=1 means that the rail end points to the next y layer at rely-1 + ^- the Y height of the rail end 1/2. A value of >=1 means that the rail end points to the next y layer at rely-1 railheight=0, ^- the height value of this rail that is saved in the path. usually the median of rely1 and rely2. - can_dig=function(pos) - return not advtrains.get_train_at_pos(pos) - end, - after_dig_node=function(pos) - advtrains.ndb.update(pos) - end, - after_place_node=function(pos) - advtrains.ndb.update(pos) + can_dig=function(pos) + return not advtrains.get_train_at_pos(pos) + end, + after_dig_node=function(pos) + advtrains.ndb.update(pos) + end, + after_place_node=function(pos) + advtrains.ndb.update(pos) end, ^- the code in these 3 default minetest API functions is required for advtrains to work, however you can add your own code - advtrains = { + advtrains = { on_train_enter=function(pos, train_id) end ^- called when a train enters the rail on_train_leave=function(pos, train_id) end - ^- called when a train leaves the rail + ^- called when a train leaves the rail } }) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 6baf811..ec8682d 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -1,5 +1,6 @@ --atan2 counts angles clockwise, minetest does counterclockwise + minetest.register_privilege("train_place", { description = "Player can place trains on tracks not owned by player", give_to_singleplayer= false, @@ -14,6 +15,11 @@ minetest.register_privilege("train_operator", { default= true, }); +local function make_inv_name(uid) + return "detached:advtrains_wgn_"..uid +end + + local wagon={ collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, --physical = true, @@ -632,8 +638,8 @@ function wagon:on_rightclick(clicker) if advtrains.player_to_train_mapping[pname] then return end if self.seat_groups then if #self.seats==0 then - if self.has_inventory and self.get_inventory_formspec then - minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname)) + if self.has_inventory and self.get_inventory_formspec and advtrains.check_driving_couple_protection(pname, data.owner, data.whitelist) then + minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname, make_inv_name(self.unique_id))) end return end @@ -757,8 +763,9 @@ end function wagon:show_get_on_form(pname) if not self.initialized then return end if #self.seats==0 then - if self.has_inventory and self.get_inventory_formspec then - minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname)) + + if self.has_inventory and self.get_inventory_formspec and advtrains.check_driving_couple_protection(pname, data.owner, data.whitelist) then + minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname, make_inv_name(self.unique_id))) end return end @@ -998,7 +1005,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if wagon.is_wagon and wagon.initialized and wagon.unique_id==uid then if fields.inv then if wagon.has_inventory and wagon.get_inventory_formspec then - minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..uid, wagon:get_inventory_formspec(player:get_player_name())) + minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..uid, wagon:get_inventory_formspec(player:get_player_name(), make_inv_name(uid))) end elseif fields.seat then local val=minetest.explode_textlist_event(fields.seat) @@ -1068,7 +1075,7 @@ function wagon:seating_from_key_helper(pname, fields, no) end end if fields.inv and self.has_inventory and self.get_inventory_formspec then - minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..self.unique_id, wagon:get_inventory_formspec(player:get_player_name())) + minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(player:get_player_name(), make_inv_name(self.unique_id))) end if fields.prop and self.owner==pname then self:show_wagon_properties(pname) diff --git a/advtrains_train_industrial/init.lua b/advtrains_train_industrial/init.lua index c654449..ed6c370 100644 --- a/advtrains_train_industrial/init.lua +++ b/advtrains_train_industrial/init.lua @@ -90,9 +90,9 @@ advtrains.register_wagon("wagon_tank", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, has_inventory = true, - get_inventory_formspec = function(self) + get_inventory_formspec = function(self, pname, invname) return "size[8,11]".. - "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,3;]".. + "list["..invname..";box;0,0;8,3;]".. "list[current_player;main;0,5;8,4;]".. "listring[]" end, @@ -111,9 +111,9 @@ advtrains.register_wagon("wagon_wood", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, has_inventory = true, - get_inventory_formspec = function(self) + get_inventory_formspec = function(self, pname, invname) return "size[8,11]".. - "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,3;]".. + "list["..invname..";box;0,0;8,3;]".. "list[current_player;main;0,5;8,4;]".. "listring[]" end, diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua index 2afbe16..4b60d53 100755 --- a/advtrains_train_steam/init.lua +++ b/advtrains_train_steam/init.lua @@ -208,9 +208,9 @@ advtrains.register_wagon("wagon_box", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, has_inventory = true, - get_inventory_formspec = function(self) + get_inventory_formspec = function(self, pname, invname) return "size[8,11]".. - "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,3;]".. + "list["..invname..";box;0,0;8,3;]".. "list[current_player;main;0,5;8,4;]".. "listring[]" end, -- cgit v1.2.3