2014-11-19 19:27:42 +01:00
|
|
|
local function sendMessage(pos, msg, channel)
|
2014-01-26 08:48:46 +01:00
|
|
|
if channel == nil then
|
|
|
|
channel = minetest.get_meta(pos):get_string("channel")
|
|
|
|
end
|
2017-03-01 04:57:58 +01:00
|
|
|
digilines:receptor_send(pos,digilines.rules.default,channel,msg)
|
2014-01-26 08:48:46 +01:00
|
|
|
end
|
|
|
|
|
2014-11-19 19:27:42 +01:00
|
|
|
local function maybeString(stack)
|
2014-01-26 08:48:46 +01:00
|
|
|
if type(stack)=='string' then return stack
|
|
|
|
elseif type(stack)=='table' then return dump(stack)
|
|
|
|
else return stack:to_string()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-19 19:27:42 +01:00
|
|
|
local function can_insert(pos, stack)
|
|
|
|
local can = minetest.get_meta(pos):get_inventory():room_for_item("main", stack)
|
|
|
|
if can then
|
|
|
|
sendMessage(pos,"put "..maybeString(stack))
|
|
|
|
else
|
|
|
|
-- overflow and lost means that items are gonna be out as entities :/
|
|
|
|
sendMessage(pos,"lost "..maybeString(stack))
|
|
|
|
end
|
|
|
|
return can
|
|
|
|
end
|
|
|
|
|
|
|
|
local tubeconn = minetest.get_modpath("pipeworks") and "^pipeworks_tube_connection_wooden.png" or ""
|
|
|
|
local tubescan = minetest.get_modpath("pipeworks") and function(pos) pipeworks.scan_for_tube_objects(pos) end or nil
|
|
|
|
|
2016-05-28 01:08:53 +02:00
|
|
|
minetest.register_alias("digilines_inventory:chest", "digilines:chest")
|
|
|
|
minetest.register_node("digilines:chest", {
|
2014-01-26 08:48:46 +01:00
|
|
|
description = "Digiline Chest",
|
2014-11-19 19:27:42 +01:00
|
|
|
tiles = {
|
|
|
|
"default_chest_top.png"..tubeconn,
|
|
|
|
"default_chest_top.png"..tubeconn,
|
|
|
|
"default_chest_side.png"..tubeconn,
|
|
|
|
"default_chest_side.png"..tubeconn,
|
|
|
|
"default_chest_side.png"..tubeconn,
|
|
|
|
"default_chest_front.png",
|
2014-01-26 08:48:46 +01:00
|
|
|
},
|
2014-11-19 19:27:42 +01:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
legacy_facedir_simple = true,
|
|
|
|
groups = {choppy=2, oddly_breakable_by_hand=2, tubedevice=1, tubedevice_receiver=1},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2014-01-26 08:48:46 +01:00
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-19 19:27:42 +01:00
|
|
|
meta:set_string("infotext", "Digiline Chest")
|
|
|
|
meta:set_string("formspec", "size[8,10]"..
|
|
|
|
((default and default.gui_bg) or "")..
|
|
|
|
((default and default.gui_bg_img) or "")..
|
|
|
|
((default and default.gui_slots) or "")..
|
|
|
|
"label[0,0;Digiline Chest]"..
|
|
|
|
"list[current_name;main;0,1;8,4;]"..
|
|
|
|
"field[2,5.5;5,1;channel;Channel;${channel}]"..
|
|
|
|
((default and default.get_hotbar_bg) and default.get_hotbar_bg(0,6) or "")..
|
|
|
|
"list[current_player;main;0,6;8,4;]")
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8*4)
|
|
|
|
end,
|
|
|
|
after_place_node = tubescan,
|
|
|
|
after_dig_node = tubescan,
|
|
|
|
can_dig = function(pos, player)
|
|
|
|
return minetest.get_meta(pos):get_inventory():is_empty("main")
|
2014-01-26 08:48:46 +01:00
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
2016-05-23 20:13:24 +02:00
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
2014-06-05 07:55:29 +02:00
|
|
|
if fields.channel ~= nil then
|
|
|
|
minetest.get_meta(pos):set_string("channel",fields.channel)
|
|
|
|
end
|
2014-01-26 08:48:46 +01:00
|
|
|
end,
|
2014-11-19 19:27:42 +01:00
|
|
|
digiline = {
|
|
|
|
receptor = {},
|
|
|
|
effector = {
|
|
|
|
action = function(pos,node,channel,msg) end
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tube = {
|
|
|
|
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1},
|
2014-01-26 08:48:46 +01:00
|
|
|
connects = function(i,param2)
|
|
|
|
return not pipeworks.connects.facingFront(i,param2)
|
|
|
|
end,
|
2014-11-19 19:27:42 +01:00
|
|
|
input_inventory = "main",
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
return can_insert(pos, stack)
|
|
|
|
end,
|
2014-01-26 08:48:46 +01:00
|
|
|
insert_object = function(pos, node, stack, direction)
|
2014-11-19 19:27:42 +01:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
local leftover = inv:add_item("main", stack)
|
2014-01-26 08:48:46 +01:00
|
|
|
local count = leftover:get_count()
|
|
|
|
if count == 0 then
|
|
|
|
local derpstack = stack:get_name()..' 1'
|
2014-11-19 19:27:42 +01:00
|
|
|
if not inv:room_for_item("main", derpstack) then
|
2014-01-26 08:48:46 +01:00
|
|
|
-- when you can't put a single more of whatever you just put,
|
|
|
|
-- you'll get a put for it, then a full
|
|
|
|
sendMessage(pos,"full "..maybeString(stack)..' '..tostring(count))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- this happens when the chest has received two stacks in a row and
|
|
|
|
-- filled up exactly with the first one.
|
|
|
|
-- You get a put for the first stack, a put for the second
|
|
|
|
-- and then a overflow with the first in stack and the second in leftover
|
|
|
|
-- and NO full?
|
|
|
|
sendMessage(pos,"overflow "..maybeString(stack)..' '..tostring(count))
|
|
|
|
end
|
|
|
|
return leftover
|
|
|
|
end,
|
2014-11-19 19:27:42 +01:00
|
|
|
},
|
2014-01-26 08:48:46 +01:00
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
2014-11-19 19:27:42 +01:00
|
|
|
if not can_insert(pos, stack) then
|
2014-01-26 08:48:46 +01:00
|
|
|
sendMessage(pos,"uoverflow "..maybeString(stack))
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end,
|
2014-11-19 19:27:42 +01:00
|
|
|
on_metadata_inventory_move = function(pos, fromlistname, fromindex, tolistname, toindex, count, player)
|
|
|
|
minetest.log("action", player:get_player_name().." moves stuff in chest at "..minetest.pos_to_string(pos))
|
|
|
|
end,
|
2014-01-26 08:48:46 +01:00
|
|
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
|
|
local channel = minetest.get_meta(pos):get_string("channel")
|
|
|
|
local send = function(msg)
|
|
|
|
sendMessage(pos,msg,channel)
|
|
|
|
end
|
|
|
|
-- direction is only for furnaces
|
|
|
|
-- as the item has already been put, can_insert should return false if the chest is now full.
|
|
|
|
local derpstack = stack:get_name()..' 1'
|
2014-11-19 19:27:42 +01:00
|
|
|
if can_insert(pos,derpstack) then
|
2014-01-26 08:48:46 +01:00
|
|
|
send("uput "..maybeString(stack))
|
|
|
|
else
|
|
|
|
send("ufull "..maybeString(stack))
|
|
|
|
end
|
2014-11-19 19:27:42 +01:00
|
|
|
minetest.log("action", player:get_player_name().." puts stuff into chest at "..minetest.pos_to_string(pos))
|
2014-01-26 08:48:46 +01:00
|
|
|
end,
|
|
|
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
2016-01-18 17:54:05 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local channel = meta:get_string("channel")
|
|
|
|
local inv = meta:get_inventory()
|
2014-12-08 02:31:06 +01:00
|
|
|
if inv:is_empty(listname) then
|
|
|
|
sendMessage(pos, "empty", channel)
|
|
|
|
end
|
2014-01-26 08:48:46 +01:00
|
|
|
sendMessage(pos,"utake "..maybeString(stack))
|
2014-11-19 19:27:42 +01:00
|
|
|
minetest.log("action", player:get_player_name().." takes stuff from chest at "..minetest.pos_to_string(pos))
|
2014-01-26 08:48:46 +01:00
|
|
|
end
|
|
|
|
})
|
2015-02-05 21:24:22 +01:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
2016-05-28 01:08:53 +02:00
|
|
|
output = "digilines:chest",
|
2015-02-05 21:24:22 +01:00
|
|
|
recipe = {"default:chest", "digilines:wire_std_00000000"}
|
|
|
|
})
|