2021-12-30 17:05:20 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2023-02-27 21:57:28 +03:00
|
|
|
Copyright (C) 2019-2023 Joachim Stolberg
|
2021-12-30 17:05:20 +03:00
|
|
|
|
|
|
|
AGPL v3
|
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-12-31 19:25:37 +03:00
|
|
|
TA5 Hyperloop Chest
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-12-30 17:05:20 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local S2P = minetest.string_to_pos
|
|
|
|
local P2S = minetest.pos_to_string
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local TA4_INV_SIZE = 32
|
2023-02-28 23:12:57 +03:00
|
|
|
local EX_POINTS = 15
|
2021-12-30 17:05:20 +03:00
|
|
|
|
|
|
|
local hyperloop = techage.hyperloop
|
|
|
|
local remote_pos = techage.hyperloop.remote_pos
|
|
|
|
local shared_inv = techage.shared_inv
|
|
|
|
local menu = techage.menu
|
|
|
|
|
|
|
|
local function formspec(pos)
|
|
|
|
local ndef = minetest.registered_nodes["techage:ta5_hl_chest"]
|
|
|
|
local status = M(pos):get_string("conn_status")
|
2023-04-01 20:09:04 +03:00
|
|
|
if hyperloop.is_server(pos) then
|
2021-12-30 17:05:20 +03:00
|
|
|
local title = ndef.description .. " " .. status
|
|
|
|
return "size[8,9]"..
|
|
|
|
"box[0,-0.1;7.8,0.5;#c6e8ff]" ..
|
2022-01-03 23:40:31 +03:00
|
|
|
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
|
2021-12-30 17:05:20 +03:00
|
|
|
"list[context;main;0,1;8,4;]"..
|
|
|
|
"list[current_player;main;0,5.3;8,4;]"..
|
|
|
|
"listring[context;main]"..
|
|
|
|
"listring[current_player;main]"
|
2023-04-01 20:09:04 +03:00
|
|
|
elseif hyperloop.is_client(pos) then
|
|
|
|
local title = ndef.description .. " " .. status
|
|
|
|
return "size[8,9]"..
|
|
|
|
"box[0,-0.1;7.8,0.5;#c6e8ff]" ..
|
|
|
|
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
|
2023-10-13 14:50:25 +03:00
|
|
|
"label[0.2,2;Inventory access on this node is disabled\ndue to minetest engine issues!]" ..
|
2023-04-01 20:09:04 +03:00
|
|
|
"list[current_player;main;0,5.3;8,4;]"
|
2021-12-30 17:05:20 +03:00
|
|
|
else
|
|
|
|
return menu.generate_formspec(pos, ndef, hyperloop.SUBMENU)
|
|
|
|
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
|
2023-04-01 20:09:04 +03:00
|
|
|
if techage.hyperloop.is_client(pos) then
|
|
|
|
return 0
|
|
|
|
end
|
2021-12-30 17:05:20 +03:00
|
|
|
shared_inv.before_inv_access(pos, listname)
|
|
|
|
local inv = minetest.get_inventory({type="node", pos=pos})
|
2023-02-27 21:57:28 +03:00
|
|
|
if inv and inv:room_for_item(listname, stack) then
|
2021-12-30 17:05:20 +03:00
|
|
|
return stack:get_count()
|
|
|
|
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
|
2023-04-01 20:09:04 +03:00
|
|
|
if techage.hyperloop.is_client(pos) then
|
|
|
|
return 0
|
|
|
|
end
|
2021-12-30 17:05:20 +03:00
|
|
|
shared_inv.before_inv_access(pos, listname)
|
|
|
|
local inv = minetest.get_inventory({type="node", pos=pos})
|
2023-02-27 21:57:28 +03:00
|
|
|
if inv and inv:contains_item(listname, stack) then
|
2021-12-30 17:05:20 +03:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
if shared_inv.before_inv_access(pos, "main") then
|
|
|
|
return 0
|
|
|
|
end
|
2023-04-01 20:09:04 +03:00
|
|
|
if techage.hyperloop.is_client(pos) then
|
|
|
|
return 0
|
|
|
|
end
|
2021-12-30 17:05:20 +03:00
|
|
|
return count
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta5_hl_chest", {
|
|
|
|
description = S("TA5 Hyperloop Chest"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5_top.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_chest_back_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_chest_back_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_chest_back_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_chest_front_ta4.png",
|
|
|
|
},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size('main', 32)
|
|
|
|
local number = techage.add_node(pos, "techage:ta5_hl_chest")
|
|
|
|
meta:set_string("node_number", number)
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
|
|
|
meta:set_string("formspec", formspec(pos))
|
|
|
|
meta:set_string("infotext", S("TA5 Hyperloop Chest").." "..number)
|
|
|
|
hyperloop.after_place_node(pos, placer, "chest")
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if techage.get_expoints(player) >= EX_POINTS then
|
|
|
|
if techage.menu.eval_input(pos, hyperloop.SUBMENU, fields) then
|
|
|
|
hyperloop.after_formspec(pos, fields)
|
2021-12-31 19:25:37 +03:00
|
|
|
shared_inv.on_rightclick(pos, player, "main")
|
2021-12-30 17:05:20 +03:00
|
|
|
M(pos):set_string("formspec", formspec(pos))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_timer = shared_inv.node_timer,
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
2021-12-31 19:25:37 +03:00
|
|
|
shared_inv.on_rightclick(pos, clicker, "main")
|
2021-12-30 17:05:20 +03:00
|
|
|
M(pos):set_string("formspec", formspec(pos))
|
|
|
|
end,
|
2021-12-31 19:25:37 +03:00
|
|
|
can_dig = function(pos, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
shared_inv.before_inv_access(pos, "main")
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
return inv:is_empty("main")
|
|
|
|
end,
|
2021-12-30 17:05:20 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
|
|
|
hyperloop.after_dig_node(pos, oldnode, oldmetadata, digger)
|
|
|
|
techage.del_mem(pos)
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
|
|
|
on_metadata_inventory_put = shared_inv.after_inv_access,
|
|
|
|
on_metadata_inventory_take = shared_inv.after_inv_access,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
techage.register_node({"techage:ta5_hl_chest"}, {
|
|
|
|
on_inv_request = function(pos, in_dir, access_type)
|
|
|
|
pos = remote_pos(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if pos then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta then
|
|
|
|
return meta:get_inventory(), "main"
|
|
|
|
end
|
|
|
|
end
|
2021-12-30 17:05:20 +03:00
|
|
|
end,
|
|
|
|
on_pull_item = function(pos, in_dir, num, item_name)
|
|
|
|
pos = remote_pos(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if pos then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv then
|
|
|
|
return techage.get_items(pos, inv, "main", num)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2021-12-30 17:05:20 +03:00
|
|
|
end,
|
2021-12-31 19:25:37 +03:00
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
if techage.hyperloop.is_paired(pos) then
|
|
|
|
pos = remote_pos(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if pos then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv then
|
|
|
|
return techage.put_items(inv, "main", stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-12-30 17:05:20 +03:00
|
|
|
end
|
2021-12-31 19:25:37 +03:00
|
|
|
return false
|
2021-12-30 17:05:20 +03:00
|
|
|
end,
|
2021-12-31 19:25:37 +03:00
|
|
|
on_unpull_item = function(pos, in_dir, stack)
|
2021-12-30 17:05:20 +03:00
|
|
|
pos = remote_pos(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if pos then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv then
|
|
|
|
return techage.put_items(inv, "main", stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2021-12-30 17:05:20 +03:00
|
|
|
end,
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
if topic == "state" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv then
|
|
|
|
return techage.get_inv_state(inv, "main")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return "error"
|
2021-12-30 17:05:20 +03:00
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
|
|
|
end,
|
2022-06-05 22:20:43 +03:00
|
|
|
on_beduino_request_data = function(pos, src, topic, payload)
|
|
|
|
if topic == 131 then -- Chest State
|
|
|
|
local meta = minetest.get_meta(pos)
|
2023-02-27 21:57:28 +03:00
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv then
|
|
|
|
return 0, {techage.get_inv_state_num(inv, "main")}
|
|
|
|
end
|
|
|
|
end
|
2022-06-05 22:20:43 +03:00
|
|
|
else
|
|
|
|
return 2, ""
|
|
|
|
end
|
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2021-12-30 17:05:20 +03:00
|
|
|
|
2021-12-31 19:25:37 +03:00
|
|
|
|
2021-12-30 17:05:20 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
|
|
|
output = "techage:ta5_hl_chest",
|
2021-12-31 19:25:37 +03:00
|
|
|
recipe = {"techage:chest_ta4", "techage:ta5_aichip"}
|
2022-01-04 21:40:27 +03:00
|
|
|
})
|
2023-05-06 19:40:15 +03:00
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
if not minetest.global_exists("hyperloop") then
|
|
|
|
minetest.clear_craft({output = "techage:ta5_hl_chest"})
|
|
|
|
end
|
2023-05-17 23:02:10 +03:00
|
|
|
end)
|