changes
This commit is contained in:
parent
7e4b735a44
commit
6b06dbf32b
25
crafts.lua
25
crafts.lua
|
@ -223,17 +223,26 @@ if pipeworks.enable_mese_tube then
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if pipeworks.enable_item_tags and pipeworks.enable_tags_tube then
|
if pipeworks.enable_item_tags and pipeworks.enable_tag_tube then
|
||||||
local book_item = "default:book"
|
minetest.register_craft( {
|
||||||
minetest.register_craft({
|
output = "pipeworks:tag_tube_000000 2",
|
||||||
output = "pipeworks:tags_tube_000000",
|
|
||||||
recipe = {
|
recipe = {
|
||||||
{ book_item, book_item, book_item },
|
{ "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
|
||||||
{ book_item, "pipeworks:mese_tube_000000", book_item },
|
{ materials.book, materials.mese_crystal, materials.book },
|
||||||
{ book_item, book_item, book_item },
|
{ "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
|
||||||
}
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft( {
|
||||||
|
type = "shapeless",
|
||||||
|
output = "pipeworks:tag_tube_000000",
|
||||||
|
recipe = {
|
||||||
|
"pipeworks:mese_tube_000000",
|
||||||
|
materials.book,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
if pipeworks.enable_sand_tube then
|
if pipeworks.enable_sand_tube then
|
||||||
minetest.register_craft( {
|
minetest.register_craft( {
|
||||||
output = "pipeworks:sand_tube_1 2",
|
output = "pipeworks:sand_tube_1 2",
|
||||||
|
|
|
@ -5,7 +5,7 @@ local prefix = "pipeworks_"
|
||||||
local settings = {
|
local settings = {
|
||||||
enable_pipes = true,
|
enable_pipes = true,
|
||||||
enable_item_tags = true,
|
enable_item_tags = true,
|
||||||
enable_tags_tube = true,
|
enable_tag_tube = true,
|
||||||
enable_lowpoly = false,
|
enable_lowpoly = false,
|
||||||
enable_autocrafter = true,
|
enable_autocrafter = true,
|
||||||
enable_deployer = true,
|
enable_deployer = true,
|
||||||
|
|
|
@ -34,8 +34,8 @@ local function set_filter_formspec(data, meta)
|
||||||
("button_exit[6.3,%f;2,1;close;" .. S("Close") .. "]"):format(form_height - 1.7)
|
("button_exit[6.3,%f;2,1;close;" .. S("Close") .. "]"):format(form_height - 1.7)
|
||||||
if pipeworks.enable_item_tags then
|
if pipeworks.enable_item_tags then
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
("field[0.5,%f;4.6,1;items_tag;"):format(form_height - 1.4) .. S("Items tag") .. ";${items_tag}]" ..
|
("field[0.5,%f;4.6,1;item_tags;"):format(form_height - 1.4) .. S("Item Tags") .. ";${item_tags}]" ..
|
||||||
("button[4.8,%f;1.5,1;set_items_tag;"):format(form_height - 1.7) .. S("Set") .. "]"
|
("button[4.8,%f;1.5,1;set_item_tags;"):format(form_height - 1.7) .. S("Set") .. "]"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local exmatch_button = ""
|
local exmatch_button = ""
|
||||||
|
@ -73,8 +73,8 @@ local function set_filter_formspec(data, meta)
|
||||||
"listring[]"
|
"listring[]"
|
||||||
if pipeworks.enable_item_tags then
|
if pipeworks.enable_item_tags then
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"field[5.8,0.5;3,0.8;items_tag;" .. S("Items tag") .. ";${items_tag}]" ..
|
"field[5.8,0.5;3,0.8;item_tags;" .. S("Item Tags") .. ";${item_tags}]" ..
|
||||||
"button[9,0.3;1,1.1;set_items_tag;" .. S("Set") .. "]"
|
"button[9,0.3;1,1.1;set_item_tags;" .. S("Set") .. "]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
meta:set_string("formspec", formspec)
|
meta:set_string("formspec", formspec)
|
||||||
|
@ -137,7 +137,7 @@ local function punch_filter(data, filtpos, filtnode, msg)
|
||||||
local slotseq_mode
|
local slotseq_mode
|
||||||
local exmatch_mode
|
local exmatch_mode
|
||||||
|
|
||||||
local item_tag = filtmeta:get_string("items_tag")
|
local item_tags = pipeworks.sanitize_tags(filtmeta:get_string("item_tags"))
|
||||||
local filters = {}
|
local filters = {}
|
||||||
if data.digiline then
|
if data.digiline then
|
||||||
local function add_filter(name, group, count, wear, metadata)
|
local function add_filter(name, group, count, wear, metadata)
|
||||||
|
@ -201,9 +201,12 @@ local function punch_filter(data, filtpos, filtnode, msg)
|
||||||
set_filter_formspec(data, filtmeta)
|
set_filter_formspec(data, filtmeta)
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.tag then
|
if type(msg.tags) == "table" then
|
||||||
item_tag = msg.tag
|
item_tags = pipeworks.sanitize_tags(msg.tags)
|
||||||
|
elseif type(msg.tag) == "string" then
|
||||||
|
item_tags = pipeworks.sanitize_tags({msg.tag})
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.nofire then
|
if msg.nofire then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -356,11 +359,8 @@ local function punch_filter(data, filtpos, filtnode, msg)
|
||||||
end
|
end
|
||||||
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
|
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
|
||||||
local start_pos = vector.add(frompos, dir)
|
local start_pos = vector.add(frompos, dir)
|
||||||
if pipeworks.enable_item_tags then
|
|
||||||
pipeworks.set_item_tag(item, item_tag)
|
|
||||||
end
|
|
||||||
pipeworks.tube_inject_item(pos, start_pos, dir, item,
|
pipeworks.tube_inject_item(pos, start_pos, dir, item,
|
||||||
fakePlayer:get_player_name())
|
fakePlayer:get_player_name(), item_tags)
|
||||||
return true -- only fire one item, please
|
return true -- only fire one item, please
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -478,8 +478,9 @@ for _, data in ipairs({
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if pipeworks.enable_item_tags and fields.items_tag and (fields.key_enter_field == "items_tag" or fields.set_items_tag) then
|
if pipeworks.enable_item_tags and fields.item_tags and (fields.key_enter_field == "item_tags" or fields.set_item_tags) then
|
||||||
meta:set_string("items_tag", fields.items_tag)
|
local tags = pipeworks.sanitize_tags(fields.item_tags)
|
||||||
|
meta:set_string("item_tags", table.concat(tags, ","))
|
||||||
end
|
end
|
||||||
--meta:set_int("slotseq_index", 1)
|
--meta:set_int("slotseq_index", 1)
|
||||||
set_filter_formspec(data, meta)
|
set_filter_formspec(data, meta)
|
||||||
|
@ -502,8 +503,9 @@ for _, data in ipairs({
|
||||||
fs_helpers.on_receive_fields(pos, fields)
|
fs_helpers.on_receive_fields(pos, fields)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int("slotseq_index", 1)
|
meta:set_int("slotseq_index", 1)
|
||||||
if pipeworks.enable_item_tags and fields.items_tag and (fields.key_enter_field == "items_tag" or fields.set_items_tag) then
|
if pipeworks.enable_item_tags and fields.item_tags and (fields.key_enter_field == "item_tags" or fields.set_item_tags) then
|
||||||
meta:set_string("items_tag", fields.items_tag)
|
local tags = pipeworks.sanitize_tags(fields.item_tags)
|
||||||
|
meta:set_string("item_tags", table.concat(tags, ","))
|
||||||
end
|
end
|
||||||
set_filter_formspec(data, meta)
|
set_filter_formspec(data, meta)
|
||||||
set_filter_infotext(data, meta)
|
set_filter_infotext(data, meta)
|
||||||
|
|
|
@ -4,31 +4,35 @@ local max_tube_limit = tonumber(minetest.settings:get("pipeworks_max_items_per_t
|
||||||
if enable_max_limit == nil then enable_max_limit = true end
|
if enable_max_limit == nil then enable_max_limit = true end
|
||||||
|
|
||||||
if pipeworks.enable_item_tags then
|
if pipeworks.enable_item_tags then
|
||||||
local item_tag_name = "pipeworks:item_tag"
|
local max_tag_length = tonumber(minetest.settings:get("pipeworks_max_item_tag_length")) or 32
|
||||||
local item_tag_name_limit = tonumber(minetest.settings:get("pipeworks_item_tag_name_limit") or "30")
|
local max_tags = tonumber(minetest.settings:get("pipeworks_max_item_tags")) or 16
|
||||||
|
|
||||||
pipeworks.safe_tag = function(tag)
|
function pipeworks.sanitize_tags(tags)
|
||||||
if tag == nil or type(tag) ~= "string" or tag == "" then return nil end
|
if type(tags) == "string" then
|
||||||
tag = tag:gsub(",", "_") -- replace commas with underscores
|
tags = tags:split(",")
|
||||||
tag = tag:trim() -- trim leading and trailing spaces
|
end
|
||||||
return tag:sub(1, item_tag_name_limit)
|
local sanitized = {}
|
||||||
end
|
for i, tag in ipairs(tags) do
|
||||||
|
if type(tag) == "string" then
|
||||||
pipeworks.set_item_tag = function(item_stack, tag)
|
tag = tag:gsub("[%s,]", "") -- Remove whitespace and commas
|
||||||
if item_stack == nil then return end
|
tag = tag:gsub("%$%b%{%}", "") -- Remove special ${key} values
|
||||||
item_stack:get_meta():set_string(item_tag_name, pipeworks.safe_tag(tag))
|
if tag ~= "" then
|
||||||
end
|
table.insert(sanitized, tag:sub(1, max_tag_length))
|
||||||
|
end
|
||||||
pipeworks.get_item_tag = function(item_stack)
|
end
|
||||||
if item_stack == nil then return nil end
|
if #sanitized >= max_tags then
|
||||||
return item_stack:get_meta():get_string(item_tag_name)
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return sanitized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function pipeworks.tube_item(pos, item)
|
function pipeworks.tube_item(pos, item)
|
||||||
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
|
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
|
||||||
end
|
end
|
||||||
|
|
||||||
function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner)
|
function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner, tags)
|
||||||
-- Take item in any format
|
-- Take item in any format
|
||||||
local stack = ItemStack(item)
|
local stack = ItemStack(item)
|
||||||
local obj = luaentity.add_entity(pos, "pipeworks:tubed_item")
|
local obj = luaentity.add_entity(pos, "pipeworks:tubed_item")
|
||||||
|
@ -36,6 +40,7 @@ function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner)
|
||||||
obj.start_pos = vector.new(start_pos)
|
obj.start_pos = vector.new(start_pos)
|
||||||
obj:set_velocity(velocity)
|
obj:set_velocity(velocity)
|
||||||
obj.owner = owner
|
obj.owner = owner
|
||||||
|
obj.tags = tags
|
||||||
--obj:set_color("red") -- todo: this is test-only code
|
--obj:set_color("red") -- todo: this is test-only code
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
@ -100,13 +105,14 @@ end
|
||||||
|
|
||||||
-- compatibility behaviour for the existing can_go() callbacks,
|
-- compatibility behaviour for the existing can_go() callbacks,
|
||||||
-- which can only specify a list of possible positions.
|
-- which can only specify a list of possible positions.
|
||||||
local function go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner)
|
local function go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner, tags)
|
||||||
local next_positions = {}
|
local next_positions = {}
|
||||||
local max_priority = 0
|
local max_priority = 0
|
||||||
local can_go
|
local can_go
|
||||||
|
|
||||||
if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
|
local def = minetest.registered_nodes[cnode.name]
|
||||||
can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack)
|
if def and def.tube and def.tube.can_go then
|
||||||
|
can_go = def.tube.can_go(pos, cnode, vel, stack, tags)
|
||||||
else
|
else
|
||||||
local adjlist_string = minetest.get_meta(pos):get_string("adjlist")
|
local adjlist_string = minetest.get_meta(pos):get_string("adjlist")
|
||||||
local adjlist = minetest.deserialize(adjlist_string) or default_adjlist -- backward compat: if not found, use old behavior: all directions
|
local adjlist = minetest.deserialize(adjlist_string) or default_adjlist -- backward compat: if not found, use old behavior: all directions
|
||||||
|
@ -165,7 +171,7 @@ end
|
||||||
-- * a "multi-mode" data table (or nil if N/A) where a stack was split apart.
|
-- * a "multi-mode" data table (or nil if N/A) where a stack was split apart.
|
||||||
-- if this is not nil, the luaentity spawns new tubed items for each new fragment stack,
|
-- if this is not nil, the luaentity spawns new tubed items for each new fragment stack,
|
||||||
-- then deletes itself (i.e. the original item stack).
|
-- then deletes itself (i.e. the original item stack).
|
||||||
local function go_next(pos, velocity, stack, owner)
|
local function go_next(pos, velocity, stack, owner, tags)
|
||||||
local cnode = minetest.get_node(pos)
|
local cnode = minetest.get_node(pos)
|
||||||
local cmeta = minetest.get_meta(pos)
|
local cmeta = minetest.get_meta(pos)
|
||||||
local speed = math.abs(velocity.x + velocity.y + velocity.z)
|
local speed = math.abs(velocity.x + velocity.y + velocity.z)
|
||||||
|
@ -193,7 +199,7 @@ local function go_next(pos, velocity, stack, owner)
|
||||||
-- n is the new value of the cycle counter.
|
-- n is the new value of the cycle counter.
|
||||||
-- XXX: this probably needs cleaning up after being split out,
|
-- XXX: this probably needs cleaning up after being split out,
|
||||||
-- seven args is a bit too many
|
-- seven args is a bit too many
|
||||||
local n, found, new_velocity, multimode = go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner)
|
local n, found, new_velocity, multimode = go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner, tags)
|
||||||
|
|
||||||
-- if not using output cycling,
|
-- if not using output cycling,
|
||||||
-- don't update the field so it stays the same for the next item.
|
-- don't update the field so it stays the same for the next item.
|
||||||
|
@ -297,6 +303,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
||||||
color_entity = nil,
|
color_entity = nil,
|
||||||
color = nil,
|
color = nil,
|
||||||
start_pos = nil,
|
start_pos = nil,
|
||||||
|
tags = nil,
|
||||||
|
|
||||||
set_item = function(self, item)
|
set_item = function(self, item)
|
||||||
local itemstring = ItemStack(item):to_string() -- Accept any input format
|
local itemstring = ItemStack(item):to_string() -- Accept any input format
|
||||||
|
@ -358,13 +365,9 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
||||||
local node = minetest.get_node(self.start_pos)
|
local node = minetest.get_node(self.start_pos)
|
||||||
if minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
if minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
|
||||||
local leftover
|
local leftover
|
||||||
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
|
local def = minetest.registered_nodes[node.name]
|
||||||
local item_tag = nil
|
if def.tube and def.tube.insert_object then
|
||||||
if pipeworks.enable_item_tags then
|
leftover = def.tube.insert_object(self.start_pos, node, stack, vel, self.owner)
|
||||||
item_tag = pipeworks.get_item_tag(stack)
|
|
||||||
pipeworks.set_item_tag(stack, nil)
|
|
||||||
end
|
|
||||||
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel, self.owner, item_tag)
|
|
||||||
else
|
else
|
||||||
leftover = stack
|
leftover = stack
|
||||||
end
|
end
|
||||||
|
@ -379,8 +382,14 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local found_next, new_velocity, multimode = go_next(self.start_pos, velocity, stack, self.owner) -- todo: color
|
local tags
|
||||||
self.itemstring = stack:to_string()
|
if pipeworks.enable_item_tags then
|
||||||
|
tags = self.tags or {}
|
||||||
|
end
|
||||||
|
local found_next, new_velocity, multimode = go_next(self.start_pos, velocity, stack, self.owner, tags) -- todo: color
|
||||||
|
if pipeworks.enable_item_tags then
|
||||||
|
self.tags = #tags > 0 and pipeworks.sanitize_tags(tags) or nil
|
||||||
|
end
|
||||||
local rev_vel = vector.multiply(velocity, -1)
|
local rev_vel = vector.multiply(velocity, -1)
|
||||||
local rev_dir = vector.direction(self.start_pos,vector.add(self.start_pos,rev_vel))
|
local rev_dir = vector.direction(self.start_pos,vector.add(self.start_pos,rev_vel))
|
||||||
local rev_node = minetest.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
|
local rev_node = minetest.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
|
||||||
|
@ -391,9 +400,6 @@ luaentity.register_entity("pipeworks:tubed_item", {
|
||||||
-- Using add_item instead of item_drop since this makes pipeworks backward
|
-- Using add_item instead of item_drop since this makes pipeworks backward
|
||||||
-- compatible with Minetest 0.4.13.
|
-- compatible with Minetest 0.4.13.
|
||||||
-- Using item_drop here makes Minetest 0.4.13 crash.
|
-- Using item_drop here makes Minetest 0.4.13 crash.
|
||||||
if pipeworks.enable_item_tags then
|
|
||||||
pipeworks.set_item_tag(stack, nil)
|
|
||||||
end
|
|
||||||
local dropped_item = minetest.add_item(self.start_pos, stack)
|
local dropped_item = minetest.add_item(self.start_pos, stack)
|
||||||
if dropped_item then
|
if dropped_item then
|
||||||
dropped_item:set_velocity(vector.multiply(velocity, 5))
|
dropped_item:set_velocity(vector.multiply(velocity, 5))
|
||||||
|
|
|
@ -10,7 +10,8 @@ local materials = {
|
||||||
mese_crystal = "default:mese_crystal",
|
mese_crystal = "default:mese_crystal",
|
||||||
mese_crystal_fragment = "default:mese_crystal_fragment",
|
mese_crystal_fragment = "default:mese_crystal_fragment",
|
||||||
teleporter = "default:mese",
|
teleporter = "default:mese",
|
||||||
glass = "default:glass"
|
glass = "default:glass",
|
||||||
|
book = "default:book",
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.get_modpath("mcl_core") then
|
if minetest.get_modpath("mcl_core") then
|
||||||
|
@ -27,6 +28,7 @@ if minetest.get_modpath("mcl_core") then
|
||||||
teleporter = "mesecons_torch:redstoneblock",
|
teleporter = "mesecons_torch:redstoneblock",
|
||||||
copper_ingot = "mcl_copper:copper_ingot",
|
copper_ingot = "mcl_copper:copper_ingot",
|
||||||
glass = "mcl_core:glass",
|
glass = "mcl_core:glass",
|
||||||
|
book = "mcl_core:book",
|
||||||
}
|
}
|
||||||
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
|
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
|
||||||
materials = {
|
materials = {
|
||||||
|
@ -58,6 +60,7 @@ elseif minetest.get_modpath("hades_core") then
|
||||||
copper_ingot = "hades_core:copper_ingot",
|
copper_ingot = "hades_core:copper_ingot",
|
||||||
tin_ingot = "hades_core:tin_ingot",
|
tin_ingot = "hades_core:tin_ingot",
|
||||||
glass = "hades_core:glass",
|
glass = "hades_core:glass",
|
||||||
|
book = "hades_core:book",
|
||||||
}
|
}
|
||||||
if minetest.get_modpath("hades_default") then
|
if minetest.get_modpath("hades_default") then
|
||||||
materials.desert_sand = "hades_default:desert_sand"
|
materials.desert_sand = "hades_default:desert_sand"
|
||||||
|
|
|
@ -809,45 +809,6 @@ local function go_back(velocity)
|
||||||
return pipeworks.notvel(adjlist, vel)
|
return pipeworks.notvel(adjlist, vel)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_item_table(stack)
|
|
||||||
local item = stack:to_table()
|
|
||||||
if pipeworks.enable_item_tags then
|
|
||||||
item.tag = pipeworks.get_item_tag(stack)
|
|
||||||
end
|
|
||||||
return item
|
|
||||||
end
|
|
||||||
|
|
||||||
local function parse_returned_msg_v1(msg, _, velocity)
|
|
||||||
if type(msg) ~= "string" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
local r = rules[msg]
|
|
||||||
return true, r and { r } or go_back(velocity)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function parse_returned_msg_v2(msg, stack, velocity)
|
|
||||||
if type(msg) ~= "table" or type(msg.side) ~= "string" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
local r = rules[msg.side]
|
|
||||||
if pipeworks.enable_item_tags and r and type(msg.tag) == "string" then
|
|
||||||
pipeworks.set_item_tag(stack, msg.tag)
|
|
||||||
end
|
|
||||||
return true, r and { r } or go_back(velocity)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function parse_returned_msg(msg, stack, velocity)
|
|
||||||
local parsers = {
|
|
||||||
parse_returned_msg_v2,
|
|
||||||
parse_returned_msg_v1,
|
|
||||||
}
|
|
||||||
for _, parser in ipairs(parsers) do
|
|
||||||
local is_processed, result = parser(msg, stack, velocity)
|
|
||||||
if is_processed then return result end
|
|
||||||
end
|
|
||||||
return go_back(velocity)
|
|
||||||
end
|
|
||||||
|
|
||||||
local tiles_base = {
|
local tiles_base = {
|
||||||
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_3.png",
|
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_3.png",
|
||||||
"pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_1.png",
|
"pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_1.png",
|
||||||
|
@ -984,7 +945,7 @@ for white = 0, 1 do
|
||||||
tube = {
|
tube = {
|
||||||
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,
|
||||||
can_go = function(pos, node, velocity, stack)
|
can_go = function(pos, node, velocity, stack, tags)
|
||||||
local src = {name = nil}
|
local src = {name = nil}
|
||||||
-- add color of the incoming tube explicitly; referring to rules, in case they change later
|
-- add color of the incoming tube explicitly; referring to rules, in case they change later
|
||||||
for _, rule in pairs(rules) do
|
for _, rule in pairs(rules) do
|
||||||
|
@ -997,13 +958,35 @@ for white = 0, 1 do
|
||||||
type = "item",
|
type = "item",
|
||||||
pin = src,
|
pin = src,
|
||||||
itemstring = stack:to_string(),
|
itemstring = stack:to_string(),
|
||||||
item = get_item_table(stack),
|
item = stack:to_table(),
|
||||||
velocity = velocity,
|
velocity = velocity,
|
||||||
|
tags = table.copy(tags),
|
||||||
|
side = src.name,
|
||||||
})
|
})
|
||||||
if not succ then
|
if not succ then
|
||||||
return go_back(velocity)
|
return go_back(velocity)
|
||||||
end
|
end
|
||||||
return parse_returned_msg(msg, stack, velocity)
|
if type(msg) == "string" then
|
||||||
|
local side = rules[msg]
|
||||||
|
return side and {side} or go_back(velocity)
|
||||||
|
elseif type(msg) == "table" then
|
||||||
|
if pipeworks.enable_item_tags then
|
||||||
|
local new_tags
|
||||||
|
if type(msg.tags) == "table" then
|
||||||
|
new_tags = msg.tags
|
||||||
|
elseif type(msg.tag) == "string" then
|
||||||
|
new_tags = {msg.tag}
|
||||||
|
end
|
||||||
|
if new_tags then
|
||||||
|
for i=1, math.max(#tags, #new_tags) do
|
||||||
|
tags[i] = new_tags[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local side = rules[msg.side]
|
||||||
|
return side and {side} or go_back(velocity)
|
||||||
|
end
|
||||||
|
return go_back(velocity)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
after_place_node = pipeworks.after_place,
|
after_place_node = pipeworks.after_place,
|
||||||
|
|
|
@ -1,61 +1,51 @@
|
||||||
local S = minetest.get_translator("pipeworks")
|
local S = minetest.get_translator("pipeworks")
|
||||||
local fs_helpers = pipeworks.fs_helpers
|
local fs_helpers = pipeworks.fs_helpers
|
||||||
|
|
||||||
if not pipeworks.enable_tags_tube then return end
|
if not pipeworks.enable_item_tags or not pipeworks.enable_tag_tube then return end
|
||||||
|
|
||||||
local notag_name = "<<notag>>"
|
local help_text = minetest.formspec_escape(
|
||||||
local tube_name = "pipeworks:tags_tube"
|
S("Separate multiple tags using commas.").."\n"..
|
||||||
local tube_description = S("Tags Sorting Pneumatic Tube Segment")
|
S("Use \"<none>\" to match items without tags.")
|
||||||
|
)
|
||||||
local safe_tags = function(tags)
|
|
||||||
local length_limit = tonumber(minetest.settings:get("pipeworks_item_tag_name_limit") or "30")
|
|
||||||
return tags:sub(1, length_limit * 6)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function escape(s)
|
|
||||||
return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]', '%%%1'))
|
|
||||||
end
|
|
||||||
|
|
||||||
local update_formspec = function(pos)
|
local update_formspec = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local buttons_formspec = ""
|
local buttons_formspec = ""
|
||||||
for i = 0, 5 do
|
for i = 0, 5 do
|
||||||
buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta,
|
buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta,
|
||||||
"image_button[9," .. (i + (i * 0.25) + 1.5) .. ";1,0.6", "l" .. (i + 1) .. "s",
|
"image_button[9," .. (i + (i * 0.25) + 0.5) .. ";1,0.6", "l" .. (i + 1) .. "s",
|
||||||
{
|
{
|
||||||
pipeworks.button_off,
|
pipeworks.button_off,
|
||||||
pipeworks.button_on
|
pipeworks.button_on
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
local size = "10.2,10"
|
local size = "10.2,9"
|
||||||
meta:set_string("formspec",
|
meta:set_string("formspec",
|
||||||
"formspec_version[2]" ..
|
"formspec_version[2]" ..
|
||||||
"size[" .. size .. "]" ..
|
"size[" .. size .. "]" ..
|
||||||
"item_image[0.2,0.2;1,1; " .. tube_name .. "]" ..
|
|
||||||
"label[1.5,0.75;" .. minetest.formspec_escape(tube_description) .. "]" ..
|
|
||||||
pipeworks.fs_helpers.get_prepends(size) ..
|
pipeworks.fs_helpers.get_prepends(size) ..
|
||||||
"field[1.5,1.25;7.25,1;tags1;;${tags1}]" ..
|
"field[1.5,0.25;7.25,1;tags1;;${tags1}]" ..
|
||||||
"field[1.5,2.5;7.25,1;tags2;;${tags2}]" ..
|
"field[1.5,1.5;7.25,1;tags2;;${tags2}]" ..
|
||||||
"field[1.5,3.75;7.25,1;tags3;;${tags3}]" ..
|
"field[1.5,2.75;7.25,1;tags3;;${tags3}]" ..
|
||||||
"field[1.5,5.0;7.25,1;tags4;;${tags4}]" ..
|
"field[1.5,4.0;7.25,1;tags4;;${tags4}]" ..
|
||||||
"field[1.5,6.25;7.25,1;tags5;;${tags5}]" ..
|
"field[1.5,5.25;7.25,1;tags5;;${tags5}]" ..
|
||||||
"field[1.5,7.5;7.25,1;tags6;;${tags6}]" ..
|
"field[1.5,6.5;7.25,1;tags6;;${tags6}]" ..
|
||||||
|
|
||||||
"image[0.22,1.25;1,1;pipeworks_white.png]" ..
|
"image[0.22,0.25;1,1;pipeworks_white.png]" ..
|
||||||
"image[0.22,2.50;1,1;pipeworks_black.png]" ..
|
"image[0.22,1.50;1,1;pipeworks_black.png]" ..
|
||||||
"image[0.22,3.75;1,1;pipeworks_green.png]" ..
|
"image[0.22,2.75;1,1;pipeworks_green.png]" ..
|
||||||
"image[0.22,5.00;1,1;pipeworks_yellow.png]" ..
|
"image[0.22,4.00;1,1;pipeworks_yellow.png]" ..
|
||||||
"image[0.22,6.25;1,1;pipeworks_blue.png]" ..
|
"image[0.22,5.25;1,1;pipeworks_blue.png]" ..
|
||||||
"image[0.22,7.50;1,1;pipeworks_red.png]" ..
|
"image[0.22,6.50;1,1;pipeworks_red.png]" ..
|
||||||
buttons_formspec ..
|
buttons_formspec ..
|
||||||
"button[6,8.75;1.5,1;set_items_tags;" .. S("Set") .. "]" ..
|
"label[0.22,7.9;"..help_text.."]"..
|
||||||
"button_exit[7.75,8.75;2,1;close;" .. S("Close") .. "]"
|
"button[7.25,7.8;1.5,0.8;set_item_tags;" .. S("Set") .. "]"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeworks.register_tube(tube_name, {
|
pipeworks.register_tube("pipeworks:tag_tube", {
|
||||||
description = tube_description,
|
description = S("Tag Sorting Pneumatic Tube Segment"),
|
||||||
inventory_image = "pipeworks_tag_tube_inv.png",
|
inventory_image = "pipeworks_tag_tube_inv.png",
|
||||||
noctr = { "pipeworks_tag_tube_noctr_1.png", "pipeworks_tag_tube_noctr_2.png", "pipeworks_tag_tube_noctr_3.png",
|
noctr = { "pipeworks_tag_tube_noctr_1.png", "pipeworks_tag_tube_noctr_2.png", "pipeworks_tag_tube_noctr_3.png",
|
||||||
"pipeworks_tag_tube_noctr_4.png", "pipeworks_tag_tube_noctr_5.png", "pipeworks_tag_tube_noctr_6.png" },
|
"pipeworks_tag_tube_noctr_4.png", "pipeworks_tag_tube_noctr_5.png", "pipeworks_tag_tube_noctr_6.png" },
|
||||||
|
@ -66,15 +56,18 @@ pipeworks.register_tube(tube_name, {
|
||||||
no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones
|
no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones
|
||||||
node_def = {
|
node_def = {
|
||||||
tube = {
|
tube = {
|
||||||
can_go = function(pos, node, velocity, stack)
|
can_go = function(pos, node, velocity, stack, tags)
|
||||||
local tbl, tbln = {}, 0
|
local tbl, tbln = {}, 0
|
||||||
local found, foundn = {}, 0
|
local found, foundn = {}, 0
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local stack_tag = pipeworks.get_item_tag(stack)
|
local tag_hash = {}
|
||||||
if not stack_tag or stack_tag == "" then
|
if #tags > 0 then
|
||||||
stack_tag = notag_name
|
for _,tag in ipairs(tags) do
|
||||||
|
tag_hash[tag] = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
tag_hash["<none>"] = true -- Matches items without tags
|
||||||
end
|
end
|
||||||
stack_tag = pipeworks.safe_tag(stack_tag)
|
|
||||||
for i, vect in ipairs(pipeworks.meseadjlist) do
|
for i, vect in ipairs(pipeworks.meseadjlist) do
|
||||||
local npos = vector.add(pos, vect)
|
local npos = vector.add(pos, vect)
|
||||||
local node = minetest.get_node(npos)
|
local node = minetest.get_node(npos)
|
||||||
|
@ -83,19 +76,17 @@ pipeworks.register_tube(tube_name, {
|
||||||
local tube_def = reg_node.tube
|
local tube_def = reg_node.tube
|
||||||
if not tube_def or not tube_def.can_insert or
|
if not tube_def or not tube_def.can_insert or
|
||||||
tube_def.can_insert(npos, node, stack, vect) then
|
tube_def.can_insert(npos, node, stack, vect) then
|
||||||
local tags_name = "tags" .. i
|
local side_tags = meta:get_string("tags" .. i)
|
||||||
local tags = meta:get_string(tags_name)
|
if side_tags ~= "" then
|
||||||
local is_empty = tags == nil or tags == ""
|
side_tags = pipeworks.sanitize_tags(side_tags)
|
||||||
if not is_empty then
|
for _,tag in ipairs(side_tags) do
|
||||||
for tag in string.gmatch(tags, "[^,]+") do
|
if tag_hash[tag] then
|
||||||
tag = pipeworks.safe_tag(tag)
|
|
||||||
if tag and (tag == stack_tag or stack_tag:find(("^%s%%."):format(escape(tag)))) then
|
|
||||||
foundn = foundn + 1
|
foundn = foundn + 1
|
||||||
found[foundn] = vect
|
found[foundn] = vect
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
if is_empty then
|
|
||||||
tbln = tbln + 1
|
tbln = tbln + 1
|
||||||
tbl[tbln] = vect
|
tbl[tbln] = vect
|
||||||
end
|
end
|
||||||
|
@ -107,13 +98,11 @@ pipeworks.register_tube(tube_name, {
|
||||||
},
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
|
||||||
for i = 1, 6 do
|
for i = 1, 6 do
|
||||||
meta:set_int("l" .. tostring(i) .. "s", 1)
|
meta:set_int("l" .. tostring(i) .. "s", 1)
|
||||||
inv:set_size("line" .. tostring(i), 6 * 1)
|
|
||||||
end
|
end
|
||||||
update_formspec(pos)
|
update_formspec(pos)
|
||||||
meta:set_string("infotext", S("Tags Sorting pneumatic tube"))
|
meta:set_string("infotext", S("Tag sorting pneumatic tube"))
|
||||||
end,
|
end,
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
if placer and placer:is_player() and placer:get_player_control().aux1 then
|
if placer and placer:is_player() and placer:get_player_control().aux1 then
|
||||||
|
@ -135,8 +124,8 @@ pipeworks.register_tube(tube_name, {
|
||||||
for i = 1, 6 do
|
for i = 1, 6 do
|
||||||
local field_name = "tags" .. tostring(i)
|
local field_name = "tags" .. tostring(i)
|
||||||
if fields[field_name] then
|
if fields[field_name] then
|
||||||
local safe_tags = safe_tags(fields[field_name])
|
local tags = pipeworks.sanitize_tags(fields[field_name])
|
||||||
meta:set_string(field_name, safe_tags)
|
meta:set_string(field_name, table.concat(tags, ","))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue