update pipeworks

This commit is contained in:
Vanessa Dannenberg 2021-03-27 20:59:31 -04:00
parent 547e44d1b5
commit d1a8445e01
6 changed files with 127 additions and 94 deletions

View File

@ -1 +0,0 @@
20210326-2343

View File

@ -45,6 +45,10 @@ local pane_box = {
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 } -- pane { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 } -- pane
} }
} }
local texture_alpha_mode = minetest.features.use_texture_alpha_string_modes
and "clip" or true
minetest.register_node("pipeworks:steel_pane_embedded_tube", { minetest.register_node("pipeworks:steel_pane_embedded_tube", {
drawtype = "nodebox", drawtype = "nodebox",
description = S("Airtight panel embedded tube"), description = S("Airtight panel embedded tube"),
@ -55,6 +59,7 @@ minetest.register_node("pipeworks:steel_pane_embedded_tube", {
"pipeworks_pane_embedded_tube_sides.png", "pipeworks_pane_embedded_tube_sides.png",
"pipeworks_pane_embedded_tube_ends.png", "pipeworks_pane_embedded_tube_ends.png", "pipeworks_pane_embedded_tube_ends.png", "pipeworks_pane_embedded_tube_ends.png",
}, },
use_texture_alpha = texture_alpha_mode,
node_box = pane_box, node_box = pane_box,
selection_box = pane_box, selection_box = pane_box,
collision_box = pane_box, collision_box = pane_box,

View File

@ -55,15 +55,22 @@ end)
-- tube overload mechanism: -- tube overload mechanism:
-- when the tube's item count (tracked in the above tube_item_count table) -- when the tube's item count (tracked in the above tube_item_count table)
-- exceeds the limit configured per tube, replace it with a broken one. -- exceeds the limit configured per tube, replace it with a broken one.
function pipeworks.break_tube(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
meta:set_string("the_tube_was", minetest.serialize(node))
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
pipeworks.scan_for_tube_objects(pos)
end
local crunch_tube = function(pos, cnode, cmeta) local crunch_tube = function(pos, cnode, cmeta)
if enable_max_limit then if enable_max_limit then
local h = minetest.hash_node_position(pos) local h = minetest.hash_node_position(pos)
local itemcount = tube_item_count[h] or 0 local itemcount = tube_item_count[h] or 0
if itemcount > max_tube_limit then if itemcount > max_tube_limit then
cmeta:set_string("the_tube_was", minetest.serialize(cnode))
pipeworks.logger("Warning - a tube at "..minetest.pos_to_string(pos).." broke due to too many items ("..itemcount..")") pipeworks.logger("Warning - a tube at "..minetest.pos_to_string(pos).." broke due to too many items ("..itemcount..")")
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"}) pipeworks.break_tube(pos)
pipeworks.scan_for_tube_objects(pos)
end end
end end
end end

View File

@ -813,82 +813,56 @@ local tiles_base = {
"pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_1.png",
"pipeworks_mese_tube_plain_6.png", "pipeworks_mese_tube_plain_5.png"} "pipeworks_mese_tube_plain_6.png", "pipeworks_mese_tube_plain_5.png"}
local tiles_on_off = {
R__0 = "^pipeworks_lua_tube_port_%s.png",
R_90 = "^(pipeworks_lua_tube_port_%s.png^[transformR90)",
R180 = "^(pipeworks_lua_tube_port_%s.png^[transformR180)",
R270 = "^(pipeworks_lua_tube_port_%s.png^[transformR270)"
}
local texture_alpha_mode = minetest.features.use_texture_alpha_string_modes
and "clip" or true
for red = 0, 1 do -- 0 = off 1 = on for red = 0, 1 do -- 0 = off 1 = on
for blue = 0, 1 do for blue = 0, 1 do
for yellow = 0, 1 do for yellow = 0, 1 do
for green = 0, 1 do for green = 0, 1 do
for black = 0, 1 do for black = 0, 1 do
for white = 0, 1 do for white = 0, 1 do
local cid = tostring(white)..tostring(black)..tostring(green).. local cid = white..black..green..yellow..blue..red
tostring(yellow)..tostring(blue)..tostring(red)
local node_name = BASENAME..cid local node_name = BASENAME..cid
local tiles = table.copy(tiles_base) local tiles = table.copy(tiles_base)
if red == 1 then -- Red
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR90)" tiles[1] = tiles[1]..tiles_on_off.R_90:format(red == 1 and "on" or "off");
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR90)" tiles[2] = tiles[2]..tiles_on_off.R_90:format(red == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR270)" tiles[5] = tiles[5]..tiles_on_off.R270:format(red == 1 and "on" or "off");
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR90)" tiles[6] = tiles[6]..tiles_on_off.R_90:format(red == 1 and "on" or "off");
else -- Blue
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR90)" tiles[1] = tiles[1]..tiles_on_off.R270:format(blue == 1 and "on" or "off");
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR90)" tiles[2] = tiles[2]..tiles_on_off.R270:format(blue == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR270)" tiles[5] = tiles[5]..tiles_on_off.R_90:format(blue == 1 and "on" or "off");
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR90)" tiles[6] = tiles[6]..tiles_on_off.R270:format(blue == 1 and "on" or "off");
end -- Yellow
if blue == 1 then tiles[1] = tiles[1]..tiles_on_off.R180:format(yellow == 1 and "on" or "off");
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR270)" tiles[2] = tiles[2]..tiles_on_off.R180:format(yellow == 1 and "on" or "off");
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR270)" tiles[5] = tiles[5]..tiles_on_off.R180:format(yellow == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR90)" tiles[6] = tiles[6]..tiles_on_off.R180:format(yellow == 1 and "on" or "off");
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR270)" -- Green
else tiles[3] = tiles[3]..tiles_on_off.R__0:format(green == 1 and "on" or "off");
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR270)" tiles[4] = tiles[4]..tiles_on_off.R__0:format(green == 1 and "on" or "off");
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR270)" tiles[5] = tiles[5]..tiles_on_off.R__0:format(green == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR90)" tiles[6] = tiles[6]..tiles_on_off.R__0:format(green == 1 and "on" or "off");
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR270)" -- Black
end tiles[1] = tiles[1]..tiles_on_off.R180:format(black == 1 and "on" or "off");
if yellow == 1 then tiles[2] = tiles[2]..tiles_on_off.R__0:format(black == 1 and "on" or "off");
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR180)" tiles[3] = tiles[3]..tiles_on_off.R_90:format(black == 1 and "on" or "off");
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR180)" tiles[4] = tiles[4]..tiles_on_off.R270:format(black == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_on.png^[transformR180)" -- White
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_on.png^[transformR180)" tiles[1] = tiles[1]..tiles_on_off.R__0:format(white == 1 and "on" or "off");
else tiles[2] = tiles[2]..tiles_on_off.R180:format(white == 1 and "on" or "off");
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR180)" tiles[3] = tiles[3]..tiles_on_off.R270:format(white == 1 and "on" or "off");
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR180)" tiles[4] = tiles[4]..tiles_on_off.R_90:format(white == 1 and "on" or "off");
tiles[5] = tiles[5].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
tiles[6] = tiles[6].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
end
if green == 1 then
tiles[3] = tiles[3].."^pipeworks_lua_tube_port_on.png"
tiles[4] = tiles[4].."^pipeworks_lua_tube_port_on.png"
tiles[5] = tiles[5].."^pipeworks_lua_tube_port_on.png"
tiles[6] = tiles[6].."^pipeworks_lua_tube_port_on.png"
else
tiles[3] = tiles[3].."^pipeworks_lua_tube_port_off.png"
tiles[4] = tiles[4].."^pipeworks_lua_tube_port_off.png"
tiles[5] = tiles[5].."^pipeworks_lua_tube_port_off.png"
tiles[6] = tiles[6].."^pipeworks_lua_tube_port_off.png"
end
if black == 1 then
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
tiles[2] = tiles[2].."^pipeworks_lua_tube_port_on.png"
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
else
tiles[1] = tiles[1].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
tiles[2] = tiles[2].."^pipeworks_lua_tube_port_off.png"
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
end
if white == 1 then
tiles[1] = tiles[1].."^pipeworks_lua_tube_port_on.png"
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_on.png^[transformR180)"
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_on.png^[transformR270)"
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_on.png^[transformR90)"
else
tiles[1] = tiles[1].."^pipeworks_lua_tube_port_off.png"
tiles[2] = tiles[2].."^(pipeworks_lua_tube_port_off.png^[transformR180)"
tiles[3] = tiles[3].."^(pipeworks_lua_tube_port_off.png^[transformR270)"
tiles[4] = tiles[4].."^(pipeworks_lua_tube_port_off.png^[transformR90)"
end
local groups = {snappy = 3, tube = 1, tubedevice = 1, overheat = 1} local groups = {snappy = 3, tube = 1, tubedevice = 1, overheat = 1}
if red + blue + yellow + green + black + white ~= 0 then if red + blue + yellow + green + black + white ~= 0 then
@ -933,6 +907,7 @@ for white = 0, 1 do
description = "Lua controlled Tube", description = "Lua controlled Tube",
drawtype = "nodebox", drawtype = "nodebox",
tiles = tiles, tiles = tiles,
use_texture_alpha = texture_alpha_mode,
paramtype = "light", paramtype = "light",
is_ground_content = false, is_ground_content = false,
groups = groups, groups = groups,
@ -1039,6 +1014,7 @@ tiles_burnt[4] = tiles_burnt[4].."^(pipeworks_lua_tube_port_burnt.png^[transform
minetest.register_node(BASENAME .. "_burnt", { minetest.register_node(BASENAME .. "_burnt", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = tiles_burnt, tiles = tiles_burnt,
use_texture_alpha = texture_alpha_mode,
is_burnt = true, is_burnt = true,
paramtype = "light", paramtype = "light",
is_ground_content = false, is_ground_content = false,

View File

@ -10,6 +10,36 @@ minetest.register_craft( {
}, },
}) })
-- 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()
local playername = player:get_player_name()
if allowed_hammers[wieldname] then
itemstack:add_wear(1000)
player:set_wielded_item(itemstack)
return true
end
return false
end
local nodecolor = 0xffff3030 local nodecolor = 0xffff3030
pipeworks.register_tube("pipeworks:broken_tube", { pipeworks.register_tube("pipeworks:broken_tube", {
@ -36,29 +66,27 @@ pipeworks.register_tube("pipeworks:broken_tube", {
local wieldname = itemstack:get_name() local wieldname = itemstack:get_name()
local playername = puncher:get_player_name() local playername = puncher:get_player_name()
local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n" local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n"
if wieldname == "anvil:hammer" local meta = minetest.get_meta(pos)
or wieldname == "cottages:hammer" local was_node = minetest.deserialize(meta:get_string("the_tube_was"))
or wieldname == "glooptest:hammer_steel" if not was_node then
or wieldname == "glooptest:hammer_bronze" pipeworks.logger(log_msg.." but it can't be repaired.")
or wieldname == "glooptest:hammer_diamond" return
or wieldname == "glooptest:hammer_mese"
or wieldname == "glooptest:hammer_alatro"
or wieldname == "glooptest:hammer_arol" then
local meta = minetest.get_meta(pos)
local was_node = minetest.deserialize(meta:get_string("the_tube_was"))
if was_node and was_node ~= "" then
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)
itemstack:add_wear(1000)
puncher:set_wielded_item(itemstack)
return itemstack
else
pipeworks.logger(log_msg.." but it can't be repaired.")
end
else
pipeworks.logger(log_msg.." with "..wieldname.." but that tool is too weak.")
end 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
else
pipeworks.logger(log_msg.." with "..wieldname.." but that tool is too weak.")
end
return
end
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)
end end
} }
}) })

