cart detector and funnel added

This commit is contained in:
Joachim Stolberg 2019-08-29 21:43:00 +02:00
parent 70e4f11665
commit 2267f00fec
18 changed files with 376 additions and 14 deletions

182
basic_machines/funnel.lua Normal file
View File

@ -0,0 +1,182 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Funnel
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local CYCLE_TIME = 2
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
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
local function formspec()
return "size[9,7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;main;0.5,0;8,2;]"..
"list[current_player;main;0.5,3.3;8,4;]"..
"listring[context;main]"..
"listring[current_player;main]"
end
local function scan_for_objects(pos, elapsed)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local lua_entity = object:get_luaentity()
if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
local obj_pos = object:getpos()
if lua_entity.itemstring ~= "" and ((obj_pos.y - pos.y) >= 0.4) then
local stack = ItemStack(lua_entity.itemstring)
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
object:remove()
end
end
end
end
return true
end
minetest.register_node("techage:ta3_funnel", {
description = "TA3 Funnel",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_appl_funnel_top.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_funnel.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_funnel.png^techage_frame_ta3.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-8/16, -8/16, -8/16, 8/16, 8/16, -6/16},
{-8/16, -8/16, 6/16, 8/16, 8/16, 8/16},
{-8/16, -8/16, -8/16, -6/16, 8/16, 8/16},
{ 6/16, -8/16, -8/16, 8/16, 8/16, 8/16},
{-6/16, -8/16, -6/16, 6/16, 4/16, 6/16},
},
},
selection_box = {
type = "fixed",
fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
},
on_construct = function(pos)
local meta = M(pos)
local inv = meta:get_inventory()
inv:set_size('main', 16)
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local own_num = techage.add_node(pos, "techage:ta3_funnel")
local node = minetest.get_node(pos)
meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "TA3 Funnel "..own_num)
meta:set_string("formspec", formspec())
meta:set_int("pull_dir", techage.side_to_indir("R", node.param2))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
on_timer = scan_for_objects,
on_rotate = screwdriver.disallow,
can_dig = function(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("main")
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.register_node({"techage:ta3_funnel"}, {
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()
return techage.get_items(inv, "main", num)
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, "main", stack)
end
end,
on_recv_message = function(pos, src, topic, payload)
if topic == "state" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return techage.get_inv_state(inv, "main")
else
return "unsupported"
end
end,
on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
})
minetest.register_craft({
output = "techage:ta3_funnel",
recipe = {
{"group:wood", "", "group:wood"},
{"group:wood", "default:mese_crystal", "techage:tubeS"},
{"group:wood", "techage:iron_ingot", "group:wood"},
},
})
techage.register_entry_page("ta3m", "funnel",
S("TA3 Funnel"),
S("The Funnel collects dropped items and stores them in its inventory.@n"..
"Items are sucked up when they are dropped on top of the funnel block.@n"..
"The scan radius is 1 m."),
"techage:ta3_funnel")

View File

@ -136,7 +136,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
stage = stage,
State = tState,
-- number of items to be processed per cycle
num_items = tNode.num_items[stage],
num_items = tNode.num_items and tNode.num_items[stage],
power_consumption = power_used and
tNode.power_consumption[stage] or 0,
node_timer = tNode.node_timer,

View File

@ -102,12 +102,12 @@ techage.register_category_page("ta3m",
S("TA3: Machines"),
S("Collection of TA3 machines, some with eletrical power supply."),
"techage:ta3_autocrafter_pas",
{"pusher", "distributor", "chest", "grinder", "gravelsieve", "autocrafter", "electronic_fab"}
{"pusher", "distributor", "chest", "grinder", "gravelsieve", "autocrafter", "electronic_fab", "funnel"}
)
techage.register_category_page("ta3l",
S("TA3: Logic"),
S("Collection of TA3 logic blocks to control your machines."),
"techage:terminal2",
{"terminal", "button", "detector", "repeater", "logic", "node_detector", "player_detector", "programmer"}
{"terminal", "button", "detector", "repeater", "logic", "node_detector", "player_detector", "cart_detector", "programmer"}
)

View File

@ -101,6 +101,7 @@ else
dofile(MP.."/basic_machines/chest.lua")
dofile(MP.."/basic_machines/autocrafter.lua")
dofile(MP.."/basic_machines/electronic_fab.lua")
dofile(MP.."/basic_machines/funnel.lua")
-- Coal power station
dofile(MP.."/coal_power_station/firebox.lua")
@ -164,6 +165,7 @@ else
dofile(MP.."/logic/lua_logic.lua")
dofile(MP.."/logic/node_detector.lua")
dofile(MP.."/logic/player_detector.lua")
dofile(MP.."/logic/cart_detector.lua")
-- Test
dofile(MP.."/recipe_checker.lua")

View File

