Skip to content

Commit

Permalink
Machine conduct digilines downwards (#49)
Browse files Browse the repository at this point in the history
* Custom digiline rules for machines

* Add custom digiline receptor and effector rules for machines

* technic.digiline.rules must be always available, even if digilines is disabled

Co-authored-by: SX <sx@minetest>
  • Loading branch information
S-S-X and SX committed May 23, 2020
1 parent f99148f commit c8e5e80
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
8 changes: 6 additions & 2 deletions technic/machines/HV/forcefield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ local mesecons = {
}

local digiline_def = {
receptor = {action = function() end},
receptor = {
rules = technic.digilines.rules,
action = function() end
},
effector = {
rules = technic.digilines.rules,
action = function(pos, node, channel, msg)
local meta = minetest.get_meta(pos)
if channel ~= meta:get_string("channel") then
Expand Down Expand Up @@ -203,7 +207,7 @@ local digiline_def = {
return
end
if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, channel, {
digilines.receptor_send(pos, technic.digilines.rules, channel, {
enabled = meta:get_int("enabled"),
range = meta:get_int("range"),
shape = meta:get_int("shape")
Expand Down
14 changes: 14 additions & 0 deletions technic/machines/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
local path = technic.modpath.."/machines"

technic.digilines = {
rules = {
-- digilines.rules.default
{x= 1,y= 0,z= 0},{x=-1,y= 0,z= 0}, -- along x beside
{x= 0,y= 0,z= 1},{x= 0,y= 0,z=-1}, -- along z beside
{x= 1,y= 1,z= 0},{x=-1,y= 1,z= 0}, -- 1 node above along x diagonal
{x= 0,y= 1,z= 1},{x= 0,y= 1,z=-1}, -- 1 node above along z diagonal
{x= 1,y=-1,z= 0},{x=-1,y=-1,z= 0}, -- 1 node below along x diagonal
{x= 0,y=-1,z= 1},{x= 0,y=-1,z=-1}, -- 1 node below along z diagonal
-- added rules for digi cable
{x = 0, y = -1, z = 0}, -- along y below
}
}

dofile(path.."/register/init.lua")

-- Tiers
Expand Down
8 changes: 6 additions & 2 deletions technic/machines/register/battery_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,12 @@ function technic.register_battery_box(data)
end
end,
digiline = {
receptor = {action = function() end},
receptor = {
rules = technic.digilines.rules,
action = function() end
},
effector = {
rules = technic.digilines.rules,
action = function(pos, node, channel, msg)
if msg ~= "GET" and msg ~= "get" then
return
Expand All @@ -369,7 +373,7 @@ function technic.register_battery_box(data)
return
end
local inv = meta:get_inventory()
digilines.receptor_send(pos, digilines.rules.default, channel, {
digilines.receptor_send(pos, technic.digilines.rules, channel, {
demand = meta:get_int(tier.."_EU_demand"),
supply = meta:get_int(tier.."_EU_supply"),
input = meta:get_int(tier.."_EU_input"),
Expand Down
8 changes: 6 additions & 2 deletions technic/machines/supply_converter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ local mesecons = {


local digiline_def = {
receptor = {action = function() end},
receptor = {
rules = technic.digilines.rules,
action = function() end
},
effector = {
rules = technic.digilines.rules,
action = function(pos, node, channel, msg)
if type(msg) ~= "string" then
return
Expand All @@ -81,7 +85,7 @@ local digiline_def = {
end
msg = msg:lower()
if msg == "get" then
digilines.receptor_send(pos, digilines.rules.default, channel, {
digilines.receptor_send(pos, technic.digilines.rules, channel, {
enabled = meta:get_int("enabled"),
power = meta:get_int("power"),
mesecon_mode = meta:get_int("mesecon_mode")
Expand Down
10 changes: 7 additions & 3 deletions technic/machines/switching_station.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ minetest.register_node("technic:switching_station",{
end,
mesecons = mesecon_def,
digiline = {
receptor = {action = function() end},
receptor = {
rules = technic.digilines.rules,
action = function() end
},
effector = {
rules = technic.digilines.rules,
action = function(pos, node, channel, msg)
if msg ~= "GET" and msg ~= "get" then
return
Expand All @@ -79,7 +83,7 @@ minetest.register_node("technic:switching_station",{
if channel ~= meta:get_string("channel") then
return
end
digilines.receptor_send(pos, digilines.rules.default, channel, {
digilines.receptor_send(pos, technic.digilines.rules, channel, {
supply = meta:get_int("supply"),
demand = meta:get_int("demand")
})
Expand Down Expand Up @@ -367,7 +371,7 @@ technic.switching_station_run = function(pos)
if PR_eu_supply ~= meta:get_int("supply") or
RE_eu_demand ~= meta:get_int("demand") then
local channel = meta:get_string("channel")
digilines.receptor_send(pos, digilines.rules.default, channel, {
digilines.receptor_send(pos, technic.digilines.rules, channel, {
supply = PR_eu_supply,
demand = RE_eu_demand
})
Expand Down

0 comments on commit c8e5e80

Please sign in to comment.