View File

@ -26,6 +26,11 @@ local texture_mt = {
end end
} }
-- This will remove any semi-transparent pixels
-- because that is still buggy in Minetest, force this as default
local texture_alpha_mode = minetest.features.use_texture_alpha_string_modes
and "clip" or true
local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style) local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style)
noctrs = noctrs or default_noctrs noctrs = noctrs or default_noctrs
setmetatable(noctrs, texture_mt) setmetatable(noctrs, texture_mt)
@ -82,6 +87,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
description = tubedesc, description = tubedesc,
drawtype = "nodebox", drawtype = "nodebox",
tiles = outimgs, tiles = outimgs,
use_texture_alpha = texture_alpha_mode,
sunlight_propagates = true, sunlight_propagates = true,
inventory_image = iimg, inventory_image = iimg,
wield_image = iimg, wield_image = iimg,
@ -107,6 +113,18 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}, connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1},
priority = 50 priority = 50
}, },
on_punch = function(pos, node, player, pointed)
local playername = player:get_player_name()
if minetest.is_protected(pos, playername) and not minetest.check_player_privs(playername, {protection_bypass=true}) then
return minetest.node_punch(pos, node, player, pointed)
end
if pipeworks.check_and_wear_hammer(player) then
local wieldname = player:get_wielded_item():get_name()
pipeworks.logger(string.format("%s struck a tube at %s with %s to break it.", playername, minetest.pos_to_string(pos), wieldname))
pipeworks.break_tube(pos)
end
return minetest.node_punch(pos, node, player, pointed)
end,
after_place_node = pipeworks.after_place, after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig, after_dig_node = pipeworks.after_dig,
on_rotate = false, on_rotate = false,