2019-03-09 15:42:51 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-03-09 15:42:51 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA2/TA3/TA4 Pusher
|
2020-03-22 13:01:44 +03:00
|
|
|
Nodes for push/pull operation of StackItems from chests or other
|
2019-03-09 15:42:51 +03:00
|
|
|
inventory/server nodes to tubes or other inventory/server nodes.
|
|
|
|
|
|
|
|
+--------+
|
|
|
|
/ /|
|
|
|
|
+--------+ |
|
|
|
|
IN (L) -->| |X--> OUT (R)
|
|
|
|
| PUSHER | +
|
|
|
|
| |/
|
|
|
|
+--------+
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
|
|
|
|
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-03-09 15:42:51 +03:00
|
|
|
|
2020-04-13 14:20:38 +03:00
|
|
|
local STANDBY_TICKS = 2
|
2020-04-05 13:36:32 +03:00
|
|
|
local COUNTDOWN_TICKS = 4
|
2019-03-09 15:42:51 +03:00
|
|
|
local CYCLE_TIME = 2
|
|
|
|
|
2020-03-22 13:01:44 +03:00
|
|
|
local function ta4_formspec(self, pos, nvm)
|
|
|
|
if CRD(pos).stage == 4 then -- TA4 node?
|
|
|
|
return "size[8,7.2]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"box[0,-0.1;7.8,0.5;#c6e8ff]"..
|
|
|
|
"label[3,-0.1;"..minetest.colorize("#000000", S("Pusher")).."]"..
|
|
|
|
techage.question_mark_help(8, S("Optionally configure\nthe pusher with one item"))..
|
|
|
|
"list[context;main;3.5,1;1,1;]"..
|
|
|
|
"image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
|
|
|
|
"list[current_player;main;0,3.5;8,4;]"..
|
|
|
|
"listring[context;main]"..
|
|
|
|
"listring[current_player;main]"
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2020-03-31 19:27:15 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if CRD(pos).State:get_state(nvm) ~= techage.STOPPED then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-03-22 13:01:44 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local list = inv:get_list(listname)
|
|
|
|
if list[index]:get_count() == 0 then
|
|
|
|
stack:set_count(1)
|
|
|
|
inv:set_stack(listname, index, stack)
|
|
|
|
return 0
|
|
|
|
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
|
|
|
|
|
2020-03-31 19:27:15 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if CRD(pos).State:get_state(nvm) ~= techage.STOPPED then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-03-22 13:01:44 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_stack(listname, index, nil)
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local function pushing(pos, crd, meta, nvm)
|
2019-03-09 21:26:15 +03:00
|
|
|
local pull_dir = meta:get_int("pull_dir")
|
|
|
|
local push_dir = meta:get_int("push_dir")
|
2020-03-22 13:01:44 +03:00
|
|
|
local items = techage.pull_items(pos, pull_dir, nvm.item_count or crd.num_items, nvm.item_name)
|
2019-03-09 21:26:15 +03:00
|
|
|
if items ~= nil then
|
2019-04-28 22:34:21 +03:00
|
|
|
if techage.push_items(pos, push_dir, items) ~= true then
|
2019-03-09 21:26:15 +03:00
|
|
|
-- place item back
|
|
|
|
techage.unpull_items(pos, pull_dir, items)
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:blocked(pos, nvm)
|
2019-03-09 21:26:15 +03:00
|
|
|
return
|
|
|
|
end
|
2020-03-22 13:01:44 +03:00
|
|
|
if nvm.item_count then -- remote job?
|
|
|
|
nvm.item_count = nil
|
|
|
|
nvm.item_name = nil
|
|
|
|
crd.State:stop(pos, nvm)
|
2020-04-15 19:08:05 +03:00
|
|
|
local number = M(pos):get_string("node_number")
|
|
|
|
techage.send_single(number, nvm.rmt_num, "off")
|
2020-03-22 13:01:44 +03:00
|
|
|
else
|
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
|
|
|
end
|
2019-03-09 21:26:15 +03:00
|
|
|
return
|
|
|
|
end
|
2020-01-26 01:15:44 +03:00
|
|
|
crd.State:idle(pos, nvm)
|
2019-03-09 21:26:15 +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)
|
2020-01-26 01:15:44 +03:00
|
|
|
pushing(pos, crd, M(pos), nvm)
|
|
|
|
crd.State:is_active(nvm)
|
2019-03-09 21:26:15 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_rightclick(pos, node, clicker)
|
2020-03-22 13:01:44 +03:00
|
|
|
if CRD(pos).stage ~= 4 then -- Not TA4 node?
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
|
|
|
if CRD(pos).State:get_state(nvm) == techage.STOPPED then
|
|
|
|
CRD(pos).State:start(pos, nvm)
|
|
|
|
else
|
|
|
|
CRD(pos).State:stop(pos, nvm)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if CRD(pos).stage == 4 then -- TA4 node?
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
CRD(pos).State:state_button_event(pos, nvm, fields)
|
|
|
|
M(pos):set_string("formspec", ta4_formspec(CRD(pos).State, pos, nvm))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function can_start(pos, nvm, state)
|
|
|
|
if CRD(pos).stage == 4 then -- TA4 node?
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local name = inv:get_stack("main", 1):get_name()
|
|
|
|
if name ~= "" then
|
|
|
|
nvm.item_name = name
|
2019-05-21 18:46:59 +03:00
|
|
|
else
|
2020-03-22 13:01:44 +03:00
|
|
|
nvm.item_name = nil
|
2019-03-09 21:26:15 +03:00
|
|
|
end
|
2020-03-22 13:01:44 +03:00
|
|
|
else
|
|
|
|
nvm.item_name = nil
|
2019-03-09 21:26:15 +03:00
|
|
|
end
|
2020-03-22 13:01:44 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function config_item(pos, payload)
|
|
|
|
local name, count = unpack(payload:split(" "))
|
|
|
|
if name and (minetest.registered_nodes[name] or minetest.registered_items[name]
|
|
|
|
or minetest.registered_craftitems[name]) then
|
|
|
|
count = tonumber(count) or 1
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_stack("main", 1, {name = name, count = 1})
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
return 0
|
2019-03-09 21:26:15 +03:00
|
|
|
end
|
|
|
|
|
2019-03-17 17:33:13 +03:00
|
|
|
local tiles = {}
|
|
|
|
-- '#' will be replaced by the stage number
|
|
|
|
-- '{power}' will be replaced by the power PNG
|
|
|
|
tiles.pas = {
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.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_appl_pusher.png^[transformR180]^techage_frame_ta#.png",
|
|
|
|
"techage_appl_pusher.png^techage_frame_ta#.png",
|
|
|
|
}
|
|
|
|
tiles.act = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.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_appl_pusher14.png^[transformR180]^techage_frame14_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_appl_pusher14.png^techage_frame14_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local tubing = {
|
2019-10-27 13:14:37 +03:00
|
|
|
-- push item through the pusher in opposit direction
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
return in_dir == M(pos):get_int("pull_dir") and techage.push_items(pos, in_dir, stack)
|
|
|
|
end,
|
2019-03-17 17:33:13 +03:00
|
|
|
is_pusher = true, -- is a pulling/pushing node
|
|
|
|
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2020-03-22 13:01:44 +03:00
|
|
|
if topic == "pull" then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
CRD(pos).State:stop(pos, nvm)
|
|
|
|
nvm.item_count = math.min(config_item(pos, payload), 12)
|
2020-04-15 19:08:05 +03:00
|
|
|
nvm.rmt_num = src
|
2020-03-22 13:01:44 +03:00
|
|
|
CRD(pos).State:start(pos, nvm)
|
|
|
|
return true
|
|
|
|
elseif topic == "config" then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
CRD(pos).State:stop(pos, nvm)
|
|
|
|
config_item(pos, payload)
|
|
|
|
CRD(pos).State:start(pos, nvm)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return CRD(pos).State:on_receive_message(pos, topic, payload)
|
|
|
|
end
|
2019-03-17 17:33:13 +03:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
local node_name_ta2, node_name_ta3, node_name_ta4 =
|
2019-07-02 22:33:12 +03:00
|
|
|
techage.register_consumer("pusher", S("Pusher"), tiles, {
|
2019-03-09 15:42:51 +03:00
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
2020-03-22 13:01:44 +03:00
|
|
|
formspec = ta4_formspec,
|
2019-03-17 17:33:13 +03:00
|
|
|
tubing = tubing,
|
2020-03-22 13:01:44 +03:00
|
|
|
can_start = can_start,
|
2019-03-09 15:42:51 +03:00
|
|
|
after_place_node = function(pos, placer)
|
2019-03-09 21:26:15 +03:00
|
|
|
local meta = M(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
meta:set_int("pull_dir", techage.side_to_outdir("L", node.param2))
|
|
|
|
meta:set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
2020-03-22 13:01:44 +03:00
|
|
|
if CRD(pos).stage == 4 then -- TA4 node?
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_size('main', 1)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
M(pos):set_string("formspec", ta4_formspec(CRD(pos).State, pos, nvm))
|
|
|
|
end
|
2019-03-09 15:42:51 +03:00
|
|
|
end,
|
|
|
|
|
2020-03-22 13:01:44 +03:00
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
2019-03-09 21:26:15 +03:00
|
|
|
on_rightclick = on_rightclick,
|
2020-03-22 13:01:44 +03:00
|
|
|
on_receive_fields = on_receive_fields,
|
2019-03-17 17:33:13 +03:00
|
|
|
node_timer = keep_running,
|
2019-03-09 15:42:51 +03:00
|
|
|
on_rotate = screwdriver.disallow,
|
2019-03-09 21:26:15 +03:00
|
|
|
|
2019-03-17 17:33:13 +03:00
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
2019-03-09 15:42:51 +03:00
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2020-03-22 13:01:44 +03:00
|
|
|
num_items = {0,2,6,12},
|
2019-03-09 15:42:51 +03:00
|
|
|
})
|
|
|
|
|
2019-03-10 13:36:00 +03:00
|
|
|
minetest.register_craft({
|
2019-03-17 17:33:13 +03:00
|
|
|
output = node_name_ta2.." 2",
|
2019-03-10 13:36:00 +03:00
|
|
|
recipe = {
|
2019-04-28 17:04:45 +03:00
|
|
|
{"group:wood", "wool:dark_green", "group:wood"},
|
|
|
|
{"techage:tubeS", "default:mese_crystal", "techage:tubeS"},
|
|
|
|
{"group:wood", "techage:iron_ingot", "group:wood"},
|
2019-03-10 13:36:00 +03:00
|
|
|
},
|
|
|
|
})
|
2019-05-11 02:21:03 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta3,
|
|
|
|
recipe = {
|
|
|
|
{"", "techage:iron_ingot", ""},
|
|
|
|
{"", node_name_ta2, ""},
|
|
|
|
{"", "techage:vacuum_tube", ""},
|
|
|
|
},
|
|
|
|
})
|
2019-07-02 22:33:12 +03:00
|
|
|
|
2020-03-17 23:43:30 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = node_name_ta4,
|
|
|
|
recipe = {
|
|
|
|
{"", "techage:iron_ingot", ""},
|
|
|
|
{"", node_name_ta3, ""},
|
|
|
|
{"", "techage:ta4_wlanchip", ""},
|
|
|
|
},
|
|
|
|
})
|
2019-07-02 22:33:12 +03:00
|
|
|
|