Compare commits
2 Commits
6a2c44da91
...
dbb30f0634
| Author | SHA1 | Date | |
|---|---|---|---|
| dbb30f0634 | |||
| 2c8f51f8ba |
@ -63,7 +63,7 @@ function logikraft.rotateCable(name,r)
|
|||||||
local newconn = {}
|
local newconn = {}
|
||||||
for i,v in ipairs(conn)
|
for i,v in ipairs(conn)
|
||||||
do
|
do
|
||||||
newconn[i] = rotate4dir(v,r)
|
newconn[i] = logikraft.rotate4dir(v,r)
|
||||||
end
|
end
|
||||||
table.sort(newconn)
|
table.sort(newconn)
|
||||||
return logikraft.cableFromConns(newconn)
|
return logikraft.cableFromConns(newconn)
|
||||||
@ -101,8 +101,11 @@ end
|
|||||||
--[[
|
--[[
|
||||||
Returns {newcablea,newcableb} if the two cables are contiguous
|
Returns {newcablea,newcableb} if the two cables are contiguous
|
||||||
Returns nil otherwise
|
Returns nil otherwise
|
||||||
|
If namea or nameb is nil, no cable is present, and we create a single pin, or we connect to the conn in the direction
|
||||||
|
If a or b is nil, we consider that
|
||||||
--]]
|
--]]
|
||||||
function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
|
function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
|
||||||
|
print("Connecting "..tostring(namea).."("..tostring(a)..") with "..tostring(nameb).."("..tostring(b)..")")
|
||||||
local dira = (posa.y == posb.y) and (
|
local dira = (posa.y == posb.y) and (
|
||||||
(posa.z + 1 == posb.z and posa.x == posb.x and 3) or
|
(posa.z + 1 == posb.z and posa.x == posb.x and 3) or
|
||||||
(posa.x + 1 == posb.x and posa.z == posb.z and 2) or
|
(posa.x + 1 == posb.x and posa.z == posb.z and 2) or
|
||||||
@ -112,21 +115,64 @@ function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
|
|||||||
if dira == nil
|
if dira == nil
|
||||||
then return nil
|
then return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not namea
|
||||||
|
then
|
||||||
|
namea = logikraft.cableFromConns({logikraft.rotate4dir(4,6-dira)})
|
||||||
|
a = 1 -- There is only one nodebox
|
||||||
|
end
|
||||||
|
if not nameb
|
||||||
|
then
|
||||||
|
nameb = logikraft.cableFromConns({logikraft.rotate4dir(4,4-dira)})
|
||||||
|
b = 1 -- There is only one nodebox
|
||||||
|
end
|
||||||
|
|
||||||
|
local cia
|
||||||
|
if not a
|
||||||
|
then
|
||||||
|
cia = logikraft.connFromDir(namea,dira)
|
||||||
|
if not cia
|
||||||
|
then
|
||||||
|
-- We need to add a tip to a
|
||||||
|
local connsa = table.copy(logikraft.cables[namea].conns)
|
||||||
|
table.insert(connsa,logikraft.rotate4dir(4,6-dira))
|
||||||
|
table.sort(connsa)
|
||||||
|
namea = logikraft.cableFromConns(connsa)
|
||||||
|
cia = logikraft.connFromDir(namea,dira)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cia = logikraft.cables[namea].nbToConn[a]
|
||||||
|
end
|
||||||
|
|
||||||
|
local cib
|
||||||
|
if not b
|
||||||
|
then
|
||||||
|
cib = logikraft.connFromDir(nameb,math.fmod(dira+2,4))
|
||||||
|
if not cib
|
||||||
|
then
|
||||||
|
-- We need to add a tip to b
|
||||||
|
local connsb = table.copy(logikraft.cables[nameb].conns)
|
||||||
|
table.insert(connsb,logikraft.rotate4dir(4,4-dira))
|
||||||
|
table.sort(connsb)
|
||||||
|
nameb = logikraft.cableFromConns(connsb)
|
||||||
|
cib = logikraft.connFromDir(nameb,math.fmod(dira+2,4))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cib = logikraft.cables[nameb].nbToConn[b]
|
||||||
|
end
|
||||||
|
|
||||||
|
print(dira)
|
||||||
|
print(namea)
|
||||||
|
print(cia)
|
||||||
|
print(nameb)
|
||||||
|
print(cib)
|
||||||
|
|
||||||
local connsa = table.copy(logikraft.cables[namea].conns)
|
local connsa = table.copy(logikraft.cables[namea].conns)
|
||||||
local connsb = table.copy(logikraft.cables[nameb].conns)
|
local connsb = table.copy(logikraft.cables[nameb].conns)
|
||||||
print(dump(connsa))
|
--print(dump(connsa))
|
||||||
print(dump(connsb))
|
--print(dump(connsb))
|
||||||
local cia = logikraft.cables[namea].nbToConn[a]
|
|
||||||
local cib = logikraft.cables[nameb].nbToConn[b]
|
|
||||||
local cia2 = logikraft.connFromDir(namea,dira)
|
local cia2 = logikraft.connFromDir(namea,dira)
|
||||||
local cib2 = logikraft.connFromDir(nameb,math.fmod(dira+2,4))
|
local cib2 = logikraft.connFromDir(nameb,math.fmod(dira+2,4))
|
||||||
print(dira)
|
|
||||||
print(cia)
|
|
||||||
print(cia2)
|
|
||||||
print(cib)
|
|
||||||
print(cib2)
|
|
||||||
|
|
||||||
|
|
||||||
-- (nba == nil) -> Need to add dira to the a
|
-- (nba == nil) -> Need to add dira to the a
|
||||||
-- (a == nba) -> Already connected
|
-- (a == nba) -> Already connected
|
||||||
|
|||||||
@ -107,7 +107,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
do
|
do
|
||||||
if string.startsWith(f,"input_")
|
if string.startsWith(f,"input_")
|
||||||
then
|
then
|
||||||
print("ploup")
|
|
||||||
local v = (x == "OFF") and 1 or 0
|
local v = (x == "OFF") and 1 or 0
|
||||||
_contexts[cn][string.without(f,"input_")] = v
|
_contexts[cn][string.without(f,"input_")] = v
|
||||||
end
|
end
|
||||||
|
|||||||
1
init.lua
1
init.lua
@ -9,7 +9,6 @@ dofile(minetest.get_modpath("logikraft") .. "/blocks/component.lua")
|
|||||||
dofile(minetest.get_modpath("logikraft") .. "/blocks/components_register.lua")
|
dofile(minetest.get_modpath("logikraft") .. "/blocks/components_register.lua")
|
||||||
dofile(minetest.get_modpath("logikraft") .. "/blocks/cable.lua")
|
dofile(minetest.get_modpath("logikraft") .. "/blocks/cable.lua")
|
||||||
dofile(minetest.get_modpath("logikraft") .. "/blocks/cables_register.lua")
|
dofile(minetest.get_modpath("logikraft") .. "/blocks/cables_register.lua")
|
||||||
dofile(minetest.get_modpath("logikraft") .. "/blocks/iocomponent.lua")
|
|
||||||
dofile(minetest.get_modpath("logikraft") .. "/items.lua")
|
dofile(minetest.get_modpath("logikraft") .. "/items.lua")
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
|||||||
92
items.lua
92
items.lua
@ -17,7 +17,6 @@ minetest.register_craftitem("logikraft:linker", {
|
|||||||
inventory_image = "linker.png",
|
inventory_image = "linker.png",
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
|
||||||
if meta:get_int("logikraft:selected_nb") ~= 0
|
if meta:get_int("logikraft:selected_nb") ~= 0
|
||||||
then
|
then
|
||||||
local selectednb = meta:get_int("logikraft:selected_nb")
|
local selectednb = meta:get_int("logikraft:selected_nb")
|
||||||
@ -25,60 +24,73 @@ minetest.register_craftitem("logikraft:linker", {
|
|||||||
local selectedy = meta:get_int("logikraft:selected_y")
|
local selectedy = meta:get_int("logikraft:selected_y")
|
||||||
local selectedz = meta:get_int("logikraft:selected_z")
|
local selectedz = meta:get_int("logikraft:selected_z")
|
||||||
local selectedpos = {x = selectedx, y = selectedy, z = selectedz}
|
local selectedpos = {x = selectedx, y = selectedy, z = selectedz}
|
||||||
if logikraft.cablenodes[node.name]
|
local pos = logikraft.cablenodes[minetest.get_node(pointed_thing.under).name] and pointed_thing.under or pointed_thing.above
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
|
local thisnb = logikraft.cablenodes[minetest.get_node(pointed_thing.under).name] and logikraft.lookingAtNbIndex(user,pointed_thing.under) or -1
|
||||||
|
if selectedx == pos.x and selectedy == pos.y and selectedz == pos.z
|
||||||
then
|
then
|
||||||
if selectedx == pointed_thing.under.x and selectedy == pointed_thing.under.y and selectedz == pointed_thing.under.z
|
if(selectednb ~= thisnb and thisnb ~= -1 and selectednb ~= -1)
|
||||||
then
|
then
|
||||||
local thisnb = logikraft.lookingAtNbIndex(user,pointed_thing.under)
|
local new = logikraft.connectInCable(logikraft.cablenodes[node.name],selectednb,thisnb)
|
||||||
if(selectednb ~= thisnb)
|
minetest.swap_node(pos, {name = "logikraft:cable_" .. new})
|
||||||
then
|
end
|
||||||
local new = logikraft.connectInCable(logikraft.cablenodes[node.name],selectednb,thisnb)
|
meta:set_int("logikraft:selected_nb",0)
|
||||||
minetest.swap_node(pointed_thing.under, {name = "logikraft:cable_" .. new})
|
meta:set_string("inventory_image","linker.png")
|
||||||
end
|
return itemstack
|
||||||
|
else
|
||||||
|
local new = logikraft.connectContiguousCable(
|
||||||
|
logikraft.cablenodes[minetest.get_node(selectedpos).name],selectedpos,(selectednb ~= -1 and selectednb) or nil,
|
||||||
|
logikraft.cablenodes[node.name],pos,(thisnb ~= -1 and thisnb) or nil)
|
||||||
|
if new
|
||||||
|
then
|
||||||
|
minetest.swap_node(selectedpos, {name = "logikraft:cable_" .. new[1]})
|
||||||
|
minetest.swap_node(pos, {name = "logikraft:cable_" .. new[2]})
|
||||||
meta:set_int("logikraft:selected_nb",0)
|
meta:set_int("logikraft:selected_nb",0)
|
||||||
meta:set_string("inventory_image","linker.png")
|
meta:set_string("inventory_image","linker.png")
|
||||||
else
|
else
|
||||||
local thisnb = logikraft.lookingAtNbIndex(user,pointed_thing.under)
|
minetest.chat_send_player(user:get_player_name(),"Les cables sont trop loins l'un de l'autre :/")
|
||||||
local new = logikraft.connectContiguousCable(
|
|
||||||
logikraft.cablenodes[minetest.get_node(selectedpos).name],selectedpos,selectednb,
|
|
||||||
logikraft.cablenodes[node.name],pointed_thing.under,thisnb)
|
|
||||||
if new
|
|
||||||
then
|
|
||||||
minetest.swap_node(selectedpos, {name = "logikraft:cable_" .. new[1]})
|
|
||||||
minetest.swap_node(pointed_thing.under, {name = "logikraft:cable_" .. new[2]})
|
|
||||||
meta:set_int("logikraft:selected_nb",0)
|
|
||||||
meta:set_string("inventory_image","linker.png")
|
|
||||||
else
|
|
||||||
minetest.chat_send_all("Les cables sont trop loins l'un de l'autre :/")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
return itemstack
|
||||||
local node_def = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name]
|
|
||||||
if not node_def or not node_def.buildable_to then
|
|
||||||
-- Then we cannot build here
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
minetest.add_node(pointed_thing.above, {name = "logikraft:cable_NSEW1"})
|
|
||||||
meta:set_int("logikraft:selected_nb",0)
|
|
||||||
meta:set_string("inventory_image","linker.png")
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
|
local pos = logikraft.cablenodes[minetest.get_node(pointed_thing.under).name] and pointed_thing.under or pointed_thing.above
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
if logikraft.cablenodes[node.name]
|
if logikraft.cablenodes[node.name]
|
||||||
then
|
then
|
||||||
-- If we are looking at a cable we activate and store data
|
-- If we are looking at a cable we activate and store data
|
||||||
meta:set_int("logikraft:selected_nb",logikraft.lookingAtNbIndex(user,pointed_thing.under))
|
local thisnb = logikraft.cablenodes[minetest.get_node(pointed_thing.under).name] and logikraft.lookingAtNbIndex(user,pointed_thing.under) or -1
|
||||||
meta:set_int("logikraft:selected_x",pointed_thing.under.x)
|
|
||||||
meta:set_int("logikraft:selected_y",pointed_thing.under.y)
|
meta:set_int("logikraft:selected_nb",thisnb)
|
||||||
meta:set_int("logikraft:selected_z",pointed_thing.under.z)
|
meta:set_int("logikraft:selected_x",pos.x)
|
||||||
|
meta:set_int("logikraft:selected_y",pos.y)
|
||||||
|
meta:set_int("logikraft:selected_z",pos.z)
|
||||||
meta:set_string("inventory_image","linker_activated.png")
|
meta:set_string("inventory_image","linker_activated.png")
|
||||||
else
|
else
|
||||||
-- Else we place a cable
|
-- Else we place a cable
|
||||||
local node_def = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name]
|
local node_def = minetest.registered_nodes[node.name]
|
||||||
if not node_def or not node_def.buildable_to then
|
if not (node_def and node_def.buildable_to)
|
||||||
-- Then we cannot build here
|
then return itemstack end
|
||||||
return itemstack
|
local new = nil
|
||||||
|
local poz = {
|
||||||
|
{x = pos.x+1, y = pos.y, z = pos.z},
|
||||||
|
{x = pos.x, y = pos.y, z = pos.z+1},
|
||||||
|
{x = pos.x-1, y = pos.y, z = pos.z},
|
||||||
|
{x = pos.x, y = pos.y, z = pos.z-1}
|
||||||
|
}
|
||||||
|
for k,pos2 in pairs(poz)
|
||||||
|
do
|
||||||
|
local cable2 = minetest.get_node(pos2)
|
||||||
|
if logikraft.cablenodes[cable2.name]
|
||||||
|
then
|
||||||
|
local contiguous = logikraft.connectContiguousCable(new, pos, 1, logikraft.cablenodes[cable2.name], pos2, nil)
|
||||||
|
new = contiguous[1]
|
||||||
|
minetest.swap_node(pos2, {name = "logikraft:cable_" .. contiguous[2]})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
minetest.add_node(pointed_thing.above, {name = "logikraft:cable_NSEW1"})
|
minetest.add_node(pos, {name = "logikraft:cable_" .. (new or "NSEW1")})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user