2020-02-18 20:34:52 +03:00
|
|
|
local S = minetest.get_translator("pipeworks")
|
2015-01-30 00:36:16 +03:00
|
|
|
-- the default tube and default textures
|
2020-02-18 20:34:52 +03:00
|
|
|
pipeworks.register_tube("pipeworks:tube", S("Pneumatic tube segment"))
|
2015-01-30 00:36:16 +03:00
|
|
|
minetest.register_craft( {
|
|
|
|
output = "pipeworks:tube_1 6",
|
|
|
|
recipe = {
|
2018-10-31 03:45:48 +03:00
|
|
|
{ "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
|
2015-01-30 00:36:16 +03:00
|
|
|
{ "", "", "" },
|
2018-10-31 03:45:48 +03:00
|
|
|
{ "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
|
2015-01-30 00:36:16 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-03-28 03:51:23 +03:00
|
|
|
-- The hammers that can be used to break/repair tubes
|
|
|
|
local allowed_hammers = {
|
|
|
|
"anvil:hammer",
|
|
|
|
"cottages:hammer",
|
|
|
|
"glooptest:hammer_steel",
|
|
|
|
"glooptest:hammer_bronze",
|
|
|
|
"glooptest:hammer_diamond",
|
|
|
|
"glooptest:hammer_mese",
|
|
|
|
"glooptest:hammer_alatro",
|
|
|
|
"glooptest:hammer_arol"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Convert the above list to a format that's easier to look up
|
|
|
|
for _,hammer in ipairs(allowed_hammers) do
|
|
|
|
allowed_hammers[hammer] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check if the player is holding a suitable hammer or not - if they are, apply wear to it
|
|
|
|
function pipeworks.check_and_wear_hammer(player)
|
|
|
|
local itemstack = player:get_wielded_item()
|
|
|
|
local wieldname = itemstack:get_name()
|
|
|
|
if allowed_hammers[wieldname] then
|
|
|
|
itemstack:add_wear(1000)
|
|
|
|
player:set_wielded_item(itemstack)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-06-08 08:54:09 +03:00
|
|
|
local nodecolor = 0xffff3030
|
|
|
|
|
2017-04-05 09:57:22 +03:00
|
|
|
pipeworks.register_tube("pipeworks:broken_tube", {
|
2020-02-18 20:34:52 +03:00
|
|
|
description = S("Broken Tube"),
|
2017-04-05 09:57:22 +03:00
|
|
|
plain = { { name = "pipeworks_broken_tube_plain.png", backface_culling = false, color = nodecolor } },
|
|
|
|
noctr = { { name = "pipeworks_broken_tube_plain.png", backface_culling = false, color = nodecolor } },
|
|
|
|
ends = { { name = "pipeworks_broken_tube_end.png", color = nodecolor } },
|
|
|
|
short = { name = "pipeworks_broken_tube_short.png", color = nodecolor },
|
|
|
|
node_def = {
|
|
|
|
drop = "pipeworks:tube_1",
|
|
|
|
groups = {not_in_creative_inventory = 1, tubedevice_receiver = 1},
|
|
|
|
tube = {
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
|
|
|
minetest.item_drop(stack, nil, pos)
|
|
|
|
return ItemStack("")
|
|
|
|
end,
|
|
|
|
can_insert = function(pos,node,stack,direction)
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
priority = 50,
|
2017-04-08 02:47:12 +03:00
|
|
|
},
|
|
|
|
on_punch = function(pos, node, puncher, pointed_thing)
|
|
|
|
local itemstack = puncher:get_wielded_item()
|
|
|
|
local wieldname = itemstack:get_name()
|
|
|
|
local playername = puncher:get_player_name()
|
2020-02-18 20:34:52 +03:00
|
|
|
local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n"
|
2021-03-28 03:51:23 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local was_node = minetest.deserialize(meta:get_string("the_tube_was"))
|
|
|
|
if not was_node then
|
|
|
|
pipeworks.logger(log_msg.." but it can't be repaired.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not pipeworks.check_and_wear_hammer(puncher) then
|
|
|
|
if wieldname == "" then
|
|
|
|
pipeworks.logger(log_msg.." by hand. It's not very effective.")
|
|
|
|
if minetest.settings:get_bool("enable_damage") then
|
|
|
|
minetest.chat_send_player(playername,S("Broken tubes may be a bit sharp. Perhaps try with a hammer?"))
|
|
|
|
puncher:set_hp(puncher:get_hp()-1)
|
|
|
|
end
|
2017-04-08 02:47:12 +03:00
|
|
|
else
|
2021-03-28 03:51:23 +03:00
|
|
|
pipeworks.logger(log_msg.." with "..wieldname.." but that tool is too weak.")
|
2017-04-08 02:47:12 +03:00
|
|
|
end
|
2021-03-28 03:51:23 +03:00
|
|
|
return
|
2017-04-08 02:47:12 +03:00
|
|
|
end
|
2021-03-28 03:51:23 +03:00
|
|
|
pipeworks.logger(log_msg.." with "..wieldname.." to repair it.")
|
|
|
|
minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
|
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
2017-04-08 02:47:12 +03:00
|
|
|
end
|
2017-04-05 09:57:22 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-02-03 17:35:44 +03:00
|
|
|
-- the high priority tube is a low-cpu replacement for sorting tubes in situations
|
|
|
|
-- where players would use them for simple routing (turning off paths)
|
|
|
|
-- without doing actual sorting, like at outputs of tubedevices that might both accept and eject items
|
|
|
|
if pipeworks.enable_priority_tube then
|
|
|
|
local color = "#ff3030:128"
|
|
|
|
pipeworks.register_tube("pipeworks:priority_tube", {
|
2020-02-18 20:34:52 +03:00
|
|
|
description = S("High Priority Tube Segment"),
|
2015-02-03 17:35:44 +03:00
|
|
|
inventory_image = "pipeworks_tube_inv.png^[colorize:" .. color,
|
2017-01-25 12:33:27 +03:00
|
|
|
plain = { { name = "pipeworks_tube_plain.png", color = nodecolor } },
|
|
|
|
noctr = { { name = "pipeworks_tube_noctr.png", color = nodecolor } },
|
|
|
|
ends = { { name = "pipeworks_tube_end.png", color = nodecolor } },
|
|
|
|
short = { name = "pipeworks_tube_short.png", color = nodecolor },
|
2015-02-03 17:35:44 +03:00
|
|
|
node_def = {
|
|
|
|
tube = { priority = 150 } -- higher than tubedevices (100)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2015-01-30 00:24:14 +03:00
|
|
|
if pipeworks.enable_accelerator_tube then
|
2015-01-31 18:10:25 +03:00
|
|
|
pipeworks.register_tube("pipeworks:accelerator_tube", {
|
2020-02-18 20:34:52 +03:00
|
|
|
description = S("Accelerating Pneumatic Tube Segment"),
|
2015-01-31 18:10:25 +03:00
|
|
|
inventory_image = "pipeworks_accelerator_tube_inv.png",
|
|
|
|
plain = { "pipeworks_accelerator_tube_plain.png" },
|
|
|
|
noctr = { "pipeworks_accelerator_tube_noctr.png" },
|
|
|
|
ends = { "pipeworks_accelerator_tube_end.png" },
|
|
|
|
short = "pipeworks_accelerator_tube_short.png",
|
|
|
|
node_def = {
|
|
|
|
tube = {can_go = function(pos, node, velocity, stack)
|
2015-01-30 00:24:14 +03:00
|
|
|
velocity.speed = velocity.speed+1
|
|
|
|
return pipeworks.notvel(pipeworks.meseadjlist, velocity)
|
|
|
|
end}
|
2015-01-31 18:10:25 +03:00
|
|
|
},
|
2015-01-30 00:24:14 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
if pipeworks.enable_crossing_tube then
|
2015-01-31 18:10:25 +03:00
|
|
|
pipeworks.register_tube("pipeworks:crossing_tube", {
|
2020-02-18 20:34:52 +03:00
|
|
|
description = S("Crossing Pneumatic Tube Segment"),
|
2015-01-31 18:10:25 +03:00
|
|
|
inventory_image = "pipeworks_crossing_tube_inv.png",
|
|
|
|
plain = { "pipeworks_crossing_tube_plain.png" },
|
|
|
|
noctr = { "pipeworks_crossing_tube_noctr.png" },
|
|
|
|
ends = { "pipeworks_crossing_tube_end.png" },
|
|
|
|
short = "pipeworks_crossing_tube_short.png",
|
|
|
|
node_def = {
|
|
|
|
tube = {can_go = function(pos, node, velocity, stack) return {velocity} end }
|
|
|
|
},
|
2015-01-30 00:24:14 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2022-02-07 07:53:29 +03:00
|
|
|
local texture_alpha_mode = minetest.features.use_texture_alpha_string_modes
|
|
|
|
and "clip" or true
|
|
|
|
|
2015-01-30 00:24:14 +03:00
|
|
|
if pipeworks.enable_one_way_tube then
|
2022-05-12 01:41:28 +03:00
|
|
|
local tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
|
|
|
|
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"}
|
|
|
|
for i, tile in ipairs(tiles) do
|
|
|
|
tiles[i] = pipeworks.make_tube_tile(tile)
|
|
|
|
end
|
2015-01-30 00:24:14 +03:00
|
|
|
minetest.register_node("pipeworks:one_way_tube", {
|
2020-02-18 20:34:52 +03:00
|
|
|
description = S("One way tube"),
|
2022-05-12 01:41:28 +03:00
|
|
|
tiles = tiles,
|
2022-02-07 07:53:29 +03:00
|
|
|
use_texture_alpha = texture_alpha_mode,
|
2015-01-30 00:24:14 +03:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
node_box = {type = "fixed",
|
|
|
|
fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
|
|
|
|
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1},
|
2022-03-15 04:39:58 +03:00
|
|
|
_sound_def = {
|
|
|
|
key = "node_sound_wood_defaults",
|
|
|
|
},
|
2015-01-30 00:24:14 +03:00
|
|
|
tube = {
|
|
|
|
connect_sides = {left = 1, right = 1},
|
|
|
|
can_go = function(pos, node, velocity, stack)
|
|
|
|
return {velocity}
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
2017-04-04 10:25:27 +03:00
|
|
|
local dir = pipeworks.facedir_to_right_dir(node.param2)
|
2015-01-30 00:24:14 +03:00
|
|
|
return vector.equals(dir, direction)
|
|
|
|
end,
|
|
|
|
priority = 75 -- Higher than normal tubes, but lower than receivers
|
|
|
|
},
|
2015-02-07 10:45:17 +03:00
|
|
|
after_place_node = pipeworks.after_place,
|
|
|
|
after_dig_node = pipeworks.after_dig,
|
2018-09-15 17:30:13 +03:00
|
|
|
on_rotate = pipeworks.on_rotate,
|
2019-09-23 19:21:54 +03:00
|
|
|
check_for_pole = pipeworks.check_for_vert_tube,
|
|
|
|
check_for_horiz_pole = pipeworks.check_for_horiz_tube
|
2015-01-30 00:24:14 +03:00
|
|
|
})
|
2021-04-02 22:48:28 +03:00
|
|
|
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:one_way_tube"
|
2015-01-30 00:24:14 +03:00
|
|
|
end
|