Compare commits

..

2 Commits

Author SHA1 Message Date
3ea8517ff9
Added the resizer 2024-05-18 20:43:35 +02:00
6e4c9f1b02
Fixed the linker 2024-05-18 20:35:10 +02:00
3 changed files with 37 additions and 7 deletions

View File

@ -367,7 +367,8 @@ function logikraft.connFromDir(name,dir)
for i,c in ipairs(conns)
do
if (math.fmod(c,2*dir8) - dir8 >= 0)
then return i
then
return i
end
end
return nil
@ -390,10 +391,12 @@ function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
local connsa = table.copy(logikraft.cablesconn[namea])
local connsb = table.copy(logikraft.cablesconn[nameb])
print(dump(connsa))
print(dump(connsb))
local cia = logikraft.cablesnbconn[namea][a]
local cib = logikraft.cablesnbconn[nameb][b]
local cia2 = logikraft.connFromDir(namea,dira)
local cib2 = logikraft.connFromDir(nameb,3 - dira)
local cib2 = logikraft.connFromDir(nameb,math.fmod(dira+2,4))
print(dira)
print(cia)
print(cia2)
@ -407,7 +410,7 @@ function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
if (cia2 == nil)
then
connsa[cia] = connsa[cia] + math.pow(2,dira)
elseif (a ~= cia2)
elseif (cia ~= cia2)
then
-- We take the v size of selected cable
local v = math.fmod(math.floor(connsa[cia]/16),2)
@ -417,8 +420,8 @@ function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
if (cib2 == nil)
then
connsb[cib] = connsb[cib] + math.pow(2,3-dira)
elseif (b ~= cib2)
connsb[cib] = connsb[cib] + math.pow(2,math.fmod(dira+2,4))
elseif (cib ~= cib2)
then
-- We take the v size of selected cable
local v = math.fmod(math.floor(connsb[cib]/16),2)
@ -455,3 +458,13 @@ function logikraft.disconnectInCable(name,a)
table.sort(conns)
return table.getkey1(logikraft.cablesconn,conns)
end
function logikraft.resizeInCable(name,a)
local conns = table.copy(logikraft.cablesconn[name])
local cindex = logikraft.cablesnbconn[name][a]
conns[cindex] = (conns[cindex] >= 16) and (conns[cindex] - 16) or (conns[cindex] + 16)
table.sort(conns)
return table.getkey1(logikraft.cablesconn,conns)
end

View File

@ -40,8 +40,8 @@ minetest.register_craftitem("logikraft:linker", {
else
local thisnb = logikraft.lookingAtNbIndex(user,pointed_thing.under)
local new = logikraft.connectContiguousCable(
string.without(node.name,"logikraft:cable_"),selectedpos,selectednb,
string.without(minetest.get_node(pointed_thing.under).name,"logikraft:cable_"),pointed_thing.under,thisnb)
string.without(minetest.get_node(selectedpos).name,"logikraft:cable_"),selectedpos,selectednb,
string.without(node.name,"logikraft:cable_"),pointed_thing.under,thisnb)
if new
then
minetest.swap_node(selectedpos, {name = "logikraft:cable_" .. new[1]})
@ -112,3 +112,20 @@ minetest.register_craftitem("logikraft:unlinker", {
return itemstack
end
})
minetest.register_craftitem("logikraft:resizer", {
description = "The Resizer",
inventory_image = "resizer.png",
on_place = function(itemstack, user, pointed_thing)
local node = minetest.get_node(pointed_thing.under)
if not string.startsWith(node.name,"logikraft:cable_")
then return itemstack
end
local index = logikraft.lookingAtNbIndex(user,pointed_thing.under)
local new = logikraft.resizeInCable(string.without(node.name,"logikraft:cable_"),index)
minetest.swap_node(pointed_thing.under, {name = "logikraft:cable_" .. new})
return itemstack
end
})

BIN
textures/resizer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB