Skip to content

Commit

Permalink
Bypass diagonal vectors and avoid determinating face by fine_pointed
Browse files Browse the repository at this point in the history
  • Loading branch information
Athozus committed Apr 7, 2024
1 parent 90a207d commit ecf55a6
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions technic/machines/register/cables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,20 @@ function technic.register_cable_plate(nodename, data)
def.node_box["connect_"..notconnects[i]] = nil
if i == 1 then
def.on_place = function(itemstack, placer, pointed_thing)
local pointed_thing_diff = vector.direction(pointed_thing.under, pointed_thing.above)
local index = pointed_thing_diff.x + (pointed_thing_diff.y*2) + (pointed_thing_diff.z*3)
local num = index < 0 and -index + 3 or index
local crtl = placer:get_player_control()
if (crtl.aux1 or crtl.sneak) and not (crtl.aux1 and crtl.sneak) and index ~= 0 then
local fine_pointed = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
fine_pointed = vector.direction(pointed_thing.above,fine_pointed)
fine_pointed[xyz[index < 0 and -index or index]] = nil
local key_a, a = next(fine_pointed)
local key_b, b = next(fine_pointed, key_a)
local far_key = math.abs(a) > math.abs(b) and key_a or key_b
local far = fine_pointed[far_key]
-- Plate facing
-- X pair floor +X 4 -X 1 -> Z pair, Y pair
-- Y pair floor +Y 5 -Y 2 -> X pair, Z pair
-- Z pair floor +Z 6 -Z 3 -> X pair, Y pair
if math.abs(far) < 0.3 then
num = num < 4 and num + 3 or num - 3
elseif far_key == "x" then
num = far < 0 and 1 or 4
elseif far_key == "y" then
num = far < 0 and 2 or 5
else
num = far < 0 and 3 or 6
-- temporary bypass for "diagonal" above/under vectors (caused by oversized nodes)
-- see github.com/mt-mods/technic/pull/358
local axis_count = 0
for axis in pairs(xyz) do
axis_count = axis_count + (pointed_thing.under[axis] == pointed_thing.above[axis] and 0 or 1)
if axis_count > 1 then
return itemstack
end
end

local pointed_thing_diff = vector.direction(pointed_thing.above, pointed_thing.under)
local dir = math.abs(pointed_thing_diff.x + 2*pointed_thing_diff.y + 3*pointed_thing_diff.z) -- 1, 2 or 3
local num = dir + 3/2*(1+pointed_thing_diff[dir]) -- dir + additional offset

local node = {name = nodename.."_"..(num ~= 0 and num or 1)}
return item_place_override_node(itemstack, placer, pointed_thing, node)
end
Expand Down

0 comments on commit ecf55a6

Please sign in to comment.