2019-05-02 00:01:14 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2022-06-05 22:20:43 +03:00
|
|
|
Copyright (C) 2019-2022 Joachim Stolberg
|
2019-05-02 00:01:14 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-05-02 00:01:14 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA2/TA3/TA4 Electronic Fab
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-05-02 00:01:14 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-05-21 14:15:13 +03:00
|
|
|
-- Consumer Related Data
|
2019-10-07 01:09:39 +03:00
|
|
|
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
2019-05-02 00:01:14 +03:00
|
|
|
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2020-04-05 13:36:32 +03:00
|
|
|
local STANDBY_TICKS = 3
|
|
|
|
local COUNTDOWN_TICKS = 4
|
2019-05-02 00:01:14 +03:00
|
|
|
local CYCLE_TIME = 6
|
|
|
|
|
2019-11-10 23:08:37 +03:00
|
|
|
local recipes = techage.recipes
|
2019-05-02 00:01:14 +03:00
|
|
|
|
2020-02-29 21:20:54 +03:00
|
|
|
local RecipeType = {
|
|
|
|
[2] = "ta2_electronic_fab",
|
2019-11-10 23:08:37 +03:00
|
|
|
[3] = "ta3_electronic_fab",
|
|
|
|
[4] = "ta4_electronic_fab",
|
2019-05-02 00:01:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local function formspec(self, pos, nvm)
|
2019-11-10 23:08:37 +03:00
|
|
|
local rtype = RecipeType[CRD(pos).stage]
|
2021-12-25 18:12:09 +03:00
|
|
|
local owner = M(pos):get_string("owner")
|
2019-11-10 23:08:37 +03:00
|
|
|
return "size[8.4,8.4]"..
|
2021-12-25 18:12:09 +03:00
|
|
|
"list[context;src;0,0;2,4;]"..
|
|
|
|
recipes.formspec(2.2, 0, rtype, nvm, owner)..
|
|
|
|
"list[context;dst;6.4,0;2,4;]"..
|
|
|
|
"image_button[3.7,3.3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[3.7,3.3;1,1;"..self:get_state_tooltip(nvm).."]"..
|
|
|
|
"list[current_player;main;0.2,4.5;8,4;]"..
|
|
|
|
"listring[context;dst]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;src]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0.2, 4.5)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2019-05-21 14:15:13 +03:00
|
|
|
local crd = CRD(pos)
|
2019-11-10 23:08:37 +03:00
|
|
|
if listname == "src" then
|
2019-05-21 14:15:13 +03:00
|
|
|
crd.State:start_if_standby(pos)
|
2019-05-02 00:01:14 +03:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local stack = inv:get_stack(from_list, from_index)
|
|
|
|
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
|
|
|
|
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
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local function making(pos, crd, nvm, inv)
|
2022-05-02 20:21:27 +03:00
|
|
|
local owner = M(pos):get_string("owner")
|
2019-11-10 23:08:37 +03:00
|
|
|
local rtype = RecipeType[crd.stage]
|
2022-05-02 20:21:27 +03:00
|
|
|
local recipe = recipes.get(nvm, rtype, owner)
|
2019-11-10 23:08:37 +03:00
|
|
|
local output = ItemStack(recipe.output.name.." "..recipe.output.num)
|
|
|
|
if inv:room_for_item("dst", output) then
|
|
|
|
for _,item in ipairs(recipe.input) do
|
|
|
|
local input = ItemStack(item.name.." "..item.num)
|
|
|
|
if not inv:contains_item("src", input) then
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:idle(pos, nvm)
|
2019-05-02 00:01:14 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2019-11-10 23:08:37 +03:00
|
|
|
for _,item in ipairs(recipe.input) do
|
|
|
|
local input = ItemStack(item.name.." "..item.num)
|
|
|
|
inv:remove_item("src", input)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
2019-11-10 23:08:37 +03:00
|
|
|
inv:add_item("dst", output)
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2019-05-02 00:01:14 +03:00
|
|
|
return
|
|
|
|
end
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:idle(pos, nvm)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function keep_running(pos, elapsed)
|
2020-01-26 01:15:44 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-05-21 14:15:13 +03:00
|
|
|
local crd = CRD(pos)
|
2019-05-02 00:01:14 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if inv then
|
2020-01-26 01:15:44 +03:00
|
|
|
making(pos, crd, nvm, inv)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-11-10 23:08:37 +03:00
|
|
|
local crd = CRD(pos)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
|
|
|
if not nvm.running then
|
2019-11-10 23:08:37 +03:00
|
|
|
recipes.on_receive_fields(pos, formname, fields, player)
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:state_button_event(pos, nvm, fields)
|
|
|
|
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function can_dig(pos, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return inv:is_empty("dst") and inv:is_empty("src")
|
|
|
|
end
|
|
|
|
|
|
|
|
local tiles = {}
|
|
|
|
-- '#' will be replaced by the stage number
|
|
|
|
tiles.pas = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
|
|
|
|
"techage_filling_ta#.png^techage_appl_electronic_fab.png^techage_frame_ta#.png",
|
|
|
|
"techage_filling_ta#.png^techage_appl_electronic_fab.png^techage_frame_ta#.png",
|
|
|
|
}
|
|
|
|
tiles.act = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta#.png^techage_appl_electronic_fab4.png^techage_frame4_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta#.png^techage_appl_electronic_fab4.png^techage_frame4_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local tubing = {
|
2021-03-08 23:27:51 +03:00
|
|
|
on_inv_request = function(pos, in_dir, access_type)
|
|
|
|
if access_type == "push" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
|
|
|
return meta:get_inventory(), "src"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
2019-05-02 00:01:14 +03:00
|
|
|
on_pull_item = function(pos, in_dir, num)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("pull_dir") == in_dir then
|
|
|
|
local inv = M(pos):get_inventory()
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.get_items(pos, inv, "dst", num)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
end,
|
2020-04-13 14:20:38 +03:00
|
|
|
on_push_item = function(pos, in_dir, stack, idx)
|
2019-05-02 00:01:14 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
|
|
|
local inv = M(pos):get_inventory()
|
2020-04-13 23:55:49 +03:00
|
|
|
--CRD(pos).State:start_if_standby(pos) -- would need power!
|
2020-04-13 14:20:38 +03:00
|
|
|
return techage.put_items(inv, "src", stack, idx)
|
2019-05-02 00:01:14 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("pull_dir") == in_dir then
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return techage.put_items(inv, "dst", stack)
|
|
|
|
end
|
|
|
|
end,
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2020-02-28 00:33:42 +03:00
|
|
|
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
2019-05-02 00:01:14 +03:00
|
|
|
end,
|
2022-06-05 22:20:43 +03:00
|
|
|
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
|
|
|
return CRD(pos).State:on_beduino_receive_cmnd(pos, topic, payload)
|
|
|
|
end,
|
|
|
|
on_beduino_request_data = function(pos, src, topic, payload)
|
|
|
|
return CRD(pos).State:on_beduino_request_data(pos, topic, payload)
|
|
|
|
end,
|
2021-05-14 19:38:08 +03:00
|
|
|
on_node_load = function(pos)
|
|
|
|
CRD(pos).State:on_node_load(pos)
|
|
|
|
end,
|
2019-05-02 00:01:14 +03:00
|
|
|
}
|
|
|
|
|
2022-01-03 23:40:31 +03:00
|
|
|
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
2019-07-02 22:33:12 +03:00
|
|
|
techage.register_consumer("electronic_fab", S("Electronic Fab"), tiles, {
|
2019-05-02 00:01:14 +03:00
|
|
|
drawtype = "normal",
|
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec = formspec,
|
|
|
|
tubing = tubing,
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local inv = M(pos):get_inventory()
|
2019-11-10 23:08:37 +03:00
|
|
|
inv:set_size("src", 8)
|
|
|
|
inv:set_size("dst", 8)
|
2019-05-02 00:01:14 +03:00
|
|
|
end,
|
|
|
|
can_dig = can_dig,
|
|
|
|
node_timer = keep_running,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
num_items = {0,1,1,1},
|
2020-04-25 22:06:19 +03:00
|
|
|
power_consumption = {0,8,12,12},
|
2020-03-17 23:43:30 +03:00
|
|
|
},
|
2020-03-27 21:44:19 +03:00
|
|
|
{false, true, true, true}) -- TA2/TA3/TA4
|
2019-05-02 00:01:14 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta2,
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "default:diamond", "group:wood"},
|
|
|
|
{"techage:tubeS", "basic_materials:gear_steel", "techage:tubeS"},
|
2019-05-04 23:31:53 +03:00
|
|
|
{"group:wood", "default:steel_ingot", "group:wood"},
|
2019-05-02 00:01:14 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-05-11 17:52:59 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta3,
|
|
|
|
recipe = {
|
|
|
|
{"", "default:diamond", ""},
|
|
|
|
{"", node_name_ta2, ""},
|
|
|
|
{"", "techage:vacuum_tube", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-03-27 21:44:19 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta4,
|
|
|
|
recipe = {
|
|
|
|
{"", "default:diamond", ""},
|
|
|
|
{"", node_name_ta3, ""},
|
|
|
|
{"", "techage:ta4_wlanchip", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-12-25 19:18:34 +03:00
|
|
|
techage.recipes.register_craft_type("ta2_electronic_fab", {
|
|
|
|
description = S("TA2 Ele Fab"),
|
|
|
|
icon = 'techage_filling_ta2.png^techage_appl_electronic_fab.png^techage_frame_ta2.png',
|
|
|
|
width = 2,
|
|
|
|
height = 2,
|
|
|
|
})
|
|
|
|
techage.recipes.register_craft_type("ta3_electronic_fab", {
|
|
|
|
description = S("TA3 Ele Fab"),
|
|
|
|
icon = 'techage_filling_ta3.png^techage_appl_electronic_fab.png^techage_frame_ta3.png',
|
|
|
|
width = 2,
|
|
|
|
height = 2,
|
|
|
|
})
|
|
|
|
techage.recipes.register_craft_type("ta4_electronic_fab", {
|
|
|
|
description = S("TA4 Ele Fab"),
|
|
|
|
icon = 'techage_filling_ta4.png^techage_appl_electronic_fab.png^techage_frame_ta4.png',
|
|
|
|
width = 2,
|
|
|
|
height = 2,
|
|
|
|
})
|