forked from Mirrorlandia_minetest/digilines
Chest not throwing away pipeworks info
tube = {...} = bad tube = tableMergeImmutable(defaultChest.tube,{...}) = good There was also a thing where the stack was sometimes already stringified.
This commit is contained in:
parent
21048dc5ac
commit
3183371050
@ -25,9 +25,18 @@ local sendMessage = function (pos, msg, channel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
tableMerge = function(first_table,second_table)
|
tableMerge = function(first_table,second_table)
|
||||||
|
if second_table == nil then return end
|
||||||
for k,v in pairs(second_table) do first_table[k] = v end
|
for k,v in pairs(second_table) do first_table[k] = v end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tableMergeImmutable = function(first_table, second_table)
|
||||||
|
if first_table == nil then return second_table end
|
||||||
|
if second_table == nil then return first_table end
|
||||||
|
copy = table.copy(first_table)
|
||||||
|
for k,v in pairs(second_table) do copy[k] = v end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
local mychest = table.copy(defaultChest)
|
local mychest = table.copy(defaultChest)
|
||||||
|
|
||||||
function defer(what,...)
|
function defer(what,...)
|
||||||
@ -36,13 +45,20 @@ function defer(what,...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tableMerge(mychest,{
|
function maybeString(stack)
|
||||||
|
if type(stack)=='string' then return stack
|
||||||
|
elseif type(stack)=='table' then return dump(stack)
|
||||||
|
else return stack:to_string()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
mychest = tableMergeImmutable(defaultChest,{
|
||||||
description = "Digiline Chest",
|
description = "Digiline Chest",
|
||||||
digiline = {
|
digiline = {
|
||||||
receptor = {
|
receptor = {},
|
||||||
rules=digiline.rules.default
|
effector = {
|
||||||
},
|
action = function(pos,node,channel,msg) end
|
||||||
effector = {}
|
}
|
||||||
},
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
defaultChest.on_construct(pos)
|
defaultChest.on_construct(pos)
|
||||||
@ -52,11 +68,14 @@ tableMerge(mychest,{
|
|||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
minetest.get_meta(pos):set_string("channel",fields.channel)
|
minetest.get_meta(pos):set_string("channel",fields.channel)
|
||||||
return defer(defaultChest.on_receive_fields, pos, formname, fields, sender)
|
return defer(defaultChest.on_receive_fields, pos, formname, fields, sender)
|
||||||
end,
|
end,
|
||||||
tube = {
|
tube = tableMergeImmutable(defaultChest.tube, {
|
||||||
-- note: mese filters cannot put part of a stack in the destination.
|
-- note: mese filters cannot put part of a stack in the destination.
|
||||||
-- space for 50 coal with 99 added will pop out 99, not 49.
|
-- space for 50 coal with 99 added will pop out 99, not 49.
|
||||||
|
connects = function(i,param2)
|
||||||
|
return not pipeworks.connects.facingFront(i,param2)
|
||||||
|
end,
|
||||||
insert_object = function(pos, node, stack, direction)
|
insert_object = function(pos, node, stack, direction)
|
||||||
local leftover = defaultChest.tube.insert_object(pos,node,stack,direction)
|
local leftover = defaultChest.tube.insert_object(pos,node,stack,direction)
|
||||||
local count = leftover:get_count()
|
local count = leftover:get_count()
|
||||||
@ -64,8 +83,8 @@ tableMerge(mychest,{
|
|||||||
local derpstack = stack:get_name()..' 1'
|
local derpstack = stack:get_name()..' 1'
|
||||||
if not defaultChest.tube.can_insert(pos, node, derpstack, direction) then
|
if not defaultChest.tube.can_insert(pos, node, derpstack, direction) then
|
||||||
-- when you can't put a single more of whatever you just put,
|
-- when you can't put a single more of whatever you just put,
|
||||||
-- you'll get a put for it, then a full
|
-- you'll get a put for it, then a full
|
||||||
sendMessage(pos,"full "..stack:to_string()..' '..tostring(count))
|
sendMessage(pos,"full "..maybeString(stack)..' '..tostring(count))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- this happens when the chest has received two stacks in a row and
|
-- this happens when the chest has received two stacks in a row and
|
||||||
@ -73,54 +92,53 @@ tableMerge(mychest,{
|
|||||||
-- You get a put for the first stack, a put for the second
|
-- 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 then a overflow with the first in stack and the second in leftover
|
||||||
-- and NO full?
|
-- and NO full?
|
||||||
sendMessage(pos,"overflow "..stack:to_string()..' '..tostring(count))
|
sendMessage(pos,"overflow "..maybeString(stack)..' '..tostring(count))
|
||||||
end
|
end
|
||||||
return leftover
|
return leftover
|
||||||
end,
|
end,
|
||||||
can_insert = function(pos, node, stack, direction)
|
can_insert = function(pos, node, stack, direction)
|
||||||
local can = defaultChest.tube.can_insert(pos, node, stack, direction)
|
local can = defaultChest.tube.can_insert(pos, node, stack, direction)
|
||||||
if can then
|
if can then
|
||||||
sendMessage(pos,"put "..stack:to_string())
|
sendMessage(pos,"put "..maybeString(stack))
|
||||||
else
|
else
|
||||||
-- overflow and lost means that items are gonna be out as entities :/
|
-- overflow and lost means that items are gonna be out as entities :/
|
||||||
sendMessage(pos,"lost "..stack:to_string())
|
sendMessage(pos,"lost "..maybeString(stack))
|
||||||
end
|
end
|
||||||
return can
|
return can
|
||||||
end,
|
end,
|
||||||
input_inventory=defaultChest.input_inventory
|
}),
|
||||||
},
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
if not mychest.can_insert(pos,nil,stack,nil) then
|
if not mychest.tube.can_insert(pos,nil,stack,nil) then
|
||||||
sendMessage(pos,"uoverflow "..stack:to_string())
|
sendMessage(pos,"uoverflow "..maybeString(stack))
|
||||||
end
|
end
|
||||||
local ret = defer(defaultChest.allow_metadata_inventory_put, pos, listname, index, stack, player)
|
local ret = defer(defaultChest.allow_metadata_inventory_put, pos, listname, index, stack, player)
|
||||||
if ret then return ret end
|
if ret then return ret end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local channel = minetest.get_meta(pos):get_string("channel")
|
local channel = minetest.get_meta(pos):get_string("channel")
|
||||||
local send = function(msg)
|
local send = function(msg)
|
||||||
sendMessage(pos,msg,channel)
|
sendMessage(pos,msg,channel)
|
||||||
end
|
end
|
||||||
-- direction is only for furnaces
|
-- direction is only for furnaces
|
||||||
-- as the item has already been put, can_insert should return false if the chest is now full.
|
-- as the item has already been put, can_insert should return false if the chest is now full.
|
||||||
local derpstack = stack:get_name()..' 1'
|
local derpstack = stack:get_name()..' 1'
|
||||||
if mychest.can_insert(pos,nil,derpstack,nil) then
|
if mychest.tube.can_insert(pos,nil,derpstack,nil) then
|
||||||
send("uput "..stack:to_string())
|
send("uput "..maybeString(stack))
|
||||||
else
|
else
|
||||||
send("ufull "..stack:to_string())
|
send("ufull "..maybeString(stack))
|
||||||
end
|
end
|
||||||
return defer(defaultChest.on_metadata_inventory_put, pos, listname, index, stack, player)
|
return defer(defaultChest.on_metadata_inventory_put, pos, listname, index, stack, player)
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
sendMessage(pos,"utake "..stack:to_string())
|
sendMessage(pos,"utake "..maybeString(stack))
|
||||||
return defaultChest.on_metadata_inventory_take(pos, listname, index, stack, player)
|
return defaultChest.on_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
if mychest.can_insert == nil then
|
if mychest.tube.can_insert == nil then
|
||||||
-- we can use the can_insert function from pipeworks, but will duplicate if not found.
|
-- we can use the can_insert function from pipeworks, but will duplicate if not found.
|
||||||
mychest.can_insert = function(pos,node,stack,direction)
|
mychest.tube.can_insert = function(pos,node,stack,direction)
|
||||||
local meta=minetest.get_meta(pos)
|
local meta=minetest.get_meta(pos)
|
||||||
local inv=meta:get_inventory()
|
local inv=meta:get_inventory()
|
||||||
return inv:room_for_item("main",stack)
|
return inv:room_for_item("main",stack)
|
||||||
|
Loading…
Reference in New Issue
Block a user