2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
local function porter_teleport(itemstack, player, pointed_thing)
|
|
|
|
local meta = itemstack:get_meta()
|
|
|
|
local storage = ele.tools.get_tool_property(itemstack, "storage")
|
|
|
|
local pos = minetest.string_to_pos(meta:get_string("receiver"))
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
if not pos or pos == "" then return itemstack end
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
local node = minetest.get_node_or_nil(pos)
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
local plname = player:get_player_name()
|
|
|
|
if not node or not ele.helpers.get_item_group(node.name, "matter_receiver") then
|
|
|
|
minetest.chat_send_player(plname, "Destination Receiver is missing or unloaded!")
|
|
|
|
return itemstack
|
|
|
|
end
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
local nmeta = minetest.get_meta(pos)
|
|
|
|
local nstorage = ele.helpers.get_node_property(nmeta, pos, "storage")
|
|
|
|
local nusage = ele.helpers.get_node_property(nmeta, pos, "usage")
|
|
|
|
local top = vector.add(pos, {x = 0, y = 1, z = 0})
|
|
|
|
local topnode = minetest.get_node_or_nil(top)
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
if topnode and topnode.name ~= "air" then
|
|
|
|
minetest.chat_send_player(plname, "Destination is obstructed!")
|
|
|
|
return itemstack
|
|
|
|
end
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
if nstorage < nusage then
|
|
|
|
minetest.chat_send_player(plname, "Receiver is out of power!")
|
|
|
|
return itemstack
|
|
|
|
end
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
if storage < nusage then
|
|
|
|
minetest.chat_send_player(plname, "Your Wireless Porter is out of power!")
|
|
|
|
return itemstack
|
|
|
|
end
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
-- Teleport player
|
|
|
|
player:set_pos(top)
|
2018-08-01 14:41:01 +00:00
|
|
|
|
2020-05-21 16:19:43 +00:00
|
|
|
-- TODO: Sound
|
|
|
|
|
|
|
|
nmeta:set_int("storage", nstorage - nusage)
|
|
|
|
ele.helpers.start_timer(pos)
|
|
|
|
|
|
|
|
-- Add wear
|
|
|
|
meta:set_int("storage", storage - nusage)
|
|
|
|
itemstack = ele.tools.update_tool_wear(itemstack)
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
ele.register_tool("elepower_wireless:wireless_porter", {
|
|
|
|
description = "Wireless Porter",
|
|
|
|
inventory_image = "elewireless_wireless_porter.png",
|
|
|
|
on_use = porter_teleport,
|
|
|
|
on_secondary_use = porter_teleport,
|
2018-08-01 14:41:01 +00:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
if not placer or placer:get_player_name() == "" then return itemstack end
|
|
|
|
local player = placer:get_player_name()
|
|
|
|
|
|
|
|
if minetest.is_protected(pos, player) then
|
|
|
|
minetest.chat_send_player(player, "You are not allowed to teleport here!")
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = itemstack:get_meta()
|
|
|
|
local pos = pointed_thing.under
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
|
|
|
|
if not node or not ele.helpers.get_item_group(node.name, "matter_receiver") then return itemstack end
|
|
|
|
|
|
|
|
local strpos = minetest.pos_to_string(pos)
|
|
|
|
local curpos = minetest.string_to_pos(meta:get_string("receiver"))
|
|
|
|
|
2018-08-02 15:26:16 +00:00
|
|
|
if (curpos and curpos ~= "") and curpos == pos then
|
2018-08-01 14:41:01 +00:00
|
|
|
minetest.chat_send_player(player, "Wireless Porter is already bound to this location!")
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
meta:set_string("receiver", strpos)
|
|
|
|
minetest.chat_send_player(player, ("Wireless Porter bound to %s!"):format(strpos))
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
ele_capacity = 1000,
|
|
|
|
})
|
2020-05-21 16:19:43 +00:00
|
|
|
|
|
|
|
minetest.register_craftitem("elepower_wireless:upgrade_item_transfer", {
|
|
|
|
description = "Wireless Upgrade\nAllows for transmission of matter",
|
|
|
|
groups = {wireless_chip = 2, ele_upgrade_component = 1},
|
|
|
|
inventory_image = "elewireless_upgrade_item_transfer.png",
|
|
|
|
ele_upgrade = {
|
|
|
|
usage = {
|
|
|
|
multiplier = 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|