mirror of
https://github.com/minetest-mods/technic.git
synced 2025-03-20 11:20:31 +01:00
begin to make battery box send information via digilines
This commit is contained in:
parent
b7cecd7f3d
commit
73c3268da8
@ -1,4 +1,5 @@
|
|||||||
-- HV battery box
|
-- HV battery box
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:hv_battery_box0',
|
output = 'technic:hv_battery_box0',
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
-- LV Battery box
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:lv_battery_box0',
|
output = 'technic:lv_battery_box0',
|
||||||
|
@ -62,7 +62,7 @@ function technic.register_battery_box(data)
|
|||||||
local ltier = string.lower(tier)
|
local ltier = string.lower(tier)
|
||||||
|
|
||||||
local formspec =
|
local formspec =
|
||||||
"invsize[8,9;]"..
|
"size[8,9]"..
|
||||||
"image[1,1;1,2;technic_power_meter_bg.png]"..
|
"image[1,1;1,2;technic_power_meter_bg.png]"..
|
||||||
"list[current_name;src;3,1;1,1;]"..
|
"list[current_name;src;3,1;1,1;]"..
|
||||||
"image[4,1;1,1;technic_battery_reload.png]"..
|
"image[4,1;1,1;technic_battery_reload.png]"..
|
||||||
@ -76,6 +76,10 @@ function technic.register_battery_box(data)
|
|||||||
"listring[current_player;main]"..
|
"listring[current_player;main]"..
|
||||||
"listring[current_name;src]"..
|
"listring[current_name;src]"..
|
||||||
"listring[current_player;main]"
|
"listring[current_player;main]"
|
||||||
|
if digilines then
|
||||||
|
formspec = formspec..
|
||||||
|
"field[0.28,4.1;3.2,1;channel;Digiline Channel;${channel}]"
|
||||||
|
end
|
||||||
|
|
||||||
if data.upgrade then
|
if data.upgrade then
|
||||||
formspec = formspec..
|
formspec = formspec..
|
||||||
@ -98,7 +102,7 @@ function technic.register_battery_box(data)
|
|||||||
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
|
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
|
||||||
end
|
end
|
||||||
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
|
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
|
||||||
|
|
||||||
-- Charge/discharge the battery with the input EUs
|
-- Charge/discharge the battery with the input EUs
|
||||||
if eu_input >= 0 then
|
if eu_input >= 0 then
|
||||||
current_charge = math.min(current_charge + eu_input, max_charge)
|
current_charge = math.min(current_charge + eu_input, max_charge)
|
||||||
@ -113,7 +117,7 @@ function technic.register_battery_box(data)
|
|||||||
current_charge, tool_empty = technic.discharge_tools(meta,
|
current_charge, tool_empty = technic.discharge_tools(meta,
|
||||||
current_charge, data.discharge_step,
|
current_charge, data.discharge_step,
|
||||||
max_charge)
|
max_charge)
|
||||||
|
|
||||||
if data.tube then
|
if data.tube then
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
technic.handle_machine_pipeworks(pos, tube_upgrade,
|
technic.handle_machine_pipeworks(pos, tube_upgrade,
|
||||||
@ -157,19 +161,19 @@ function technic.register_battery_box(data)
|
|||||||
end
|
end
|
||||||
meta:set_string("infotext", infotext)
|
meta:set_string("infotext", infotext)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 0, 8 do
|
for i = 0, 8 do
|
||||||
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
|
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
|
||||||
technic_machine=1, ["technic_"..ltier]=1}
|
technic_machine=1, ["technic_"..ltier]=1}
|
||||||
if i ~= 0 then
|
if i ~= 0 then
|
||||||
groups.not_in_creative_inventory = 1
|
groups.not_in_creative_inventory = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.tube then
|
if data.tube then
|
||||||
groups.tubedevice = 1
|
groups.tubedevice = 1
|
||||||
groups.tubedevice_receiver = 1
|
groups.tubedevice_receiver = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("technic:"..ltier.."_battery_box"..i, {
|
minetest.register_node("technic:"..ltier.."_battery_box"..i, {
|
||||||
description = S("%s Battery Box"):format(tier),
|
description = S("%s Battery Box"):format(tier),
|
||||||
tiles = {"technic_"..ltier.."_battery_box_top.png",
|
tiles = {"technic_"..ltier.."_battery_box_top.png",
|
||||||
@ -191,6 +195,7 @@ function technic.register_battery_box(data)
|
|||||||
|
|
||||||
meta:set_string("infotext", S("%s Battery Box"):format(tier))
|
meta:set_string("infotext", S("%s Battery Box"):format(tier))
|
||||||
meta:set_string("formspec", formspec)
|
meta:set_string("formspec", formspec)
|
||||||
|
meta:set_string("channel", tier.."_battery_box"..minetest.pos_to_string(pos))
|
||||||
meta:set_int(tier.."_EU_demand", 0)
|
meta:set_int(tier.."_EU_demand", 0)
|
||||||
meta:set_int(tier.."_EU_supply", 0)
|
meta:set_int(tier.."_EU_supply", 0)
|
||||||
meta:set_int(tier.."_EU_input", 0)
|
meta:set_int(tier.."_EU_input", 0)
|
||||||
@ -206,7 +211,43 @@ function technic.register_battery_box(data)
|
|||||||
allow_metadata_inventory_move = technic.machine_inventory_move,
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
||||||
technic_run = run,
|
technic_run = run,
|
||||||
after_place_node = data.tube and pipeworks.after_place,
|
after_place_node = data.tube and pipeworks.after_place,
|
||||||
after_dig_node = technic.machine_after_dig_node
|
after_dig_node = technic.machine_after_dig_node,
|
||||||
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
|
if not fields.channel then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local plname = sender:get_player_name()
|
||||||
|
if minetest.is_protected(pos, plname) then
|
||||||
|
minetest.record_protection_violation(pos, plname)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("channel", fields.channel)
|
||||||
|
end,
|
||||||
|
mesecons = {effector = {
|
||||||
|
rules = mesecon.rules.default,
|
||||||
|
}},
|
||||||
|
digiline = {
|
||||||
|
receptor = {action = function() end},
|
||||||
|
effector = {
|
||||||
|
action = function(pos, node, channel, msg)
|
||||||
|
if msg ~= "GET" and msg ~= "get" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if channel ~= meta:get_string("channel") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
digilines.receptor_send(pos, digilines.rules.default, channel, {
|
||||||
|
demand = meta:get_int(tier.."_EU_demand"),
|
||||||
|
supply = meta:get_int(tier.."_EU_supply"),
|
||||||
|
input = meta:get_int(tier.."_EU_input"),
|
||||||
|
charge = meta:get_int("internal_EU_charge")
|
||||||
|
-- todo: tool and its charge...; maxcharge?
|
||||||
|
})
|
||||||
|
end
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user