update areasprotector mod, pipeworks, technic

This commit is contained in:
Vanessa Ezekowitz 2017-04-05 00:23:23 -04:00
parent 8958d61761
commit 4c9e8e6bf0
22 changed files with 422 additions and 84 deletions

View File

@ -1,3 +1,6 @@
local creative_mode = minetest.setting_getbool("creative_mode")
local function cyan(str)
return minetest.colorize("#00FFFF",str)
end
@ -54,13 +57,31 @@ minetest.register_node("areasprotector:protector",{
end
return itemstack
end,
on_destruct = function(pos)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local id = meta:get_int("area_id")
if areas.areas[id] and areas:isAreaOwner(id,owner) then
areas:remove(id)
areas:save()
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldmetadata and oldmetadata.fields then
local owner = oldmetadata.fields.owner
local id = tonumber(oldmetadata.fields.area_id)
local playername = digger:get_player_name()
if areas.areas[id] and areas:isAreaOwner(id,owner) then
if digger:get_player_control().sneak then
local inv = digger:get_inventory()
if not creative_mode then
if inv:room_for_item("main", "default:steel_ingot 6") then
inv:remove_item("main", "areasprotector:protector 1")
inv:add_item("main", "default:steel_ingot 6")
else
minetest.chat_send_player(playername, "No room for the replacement ingots, just digging the protector and deleting the area normally.")
areas:remove(id)
areas:save()
end
else
inv:remove_item("main", "areasprotector:protector 1")
end
else
areas:remove(id)
areas:save()
end
end
end
end,
on_punch = function(pos, node, puncher)

View File

@ -1,7 +1,7 @@
-- autorouting for pneumatic tubes
local function is_tube(nodename)
return table.contains(pipeworks.tubenodes, nodename)
return pipeworks.table_contains(pipeworks.tubenodes, nodename)
end
--a function for determining which side of the node we are on
@ -11,23 +11,23 @@ local function nodeside(node, tubedir)
end
local backdir = minetest.facedir_to_dir(node.param2)
local back = vector.dot(backdir, tubedir)
local back = pipeworks.vector_dot(backdir, tubedir)
if back == 1 then
return "back"
elseif back == -1 then
return "front"
end
local topdir = minetest.facedir_to_top_dir(node.param2)
local top = vector.dot(topdir, tubedir)
local topdir = pipeworks.facedir_to_top_dir(node.param2)
local top = pipeworks.vector_dot(topdir, tubedir)
if top == 1 then
return "top"
elseif top == -1 then
return "bottom"
end
local rightdir = minetest.facedir_to_right_dir(node.param2)
local right = vector.dot(rightdir, tubedir)
local rightdir = pipeworks.facedir_to_right_dir(node.param2)
local right = pipeworks.vector_dot(rightdir, tubedir)
if right == 1 then
return "right"
else
@ -99,7 +99,7 @@ end
function pipeworks.scan_for_tube_objects(pos)
for side = 0, 6 do
tube_autoroute(vector.add(pos, directions.side_to_dir(side)))
tube_autoroute(vector.add(pos, pipeworks.directions.side_to_dir(side)))
end
end

View File

@ -2,7 +2,7 @@
-- Vector functions --
----------------------
function vector.cross(a, b)
function pipeworks.vector_cross(a, b)
return {
x = a.y * b.z - a.z * b.y,
y = a.z * b.x - a.x * b.z,
@ -10,7 +10,7 @@ function vector.cross(a, b)
}
end
function vector.dot(a, b)
function pipeworks.vector_dot(a, b)
return a.x * b.x + a.y * b.y + a.z * b.z
end
@ -18,7 +18,7 @@ end
-- Facedir functions --
-----------------------
function minetest.facedir_to_top_dir(facedir)
function pipeworks.facedir_to_top_dir(facedir)
return ({[0] = {x = 0, y = 1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1},
@ -28,14 +28,15 @@ function minetest.facedir_to_top_dir(facedir)
[math.floor(facedir / 4)]
end
function minetest.facedir_to_right_dir(facedir)
return vector.cross(
minetest.facedir_to_top_dir(facedir),
function pipeworks.facedir_to_right_dir(facedir)
return pipeworks.vector_cross(
pipeworks.facedir_to_top_dir(facedir),
minetest.facedir_to_dir(facedir)
)
end
directions = {}
local directions = {}
pipeworks.directions = directions
function directions.side_to_dir(side)
return ({[0] = vector.new(),
vector.new( 0, 1, 0),
@ -48,7 +49,7 @@ function directions.side_to_dir(side)
end
function directions.dir_to_side(dir)
local c = vector.dot(dir, vector.new(1, 2, 3)) + 4
local c = pipeworks.vector_dot(dir, vector.new(1, 2, 3)) + 4
return ({6, 2, 4, 0, 3, 1, 5})[c]
end
@ -56,7 +57,7 @@ end
-- String functions --
----------------------
--[[function string.split(str, sep)
--[[function pipeworks.string_split(str, sep)
local fields = {}
local index = 1
local expr = "([^"..sep.."])+"
@ -67,7 +68,7 @@ end
return fields
end]]
function string.startswith(str, substr)
function pipeworks.string_startswith(str, substr)
return str:sub(1, substr:len()) == substr
end
@ -75,7 +76,7 @@ end
-- Table functions --
---------------------
function table.contains(tbl, element)
function pipeworks.table_contains(tbl, element)
for _, elt in pairs(tbl) do
if elt == element then
return true
@ -84,7 +85,7 @@ function table.contains(tbl, element)
return false
end
function table.extend(tbl, tbl2)
function pipeworks.table_extend(tbl, tbl2)
local index = #tbl + 1
for _, elt in ipairs(tbl2) do
tbl[index] = elt
@ -92,11 +93,11 @@ function table.extend(tbl, tbl2)
end
end
function table.recursive_replace(tbl, pattern, replace_with)
function pipeworks.table_recursive_replace(tbl, pattern, replace_with)
if type(tbl) == "table" then
local tbl2 = {}
for key, value in pairs(tbl) do
tbl2[key] = table.recursive_replace(value, pattern, replace_with)
tbl2[key] = pipeworks.table_recursive_replace(value, pattern, replace_with)
end
return tbl2
elseif type(tbl) == "string" then
@ -110,11 +111,12 @@ end
-- Formspec functions --
------------------------
fs_helpers = {}
local fs_helpers = {}
pipeworks.fs_helpers = fs_helpers
function fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
for field, value in pairs(fields) do
if field:startswith("fs_helpers_cycling:") then
if pipeworks.string_startswith(field, "fs_helpers_cycling:") then
local l = field:split(":")
local new_value = tonumber(l[2])
local meta_name = l[3]
@ -146,7 +148,7 @@ end
-- Env --
---------
function minetest.load_position(pos)
function pipeworks.load_position(pos)
if pos.x < -30912 or pos.y < -30912 or pos.z < -30912 or
pos.x > 30927 or pos.y > 30927 or pos.z > 30927 then return end
if minetest.get_node_or_nil(pos) then

View File

@ -1,3 +1,5 @@
local fs_helpers = pipeworks.fs_helpers
local function delay(x)
return (function() return x end)
end
@ -169,7 +171,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
is_fake_player = ":pipeworks",
get_wielded_item = delay(ItemStack(nil))
} -- TODO: use a mechanism as the wielder one
local dir = minetest.facedir_to_right_dir(filtnode.param2)
local dir = pipeworks.facedir_to_right_dir(filtnode.param2)
local frompos = vector.subtract(filtpos, dir)
local fromnode = minetest.get_node(frompos)
if not fromnode then return end

View File

@ -1,3 +1,6 @@
local luaentity = pipeworks.luaentity
local max_tube_limit = minetest.setting_get("pipeworks_max_tube_limit") or 30
function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
@ -29,6 +32,9 @@ function pipeworks.notvel(tbl, vel)
return tbl2
end
local tube_last_times = {}
local tube_item_count = {}
local function go_next(pos, velocity, stack)
local next_positions = {}
local max_priority = 0
@ -55,7 +61,7 @@ local function go_next(pos, velocity, stack)
end
for _, vect in ipairs(can_go) do
local npos = vector.add(pos, vect)
minetest.load_position(npos)
pipeworks.load_position(npos)
local node = minetest.get_node(npos)
local reg_node = minetest.registered_nodes[node.name]
if reg_node then
@ -75,6 +81,21 @@ local function go_next(pos, velocity, stack)
end
end
local gt = minetest.get_gametime()
local h = minetest.hash_node_position(pos)
if tube_last_times[h] == gt then
local k = tube_item_count[h] or 0
if k > max_tube_limit then
-- Kill tube
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
pipeworks.scan_for_tube_objects(pos)
end
tube_item_count[h] = k + 1
else
tube_last_times[h] = gt
tube_item_count[h] = 1
end
if not next_positions[1] then
return false, nil
end
@ -225,7 +246,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
moved = true
end
minetest.load_position(self.start_pos)
pipeworks.load_position(self.start_pos)
local node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover

View File

@ -1,6 +1,7 @@
local max_entity_id = 1000000000000 -- If you need more, there's a problem with your code
luaentity = {}
local luaentity = {}
pipeworks.luaentity = luaentity
luaentity.registered_entities = {}

View File

@ -9,6 +9,29 @@ minetest.register_craft( {
},
})
pipeworks.register_tube("pipeworks:broken_tube", {
description = "Broken Tube (you hacker you)",
inventory_image = "pipeworks_tube_broken_inv.png",
plain = { { name = "pipeworks_tube_broken_plain.png", color = nodecolor, backface_culling = false } },
noctr = { { name = "pipeworks_tube_broken_plain.png", color = nodecolor, backface_culling = false } },
ends = { { name = "pipeworks_tube_broken_end.png", color = nodecolor } },
short = { name = "pipeworks_tube_broken_short.png", color = nodecolor },
node_def = {
drop = "pipeworks:tube_1",
groups = {not_in_creative_inventory = 1, tubedevice_receiver = 1},
tube = {
insert_object = function(pos, node, stack, direction)
minetest.item_drop(stack, nil, pos)
return ItemStack("")
end,
can_insert = function(pos,node,stack,direction)
return true
end,
priority = 50,
}
}
})
-- the high priority tube is a low-cpu replacement for sorting tubes in situations
-- where players would use them for simple routing (turning off paths)
-- without doing actual sorting, like at outputs of tubedevices that might both accept and eject items
@ -101,7 +124,7 @@ if pipeworks.enable_one_way_tube then
return {velocity}
end,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_right_dir(node.param2)
local dir = pipeworks.facedir_to_right_dir(node.param2)
return vector.equals(dir, direction)
end,
priority = 75 -- Higher than normal tubes, but lower than receivers

View File

@ -1,3 +1,5 @@
local fs_helpers = pipeworks.fs_helpers
if pipeworks.enable_mese_tube then
local function update_formspec(pos)
local meta = minetest.get_meta(pos)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

View File

@ -44,7 +44,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
end
for _, v in ipairs(connects) do
table.extend(outboxes, pipeworks.tube_boxes[v])
pipeworks.table_extend(outboxes, pipeworks.tube_boxes[v])
table.insert(outsel, pipeworks.tube_selectboxes[v])
outimgs[vti[v]] = noctrs[v]
end
@ -127,7 +127,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
nodedef.tube[key] = val
end
else
nodedef[key] = table.recursive_replace(value, "#id", tname)
nodedef[key] = pipeworks.table_recursive_replace(value, "#id", tname)
end
end

View File

@ -1,4 +1,5 @@
-- HV battery box
minetest.register_craft({
output = 'technic:hv_battery_box0',
recipe = {

View File

@ -6,6 +6,8 @@
-- How expensive is the generator?
-- Leaves room for upgrades lowering the power drain?
local digilines_path = minetest.get_modpath("digilines")
local forcefield_power_drain = 10
local S = technic.getter
@ -90,7 +92,14 @@ local function update_forcefield(pos, meta, active, first)
end
local function set_forcefield_formspec(meta)
local formspec = "size[5,2.25]"..
local formspec
if digilines_path then
formspec = "size[5,3.25]"..
"field[0.3,3;5,1;channel;Digiline Channel;"..meta:get_string("channel").."]"
else
formspec = "size[5,2.25]"
end
formspec = formspec..
"field[0.3,0.5;2,1;range;"..S("Range")..";"..meta:get_int("range").."]"
-- The names for these toggle buttons are explicit about which
-- state they'll switch to, so that multiple presses (arising
@ -130,9 +139,10 @@ local forcefield_receive_fields = function(pos, formname, fields, sender)
update_forcefield(pos, meta, false)
end
if range then meta:set_int("range", range) end
if fields.shape0 then meta:set_int("shape", 0) end
if fields.shape1 then meta:set_int("shape", 1) end
if fields.enable then meta:set_int("enabled", 1) end
if fields.channel then meta:set_string("channel", fields.channel) end
if fields.shape0 then meta:set_int("shape", 0) end
if fields.shape1 then meta:set_int("shape", 1) end
if fields.enable then meta:set_int("enabled", 1) end
if fields.disable then meta:set_int("enabled", 0) end
if fields.mesecon_mode_0 then meta:set_int("mesecon_mode", 0) end
if fields.mesecon_mode_1 then meta:set_int("mesecon_mode", 1) end
@ -150,6 +160,60 @@ local mesecons = {
}
}
local digiline_def = {
receptor = {action = function() end},
effector = {
action = function(pos, node, channel, msg)
local meta = minetest.get_meta(pos)
if channel ~= meta:get_string("channel") then
return
end
msg = msg:lower()
if msg == "get" then
digilines.receptor_send(pos, digilines.rules.default, channel, {
enabled = meta:get_int("enabled"),
range = meta:get_int("range"),
shape = meta:get_int("shape")
})
return
elseif msg == "off" then
meta:set_int("enabled", 0)
elseif msg == "on" then
meta:set_int("enabled", 1)
elseif msg == "toggle" then
local onn = meta:get_int("enabled")
onn = 1-onn -- Mirror onn with pivot 0.5, so switch between 1 and 0.
meta:set_int("enabled", onn)
elseif msg:sub(1, 5) == "range" then
local range = tonumber(msg:sub(7))
if not range then
return
end
range = math.max(range, 5)
range = math.min(range, 20)
update_forcefield(pos, meta, false)
meta:set_int("range", range)
elseif msg:sub(1, 5) == "shape" then
local shape = msg:sub(7):lower()
if shape == "sphere" then
shape = 0
elseif shape == "cube" then
shape = 1
end
shape = tonumber(shape)
if not shape then
return
end
update_forcefield(pos, meta, false)
meta:set_int("shape", shape)
else
return
end
set_forcefield_formspec(meta)
end
},
}
local function run(pos, node)
local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("HV_EU_input")
@ -205,10 +269,14 @@ minetest.register_node("technic:forcefield_emitter_off", {
meta:set_int("enabled", 0)
meta:set_int("mesecon_mode", 0)
meta:set_int("mesecon_effect", 0)
if digilines_path then
meta:set_string("channel", "forcefield"..minetest.pos_to_string(pos))
end
meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV"))
set_forcefield_formspec(meta)
end,
mesecons = mesecons,
digiline = digiline_def,
technic_run = run,
})
@ -224,6 +292,7 @@ minetest.register_node("technic:forcefield_emitter_on", {
update_forcefield(pos, meta, false)
end,
mesecons = mesecons,
digiline = digiline_def,
technic_run = run,
technic_on_disable = function (pos, node)
local meta = minetest.get_meta(pos)

View File

@ -1,3 +1,4 @@
-- LV Battery box
minetest.register_craft({
output = 'technic:lv_battery_box0',

View File

@ -1,4 +1,6 @@
local digilines_path = minetest.get_modpath("digilines")
local S = technic.getter
technic.register_power_tool("technic:battery", 10000)
@ -62,29 +64,32 @@ function technic.register_battery_box(data)
local ltier = string.lower(tier)
local formspec =
"invsize[8,9;]"..
"size[8,9]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[context;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"list[context;dst;5,1;1,1;]"..
"label[0,0;"..S("%s Battery Box"):format(tier).."]"..
"label[3,0;"..S("Charge").."]"..
"label[5,0;"..S("Discharge").."]"..
"label[1,3;"..S("Power level").."]"..
"list[current_player;main;0,5;8,4;]"..
"listring[current_name;dst]"..
"listring[context;dst]"..
"listring[current_player;main]"..
"listring[current_name;src]"..
"listring[context;src]"..
"listring[current_player;main]"
if digilines_path then
formspec = formspec.."button[0.6,3.7;2,1;edit_channel;edit Channel]"
end
if data.upgrade then
formspec = formspec..
"list[current_name;upgrade1;3.5,3;1,1;]"..
"list[current_name;upgrade2;4.5,3;1,1;]"..
"list[context;upgrade1;3.5,3;1,1;]"..
"list[context;upgrade2;4.5,3;1,1;]"..
"label[3.5,4;"..S("Upgrade Slots").."]"..
"listring[current_name;upgrade1]"..
"listring[context;upgrade1]"..
"listring[current_player;main]"..
"listring[current_name;upgrade2]"..
"listring[context;upgrade2]"..
"listring[current_player;main]"
end
@ -98,7 +103,7 @@ function technic.register_battery_box(data)
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
-- Charge/discharge the battery with the input EUs
if eu_input >= 0 then
current_charge = math.min(current_charge + eu_input, max_charge)
@ -113,7 +118,7 @@ function technic.register_battery_box(data)
current_charge, tool_empty = technic.discharge_tools(meta,
current_charge, data.discharge_step,
max_charge)
if data.tube then
local inv = meta:get_inventory()
technic.handle_machine_pipeworks(pos, tube_upgrade,
@ -157,27 +162,28 @@ function technic.register_battery_box(data)
end
meta:set_string("infotext", infotext)
end
for i = 0, 8 do
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
technic_machine=1, ["technic_"..ltier]=1}
if i ~= 0 then
groups.not_in_creative_inventory = 1
end
if data.tube then
groups.tubedevice = 1
groups.tubedevice_receiver = 1
end
minetest.register_node("technic:"..ltier.."_battery_box"..i, {
description = S("%s Battery Box"):format(tier),
tiles = {"technic_"..ltier.."_battery_box_top.png",
"technic_"..ltier.."_battery_box_bottom.png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"},
tiles = {
"technic_"..ltier.."_battery_box_top.png",
"technic_"..ltier.."_battery_box_bottom.png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"},
groups = groups,
connect_sides = {"bottom"},
tube = data.tube and tube or nil,
@ -191,6 +197,7 @@ function technic.register_battery_box(data)
meta:set_string("infotext", S("%s Battery Box"):format(tier))
meta:set_string("formspec", formspec)
meta:set_string("channel", ltier.."_battery_box"..minetest.pos_to_string(pos))
meta:set_int(tier.."_EU_demand", 0)
meta:set_int(tier.."_EU_supply", 0)
meta:set_int(tier.."_EU_input", 0)
@ -206,7 +213,42 @@ function technic.register_battery_box(data)
allow_metadata_inventory_move = technic.machine_inventory_move,
technic_run = run,
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.edit_channel then
return
end
local meta = minetest.get_meta(pos)
minetest.show_formspec(sender:get_player_name(),
"technic:battery_box_edit_channel"..minetest.pos_to_string(pos),
"field[channel;Digiline Channel;"..meta:get_string("channel").."]")
end,
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
local inv = meta:get_inventory()
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"),
max_charge = data.max_charge * (1 + technic.handle_machine_upgrades(meta) / 10),
src = inv:get_stack("src", 1):to_table(),
dst = inv:get_stack("dst", 1):to_table(),
upgrade1 = inv:get_stack("upgrade1", 1):to_table(),
upgrade2 = inv:get_stack("upgrade2", 1):to_table()
})
end
},
},
})
end
@ -218,6 +260,23 @@ function technic.register_battery_box(data)
end -- End registration
minetest.register_on_player_receive_fields(
function(player, formname, fields)
if formname:sub(1, 32) ~= "technic:battery_box_edit_channel" or
not fields.channel then
return
end
local pos = minetest.string_to_pos(formname:sub(33))
local plname = player: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
)
function technic.charge_tools(meta, batt_charge, charge_step)
local inv = meta:get_inventory()

View File

@ -121,7 +121,8 @@ function technic.register_cable(tier, size)
local ltier = string.lower(tier)
cable_tier["technic:"..ltier.."_cable"] = tier
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
["technic_"..ltier.."_cable"] = 1}
local node_box = {
type = "connected",
@ -146,11 +147,86 @@ function technic.register_cable(tier, size)
sunlight_propagates = true,
drawtype = "nodebox",
node_box = node_box,
connects_to = {"technic:"..ltier.."_cable",
connects_to = {"group:technic_"..ltier.."_cable",
"group:technic_"..ltier, "group:technic_all_tiers"},
on_construct = clear_networks,
on_destruct = clear_networks,
})
local xyz = {
["-x"] = 1,
["-y"] = 2,
["-z"] = 3,
["x"] = 4,
["y"] = 5,
["z"] = 6,
}
local notconnects = {
[1] = "left",
[2] = "bottom",
[3] = "front",
[4] = "right",
[5] = "top",
[6] = "back",
}
local function s(p)
if p:find("-") then
return p:sub(2)
else
return "-"..p
end
end
for p, i in pairs(xyz) do
local def = {
description = S("%s Cable Plate"):format(tier),
tiles = {"technic_"..ltier.."_cable.png"},
groups = table.copy(groups),
sounds = default.node_sound_wood_defaults(),
drop = "technic:"..ltier.."_cable",
paramtype = "light",
sunlight_propagates = true,
drawtype = "nodebox",
node_box = table.copy(node_box),
connects_to = {"group:technic_"..ltier.."_cable",
"group:technic_"..ltier, "group:technic_all_tiers"},
on_construct = clear_networks,
on_destruct = clear_networks,
}
def.node_box.fixed = {
{-size, -size, -size, size, size, size},
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
}
def.node_box.fixed[1][xyz[p]] = 7/16 * (i-3.5)/math.abs(i-3.5)
def.node_box.fixed[2][xyz[s(p)]] = 3/8 * (i-3.5)/math.abs(i-3.5)
def.node_box["connect_"..notconnects[i]] = nil
if i == 1 then
def.on_place = function(itemstack, placer, pointed_thing)
local pointed_thing_diff = vector.subtract(pointed_thing.above, pointed_thing.under)
local num
for k, v in pairs(pointed_thing_diff) do
if v ~= 0 then
num = xyz[s(tostring(v):sub(-2, -2)..k)]
break
end
end
minetest.set_node(pointed_thing.above, {name = "technic:"..ltier.."_cable_plate_"..num})
end
else
def.groups.not_in_creative_inventory = 1
end
minetest.register_node("technic:"..ltier.."_cable_plate_"..i, def)
cable_tier["technic:"..ltier.."_cable_plate_"..i] = tier
end
local c = "technic:"..ltier.."_cable"
minetest.register_craft({
output = "technic:"..ltier.."_cable_plate_1 5",
recipe = {
{"", "", c},
{c , c , c},
{"", "", c},
}
})
end

View File

@ -7,11 +7,17 @@
-- Once the receiver side is powered it will deliver power to the other side.
-- Unused power is wasted just like any other producer!
local digilines_path = minetest.get_modpath("digilines")
local S = technic.getter
local function set_supply_converter_formspec(meta)
local formspec = "size[5,2.25]"..
"field[0.3,0.5;2,1;power;"..S("Input Power")..";"..meta:get_int("power").."]"
if digilines_path then
formspec = formspec..
"field[2.3,0.5;3,1;channel;Digiline Channel;"..meta:get_string("channel").."]"
end
-- The names for these toggle buttons are explicit about which
-- state they'll switch to, so that multiple presses (arising
-- from the ambiguity between lag and a missed press) only make
@ -34,13 +40,14 @@ local supply_converter_receive_fields = function(pos, formname, fields, sender)
local power = nil
if fields.power then
power = tonumber(fields.power) or 0
power = 100 * math.floor(power / 100)
power = math.max(power, 0)
power = math.min(power, 10000)
power = 100 * math.floor(power / 100)
if power == meta:get_int("power") then power = nil end
end
if power then meta:set_int("power", power) end
if fields.enable then meta:set_int("enabled", 1) end
if fields.channel then meta:set_string("channel", fields.channel) end
if fields.enable then meta:set_int("enabled", 1) end
if fields.disable then meta:set_int("enabled", 0) end
if fields.mesecon_mode_0 then meta:set_int("mesecon_mode", 0) end
if fields.mesecon_mode_1 then meta:set_int("mesecon_mode", 1) end
@ -58,6 +65,48 @@ local mesecons = {
}
}
local digiline_def = {
receptor = {action = function() end},
effector = {
action = function(pos, node, channel, msg)
local meta = minetest.get_meta(pos)
if channel ~= meta:get_string("channel") then
return
end
msg = msg:lower()
if msg == "get" then
digilines.receptor_send(pos, digilines.rules.default, channel, {
enabled = meta:get_int("enabled"),
power = meta:get_int("power"),
mesecon_mode = meta:get_int("mesecon_mode")
})
return
elseif msg == "off" then
meta:set_int("enabled", 0)
elseif msg == "on" then
meta:set_int("enabled", 1)
elseif msg == "toggle" then
local onn = meta:get_int("enabled")
onn = -(onn-1) -- Mirror onn with pivot 0.5, so switch between 1 and 0.
meta:set_int("enabled", onn)
elseif msg:sub(1, 5) == "power" then
local power = tonumber(msg:sub(7))
if not power then
return
end
power = math.max(power, 0)
power = math.min(power, 10000)
power = 100 * math.floor(power / 100)
meta:set_int("power", power)
elseif msg:sub(1, 12) == "mesecon_mode" then
meta:set_int("mesecon_mode", tonumber(msg:sub(14)))
end
set_supply_converter_formspec(meta)
end
},
}
local run = function(pos, node, run_stage)
-- run only in producer stage.
if run_stage == technic.receiver then
@ -120,6 +169,9 @@ minetest.register_node("technic:supply_converter", {
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Supply Converter"))
if digilines_path then
meta:set_string("channel", "supply_converter"..minetest.pos_to_string(pos))
end
meta:set_int("power", 10000)
meta:set_int("enabled", 1)
meta:set_int("mesecon_mode", 0)
@ -127,6 +179,7 @@ minetest.register_node("technic:supply_converter", {
set_supply_converter_formspec(meta)
end,
mesecons = mesecons,
digiline = digiline_def,
technic_run = run,
technic_on_disable = run,
})

View File

@ -48,6 +48,13 @@ minetest.register_craft({
}
})
local mesecon_def
if mesecons_path then
mesecon_def = {effector = {
rules = mesecon.rules.default,
}}
end
minetest.register_node("technic:switching_station",{
description = S("Switching Station"),
tiles = {"technic_water_mill_top_active.png", "technic_water_mill_top_active.png",
@ -80,9 +87,7 @@ minetest.register_node("technic:switching_station",{
local meta = minetest.get_meta(pos)
meta:set_string("channel", fields.channel)
end,
mesecons = {effector = {
rules = mesecon.rules.default,
}},
mesecons = mesecon_def,
digiline = {
receptor = {action = function() end},
effector = {

View File

@ -1,14 +1,14 @@
local uranium_params = {offset = 0, scale = 1, spread = {x = 100, y = 100, z = 100}, seed = 420, octaves = 3, persist = 0.7}
local uranium_threshhold = 0.55
local uranium_threshold = 0.55
local chromium_params = {offset = 0, scale = 1, spread = {x = 100, y = 100, z = 100}, seed = 421, octaves = 3, persist = 0.7}
local chromium_threshhold = 0.55
local chromium_threshold = 0.55
local zinc_params = {offset = 0, scale = 1, spread = {x = 100, y = 100, z = 100}, seed = 422, octaves = 3, persist = 0.7}
local zinc_threshhold = 0.5
local zinc_threshold = 0.5
local lead_params = {offset = 0, scale = 1, spread = {x = 100, y = 100, z = 100}, seed = 423, octaves = 3, persist = 0.7}
local lead_threshhold = 0.3
local lead_threshold = 0.3
minetest.register_ore({
ore_type = "scatter",
@ -20,7 +20,7 @@ minetest.register_ore({
y_min = -300,
y_max = -80,
noise_params = uranium_params,
noise_threshhold = uranium_threshhold,
noise_threshold = uranium_threshold,
})
minetest.register_ore({
@ -33,7 +33,7 @@ minetest.register_ore({
y_min = -200,
y_max = -100,
noise_params = chromium_params,
noise_threshhold = chromium_threshhold,
noise_threshold = chromium_threshold,
})
minetest.register_ore({
@ -47,7 +47,7 @@ minetest.register_ore({
y_max = -200,
flags = "absheight",
noise_params = chromium_params,
noise_threshhold = chromium_threshhold,
noise_threshold = chromium_threshold,
})
minetest.register_ore({
@ -58,7 +58,9 @@ minetest.register_ore({
clust_num_ores = 5,
clust_size = 7,
y_min = -32,
y_max = 2
y_max = 2,
noise_params = zinc_params,
noise_threshold = zinc_threshold,
})
minetest.register_ore({
@ -72,7 +74,7 @@ minetest.register_ore({
y_max = -32,
flags = "absheight",
noise_params = zinc_params,
noise_threshhold = zinc_threshhold,
noise_threshold = zinc_threshold,
})
minetest.register_ore({
@ -85,7 +87,7 @@ minetest.register_ore({
y_min = -16,
y_max = 16,
noise_params = lead_params,
noise_threshhold = lead_threshhold,
noise_threshold = lead_threshold,
})
minetest.register_ore({
@ -98,7 +100,7 @@ minetest.register_ore({
y_min = -128,
y_max = -16,
noise_params = lead_params,
noise_threshhold = lead_threshhold,
noise_threshold = lead_threshold,
})
minetest.register_ore({
@ -112,7 +114,7 @@ minetest.register_ore({
y_max = -128,
flags = "absheight",
noise_params = lead_params,
noise_threshhold = lead_threshhold,
noise_threshold = lead_threshold,
})
-- Sulfur
@ -170,7 +172,7 @@ minetest.register_ore({
clust_size = 3,
y_min = -31000,
y_max = -50,
noise_threshhold = 0.4,
noise_threshold = 0.4,
noise_params = {offset=0, scale=15, spread={x=150, y=150, z=150}, seed=23, octaves=3, persist=0.70}
})
end
@ -185,7 +187,7 @@ minetest.register_ore({
clust_size = 4,
y_min = -31000,
y_max = -150,
noise_threshhold = 0.4,
noise_threshold = 0.4,
noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70}
})
end