Straight ahead tubes can be placed my means of the "sneak" button

This commit is contained in:
Joachim Stolberg 2018-09-21 22:10:33 +02:00
parent 6aaf32e18a
commit 2437f3ae09
4 changed files with 28 additions and 10 deletions

@ -1,6 +1,18 @@
# Release Notes of the ModPack TechPack [techpack] # Release Notes of the ModPack TechPack [techpack]
## V1.16.1 (2018-09-21)
### Additions
- Straight ahead tubes can be placed my means of the "sneak" button
### Fixes
- Minor tube placing bug fixed
## V1.16 (2018-09-20) ## V1.16 (2018-09-20)
### Changes ### Changes

@ -217,7 +217,7 @@ end
function smartline.formspecNotes(meta) function smartline.formspecNotes(meta)
local running = meta:get_int("state") == tubelib.RUNNING local running = meta:get_int("state") == tubelib.RUNNING
local cmnd = running and "stop;Stop" or "start;Start" local cmnd = running and "stop;Stop" or "start;Start"
local notes = meta:get_string("notes") local notes = meta:get_string("notes") or ""
if notes == "" then notes = "<space for your notes>" end if notes == "" then notes = "<space for your notes>" end
notes = minetest.formspec_escape(notes) notes = minetest.formspec_escape(notes)
return SIZE.. return SIZE..

@ -58,6 +58,7 @@ end
-- Convertion of 'dir' (view from the outside to inside and vs) -- Convertion of 'dir' (view from the outside to inside and vs)
local Turn180Deg = {3,4,1,2,6,5} local Turn180Deg = {3,4,1,2,6,5}
local Turn90Deg = {2,3,4,5,6,1}
local Dir2Offset = { local Dir2Offset = {
{x=0, y=0, z=1}, {x=0, y=0, z=1},
@ -227,10 +228,12 @@ local function update_next_tube(dir, pos)
local conn1 = is_connected(pos, dir1) or is_known_node(pos, dir1) local conn1 = is_connected(pos, dir1) or is_known_node(pos, dir1)
local conn2 = is_connected(pos, dir2) or is_known_node(pos, dir2) local conn2 = is_connected(pos, dir2) or is_known_node(pos, dir2)
-- already connected or no tube arround? -- already connected or no tube arround?
if conn1 == conn2 then if (conn1 and conn2) or (not dir1 and not dir2) then
return return
end elseif not conn1 and not conn2 then
if conn1 then dir1 = Turn90Deg[dir1]
dir2 = Turn180Deg[dir1]
elseif conn1 then
dir2 = Turn180Deg[dir] dir2 = Turn180Deg[dir]
else else
dir1 = Turn180Deg[dir] dir1 = Turn180Deg[dir]
@ -267,7 +270,7 @@ local function update_tube(pos, dir)
swap_node(pos, node_num, param2) swap_node(pos, node_num, param2)
end end
function tubelib.update_tubes(pos, dir) function tubelib.update_tubes(pos, dir, straight_ahead)
-- Update all tubes arround the currently placed tube -- Update all tubes arround the currently placed tube
update_next_tube(1, {x=pos.x , y=pos.y , z=pos.z+1}) update_next_tube(1, {x=pos.x , y=pos.y , z=pos.z+1})
update_next_tube(2, {x=pos.x+1, y=pos.y , z=pos.z }) update_next_tube(2, {x=pos.x+1, y=pos.y , z=pos.z })
@ -275,8 +278,10 @@ function tubelib.update_tubes(pos, dir)
update_next_tube(4, {x=pos.x-1, y=pos.y , z=pos.z }) update_next_tube(4, {x=pos.x-1, y=pos.y , z=pos.z })
update_next_tube(5, {x=pos.x , y=pos.y-1, z=pos.z }) update_next_tube(5, {x=pos.x , y=pos.y-1, z=pos.z })
update_next_tube(6, {x=pos.x , y=pos.y+1, z=pos.z }) update_next_tube(6, {x=pos.x , y=pos.y+1, z=pos.z })
-- Update the placed tube if not straight_ahead then
update_tube(pos, dir) -- Update the placed tube
update_tube(pos, dir)
end
return tubelib.delete_meta_data(pos, minetest.get_node(pos)) < MAX_TUBE_LENGTH return tubelib.delete_meta_data(pos, minetest.get_node(pos)) < MAX_TUBE_LENGTH
end end

@ -174,14 +174,15 @@ for idx,pos in ipairs(DirCorrections) do
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local res local res
local pitch = placer:get_look_pitch() local pitch = placer:get_look_pitch()
local straight_ahead = placer:get_player_control().sneak
if pitch > 1 then if pitch > 1 then
res = tubelib.update_tubes(pos, 6) res = tubelib.update_tubes(pos, 6, straight_ahead)
elseif pitch < -1 then elseif pitch < -1 then
res = tubelib.update_tubes(pos, 5) res = tubelib.update_tubes(pos, 5, straight_ahead)
else else
local dir = placer:get_look_dir() local dir = placer:get_look_dir()
local facedir = minetest.dir_to_facedir(dir) local facedir = minetest.dir_to_facedir(dir)
res = tubelib.update_tubes(pos, facedir + 1) res = tubelib.update_tubes(pos, facedir + 1, straight_ahead)
end end
if res == false then if res == false then
tubelib.delete_meta_data(pos, minetest.get_node(pos)) tubelib.delete_meta_data(pos, minetest.get_node(pos))