Tube capability for tool workshop

Tool workshop can now accept tools to repair via tube.  It has upgrade
slots.  Battery upgrade reduces its power consumption.  Tube upgrade
makes it eject fully-repaired (or unrepairable) items via tube.
This commit is contained in:
Zefram 2014-08-18 17:09:37 +01:00
parent 814646b542
commit 7d610b7c80

View File

@ -14,10 +14,15 @@ minetest.register_craft({
} }
}) })
local workshop_demand = {5000, 3500, 2000}
local workshop_formspec = local workshop_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;src;3,1;1,1;]"..
"label[0,0;"..S("%s Tool Workshop"):format("MV").."]".. "label[0,0;"..S("%s Tool Workshop"):format("MV").."]"..
"list[current_name;upgrade1;1,3;1,1;]"..
"list[current_name;upgrade2;2,3;1,1;]"..
"label[1,4;"..S("Upgrade Slots").."]"..
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
local run = function(pos, node) local run = function(pos, node)
@ -26,15 +31,16 @@ local run = function(pos, node)
local eu_input = meta:get_int("MV_EU_input") local eu_input = meta:get_int("MV_EU_input")
local machine_name = S("%s Tool Workshop"):format("MV") local machine_name = S("%s Tool Workshop"):format("MV")
local machine_node = "technic:tool_workshop" local machine_node = "technic:tool_workshop"
local demand = 5000
-- Setup meta data if it does not exist. -- Setup meta data if it does not exist.
if not eu_input then if not eu_input then
meta:set_int("MV_EU_demand", demand) meta:set_int("MV_EU_demand", workshop_demand[1])
meta:set_int("MV_EU_input", 0) meta:set_int("MV_EU_input", 0)
return return
end end
local EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
local repairable = false local repairable = false
local srcstack = inv:get_stack("src", 1) local srcstack = inv:get_stack("src", 1)
if not srcstack:is_empty() then if not srcstack:is_empty() then
@ -46,27 +52,32 @@ local run = function(pos, node)
repairable = true repairable = true
end end
end end
technic.handle_machine_pipeworks(pos, tube_upgrade, function (pos, x_velocity, z_velocity)
if not repairable then
technic.send_items(pos, x_velocity, z_velocity, "src")
end
end)
if not repairable then if not repairable then
meta:set_string("infotext", S("%s Idle"):format(machine_name)) meta:set_string("infotext", S("%s Idle"):format(machine_name))
meta:set_int("MV_EU_demand", 0) meta:set_int("MV_EU_demand", 0)
return return
end end
if eu_input < demand then if eu_input < workshop_demand[EU_upgrade+1] then
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
elseif eu_input >= demand then elseif eu_input >= workshop_demand[EU_upgrade+1] then
meta:set_string("infotext", S("%s Active"):format(machine_name)) meta:set_string("infotext", S("%s Active"):format(machine_name))
srcstack:add_wear(-1000) srcstack:add_wear(-1000)
inv:set_stack("src", 1, srcstack) inv:set_stack("src", 1, srcstack)
end end
meta:set_int("MV_EU_demand", demand) meta:set_int("MV_EU_demand", workshop_demand[EU_upgrade+1])
end end
minetest.register_node("technic:tool_workshop", { minetest.register_node("technic:tool_workshop", {
description = S("%s Tool Workshop"):format("MV"), description = S("%s Tool Workshop"):format("MV"),
tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png",
"technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, "technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1}, groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, tubedevice=1, tubedevice_receiver=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -74,10 +85,21 @@ minetest.register_node("technic:tool_workshop", {
meta:set_string("formspec", workshop_formspec) meta:set_string("formspec", workshop_formspec)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end, end,
can_dig = technic.machine_can_dig, can_dig = technic.machine_can_dig,
allow_metadata_inventory_put = technic.machine_inventory_put, allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take, allow_metadata_inventory_take = technic.machine_inventory_take,
tube = {
can_insert = function (pos, node, stack, direction)
return minetest.get_meta(pos):get_inventory():room_for_item("src", stack)
end,
insert_object = function (pos, node, stack, direction)
return minetest.get_meta(pos):get_inventory():add_item("src", stack)
end,
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
},
technic_run = run, technic_run = run,
}) })