~gpcf/advtrains-devel

Allow operate on_rightclick nodes with track placers and wagon placers v1 PROPOSED

1F616EMO: 1
 Allow operate on_rightclick nodes with track placers and wagon placers

 2 files changed, 33 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~gpcf/advtrains-devel/patches/54932/mbox | git am -3
Learn more about email & git

[PATCH] Allow operate on_rightclick nodes with track placers and wagon placers Export this patch

From: 1F616EMO <root@1f616emo.xyz>

Press sneak to force default behavior.
---
 advtrains/trackplacer.lua | 21 +++++++++++++++++----
 advtrains/wagons.lua      | 22 ++++++++++++++++------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/advtrains/trackplacer.lua b/advtrains/trackplacer.lua
index fe76290..83a6305 100644
--- a/advtrains/trackplacer.lua
+++ b/advtrains/trackplacer.lua
@@ -275,11 +275,24 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname, def)
		groups={advtrains_trackplacer=1, digtron_on_place=1},
		liquids_pointable = def.liquids_pointable,
		on_place = function(itemstack, placer, pointed_thing)
				local name = placer:get_player_name()
				if not name then
				   return itemstack, false
				end
				if pointed_thing.type=="node" then
					do
						local pointed_pos = pointed_thing.under
						local pointed_node = minetest.get_node(pointed_pos)
						local pointed_def = minetest.registered_nodes[pointed_node.name]
						if pointed_def and pointed_def.on_rightclick then
							local controls = placer:get_player_control()
							if not controls.sneak then
								return pointed_def.on_rightclick(pointed_pos, pointed_node, placer, itemstack, pointed_thing)
							end
						end
					end

					local name = placer:get_player_name()
					if not name then
					return itemstack, false
					end

					local pos=pointed_thing.above
					local upos=vector.subtract(pointed_thing.above, {x=0, y=1, z=0})
					if not advtrains.check_track_protection(pos, name) then
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 536c8d4..f6a116c 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -1387,13 +1387,23 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
		groups = wagon_groups,

		on_place = function(itemstack, placer, pointed_thing)
				if not pointed_thing.type == "node" then
				if pointed_thing.type ~= "node" then
					return
				end

				local pos = pointed_thing.under
				local node = minetest.get_node(pos)
				local pointed_def = minetest.registered_nodes[node.name]
				if pointed_def and pointed_def.on_rightclick then
					local controls = placer:get_player_control()
					if not controls.sneak then
						return pointed_def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
					end
				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
				if node.name == "ignore" then atprint("[advtrains]Ignore at placer position") return itemstack end
				local nodename=node.name
				if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then
					atprint("no track here, not placing.")
@@ -1403,14 +1413,14 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
					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
				if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pos, 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, prototype.drives_on)
				local prevpos = advtrains.get_adjacent_rail(pos, tconns, plconnid, prototype.drives_on)
				if not prevpos then
					minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!")
					return
@@ -1418,7 +1428,7 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
				
				local wid = advtrains.create_wagon(sysname, pname)
				
				local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, {wid})
				local id=advtrains.create_new_train_at(pos, plconnid, 0, {wid})
				
				if not advtrains.is_creative(pname) then
					itemstack:take_item()
-- 
2.46.0