From 9d7cec6151c0a9eca2454e9d6c85bc5596c5e946 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Fri, 9 Aug 2024 19:47:27 +0800 Subject: Add Wagon Properties Tool Also added the Wagon ID to the Wagon Properties formspec --- advtrains/init.lua | 1 + advtrains/textures/advtrains_wagon_prop_tool.png | Bin 0 -> 779 bytes advtrains/wagonprop_tool.lua | 43 +++++++++++++++++++++++ advtrains/wagons.lua | 1 + 4 files changed, 45 insertions(+) create mode 100644 advtrains/textures/advtrains_wagon_prop_tool.png create mode 100644 advtrains/wagonprop_tool.lua (limited to 'advtrains') diff --git a/advtrains/init.lua b/advtrains/init.lua index f7d3b13..06e456f 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -209,6 +209,7 @@ dofile(advtrains.modpath.."/trainlogic.lua") dofile(advtrains.modpath.."/trainhud.lua") dofile(advtrains.modpath.."/trackplacer.lua") dofile(advtrains.modpath.."/copytool.lua") +dofile(advtrains.modpath.."/wagonprop_tool.lua") dofile(advtrains.modpath.."/tracks.lua") dofile(advtrains.modpath.."/occupation.lua") dofile(advtrains.modpath.."/atc.lua") diff --git a/advtrains/textures/advtrains_wagon_prop_tool.png b/advtrains/textures/advtrains_wagon_prop_tool.png new file mode 100644 index 0000000..6352c55 Binary files /dev/null and b/advtrains/textures/advtrains_wagon_prop_tool.png differ diff --git a/advtrains/wagonprop_tool.lua b/advtrains/wagonprop_tool.lua new file mode 100644 index 0000000..2a4a9e2 --- /dev/null +++ b/advtrains/wagonprop_tool.lua @@ -0,0 +1,43 @@ +minetest.register_craftitem("advtrains:wagon_prop_tool",{ --craftitem because it does nothing on its own + description = attrans("Wagon Properties Tool\nPunch a wagon to view and edit the Wagon Properties"), + short_description = attrans("Wagon Properties Tool"), + groups = {}, + inventory_image = "advtrains_wagon_prop_tool.png", + wield_image = "advtrains_wagon_prop_tool.png", + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) + local pname = user:get_player_name() + if not pname or pname == "" then + return + end + + --sanity checks in case of clicking the wrong entity/node/nothing + if pointed_thing.type ~= "object" then return end --not an entity + local object = pointed_thing.ref:get_luaentity() + if not object.id then return end --entity doesn't have an id field + + local wagon = advtrains.wagons[object.id] --check if wagon exists in advtrains + if not wagon then --not a wagon + return + end --end sanity checks + + --whitelist protection check + if not advtrains.check_driving_couple_protection(pname,wagon.owner,wagon.whitelist) then + minetest.chat_send_player(pname, attrans("Insufficient privileges to use this!")) + return + end + object:show_wagon_properties(pname) + return itemstack + end, +}) + +if minetest.get_modpath("default") then --register recipe + minetest.register_craft({ + output = "advtrains:wagon_prop_tool", + recipe = { + {"advtrains:dtrack_placer","dye:black","default:paper"}, + {"screwdriver:screwdriver","default:paper","default:paper"}, + {"","","group:wood"}, + } + }) +end \ No newline at end of file diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 677014a..73200a3 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -868,6 +868,7 @@ function wagon:show_wagon_properties(pname) ]] local data = advtrains.wagons[self.id] local form="size[5,5]" + form=form.."label[0.2,0;"..attrans("This Wagon ID")..": "..self.id.."]" form = form .. "field[0.5,1;4.5,1;whitelist;Allow these players to access your wagon:;"..minetest.formspec_escape(data.whitelist or "").."]" form = form .. "field[0.5,2;4.5,1;roadnumber;Wagon road number:;"..minetest.formspec_escape(data.roadnumber or "").."]" local fc = "" -- cgit v1.2.3