aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author1F616EMO <root@1f616emo.xyz>2024-09-08 08:57:32 +0800
committerorwell <orwell@bleipb.de>2024-11-09 22:05:46 +0100
commit671cb16e9599f9989cf5b12f76f1eb0a21252172 (patch)
tree0e6802dfab5859cfe7a32ee5b8e55b2334496a91
parent63f81cb2043de58f0b1be9d0688368572807b742 (diff)
downloadadvtrains-671cb16e9599f9989cf5b12f76f1eb0a21252172.tar.gz
advtrains-671cb16e9599f9989cf5b12f76f1eb0a21252172.tar.bz2
advtrains-671cb16e9599f9989cf5b12f76f1eb0a21252172.zip
Allow operate on_rightclick nodes with track placers and wagon placers
Press sneak to force default behavior.
-rw-r--r--advtrains/trackplacer.lua21
-rw-r--r--advtrains/wagons.lua22
2 files changed, 33 insertions, 10 deletions
diff --git a/advtrains/trackplacer.lua b/advtrains/trackplacer.lua
index 9f97171..2588088 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 ddff2f5..50ce4ab 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -1393,13 +1393,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.")
@@ -1409,14 +1419,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
@@ -1424,7 +1434,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()