techage/liquids/silo.lua
Joachim Stolberg 0a6392b2b9 items bauxite, gibbsite, aluminum, red mud, powders, lye added
nodes silo and furnace heater added
chemical doser/reactor activated
netID location (networks) moved to pumps
expoxy recipe changed
files/folders restructured
2019-11-17 00:08:10 +01:00

216 lines
5.6 KiB
Lua

--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3/TA4 Powder Silo
]]--
local S2P = minetest.string_to_pos
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local INV_SIZE = 8
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local mem = tubelib2.get_mem(pos)
mem.item_name = nil
local inv = minetest.get_meta(pos):get_inventory()
if inv:is_empty(listname) then
return stack:get_count()
end
if inv:contains_item(listname, ItemStack(stack:get_name())) then
return stack:get_count()
end
return 0
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local mem = tubelib2.get_mem(pos)
mem.item_name = nil
return stack:get_count()
end
local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("main")
end
local function get_item_name(mem, inv)
for idx = 1, INV_SIZE do
local stack = inv:get_stack("main", idx)
if stack:get_count() > 0 then
mem.item_name = stack:get_name()
return mem.item_name
end
end
end
local function formspec()
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;main;0,0;8,2;]"..
"list[current_player;main;0,2.3;8,4;]"..
"listring[context;main]"..
"listring[current_player;main]"
end
minetest.register_node("techage:ta3_silo", {
description = S("TA3 Silo"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_silo.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_silo.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_silo.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_silo.png",
},
on_construct = function(pos)
local inv = M(pos):get_inventory()
inv:set_size('main', INV_SIZE)
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local number = techage.add_node(pos, "techage:ta3_silo")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem))
meta:set_string("infotext", S("TA3 Silo").." "..number)
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
end,
on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem))
return mem.countdown > 0
end
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
techage.remove_node(pos)
end,
liquid = {
capa = 0,
peek = function(pos, indir)
local mem = tubelib2.get_mem(pos)
local inv = M(pos):get_inventory()
if not inv:is_empty("main") then
return mem.item_name or get_item_name(mem, inv)
end
end,
put = function(pos, indir, name, amount)
local inv = M(pos):get_inventory()
local stack = ItemStack(name.." "..amount)
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
return 0
end
return amount
end,
take = function(pos, indir, name, amount)
local inv = M(pos):get_inventory()
local stack = ItemStack(name.." "..amount)
if inv:contains_item("main", stack) then
inv:room_for_item("main", stack)
return amount, name
end
return 0
end,
},
networks = {
pipe = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
},
can_dig = can_dig,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, {
on_pull_item = function(pos, in_dir, num)
local inv = M(pos):get_inventory()
if not inv:is_empty("main") then
return techage.get_items(inv, "main", num)
end
end,
on_push_item = function(pos, in_dir, stack)
local inv = M(pos):get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
return true
end
return false
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = M(pos)
local inv = meta:get_inventory()
return techage.put_items(inv, "main", stack)
end,
on_recv_message = function(pos, src, topic, payload)
if topic == "state" then
local meta = M(pos)
local inv = meta:get_inventory()
return techage.get_inv_state(inv, "main")
else
return "unsupported"
end
end,
})
Pipe:add_secondary_node_names({"techage:ta3_silo", "techage:ta4_silo"})
minetest.register_craft({
output = "techage:ta3_silo",
recipe = {
{"", "", ""},
{"techage:tubeS", "techage:chest_ta3", "techage:ta3_pipeS"},
{"", "", ""},
},
})
minetest.register_craft({
output = "techage:ta4_silo",
recipe = {
{"default:tin_ingot", "dye:blue", "default:steel_ingot"},
{"", "techage:ta3_silo", ""},
{"", "", ""},
},
})