@ -81,7 +81,6 @@ minetest.register_node("techage:ta3_button_off", {
if not techage.check_numbers(fields.numbers, player:get_player_name()) then
return
end
print(dump(fields))
meta:set_string("numbers", fields.numbers)
if fields.public then
meta:set_string("public", fields.public)

173
logic/cart_detector.lua Normal file
View File

@ -0,0 +1,173 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Cart Detector/Starter
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local logic = techage.logic
local CYCLE_TIME = 2
local function switch_on(pos)
if logic.swap_node(pos, "techage:ta3_cartdetector_on") then
logic.send_on(pos, M(pos))
end
end
local function switch_off(pos)
if logic.swap_node(pos, "techage:ta3_cartdetector_off") then
logic.send_off(pos, M(pos))
end
end
local function check_cart(pos)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if object:get_entity_name() == "minecart:cart" then
return true
end
end
return false
end
local function punch_cart(pos)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if object:get_entity_name() == "minecart:cart" then
object:punch(object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 1},
}, minetest.facedir_to_dir(0))
break -- start only one cart
end
end
end
local function node_timer(pos)
if check_cart(pos)then
switch_on(pos)
else
switch_off(pos)
end
return true
end
local function formspec(meta)
local numbers = meta:get_string("numbers") or ""
return "size[7.5,4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"button_exit[2,2.2;3,1;accept;"..S("accept").."]"
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local meta = minetest.get_meta(pos)
if fields.accept then
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Cart Detector"))
end
meta:set_string("formspec", formspec(meta))
end
end
local function techage_set_numbers(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Cart Detector"))
meta:set_string("formspec", formspec(meta))
return res
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
end
minetest.register_node("techage:ta3_cartdetector_off", {
description = S("TA3 Cart Detector"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_cartdetector.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
logic.after_place_node(pos, placer, "techage:ta3_cartdetector_off", S("TA3 Player Detector"))
logic.infotext(meta, S("TA3 Cart Detector"))
meta:set_string("formspec", formspec(meta))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
on_receive_fields = on_receive_fields,
on_timer = node_timer,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
minetest.register_node("techage:ta3_cartdetector_on", {
description = "TA3 Cart Detector",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_cartdetector_on.png",
},
on_receive_fields = on_receive_fields,
on_timer = node_timer,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
drop = "techage:ta3_cartdetector_off"
})
minetest.register_craft({
output = "techage:ta3_cartdetector_off",
recipe = {
{"", "group:wood", "default:mese_crystal"},
{"", "default:copper_ingot", "techage:vacuum_tube"},
{"", "group:wood", "basic_materials:motor"},
},
})
techage.register_node({"techage:ta3_cartdetector_off", "techage:ta3_cartdetector_on"}, {
on_recv_message = function(pos, src, topic, payload)
if topic == "on" then
punch_cart(pos)
else
return "unsupported"
end
end,
on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
})
techage.register_entry_page("ta3l", "cart_detector",
S("TA3 Cart Detector"),
S("The Cart Detector sends a 'on' signal if a cart (Minecart) is nearby@n"..
"In addition the node starts the cart again, if a 'on' signal is received.@n"),
"techage:ta3_cartdetector_off")

View File

@ -240,7 +240,7 @@ techage.register_node({"techage:ta3_logic"}, {
mem.inp_tbl.inp = false
mem.inp_tbl["n"..src] = false
else
return
return "unsupported"
end
minetest.get_node_timer(pos):start(0.1)
end,

View File

@ -41,13 +41,13 @@ local function formspec(meta, mem)
local numbers = meta:get_string("numbers") or ""
local label = S("added")..","..S("removed")..","..S("added or removed")
return "size[7.5,4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"field[0.5,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"label[0.2,1.6;"..S("Send signal if nodes have been:").."]"..
"dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(mem.mode or 3).."]"..
"button_exit[2,3.2;3,1;accept;"..S("accept").."]"
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"field[0.5,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"label[0.2,1.6;"..S("Send signal if nodes have been:").."]"..
"dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(mem.mode or 3).."]"..
"button_exit[2,3.2;3,1;accept;"..S("accept").."]"
end
local function any_node_changed(pos)

View File

@ -191,6 +191,8 @@ techage.register_node({"techage:ta3_playerdetector_off", "techage:ta3_playerdete
if topic == "name" then
local mem = tubelib2.get_mem(pos)
return mem.player_name or ""
else
return "unsupported"
end
end,
on_node_load = function(pos)
@ -203,4 +205,4 @@ techage.register_entry_page("ta3l", "player_detector",
S("The Player Detector sends a 'on' signal when it detects a player@n"..
"within a radius of 4 m around the node.@n"..
"The detector can be configured with player names to scan for."),
"techage:ta3_playerdetector_on")
"techage:ta3_playerdetector_off")

View File

@ -210,7 +210,7 @@ minetest.register_node("techage:ta3_sequencer", {
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
logic.after_place_node(pos, placer, "techage:ta3_sequencer", S("TA3 Sequencer"))
logic.infotext(meta, S("TA3 Sequencer", "stopped"))
logic.infotext(meta, S("TA3 Sequencer"), S("stopped"))
mem.rules = new_rules()
mem.index = 1
mem.running = false
@ -258,6 +258,8 @@ techage.register_node({"techage:ta3_sequencer"}, {
-- do not stop immediately
local mem = tubelib2.get_mem(pos)
mem.endless = false
else
return "unsupported"
end
end,
on_node_load = function(pos)

View File

@ -119,6 +119,8 @@ techage.register_node({"techage:signal_lamp_off", "techage:signal_lamp_on"}, {
elseif topic == "off" then
local node = minetest.get_node(pos)
switch_off(pos, node)
else
return "unsupported"
end
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 B

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 B

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B

After

Width:  |  Height:  |  Size: 248 B