mirror of
https://github.com/minetest-mods/digilines.git
synced 2025-07-03 08:40:43 +02:00
Send messages from digiline chest when itemsare moved with tubelib
This commit is contained in:
188
inventory.lua
188
inventory.lua
@ -51,65 +51,7 @@ local last_inventory_put_stack
|
|||||||
-- that should be removed once that’s fixed.
|
-- that should be removed once that’s fixed.
|
||||||
local last_inventory_take_index
|
local last_inventory_take_index
|
||||||
|
|
||||||
minetest.register_alias("digilines_inventory:chest", "digilines:chest")
|
local tube_can_insert = function(pos, _, stack, direction)
|
||||||
minetest.register_node("digilines:chest", {
|
|
||||||
description = "Digiline Chest",
|
|
||||||
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",
|
|
||||||
},
|
|
||||||
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(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
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;]"..
|
|
||||||
"listring[]")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 8*4)
|
|
||||||
end,
|
|
||||||
after_place_node = tubescan,
|
|
||||||
after_dig_node = tubescan,
|
|
||||||
can_dig = function(pos)
|
|
||||||
return minetest.get_meta(pos):get_inventory():is_empty("main")
|
|
||||||
end,
|
|
||||||
on_receive_fields = function(pos, _, fields, sender)
|
|
||||||
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
|
|
||||||
if fields.channel ~= nil then
|
|
||||||
minetest.get_meta(pos):set_string("channel",fields.channel)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
digilines = {
|
|
||||||
receptor = {},
|
|
||||||
effector = {
|
|
||||||
action = function() end
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tube = {
|
|
||||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1},
|
|
||||||
connects = function(i,param2)
|
|
||||||
return not pipeworks.connects.facingFront(i,param2)
|
|
||||||
end,
|
|
||||||
input_inventory = "main",
|
|
||||||
can_insert = function(pos, _, stack, direction)
|
|
||||||
local ret = minetest.get_meta(pos):get_inventory():room_for_item("main", stack)
|
local ret = minetest.get_meta(pos):get_inventory():room_for_item("main", stack)
|
||||||
if not ret then
|
if not ret then
|
||||||
-- The stack cannot be accepted. It will never be passed to
|
-- The stack cannot be accepted. It will never be passed to
|
||||||
@ -120,8 +62,9 @@ minetest.register_node("digilines:chest", {
|
|||||||
send_message(pos, "toverflow", stack, nil, nil, side)
|
send_message(pos, "toverflow", stack, nil, nil, side)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end,
|
end
|
||||||
insert_object = function(pos, _, original_stack, direction)
|
|
||||||
|
local tube_insert_object = function(pos, _, original_stack, direction)
|
||||||
-- Here, direction = direction item is moving, which is into side.
|
-- Here, direction = direction item is moving, which is into side.
|
||||||
local side = vector.multiply(direction, -1)
|
local side = vector.multiply(direction, -1)
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
@ -199,7 +142,68 @@ minetest.register_node("digilines:chest", {
|
|||||||
send_message(pos, "toverflow", stack, nil, nil, side)
|
send_message(pos, "toverflow", stack, nil, nil, side)
|
||||||
end
|
end
|
||||||
return stack
|
return stack
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_alias("digilines_inventory:chest", "digilines:chest")
|
||||||
|
minetest.register_node("digilines:chest", {
|
||||||
|
description = "Digiline Chest",
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
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(),
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
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;]"..
|
||||||
|
"listring[]")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("main", 8*4)
|
||||||
end,
|
end,
|
||||||
|
after_place_node = tubescan,
|
||||||
|
after_dig_node = tubescan,
|
||||||
|
can_dig = function(pos)
|
||||||
|
return minetest.get_meta(pos):get_inventory():is_empty("main")
|
||||||
|
end,
|
||||||
|
on_receive_fields = function(pos, _, fields, sender)
|
||||||
|
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
|
||||||
|
if fields.channel ~= nil then
|
||||||
|
minetest.get_meta(pos):set_string("channel",fields.channel)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
digilines = {
|
||||||
|
receptor = {},
|
||||||
|
effector = {
|
||||||
|
action = function() end
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tube = {
|
||||||
|
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1},
|
||||||
|
connects = function(i,param2)
|
||||||
|
return not pipeworks.connects.facingFront(i,param2)
|
||||||
|
end,
|
||||||
|
input_inventory = "main",
|
||||||
|
can_insert = tube_can_insert,
|
||||||
|
insert_object = tube_insert_object,
|
||||||
remove_items = function(pos, _, stack, dir, count)
|
remove_items = function(pos, _, stack, dir, count)
|
||||||
-- Here, stack is the ItemStack in our own inventory that is being
|
-- Here, stack is the ItemStack in our own inventory that is being
|
||||||
-- pulled from, NOT the stack that is actually pulled out.
|
-- pulled from, NOT the stack that is actually pulled out.
|
||||||
@ -310,6 +314,68 @@ minetest.register_node("digilines:chest", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if minetest.global_exists("tubelib") and minetest.global_exists("tubelib2") then
|
||||||
|
local speculative_pull = nil
|
||||||
|
local pull_succeeded = function(passed_speculative_pull)
|
||||||
|
if passed_speculative_pull.canceled then return end
|
||||||
|
|
||||||
|
send_message(passed_speculative_pull.pos, "ttake", passed_speculative_pull.taken,
|
||||||
|
passed_speculative_pull.index, nil, passed_speculative_pull.dir)
|
||||||
|
check_empty(passed_speculative_pull.pos)
|
||||||
|
end
|
||||||
|
local function tube_side(pos, side)
|
||||||
|
if side == "U" then return {x=0,y=-1,z=0}
|
||||||
|
elseif side == "D" then return {x=0,y=1,z=0}
|
||||||
|
end
|
||||||
|
local param2 = minetest.get_node(pos).param2
|
||||||
|
return vector.multiply(
|
||||||
|
minetest.facedir_to_dir(
|
||||||
|
tubelib2.side_to_dir(side, param2) - 1),
|
||||||
|
-1)
|
||||||
|
end
|
||||||
|
tubelib.register_node("digilines:chest", {}, {
|
||||||
|
on_pull_item = function(pos, side, player_name)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
for i, stack in pairs(inv:get_list("main")) do
|
||||||
|
if not stack:is_empty() then
|
||||||
|
speculative_pull = {
|
||||||
|
canceled = false,
|
||||||
|
pos = pos,
|
||||||
|
taken = stack,
|
||||||
|
index = i,
|
||||||
|
dir = vector.multiply(tube_side(pos, side), -1)
|
||||||
|
}
|
||||||
|
minetest.after(0, pull_succeeded, speculative_pull)
|
||||||
|
return inv:remove_item("main", stack:get_name())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
on_push_item = function(pos, side, item, player_name)
|
||||||
|
local dir_vec = tube_side(pos, side)
|
||||||
|
if tube_can_insert(pos, nil, item, dir_vec) then
|
||||||
|
tube_insert_object(pos, nil, item, dir_vec)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
on_unpull_item = function(pos, side, item, player_name)
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
if inv:room_for_item("main", item) then
|
||||||
|
-- Cancel speculative pull
|
||||||
|
-- this callback should be called immediately after on_pull_item if it fails
|
||||||
|
-- so this should be procedural
|
||||||
|
speculative_pull.canceled = true
|
||||||
|
speculative_pull = nil
|
||||||
|
inv:add_item("main", item)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
output = "digilines:chest",
|
output = "digilines:chest",
|
||||||
|
1
mod.conf
1
mod.conf
@ -1,5 +1,6 @@
|
|||||||
name = digilines
|
name = digilines
|
||||||
depends = default
|
depends = default
|
||||||
|
optional_depends = tubelib,tubelib2
|
||||||
description = """
|
description = """
|
||||||
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
|
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
|
||||||
Can be used together with the luacontroller from mesecons.
|
Can be used together with the luacontroller from mesecons.
|
||||||
|
Reference in New Issue
Block a user