From 5b0dceb44a26b88ee99a005591e0dd9479f9406d Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Fri, 29 Dec 2023 11:01:08 -0800 Subject: [PATCH 01/30] add dummy implementations of all current API calls to fake player (#98) * add dummy implementations of all current API calls to fake player * fakeplayer: move all stateless API into a metatable * correctly set metatable --- common.lua | 226 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 185 insertions(+), 41 deletions(-) diff --git a/common.lua b/common.lua index 3a45e91..b057fe4 100644 --- a/common.lua +++ b/common.lua @@ -248,6 +248,183 @@ local function get_set_wrap(name, is_dynamic) end) end +local fake_player_metatable = { + is_player = delay(true), + is_fake_player = true, + + -- dummy implementation of the rest of the player API: + add_player_velocity = delay(), -- deprecated + add_velocity = delay(), + get_acceleration = delay(), -- no-op for players + get_animation = delay({x = 0, y = 0}, 0, 0, false), + get_armor_groups = delay({}), + get_attach = delay(), + get_attribute = delay(), -- deprecated + get_bone_position = delay(vector.zero(), vector.zero()), + get_children = delay({}), + get_clouds = delay({ + ambient = { r = 0, b = 0, g = 0, a = 0 }, + color = { r = 0, b = 0, g = 0, a = 0 }, + density = 0, + height = 120, + thickness = 10, + speed = vector.zero(), + }), + get_day_night_ratio = delay(), + get_entity_name = delay(), + get_formspec_prepend = delay(""), + get_fov = delay(0, false, 0), + get_lighting = delay({ + exposure = { + center_weight_power = 1, + exposure_correction = 0, + luminance_max = -3, + luminance_min = -3, + speed_bright_dark = 1000, + speed_dark_bright = 1000, + }, + saturation = 1, + shadows = { + intensity = .6212, + }, + }), + get_local_animation = delay({x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, 30), + get_luaentity = delay(), + get_meta = delay({ + contains = delay(false), + get = delay(), + set_string = delay(), + get_string = delay(""), + set_int = delay(), + get_int = delay(0), + set_float = delay(), + get_float = delay(0), + get_keys = delay({}), + to_table = delay({fields = {}}), + from_table = delay(false), + equals = delay(false), + }), + get_moon = delay({ + scale = 1, + texture = "", + tonemap = "", + visible = false, + }), + get_physics_override = delay({ + acceleration_air = 1, + acceleration_default = 1, + gravity = 1, + jump = 1, + liquid_fluidity = 1, + liquid_fluidity_smooth = 1, + liquid_sink = 1, + new_move = true, + sneak = true, + sneak_glitch = false, + speed = 1, + speed_climb = 1, + speed_crouch = 1, + }), + get_player_velocity = vector.zero, -- deprecated + get_rotation = delay(), -- no-op for players + get_sky = delay({ r = 0, g = 0, b = 0, a = 0 }, "regular", {}, true), + get_sky_color = delay({ + dawn_horizon = { r = 0, g = 0, b = 0, a = 0 }, + dawn_sky = { r = 0, g = 0, b = 0, a = 0 }, + day_horizon = { r = 0, g = 0, b = 0, a = 0 }, + day_sky = { r = 0, g = 0, b = 0, a = 0 }, + fog_moon_tint = { r = 0, g = 0, b = 0, a = 0 }, + fog_sun_tint = { r = 0, g = 0, b = 0, a = 0 }, + fog_tint_type = "default", + indoors = { r = 0, g = 0, b = 0, a = 0 }, + night_horizon = { r = 0, g = 0, b = 0, a = 0 }, + night_sky = { r = 0, g = 0, b = 0, a = 0 }, + }), + get_stars = delay({ + count = 1000, + day_opacity = 0, + scale = 1, + star_color = { r = 0, g = 0, b = 0, a = 0 }, + visible = true, + }), + get_sun = delay({ + scale = 1, + sunrise = "", + sunrise_visible = true, + texture = "", + tonemap = "", + visible = true, + }), + get_texture_mod = delay(), -- no-op for players + get_velocity = vector.zero, + get_yaw = delay(), -- no-op for players + getacceleration = delay(), -- backward compatibility + getvelocity = vector.zero, -- backward compatibility + getyaw = delay(), -- backward compatibility + hud_add = delay(), + hud_change = delay(), + hud_get = delay(), + hud_get_flags = delay({ + basic_debug = false, + breathbar = false, + chat = false, + crosshair = false, + healthbar = false, + hotbar = false, + minimap = false, + minimap_radar = false, + wielditem = false, + }), + hud_get_hotbar_image = delay(""), + hud_get_hotbar_itemcount = delay(1), + hud_get_hotbar_selected_image = delay(""), + hud_remove = delay(), + hud_set_flags = delay(), + hud_set_hotbar_image = delay(), + hud_set_hotbar_itemcount = delay(), + hud_set_hotbar_selected_image = delay(), + override_day_night_ratio = delay(), + punch = delay(), + remove = delay(), + respawn = delay(), + right_click = delay(), + send_mapblock = delay(), + set_acceleration = delay(), + set_animation = delay(), + set_animation_frame_speed = delay(), + set_armor_groups = delay(), + set_attach = delay(), + set_attribute = delay(), -- deprecated + set_bone_position = delay(), + set_clouds = delay(), + set_detach = delay(), + set_formspec_prepend = delay(), + set_fov = delay(), + set_lighting = delay(), + set_local_animation = delay(), + set_look_horizontal = delay(), + set_look_pitch = delay(), + set_look_vertical = delay(), + set_look_yaw = delay(), + set_minimap_modes = delay(), + set_moon = delay(), + set_nametag_attributes = delay(), + set_physics_override = delay(), + set_rotation = delay(), -- no-op for players + set_sky = delay(), + set_sprite = delay(), -- no-op for players + set_stars = delay(), + set_sun = delay(), + set_texture_mod = delay(), -- no-op for players + set_velocity = delay(), -- no-op for players + set_yaw = delay(), -- no-op for players + setacceleration = delay(), -- backward compatibility + setsprite = delay(), -- backward compatibility + settexturemod = delay(), -- backward compatibility + setvelocity = delay(), -- backward compatibility + setyaw = delay(), -- backward compatibility +} + function pipeworks.create_fake_player(def, is_dynamic) local wielded_item = ItemStack("") if def.inventory and def.wield_list then @@ -255,8 +432,6 @@ function pipeworks.create_fake_player(def, is_dynamic) end local p = { get_player_name = delay(def.name), - is_player = delay(true), - is_fake_player = true, _formspec = def.formspec or "", _hp = def.hp or 20, @@ -277,12 +452,11 @@ function pipeworks.create_fake_player(def, is_dynamic) get_eye_offset = function(self) return self._eye_offset1, self._eye_offset3 end, - get_look_dir = delay(def.look_dir or {x=0, y=0, z=1}), + get_look_dir = delay(def.look_dir or vector.new()), get_look_pitch = delay(def.look_pitch or 0), get_look_yaw = delay(def.look_yaw or 0), get_look_horizontal = delay(def.look_yaw or 0), get_look_vertical = delay(-(def.look_pitch or 0)), - set_animation = delay(), -- Controls get_player_control = delay({ @@ -308,14 +482,11 @@ function pipeworks.create_fake_player(def, is_dynamic) return ItemStack(self._wielded_item) end, get_wield_list = delay(def.wield_list), - - punch = delay(), - remove = delay(), - right_click = delay(), - set_attach = delay(), - set_detach = delay(), - set_bone_position = delay(), - hud_change = delay(), + get_nametag_attributes = delay({ + bgcolor = false, + color = { r = 0, g = 0, b = 0, a = 0 }, + text = def.name, + }), } -- Getter & setter functions p.get_inventory_formspec, p.set_inventory_formspec @@ -329,37 +500,10 @@ function pipeworks.create_fake_player(def, is_dynamic) -- For players, move_to and get_pos do the same p.move_to = p.get_pos - -- Backwards compatibilty + -- Backwards compatibility p.getpos = p.get_pos p.setpos = p.set_pos p.moveto = p.move_to - - -- TODO "implement" all these - -- set_armor_groups - -- get_armor_groups - -- get_animation - -- get_bone_position - -- get_player_velocity - -- set_look_pitch - -- set_look_yaw - -- set_physics_override - -- get_physics_override - -- hud_add - -- hud_remove - -- hud_get - -- hud_set_flags - -- hud_get_flags - -- hud_set_hotbar_itemcount - -- hud_get_hotbar_itemcount - -- hud_set_hotbar_image - -- hud_get_hotbar_image - -- hud_set_hotbar_selected_image - -- hud_get_hotbar_selected_image - -- hud_replace_builtin - -- set_sky - -- get_sky - -- override_day_night_ratio - -- get_day_night_ratio - -- set_local_animation + setmetatable(p, { __index = fake_player_metatable }) return p end From dd6950f7b037d17895d41db2bbbddfdfddcdf25c Mon Sep 17 00:00:00 2001 From: OgelGames Date: Fri, 5 Jan 2024 16:11:23 +1100 Subject: [PATCH 02/30] bump `min_minetest_version` to 5.5.0 for `vector.zero()` closes #100 --- mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.conf b/mod.conf index c9dbf62..3e57efe 100644 --- a/mod.conf +++ b/mod.conf @@ -2,4 +2,4 @@ name = pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. depends = basic_materials optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience -min_minetest_version = 5.4.0 +min_minetest_version = 5.5.0 From 578e45257bd37f748c53c48cff7b4d91d3a806b9 Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Sun, 14 Jan 2024 02:40:01 +0100 Subject: [PATCH 03/30] code and registrations cleanup (#101) * code and registrations cleanup * don't expose materials to global env --------- Co-authored-by: BuckarooBanzay --- .github/workflows/luacheck.yml | 13 +- common.lua | 93 +++++++++++ crafts.lua | 76 +-------- init.lua | 155 ++++-------------- materials.lua | 67 ++++++++ tubes/embedded_tube.lua | 68 ++++++++ lua_tube.lua => tubes/lua.lua | 0 .../pane_embedded_tube.lua | 33 ---- .../registration.lua | 0 routing_tubes.lua => tubes/routing.lua | 0 signal_tubes.lua => tubes/signal.lua | 0 sorting_tubes.lua => tubes/sorting.lua | 0 teleport_tube.lua => tubes/teleport.lua | 0 vacuum_tubes.lua => tubes/vacuum.lua | 0 14 files changed, 268 insertions(+), 237 deletions(-) create mode 100644 materials.lua create mode 100644 tubes/embedded_tube.lua rename lua_tube.lua => tubes/lua.lua (100%) rename decorative_tubes.lua => tubes/pane_embedded_tube.lua (60%) rename tube_registration.lua => tubes/registration.lua (100%) rename routing_tubes.lua => tubes/routing.lua (100%) rename signal_tubes.lua => tubes/signal.lua (100%) rename sorting_tubes.lua => tubes/sorting.lua (100%) rename teleport_tube.lua => tubes/teleport.lua (100%) rename vacuum_tubes.lua => tubes/vacuum.lua (100%) diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index a13efa9..b501650 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -1,13 +1,10 @@ name: luacheck on: [push, pull_request] jobs: - build: + luacheck: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: apt - run: sudo apt-get install -y luarocks - - name: luacheck install - run: luarocks install --local luacheck - - name: luacheck run - run: $HOME/.luarocks/bin/luacheck ./ + - name: Checkout + uses: actions/checkout@master + - name: Luacheck + uses: lunarmodules/luacheck@master \ No newline at end of file diff --git a/common.lua b/common.lua index b057fe4..5db3feb 100644 --- a/common.lua +++ b/common.lua @@ -1,3 +1,96 @@ +local S = minetest.get_translator("pipeworks") + +-- Random variables + +pipeworks.expect_infinite_stacks = true +if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then + pipeworks.expect_infinite_stacks = false +end + +pipeworks.meseadjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}} + +pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0}, + {x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0}, + {x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0}, + {x=0, y=1, z=0}, {x=0, y=-1, z=0}} + +pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}} +pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}} + +pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1] +if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end + +pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"} +pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"} +pipeworks.button_base = "image_button[0,4.3;1,0.6" +pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]" + +-- Helper functions + +function pipeworks.fix_image_names(table, replacement) + local outtable={} + for i in ipairs(table) do + outtable[i]=string.gsub(table[i], "_XXXXX", replacement) + end + + return outtable +end + +local function overlay_tube_texture(texture) + -- The texture appears the first time to be colorized as the opaque background. + return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture) +end + +function pipeworks.make_tube_tile(tile) + if pipeworks.use_real_entities then + return tile + elseif type(tile) == "string" then + return overlay_tube_texture(tile) + else + tile = table.copy(tile) + if tile.color then + -- Won't work 100% of the time, but good enough. + tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color) + tile.color = nil + end + tile.name = overlay_tube_texture(tile.name) + tile.backface_culling = nil -- The texture is opaque + return tile + end +end + +function pipeworks.add_node_box(t, b) + if not t or not b then return end + for i in ipairs(b) + do table.insert(t, b[i]) + end +end + +function pipeworks.may_configure(pos, player) + local name = player:get_player_name() + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + + if owner ~= "" and owner == name then -- wielders and filters + return true + end + return not minetest.is_protected(pos, name) +end + +function pipeworks.replace_name(tbl,tr,name) + local ntbl={} + for key,i in pairs(tbl) do + if type(i)=="string" then + ntbl[key]=string.gsub(i,tr,name) + elseif type(i)=="table" then + ntbl[key]=pipeworks.replace_name(i,tr,name) + else + ntbl[key]=i + end + end + return ntbl +end + ---------------------- -- Vector functions -- ---------------------- diff --git a/crafts.lua b/crafts.lua index dc9319b..7ed9671 100644 --- a/crafts.lua +++ b/crafts.lua @@ -1,70 +1,5 @@ -local materials = { - stone = "default:stone", - desert_stone = "default:desert_stone", - desert_sand = "default:desert_sand", - chest = "default:chest", - copper_ingot = "default:copper_ingot", - steel_ingot = "default:steel_ingot", - gold_ingot = "default:gold_ingot", - mese = "default:mese", - mese_crystal = "default:mese_crystal", - mese_crystal_fragment = "default:mese_crystal_fragment", - teleporter = "default:mese", - glass = "default:glass", -} - -if minetest.get_modpath("mcl_core") then - materials = { - stone = "mcl_core:stone", - desert_stone = "mcl_core:redsandstone", - desert_sand = "mcl_core:sand", - chest = "mcl_chests:chest", - steel_ingot = "mcl_core:iron_ingot", - gold_ingot = "mcl_core:gold_ingot", - mese = "mesecons_torch:redstoneblock", - mese_crystal = "mesecons:redstone", - mese_crystal_fragment = "mesecons:redstone", - teleporter = "mesecons_torch:redstoneblock", - copper_ingot = "mcl_copper:copper_ingot", - glass = "mcl_core:glass", - } -elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then - materials = { - stone = "fl_stone:stone", - desert_stone = "fl_stone:desert_stone", - desert_sand = "fl_stone:desert_sand", - chest = "fl_storage:wood_chest", - steel_ingot = "fl_ores:iron_ingot", - gold_ingot = "fl_ores:gold_ingot", - mese = "fl_ores:iron_ingot", - mese_crystal = "fl_ores:iron_ingot", - mese_crystal_fragment = "fl_ores:iron_ingot", - teleporter = "fl_ores:iron_ingot", - copper_ingot = "fl_ores:copper_ingot", - glass = "fl_glass:framed_glass", - } -elseif minetest.get_modpath("hades_core") then - materials = { - stone = "hades_core:stone", - desert_stone = "hades_core:stone_baked", - desert_sand = "hades_core:volcanic_sand", - chest = "hades_chests:chest"; - steel_ingot = "hades_core:steel_ingot", - gold_ingot = "hades_core:gold_ingot", - mese = "hades_core:mese", - mese_crystal = "hades_core:mese_crystal", - mese_crystal_fragment = "hades_core:mese_crystal_fragment", - teleporter = "hades_materials:teleporter_device", - copper_ingot = "hades_core:copper_ingot", - tin_ingot = "hades_core:tin_ingot", - glass = "hades_core:glass", - } - if minetest.get_modpath("hades_default") then - materials.desert_sand = "hades_default:desert_sand" - end -end - -- Crafting recipes for pipes +local materials = ... minetest.register_craft( { output = "pipeworks:pipe_1_empty 12", @@ -194,15 +129,6 @@ minetest.register_craft( { }, }) -minetest.register_craft( { - output = "pipeworks:steel_block_embedded_tube 1", - recipe = { - { materials.steel_ingot, materials.steel_ingot, materials.steel_ingot }, - { materials.steel_ingot, "pipeworks:tube_1", materials.steel_ingot }, - { materials.steel_ingot, materials.steel_ingot, materials.steel_ingot } - }, -}) - minetest.register_craft( { output = "pipeworks:steel_pane_embedded_tube 1", recipe = { diff --git a/init.lua b/init.lua index 2c21c84..5a86a01 100644 --- a/init.lua +++ b/init.lua @@ -4,21 +4,20 @@ -- and devices that they can connect to. -- -pipeworks = {} -pipeworks.ui_cat_tube_list = {} - -pipeworks.worldpath = minetest.get_worldpath() -pipeworks.modpath = minetest.get_modpath("pipeworks") -local S = minetest.get_translator("pipeworks") - -pipeworks.liquids = {} -pipeworks.liquids.water = { - source = minetest.registered_nodes["mapgen_water_source"].name, - flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing -} -pipeworks.liquids.river_water = { - source = minetest.registered_nodes["mapgen_river_water_source"].name, - flowing = minetest.registered_nodes["mapgen_river_water_source"].liquid_alternative_flowing +pipeworks = { + ui_cat_tube_list = {}, + worldpath = minetest.get_worldpath(), + modpath = minetest.get_modpath("pipeworks"), + liquids = { + water = { + source = minetest.registered_nodes["mapgen_water_source"].name, + flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing + }, + river_water = { + source = minetest.registered_nodes["mapgen_river_water_source"].name, + flowing = minetest.registered_nodes["mapgen_river_water_source"].liquid_alternative_flowing + } + } } dofile(pipeworks.modpath.."/default_settings.lua") @@ -36,97 +35,6 @@ if pipeworks.entity_update_interval >= 0.2 and pipeworks.enable_accelerator_tube minetest.log("warning", "pipeworks accelerator tubes will not entirely work with an entity update interval 0.2 or above.") end --- Random variables - -pipeworks.expect_infinite_stacks = true -if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then - pipeworks.expect_infinite_stacks = false -end - -pipeworks.meseadjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}} - -pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0}, - {x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0}, - {x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0}, - {x=0, y=1, z=0}, {x=0, y=-1, z=0}} - -pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}} -pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}} - -pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1] -if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end - -pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"} -pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"} -pipeworks.button_base = "image_button[0,4.3;1,0.6" -pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]" - --- Helper functions - -function pipeworks.fix_image_names(table, replacement) - local outtable={} - for i in ipairs(table) do - outtable[i]=string.gsub(table[i], "_XXXXX", replacement) - end - - return outtable -end - -local function overlay_tube_texture(texture) - -- The texture appears the first time to be colorized as the opaque background. - return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture) -end - -function pipeworks.make_tube_tile(tile) - if pipeworks.use_real_entities then - return tile - elseif type(tile) == "string" then - return overlay_tube_texture(tile) - else - tile = table.copy(tile) - if tile.color then - -- Won't work 100% of the time, but good enough. - tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color) - tile.color = nil - end - tile.name = overlay_tube_texture(tile.name) - tile.backface_culling = nil -- The texture is opaque - return tile - end -end - -function pipeworks.add_node_box(t, b) - if not t or not b then return end - for i in ipairs(b) - do table.insert(t, b[i]) - end -end - -function pipeworks.may_configure(pos, player) - local name = player:get_player_name() - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - - if owner ~= "" and owner == name then -- wielders and filters - return true - end - return not minetest.is_protected(pos, name) -end - -function pipeworks.replace_name(tbl,tr,name) - local ntbl={} - for key,i in pairs(tbl) do - if type(i)=="string" then - ntbl[key]=string.gsub(i,tr,name) - elseif type(i)=="table" then - ntbl[key]=pipeworks.replace_name(i,tr,name) - else - ntbl[key]=i - end - end - return ntbl -end - pipeworks.logger = function(msg) minetest.log("action", "[pipeworks] "..msg) end @@ -150,15 +58,29 @@ dofile(pipeworks.modpath.."/autoplace_tubes.lua") dofile(pipeworks.modpath.."/luaentity.lua") dofile(pipeworks.modpath.."/item_transport.lua") dofile(pipeworks.modpath.."/flowing_logic.lua") -dofile(pipeworks.modpath.."/tube_registration.lua") -dofile(pipeworks.modpath.."/routing_tubes.lua") -dofile(pipeworks.modpath.."/sorting_tubes.lua") -dofile(pipeworks.modpath.."/signal_tubes.lua") -dofile(pipeworks.modpath.."/decorative_tubes.lua") dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") +local materials = loadfile(pipeworks.modpath.."/materials.lua")() + +dofile(pipeworks.modpath.."/tubes/registration.lua") +dofile(pipeworks.modpath.."/tubes/routing.lua") +dofile(pipeworks.modpath.."/tubes/sorting.lua") +dofile(pipeworks.modpath.."/tubes/signal.lua") +loadfile(pipeworks.modpath.."/tubes/embedded_tube.lua")(materials) +dofile(pipeworks.modpath.."/tubes/pane_embedded_tube.lua") + +if pipeworks.enable_teleport_tube then + dofile(pipeworks.modpath.."/tubes/teleport.lua") +end +if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then + dofile(pipeworks.modpath.."/tubes/lua.lua") +end +if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then + dofile(pipeworks.modpath.."/tubes/vacuum.lua") +end + local logicdir = "/pressure_logic/" -- note that even with these files the new flow logic is not yet default. @@ -172,9 +94,6 @@ dofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua") if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end -if pipeworks.enable_teleport_tube then - dofile(pipeworks.modpath.."/teleport_tube.lua") -end if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end @@ -191,14 +110,8 @@ end if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end -if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then - dofile(pipeworks.modpath.."/lua_tube.lua") -end -if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then - dofile(pipeworks.modpath.."/vacuum_tubes.lua") -end -dofile(pipeworks.modpath.."/crafts.lua") +loadfile(pipeworks.modpath.."/crafts.lua")(materials) minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") diff --git a/materials.lua b/materials.lua new file mode 100644 index 0000000..ca9adf5 --- /dev/null +++ b/materials.lua @@ -0,0 +1,67 @@ +local materials = { + stone = "default:stone", + desert_stone = "default:desert_stone", + desert_sand = "default:desert_sand", + chest = "default:chest", + copper_ingot = "default:copper_ingot", + steel_ingot = "default:steel_ingot", + gold_ingot = "default:gold_ingot", + mese = "default:mese", + mese_crystal = "default:mese_crystal", + mese_crystal_fragment = "default:mese_crystal_fragment", + teleporter = "default:mese", + glass = "default:glass" +} + +if minetest.get_modpath("mcl_core") then + materials = { + stone = "mcl_core:stone", + desert_stone = "mcl_core:redsandstone", + desert_sand = "mcl_core:sand", + chest = "mcl_chests:chest", + steel_ingot = "mcl_core:iron_ingot", + gold_ingot = "mcl_core:gold_ingot", + mese = "mesecons_torch:redstoneblock", + mese_crystal = "mesecons:redstone", + mese_crystal_fragment = "mesecons:redstone", + teleporter = "mesecons_torch:redstoneblock", + copper_ingot = "mcl_copper:copper_ingot", + glass = "mcl_core:glass", + } +elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then + materials = { + stone = "fl_stone:stone", + desert_stone = "fl_stone:desert_stone", + desert_sand = "fl_stone:desert_sand", + chest = "fl_storage:wood_chest", + steel_ingot = "fl_ores:iron_ingot", + gold_ingot = "fl_ores:gold_ingot", + mese = "fl_ores:iron_ingot", + mese_crystal = "fl_ores:iron_ingot", + mese_crystal_fragment = "fl_ores:iron_ingot", + teleporter = "fl_ores:iron_ingot", + copper_ingot = "fl_ores:copper_ingot", + glass = "fl_glass:framed_glass", + } +elseif minetest.get_modpath("hades_core") then + materials = { + stone = "hades_core:stone", + desert_stone = "hades_core:stone_baked", + desert_sand = "hades_core:volcanic_sand", + chest = "hades_chests:chest"; + steel_ingot = "hades_core:steel_ingot", + gold_ingot = "hades_core:gold_ingot", + mese = "hades_core:mese", + mese_crystal = "hades_core:mese_crystal", + mese_crystal_fragment = "hades_core:mese_crystal_fragment", + teleporter = "hades_materials:teleporter_device", + copper_ingot = "hades_core:copper_ingot", + tin_ingot = "hades_core:tin_ingot", + glass = "hades_core:glass", + } + if minetest.get_modpath("hades_default") then + materials.desert_sand = "hades_default:desert_sand" + end +end + +return materials \ No newline at end of file diff --git a/tubes/embedded_tube.lua b/tubes/embedded_tube.lua new file mode 100644 index 0000000..cc4c259 --- /dev/null +++ b/tubes/embedded_tube.lua @@ -0,0 +1,68 @@ +local materials = ... +local S = minetest.get_translator("pipeworks") + +local straight = function(pos, node, velocity, stack) return {velocity} end +local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3" +if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end + +-- register an embedded tube +function pipeworks.register_embedded_tube(nodename, opts) + minetest.register_node(nodename, { + description = opts.description, + tiles = { + opts.base_texture, + opts.base_texture, + opts.base_texture, + opts.base_texture, + opts.base_texture .. "^pipeworks_tube_connection_metallic.png", + opts.base_texture .. "^pipeworks_tube_connection_metallic.png", + }, + paramtype = "light", + paramtype2 = "facedir", + groups = { + cracky = 1, + oddly_breakable_by_hand = 1, + tubedevice = 1, + dig_glass = 2, + pickaxey=1, + handy=1 + }, + _mcl_hardness = 0.8, + legacy_facedir_simple = true, + _sound_def = { + key = "node_sound_stone_defaults", + }, + tube = { + connect_sides = { + front = 1, + back = 1 + }, + priority = 50, + can_go = straight, + can_insert = function(pos, node, stack, direction) + local dir = minetest.facedir_to_dir(node.param2) + return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction) + end + }, + after_place_node = pipeworks.after_place, + after_dig_node = pipeworks.after_dig, + on_rotate = pipeworks.on_rotate, + }) + + minetest.register_craft( { + output = nodename .. " 1", + recipe = { + { opts.base_ingredient, opts.base_ingredient, opts.base_ingredient }, + { opts.base_ingredient, "pipeworks:tube_1", opts.base_ingredient }, + { opts.base_ingredient, opts.base_ingredient, opts.base_ingredient } + }, + }) + pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = nodename +end + +-- steelblock embedded tube +pipeworks.register_embedded_tube("pipeworks:steel_block_embedded_tube", { + description = S("Airtight steelblock embedded tube"), + base_texture = steel_tex, + base_ingredient = materials.steel_ingot +}) diff --git a/lua_tube.lua b/tubes/lua.lua similarity index 100% rename from lua_tube.lua rename to tubes/lua.lua diff --git a/decorative_tubes.lua b/tubes/pane_embedded_tube.lua similarity index 60% rename from decorative_tubes.lua rename to tubes/pane_embedded_tube.lua index 4893d0c..b52aa58 100644 --- a/decorative_tubes.lua +++ b/tubes/pane_embedded_tube.lua @@ -1,39 +1,6 @@ local S = minetest.get_translator("pipeworks") local straight = function(pos, node, velocity, stack) return {velocity} end -local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3" -if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end - -minetest.register_node("pipeworks:steel_block_embedded_tube", { - description = S("Airtight steelblock embedded tube"), - tiles = { - steel_tex, steel_tex, - steel_tex, steel_tex, - steel_tex .. "^pipeworks_tube_connection_metallic.png", - steel_tex .. "^pipeworks_tube_connection_metallic.png", - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1, dig_glass = 2, pickaxey=1, handy=1}, - _mcl_hardness=0.8, - legacy_facedir_simple = true, - _sound_def = { - key = "node_sound_stone_defaults", - }, - tube = { - connect_sides = {front = 1, back = 1,}, - priority = 50, - can_go = straight, - can_insert = function(pos, node, stack, direction) - local dir = minetest.facedir_to_dir(node.param2) - return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction) - end, - }, - after_place_node = pipeworks.after_place, - after_dig_node = pipeworks.after_dig, - on_rotate = pipeworks.on_rotate, -}) -pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:steel_block_embedded_tube" local pane_box = { type = "fixed", diff --git a/tube_registration.lua b/tubes/registration.lua similarity index 100% rename from tube_registration.lua rename to tubes/registration.lua diff --git a/routing_tubes.lua b/tubes/routing.lua similarity index 100% rename from routing_tubes.lua rename to tubes/routing.lua diff --git a/signal_tubes.lua b/tubes/signal.lua similarity index 100% rename from signal_tubes.lua rename to tubes/signal.lua diff --git a/sorting_tubes.lua b/tubes/sorting.lua similarity index 100% rename from sorting_tubes.lua rename to tubes/sorting.lua diff --git a/teleport_tube.lua b/tubes/teleport.lua similarity index 100% rename from teleport_tube.lua rename to tubes/teleport.lua diff --git a/vacuum_tubes.lua b/tubes/vacuum.lua similarity index 100% rename from vacuum_tubes.lua rename to tubes/vacuum.lua From 360ed9bdde6158f7e4f3c768a5d4bf15dd69d86f Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Sun, 14 Jan 2024 02:41:28 +0100 Subject: [PATCH 04/30] Autocrafter groups support (#74) * Add support for recipes with groups to autocrafter * fix autocrafter replacements * remove unnecessary check and move some code * reorder and change back var name * only whitespace changes * reuse hash that is asigned to variable anyway * add get_matching_craft function that looks for the best matching recipe according to what user put in recipe inventory some crafts use groups in multiple recipes * return right away if there is a chached craft gives us more horizontal space to work with * indentation adjusting * use get_matching_craft to get best craft this line was buggy anyhow * new craft format: decremented_input craft.decremented_input now only holds the items. Extra parameters are dropped * bugfix: when item has no groups "" and unknown items have no def and thus no groups * add function has_room_for_output moving the output space calculation into its own function helps keep autocraft() short and overseeable * use has_room_for_output * remove double-check of available materials * add warning to ensure double-check was not needed * rebuild cache whenever recipe inv changes no need to check if still current, this only happens when user is interacting and can only be better to do so. Otherwise we would have to check groups etc. again just to check, so might as well reset cache. * remove unused line * use minetest.get_item_group() * whitespace cleanup make code easier to read and give it a more "thoughtthrough" look than the "smash it in to make it work" look it has had. (I'm holding back, there would be more to do overall through this mod) * add .editorconfig this should also help keep consistency throughout this mod * changelog updated at least the most recent more important ones * whitespace changelog (trailing spaces) --------- Co-authored-by: rubenwardy Co-authored-by: OgelGames Co-authored-by: wsor4035 <24964441+wsor4035@users.noreply.github.com> --- .editorconfig | 9 ++ autocrafter.lua | 353 ++++++++++++++++++++++++++++++++++-------------- changelog.txt | 150 +++++++++++++------- 3 files changed, 364 insertions(+), 148 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..faf22a9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +tab_width = 4 +charset = utf-8 +end_of_line = lf +indent_style = tab +insert_final_newline = false +trim_trailing_whitespace = true diff --git a/autocrafter.lua b/autocrafter.lua index b623672..cc7a86e 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -1,11 +1,14 @@ local S = minetest.get_translator("pipeworks") -local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second +-- cache some recipe data to avoid calling the slow function +-- minetest.get_craft_result() every second +local autocrafterCache = {} local craft_time = 1 local function count_index(invlist) local index = {} for _, stack in pairs(invlist) do + stack = ItemStack(stack) if not stack:is_empty() then local stack_name = stack:get_name() index[stack_name] = (index[stack_name] or 0) + stack:get_count() @@ -21,41 +24,152 @@ local function get_item_info(stack) return description, name end +-- Get best matching recipe for what user has put in crafting grid. +-- This function does not consider crafting method (mix vs craft) +local function get_matching_craft(output_name, example_recipe) + local recipes = minetest.get_all_craft_recipes(output_name) + if not recipes then + return example_recipe + end + + if 1 == #recipes then + return recipes[1].items + end + + local index_example = count_index(example_recipe) + local best_score = 0 + local index_recipe, best_index, score, group + for i = 1, #recipes do + score = 0 + index_recipe = count_index(recipes[i].items) + for recipe_item_name, _ in pairs(index_recipe) do + if index_example[recipe_item_name] then + score = score + 1 + elseif recipe_item_name:sub(1, 6) == "group:" then + group = recipe_item_name:sub(7) + for example_item_name, _ in pairs(index_example) do + if minetest.get_item_group(example_item_name, group) > 0 then + score = score + 1 + break + end + end + end + end + if best_score < score then + best_index = i + end + end + + return best_index and recipes[best_index].items or example_recipe +end + local function get_craft(pos, inventory, hash) local hash = hash or minetest.hash_node_position(pos) local craft = autocrafterCache[hash] - if not craft then - local recipe = inventory:get_list("recipe") - local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe}) - craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input} - autocrafterCache[hash] = craft + if craft then return craft end + + local example_recipe = inventory:get_list("recipe") + local output, decremented_input = minetest.get_craft_result({ + method = "normal", width = 3, items = example_recipe + }) + + local recipe = example_recipe + if output and not output.item:is_empty() then + recipe = get_matching_craft(output.item:get_name(), example_recipe) end + + craft = { + recipe = recipe, + consumption = count_index(recipe), + output = output, + decremented_input = decremented_input.items + } + autocrafterCache[hash] = craft return craft end -local function autocraft(inventory, craft) - if not craft then return false end - -- check if we have enough material available - local inv_index = count_index(inventory:get_list("src")) - for itemname, number in pairs(craft.consumption) do - if (not inv_index[itemname]) or inv_index[itemname] < number then return false end - end - -- check if output and all replacements fit in dst - local output = craft.output.item - local out_items = count_index(craft.decremented_input.items) - out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count() - local empty_count = 0 - for _,item in pairs(inventory:get_list("dst")) do - if item:is_empty() then - empty_count = empty_count + 1 +-- From a consumption table with groups and an inventory index, build +-- a consumption table without groups +local function calculate_consumption(inv_index, consumption_with_groups) + inv_index = table.copy(inv_index) + consumption_with_groups = table.copy(consumption_with_groups) + + local consumption = {} + local groups = {} + + -- First consume all non-group requirements + -- This is done to avoid consuming a non-group item which is also + -- in a group + for key, count in pairs(consumption_with_groups) do + if key:sub(1, 6) == "group:" then + groups[#groups + 1] = key:sub(7, #key) else - local name = item:get_name() - if out_items[name] then - out_items[name] = out_items[name] - item:get_free_space() + if not inv_index[key] or inv_index[key] < count then + return nil + end + + consumption[key] = (consumption[key] or 0) + count + consumption_with_groups[key] = consumption_with_groups[key] - count + assert(consumption_with_groups[key] == 0) + consumption_with_groups[key] = nil + inv_index[key] = inv_index[key] - count + assert(inv_index[key] >= 0) + end + end + + -- Next, resolve groups using the remaining items in the inventory + local take + if #groups > 0 then + for itemname, count in pairs(inv_index) do + if count > 0 then + local def = minetest.registered_items[itemname] + local item_groups = def and def.groups or {} + for i = 1, #groups do + local group = groups[i] + local groupname = "group:" .. group + if item_groups[group] and item_groups[group] >= 1 + and consumption_with_groups[groupname] > 0 + then + take = math.min(count, consumption_with_groups[groupname]) + consumption_with_groups[groupname] = + consumption_with_groups[groupname] - take + + assert(consumption_with_groups[groupname] >= 0) + consumption[itemname] = + (consumption[itemname] or 0) + take + + inv_index[itemname] = inv_index[itemname] - take + assert(inv_index[itemname] >= 0) + end + end end end end - for _,count in pairs(out_items) do + + -- Finally, check everything has been consumed + for key, count in pairs(consumption_with_groups) do + if count > 0 then + return nil + end + end + + return consumption +end + +local function has_room_for_output(list_output, index_output) + local name + local empty_count = 0 + for _, item in pairs(list_output) do + if item:is_empty() then + empty_count = empty_count + 1 + else + name = item:get_name() + if index_output[name] then + index_output[name] = index_output[name] - item:get_free_space() + end + end + end + for _, count in pairs(index_output) do if count > 0 then empty_count = empty_count - 1 end @@ -63,22 +177,54 @@ local function autocraft(inventory, craft) if empty_count < 0 then return false end + + return true +end + +local function autocraft(inventory, craft) + if not craft then return false end + + -- check if output and all replacements fit in dst + local output = craft.output.item + local out_items = count_index(craft.decremented_input) + out_items[output:get_name()] = + (out_items[output:get_name()] or 0) + output:get_count() + + if not has_room_for_output(inventory:get_list("dst"), out_items) then + return false + end + + -- check if we have enough material available + local inv_index = count_index(inventory:get_list("src")) + local consumption = calculate_consumption(inv_index, craft.consumption) + if not consumption then + return false + end + -- consume material - for itemname, number in pairs(craft.consumption) do - for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max + for itemname, number in pairs(consumption) do + -- We have to do that since remove_item does not work if count > stack_max + for _ = 1, number do inventory:remove_item("src", ItemStack(itemname)) end end + -- craft the result into the dst inventory and add any "replacements" as well inventory:add_item("dst", output) + local leftover for i = 1, 9 do - inventory:add_item("dst", craft.decremented_input.items[i]) + leftover = inventory:add_item("dst", craft.decremented_input[i]) + if leftover and not leftover:is_empty() then + minetest.log("warning", "[pipeworks] autocrafter didn't " .. + "calculate output space correctly.") + end end return true end -- returns false to stop the timer, true to continue running --- is started only from start_autocrafter(pos) after sanity checks and cached recipe +-- is started only from start_autocrafter(pos) after sanity checks and +-- recipe is cached local function run_autocrafter(pos, elapsed) local meta = minetest.get_meta(pos) local inventory = meta:get_inventory() @@ -90,7 +236,7 @@ local function run_autocrafter(pos, elapsed) return false end - for _ = 1, math.floor(elapsed/craft_time) do + for _ = 1, math.floor(elapsed / craft_time) do local continue = autocraft(inventory, craft) if not continue then return false end end @@ -114,33 +260,17 @@ end -- note, that this function assumes allready being updated to virtual items -- and doesn't handle recipes with stacksizes > 1 local function after_recipe_change(pos, inventory) + local hash = minetest.hash_node_position(pos) local meta = minetest.get_meta(pos) + autocrafterCache[hash] = nil -- if we emptied the grid, there's no point in keeping it running or cached if inventory:is_empty("recipe") then minetest.get_node_timer(pos):stop() - autocrafterCache[minetest.hash_node_position(pos)] = nil meta:set_string("infotext", S("unconfigured Autocrafter")) inventory:set_stack("output", 1, "") return end - local recipe = inventory:get_list("recipe") - - local hash = minetest.hash_node_position(pos) - local craft = autocrafterCache[hash] - - if craft then - -- check if it changed - local cached_recipe = craft.recipe - for i = 1, 9 do - if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then - autocrafterCache[hash] = nil -- invalidate recipe - craft = nil - break - end - end - end - - craft = craft or get_craft(pos, inventory, hash) + local craft = get_craft(pos, inventory, hash) local output_item = craft.output.item local description, name = get_item_info(output_item) meta:set_string("infotext", S("'@1' Autocrafter (@2)", description, name)) @@ -149,7 +279,8 @@ local function after_recipe_change(pos, inventory) after_inventory_change(pos) end --- clean out unknown items and groups, which would be handled like unknown items in the crafting grid +-- clean out unknown items and groups, which would be handled like unknown +-- items in the crafting grid -- if minetest supports query by group one day, this might replace them -- with a canonical version instead local function normalize(item_list) @@ -180,58 +311,65 @@ local function on_output_change(pos, inventory, stack) end width_idx = (width_idx < 3) and (width_idx + 1) or 1 end - -- we'll set the output slot in after_recipe_change to the actual result of the new recipe + -- we'll set the output slot in after_recipe_change to the actual + -- result of the new recipe end after_recipe_change(pos, inventory) end --- returns false if we shouldn't bother attempting to start the timer again after this +-- returns false if we shouldn't bother attempting to start the timer again +-- after this local function update_meta(meta, enabled) local state = enabled and "on" or "off" meta:set_int("enabled", enabled and 1 or 0) local list_backgrounds = "" if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then list_backgrounds = "style_type[box;colors=#666]" - for i=0, 2 do - for j=0, 2 do - list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]" + for i = 0, 2 do + for j = 0, 2 do + list_backgrounds = list_backgrounds .. "box[" .. + 0.22 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]" end end - for i=0, 3 do - for j=0, 2 do - list_backgrounds = list_backgrounds .. "box[".. 5.28+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]" + for i = 0, 3 do + for j = 0, 2 do + list_backgrounds = list_backgrounds .. "box[" .. + 5.28 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]" end end - for i=0, 7 do - for j=0, 2 do - list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 5+(j*1.25) ..";1,1;]" + for i = 0, 7 do + for j = 0, 2 do + list_backgrounds = list_backgrounds .. "box[" .. + 0.22 + (i * 1.25) .. "," .. 5 + (j * 1.25) .. ";1,1;]" end end end local size = "10.2,14" local fs = - "formspec_version[2]".. - "size["..size.."]".. - pipeworks.fs_helpers.get_prepends(size).. - list_backgrounds.. - "list[context;recipe;0.22,0.22;3,3;]".. - "image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]".. - "list[context;output;4,1.45;1,1;]".. - "image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" .. - "list[context;dst;5.28,0.22;4,3;]".. - "list[context;src;0.22,5;8,3;]".. - pipeworks.fs_helpers.get_inv(9).. - "listring[current_player;main]".. + "formspec_version[2]" .. + "size[" .. size .. "]" .. + pipeworks.fs_helpers.get_prepends(size) .. + list_backgrounds .. + "list[context;recipe;0.22,0.22;3,3;]" .. + "image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]" .. + "list[context;output;4,1.45;1,1;]" .. + "image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. + state .. ";;;false;pipeworks_button_interm.png]" .. + "list[context;dst;5.28,0.22;4,3;]" .. + "list[context;src;0.22,5;8,3;]" .. + pipeworks.fs_helpers.get_inv(9) .. + "listring[current_player;main]" .. "listring[context;src]" .. - "listring[current_player;main]".. + "listring[current_player;main]" .. "listring[context;dst]" .. "listring[current_player;main]" if minetest.get_modpath("digilines") then - fs = fs.."field[0.22,4.1;4.5,0.75;channel;"..S("Channel")..";${channel}]".. - "button[5,4.1;1.5,0.75;set_channel;"..S("Set").."]".. - "button_exit[6.8,4.1;2,0.75;close;"..S("Close").."]" + fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("Channel") .. + ";${channel}]" .. + "button[5,4.1;1.5,0.75;set_channel;" .. S("Set") .. "]" .. + "button_exit[6.8,4.1;2,0.75;close;" .. S("Close") .. "]" end - meta:set_string("formspec",fs) + meta:set_string("formspec", fs) -- toggling the button doesn't quite call for running a recipe change check -- so instead we run a minimal version for infotext setting only @@ -251,9 +389,12 @@ local function update_meta(meta, enabled) end -- 1st version of the autocrafter had actual items in the crafting grid --- the 2nd replaced these with virtual items, dropped the content on update and set "virtual_items" to string "1" --- the third added an output inventory, changed the formspec and added a button for enabling/disabling --- so we work out way backwards on this history and update each single case to the newest version +-- the 2nd replaced these with virtual items, dropped the content on update and +-- set "virtual_items" to string "1" +-- the third added an output inventory, changed the formspec and added a button +-- for enabling/disabling +-- so we work out way backwards on this history and update each single case +-- to the newest version local function upgrade_autocrafter(pos, meta) local meta = meta or minetest.get_meta(pos) local inv = meta:get_inventory() @@ -264,7 +405,8 @@ local function upgrade_autocrafter(pos, meta) update_meta(meta, true) if meta:get_string("virtual_items") == "1" then -- we are version 2 - -- we already dropped stuff, so lets remove the metadatasetting (we are not being called again for this node) + -- we already dropped stuff, so lets remove the metadatasetting + -- (we are not being called again for this node) meta:set_string("virtual_items", "") else -- we are version 1 local recipe = inv:get_list("recipe") @@ -304,18 +446,23 @@ minetest.register_node("pipeworks:autocrafter", { return inv:room_for_item("src", stack) end, input_inventory = "dst", - connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}}, + connect_sides = { + left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1 + } + }, on_construct = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - inv:set_size("src", 3*8) - inv:set_size("recipe", 3*3) - inv:set_size("dst", 4*3) + inv:set_size("src", 3 * 8) + inv:set_size("recipe", 3 * 3) + inv:set_size("dst", 4 * 3) inv:set_size("output", 1) update_meta(meta, false) end, on_receive_fields = function(pos, formname, fields, sender) - if (fields.quit and not fields.key_enter_field) or not pipeworks.may_configure(pos, sender) then + if (fields.quit and not fields.key_enter_field) + or not pipeworks.may_configure(pos, sender) + then return end local meta = minetest.get_meta(pos) @@ -362,7 +509,9 @@ minetest.register_node("pipeworks:autocrafter", { end, allow_metadata_inventory_take = function(pos, listname, index, stack, player) if not pipeworks.may_configure(pos, player) then - minetest.log("action", string.format("%s attempted to take from autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos))) + minetest.log("action", string.format("%s attempted to take from " .. + "autocrafter at %s", + player:get_player_name(), minetest.pos_to_string(pos))) return 0 end upgrade_autocrafter(pos) @@ -378,7 +527,9 @@ minetest.register_node("pipeworks:autocrafter", { after_inventory_change(pos) return stack:get_count() end, - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + allow_metadata_inventory_move = function( + pos, from_list, from_index, to_list, to_index, count, player) + if not pipeworks.may_configure(pos, player) then return 0 end upgrade_autocrafter(pos) local inv = minetest.get_meta(pos):get_inventory() @@ -419,13 +570,14 @@ minetest.register_node("pipeworks:autocrafter", { if type(msg) == "table" then if #msg < 3 then return end local inv = meta:get_inventory() - for y=0,2,1 do - for x=1,3,1 do - local slot = y*3+x - if minetest.registered_items[msg[y+1][x]] then - inv:set_stack("recipe",slot,ItemStack(msg[y+1][x])) + for y = 0, 2, 1 do + for x = 1, 3, 1 do + local slot = y * 3 + x + if minetest.registered_items[msg[y + 1][x]] then + inv:set_stack("recipe", slot, ItemStack( + msg[y + 1][x])) else - inv:set_stack("recipe",slot,ItemStack("")) + inv:set_stack("recipe", slot, ItemStack("")) end end end @@ -434,11 +586,12 @@ minetest.register_node("pipeworks:autocrafter", { local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local recipe = {} - for y=0,2,1 do + for y = 0, 2, 1 do local row = {} - for x=1,3,1 do - local slot = y*3+x - table.insert(row, inv:get_stack("recipe",slot):get_name()) + for x = 1, 3, 1 do + local slot = y * 3 + x + table.insert(row, inv:get_stack( + "recipe", slot):get_name()) end table.insert(recipe, row) end @@ -465,4 +618,4 @@ minetest.register_node("pipeworks:autocrafter", { }, }, }) -pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:autocrafter" +pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list + 1] = "pipeworks:autocrafter" diff --git a/changelog.txt b/changelog.txt index d33ed87..59ea40d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,60 @@ Changelog +2023-06-22 (SwissalpS, rubenwardy) +groups support in recipe. Set recipe as usual via recipe formspec or digilines. +Autocrafter now resolves matching recipe using groups so that items in input +inventory are used, that match group and no longer only strictly what user +has in recipe-inventory + + + +2023-06-21 (OgelGames, BuckarooBanzay) +fix autocrafter destroying replacement items (OG) +remove facedir debugging logs (BB) + + + +2023-05-28 (SwissalpS) +support setting 'can_receive' for teleport tubes via digiline + + + +2023-05-19 (fluxionary, OgelGames) +log items going through teleport tubes + + + +2022-12-02 (wsor4035) +bring back compatibility with mineclone2 + + + +2022-11-11 (OgelGames) +prevent tp- and sand-tubes from breaking themselves and refactor part of code + +2022-09-18 (fluxionary) +protection checks before break-/placeing a node -> less violation logs + + +2022-08-14 (wsor4035) +prevent tubes from connecting to furnace front + + + +2022-08-13 (TurkeyMcMac) +moved teleport-tube database to mod-storage + + + +2022-06-23 (S-S-X) +on_repair tweak, improved repairing tubes + + +* many updates not mentioned here * + + + 2017-10-19 (thetaepsilon) Directional flowables are now implemented. All devices for which it is relevant (valve, flow sensor etc.) have been converted so that they only flow on their connecting sides, so pressure propogation now works as expected for these devices when pressure logic is enabled. @@ -50,91 +104,91 @@ What *does not* work: *seems this hasn't been updated in a while* -2013-01-13: Tubes can transport items now! Namely, I added Novatux/Nore's item +2013-01-13: Tubes can transport items now! Namely, I added Novatux/Nore's item transport mod as a default part of this mod, to make tubes do something useful! Thanks to Nore and RealBadAngel for the code contributions! -2013-01-05: made storage tanks connect from top/bottom, made storage tank and -pipe textures use the ^ combine operator so they can show the actual liquid +2013-01-05: made storage tanks connect from top/bottom, made storage tank and +pipe textures use the ^ combine operator so they can show the actual liquid going through the pipes/tanks. -2013-01-04 (a bit later): Made pipes able to carry water! It was just a minor -logic error resulting from moving the water flowing code into it's own file +2013-01-04 (a bit later): Made pipes able to carry water! It was just a minor +logic error resulting from moving the water flowing code into it's own file when I originally imported it. Many thanks to Mauvebic for writing it! -2013-01-04: First stage of integrating Mauvebic's water flowing code. This is -experimental and doesn't move water yet - but at least it doesn't break +2013-01-04: First stage of integrating Mauvebic's water flowing code. This is +experimental and doesn't move water yet - but at least it doesn't break anything :-) -2013-01-01: Various minor tweaks to textures, facedir settings, some other -stuff. Changed crafting recipes to account for revamped pumps, valves, etc. -Now requires the moreores mod and most recent git (for mese crystal fragments) -to craft a pump. Added a "sealed" entry/exit panel (really just a horizontal -pipe with a metal panel overlayed into the middle). Also, tweaked pipes to -always drop the empty ones. Revamped pumps so that now they should sit in/on -liquid and be connected only from the top, relegated grates to decorational- -only, added outlet spigot. Got rid of a few obsolete textures. Got rid of -that whole _x and _z naming thing - now all directional devices (pumps, valves, -spigots, tanks) use facedir. Valves, spigots no longer auto-rotate to find +2013-01-01: Various minor tweaks to textures, facedir settings, some other +stuff. Changed crafting recipes to account for revamped pumps, valves, etc. +Now requires the moreores mod and most recent git (for mese crystal fragments) +to craft a pump. Added a "sealed" entry/exit panel (really just a horizontal +pipe with a metal panel overlayed into the middle). Also, tweaked pipes to +always drop the empty ones. Revamped pumps so that now they should sit in/on +liquid and be connected only from the top, relegated grates to decorational- +only, added outlet spigot. Got rid of a few obsolete textures. Got rid of +that whole _x and _z naming thing - now all directional devices (pumps, valves, +spigots, tanks) use facedir. Valves, spigots no longer auto-rotate to find nearby pipes. -2012-09-17: Added test object for pneumatic tube autorouting code, made tubes -connect to it and any object that bears groups={tubedevice=1} (connects to any +2012-09-17: Added test object for pneumatic tube autorouting code, made tubes +connect to it and any object that bears groups={tubedevice=1} (connects to any side) -2012-09-05: All recipes doubled except for junglegrass -> plastic sheet (since +2012-09-05: All recipes doubled except for junglegrass -> plastic sheet (since that is derived from home decor) -2012-09-02: Fixed plastic sheeting recipe. Added crafting recipes for various -objects, with options: If homedecor is installed, use the plastic sheeting -therein. If not, we define it manually. If the Technic mod is installed, -don't define any recipes at all. Also removed the extra "loaded!" messages and -tweaked the default pipe alias to point to something that is actually visible +2012-09-02: Fixed plastic sheeting recipe. Added crafting recipes for various +objects, with options: If homedecor is installed, use the plastic sheeting +therein. If not, we define it manually. If the Technic mod is installed, +don't define any recipes at all. Also removed the extra "loaded!" messages and +tweaked the default pipe alias to point to something that is actually visible :-) 2012-09-01: flattened wielded pipe segment. -2012-08-24: Added square-ish pneumatic tubes with their own autoplace code -(does not connect to steel pipes or pipe-oriented devices), then revised their -textures shortly after. Fixed a recursion bug that sometimes caused a stack -overflow. Old pipes were overriding the pipeworks:pipe defintion that belongs +2012-08-24: Added square-ish pneumatic tubes with their own autoplace code +(does not connect to steel pipes or pipe-oriented devices), then revised their +textures shortly after. Fixed a recursion bug that sometimes caused a stack +overflow. Old pipes were overriding the pipeworks:pipe defintion that belongs with the new pipes. -2012-08-22: Added outlet grate, made it participate in autoplace algorithm. -Extended storage tank to show fill level in 10% steps (0% to 100%). Added -"expansion tank" that appears if the user stacks tanks upwards. (Downwards is +2012-08-22: Added outlet grate, made it participate in autoplace algorithm. +Extended storage tank to show fill level in 10% steps (0% to 100%). Added +"expansion tank" that appears if the user stacks tanks upwards. (Downwards is not checked). -2012-08-21: Made storage tank participate in autoplace algorithm. Tuned API a -little to allow for more flexible placement. Re-organized code a bit to allow -for some upcoming rules changes. Made storage tanks' upper/lower fittins and +2012-08-21: Made storage tank participate in autoplace algorithm. Tuned API a +little to allow for more flexible placement. Re-organized code a bit to allow +for some upcoming rules changes. Made storage tanks' upper/lower fittins and intake grate participate in autoplace algorithm. -2012-08-20: Added temporary nodes for storage tank and intake grating, but +2012-08-20: Added temporary nodes for storage tank and intake grating, but without autoplace. -2012-08-19: Pumps and valves now fully participate in the +2012-08-19: Pumps and valves now fully participate in the auto-rotate/auto-place algorithm. -2012-08-18: Total rewrite again. All pipes are now nice and round-looking, and -they auto-connect! Also added temporary nodes for pump and valve (each with an -on/off setting - punch to change). No crafting recipes yet and the pipes still +2012-08-18: Total rewrite again. All pipes are now nice and round-looking, and +they auto-connect! Also added temporary nodes for pump and valve (each with an +on/off setting - punch to change). No crafting recipes yet and the pipes still don't do anything useful yet. Soon. 2012-08-06: Moved this changelog off the forum post and into a separate file. -2012-08-05 (multiple updates): Rewrote pipeworks to use loops and tables to -create the nodes. Requires far less code now. Added -X, +X, -Y, +Y, -Z, +Z -capped stubs and a short centered horizontal segment. Changed node definitions -so that the aforementioned "short centered" segment is given on dig/drop. -Renamed it to just "pipeworks:pipe" (and pipe_loaded). Added empty/loaded -indicator images to the capped ends, removed some redundant comments. Made the +2012-08-05 (multiple updates): Rewrote pipeworks to use loops and tables to +create the nodes. Requires far less code now. Added -X, +X, -Y, +Y, -Z, +Z +capped stubs and a short centered horizontal segment. Changed node definitions +so that the aforementioned "short centered" segment is given on dig/drop. +Renamed it to just "pipeworks:pipe" (and pipe_loaded). Added empty/loaded +indicator images to the capped ends, removed some redundant comments. Made the empty/loaded indication at the capped end more prominent. -2012-07-21: Added screenshot showing pipes as they look now that nodebox +2012-07-21: Added screenshot showing pipes as they look now that nodebox texture rotation is fixed. -2012-07-18: Changed the mod name and all internals to 'pipeworks' instead of +2012-07-18: Changed the mod name and all internals to 'pipeworks' instead of 'pipes'... after a couple of mistakes :-) 2012-07-12: moved project to github. From 04df87a6c2ab12f6fef2350ce8b22b2f25110807 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sun, 14 Jan 2024 14:29:55 +1100 Subject: [PATCH 05/30] Delete .editorconfig --- .editorconfig | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index faf22a9..0000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -tab_width = 4 -charset = utf-8 -end_of_line = lf -indent_style = tab -insert_final_newline = false -trim_trailing_whitespace = true From 6d824a318a635193893144b23157aed6d0d0302a Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sun, 14 Jan 2024 20:10:24 +1100 Subject: [PATCH 06/30] Tube repair fixes (#102) * restart vacuum tube node timers after repair * clear metadata value after repair --- tubes/routing.lua | 1 + tubes/vacuum.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/tubes/routing.lua b/tubes/routing.lua index f6fec5e..ae84e7d 100644 --- a/tubes/routing.lua +++ b/tubes/routing.lua @@ -93,6 +93,7 @@ pipeworks.register_tube("pipeworks:broken_tube", { minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 }) pipeworks.scan_for_tube_objects(pos) end + meta:set_string("the_tube_was", "") else pipeworks.logger(log_msg.." but original node "..was_node.name.." is not registered anymore.") minetest.chat_send_player(playername, S("This tube cannot be repaired.")) diff --git a/tubes/vacuum.lua b/tubes/vacuum.lua index 91ed02b..8298cc5 100644 --- a/tubes/vacuum.lua +++ b/tubes/vacuum.lua @@ -32,6 +32,12 @@ local function set_timer(pos) timer:start(math.random(10, 20) * 0.1) end +local function repair_tube(pos, was_node) + minetest.swap_node(pos, {name = was_node.name, param2 = was_node.param2}) + pipeworks.scan_for_tube_objects(pos) + set_timer(pos) +end + if pipeworks.enable_sand_tube then pipeworks.register_tube("pipeworks:sand_tube", { description = S("Vacuuming Pneumatic Tube Segment"), @@ -42,6 +48,9 @@ if pipeworks.enable_sand_tube then ends = {"pipeworks_sand_tube_end.png"}, node_def = { groups = {vacuum_tube = 1}, + tube = { + on_repair = repair_tube, + }, on_construct = set_timer, on_timer = function(pos, elapsed) vacuum(pos, 2) @@ -68,6 +77,9 @@ if pipeworks.enable_mese_sand_tube then ends = {"pipeworks_mese_sand_tube_end.png"}, node_def = { groups = {vacuum_tube = 1}, + tube = { + on_repair = repair_tube, + }, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_int("dist", 2) From c87522c52625bc9917d2bd4d9708c1656e87b57e Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:08:24 +0100 Subject: [PATCH 07/30] export `pipeworks.tptube.remove_tube` (#105) Co-authored-by: BuckarooBanzay --- tubes/teleport.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/tubes/teleport.lua b/tubes/teleport.lua index 9439ddd..83d9344 100644 --- a/tubes/teleport.lua +++ b/tubes/teleport.lua @@ -357,6 +357,7 @@ pipeworks.tptube = { hash = hash_pos, get_db = function() return tube_db end, save_tube_db = save_tube_db, + remove_tube = remove_tube, set_tube = set_tube, save_tube = save_tube, update_tube = update_tube, From 96dca7e54062201b2664b3ddcf65b37c8369a978 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 8 Feb 2024 11:01:54 +0100 Subject: [PATCH 08/30] Fix autocrafter crafting bug (#108) --- autocrafter.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/autocrafter.lua b/autocrafter.lua index cc7a86e..37c109c 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -57,6 +57,7 @@ local function get_matching_craft(output_name, example_recipe) end if best_score < score then best_index = i + best_score = score end end From c7b153f1efa4960f4b3f5fb158ffc90cee52d6be Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Tue, 27 Feb 2024 00:44:40 +0100 Subject: [PATCH 09/30] Is ground content (#110) * trashcan isn't ground content * pipes aren't ground content * auto tree tap isn't ground content * filter-injectors aren't ground content * devices aren't ground content also some whitespace indentation fixes * is_ground_content * autocrafter isn't ground content * tubes aren't ground content * pane_embedded_tube isn't ground content * embedded_tube isn't ground content * routing tubes aren't ground content * whitespace fix indentation --- autocrafter.lua | 1 + changelog.txt | 5 +++ devices.lua | 64 ++++++++++++++++++++++-------------- filter-injector.lua | 1 + legacy.lua | 2 +- pipes.lua | 4 +++ trashcan.lua | 1 + tubes/embedded_tube.lua | 1 + tubes/pane_embedded_tube.lua | 5 +-- tubes/registration.lua | 2 ++ tubes/routing.lua | 2 ++ 11 files changed, 61 insertions(+), 27 deletions(-) diff --git a/autocrafter.lua b/autocrafter.lua index 37c109c..bd9a669 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -433,6 +433,7 @@ minetest.register_node("pipeworks:autocrafter", { drawtype = "normal", tiles = {"pipeworks_autocrafter.png"}, groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 1, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, tube = {insert_object = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) diff --git a/changelog.txt b/changelog.txt index 59ea40d..76a1755 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,11 @@ Changelog +2024-02-26 (SwissalpS) +set is_ground_content to false for various nodes. + + + 2023-06-22 (SwissalpS, rubenwardy) groups support in recipe. Set recipe as usual via recipe formspec or digilines. Autocrafter now resolves matching recipe using groups so that items in input diff --git a/devices.lua b/devices.lua index 5384b7d..9d0a2a1 100644 --- a/devices.lua +++ b/devices.lua @@ -148,6 +148,7 @@ for s in ipairs(states) do paramtype = "light", paramtype2 = "facedir", groups = dgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -203,6 +204,7 @@ for s in ipairs(states) do fixed = { -5/16, -4/16, -8/16, 5/16, 5/16, 8/16 } }, groups = dgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -254,10 +256,11 @@ minetest.register_node(nodename_valve_loaded, { fixed = { -5/16, -4/16, -8/16, 5/16, 5/16, 8/16 } }, groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -307,10 +310,11 @@ minetest.register_node("pipeworks:grating", { sunlight_propagates = true, paramtype = "light", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, pipe_connections = { top = 1 }, after_place_node = function(pos) @@ -335,10 +339,11 @@ minetest.register_node(nodename_spigot_empty, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, pipe_connections = { left=1, right=1, front=1, back=1, left_param2 = 3, right_param2 = 1, front_param2 = 2, back_param2 = 0 }, @@ -373,10 +378,11 @@ minetest.register_node(nodename_spigot_loaded, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, pipe_connections = { left=1, right=1, front=1, back=1, left_param2 = 3, right_param2 = 1, front_param2 = 2, back_param2 = 0 }, @@ -432,10 +438,11 @@ minetest.register_node(nodename_panel_empty, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -455,10 +462,11 @@ minetest.register_node(nodename_panel_loaded, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -488,10 +496,11 @@ minetest.register_node(nodename_sensor_empty, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -530,10 +539,11 @@ minetest.register_node(nodename_sensor_loaded, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -600,6 +610,7 @@ for fill = 0, 10 do paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -631,6 +642,7 @@ for fill = 0, 10 do paramtype = "light", paramtype2 = "facedir", groups = sgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -661,10 +673,11 @@ minetest.register_node(nodename_fountain_empty, { sunlight_propagates = true, paramtype = "light", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, pipe_connections = { bottom = 1 }, after_place_node = function(pos) @@ -699,10 +712,11 @@ minetest.register_node(nodename_fountain_loaded, { sunlight_propagates = true, paramtype = "light", groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, pipe_connections = { bottom = 1 }, after_place_node = function(pos) @@ -752,10 +766,11 @@ minetest.register_node(nodename_sp_empty, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) @@ -777,10 +792,11 @@ minetest.register_node(nodename_sp_loaded, { paramtype = "light", paramtype2 = "facedir", groups = {snappy=3, pipe=1, not_in_creative_inventory=1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { - key = "node_sound_metal_defaults", - }, + key = "node_sound_metal_defaults", + }, walkable = true, on_place = pipeworks.rotate_on_place, after_dig_node = function(pos) diff --git a/filter-injector.lua b/filter-injector.lua index 22e8b86..908417d 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -389,6 +389,7 @@ for _, data in ipairs({ }, paramtype2 = "facedir", groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, legacy_facedir_simple = true, _sound_def = { diff --git a/legacy.lua b/legacy.lua index fdaa0de..743d6f1 100644 --- a/legacy.lua +++ b/legacy.lua @@ -24,7 +24,7 @@ if not minetest.get_modpath("auto_tree_tap") and description = S("Auto-Tap"), tiles = {"pipeworks_nodebreaker_top_off.png","pipeworks_nodebreaker_bottom_off.png","pipeworks_nodebreaker_side2_off.png","pipeworks_nodebreaker_side1_off.png", "pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_off.png"}, - is_ground_content = true, + is_ground_content = false, paramtype2 = "facedir", groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, not_in_creative_inventory=1, axey=1, handy=1, pickaxey=1}, _mcl_hardness=0.8, diff --git a/pipes.lua b/pipes.lua index 8b9f01b..45d5b8f 100644 --- a/pipes.lua +++ b/pipes.lua @@ -76,6 +76,7 @@ for index, connects in ipairs(cconnects) do fixed = outsel }, groups = pgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -113,6 +114,7 @@ for index, connects in ipairs(cconnects) do fixed = outsel }, groups = pgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_metal_defaults", @@ -151,6 +153,7 @@ if REGISTER_COMPATIBILITY then paramtype = "light", description = S("Pipe Segment (legacy)"), groups = {not_in_creative_inventory = 1, pipe_to_update = 1}, + is_ground_content = false, drop = "pipeworks:pipe_1_empty", after_place_node = function(pos) pipeworks.scan_for_pipe_objects(pos) @@ -163,6 +166,7 @@ if REGISTER_COMPATIBILITY then sunlight_propagates = true, paramtype = "light", groups = {not_in_creative_inventory = 1, pipe_to_update = 1}, + is_ground_content = false, drop = "pipeworks:pipe_1_empty", after_place_node = function(pos) pipeworks.scan_for_pipe_objects(pos) diff --git a/trashcan.lua b/trashcan.lua index 29a4d08..c8ae9b2 100644 --- a/trashcan.lua +++ b/trashcan.lua @@ -11,6 +11,7 @@ minetest.register_node("pipeworks:trashcan", { "pipeworks_trashcan_side.png", }, groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 4, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, tube = { insert_object = function(pos, node, stack, direction) diff --git a/tubes/embedded_tube.lua b/tubes/embedded_tube.lua index cc4c259..05e0672 100644 --- a/tubes/embedded_tube.lua +++ b/tubes/embedded_tube.lua @@ -27,6 +27,7 @@ function pipeworks.register_embedded_tube(nodename, opts) pickaxey=1, handy=1 }, + is_ground_content = false, _mcl_hardness = 0.8, legacy_facedir_simple = true, _sound_def = { diff --git a/tubes/pane_embedded_tube.lua b/tubes/pane_embedded_tube.lua index b52aa58..4bc1e83 100644 --- a/tubes/pane_embedded_tube.lua +++ b/tubes/pane_embedded_tube.lua @@ -31,11 +31,12 @@ minetest.register_node("pipeworks:steel_pane_embedded_tube", { paramtype = "light", paramtype2 = "facedir", groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1, dig_glass = 2, pickaxey=1, handy=1}, + is_ground_content = false, _mcl_hardness=0.8, legacy_facedir_simple = true, _sound_def = { - key = "node_sound_stone_defaults", - }, + key = "node_sound_stone_defaults", + }, tube = { connect_sides = {front = 1, back = 1,}, priority = 50, diff --git a/tubes/registration.lua b/tubes/registration.lua index b837cb8..14a5df5 100644 --- a/tubes/registration.lua +++ b/tubes/registration.lua @@ -106,6 +106,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e fixed = outboxes }, groups = tgroups, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_wood_defaults", @@ -227,6 +228,7 @@ local register_all_tubes = function(name, desc, plain, noctrs, ends, short, inv, description = S("Pneumatic tube segment (legacy)"), after_place_node = pipeworks.after_place, groups = {not_in_creative_inventory = 1, tube_to_update = 1, tube = 1}, + is_ground_content = false, tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}}, drop = name.."_1", }) diff --git a/tubes/routing.lua b/tubes/routing.lua index ae84e7d..e0a90aa 100644 --- a/tubes/routing.lua +++ b/tubes/routing.lua @@ -50,6 +50,7 @@ pipeworks.register_tube("pipeworks:broken_tube", { node_def = { drop = "pipeworks:tube_1", groups = {not_in_creative_inventory = 1, tubedevice_receiver = 1}, + is_ground_content = false, tube = { insert_object = function(pos, node, stack, direction) minetest.item_drop(stack, nil, pos) @@ -179,6 +180,7 @@ if pipeworks.enable_one_way_tube then 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, axey=1, handy=1, pickaxey=1}, + is_ground_content = false, _mcl_hardness=0.8, _sound_def = { key = "node_sound_wood_defaults", From cb2a59131c9471de7034520d28ddbdd352aba4b5 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Sun, 3 Mar 2024 02:52:23 +0100 Subject: [PATCH 10/30] Make wielder nodes not ground content (#112) nodebreaker, deployer and dispenser --- wielder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wielder.lua b/wielder.lua index 0cc26f9..44121ba 100644 --- a/wielder.lua +++ b/wielder.lua @@ -195,7 +195,7 @@ local function register_wielder(data) return stack:get_count() end, }, - is_ground_content = true, + is_ground_content = false, paramtype2 = "facedir", tubelike = 1, groups = groups, From 8724c2893943e16c4682b6064f4e1730bb40dfba Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 3 Mar 2024 06:37:46 -0500 Subject: [PATCH 11/30] switch to using xcompat (#113) --- .luacheckrc | 3 +- crafts.lua | 4 +-- init.lua | 7 ++--- materials.lua | 67 ----------------------------------------- mod.conf | 2 +- tubes/embedded_tube.lua | 2 +- 6 files changed, 8 insertions(+), 77 deletions(-) delete mode 100644 materials.lua diff --git a/.luacheckrc b/.luacheckrc index d128c79..215a236 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -20,6 +20,7 @@ read_globals = { -- mods "default", "mesecon", "digiline", "screwdriver", "unified_inventory", - "i3", "mcl_experience", "awards" + "i3", "mcl_experience", "awards", + "xcompat", } diff --git a/crafts.lua b/crafts.lua index 7ed9671..058cc8a 100644 --- a/crafts.lua +++ b/crafts.lua @@ -1,5 +1,5 @@ -- Crafting recipes for pipes -local materials = ... +local materials = xcompat.materials minetest.register_craft( { output = "pipeworks:pipe_1_empty 12", @@ -151,7 +151,7 @@ minetest.register_craft( { output = "pipeworks:teleport_tube_1 2", recipe = { { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }, - { materials.desert_stone, materials.teleporter, materials.desert_stone }, + { materials.desert_stone, materials.mese, materials.desert_stone }, { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" } }, }) diff --git a/init.lua b/init.lua index 5a86a01..42ad9b7 100644 --- a/init.lua +++ b/init.lua @@ -61,14 +61,11 @@ dofile(pipeworks.modpath.."/flowing_logic.lua") dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") - -local materials = loadfile(pipeworks.modpath.."/materials.lua")() - dofile(pipeworks.modpath.."/tubes/registration.lua") dofile(pipeworks.modpath.."/tubes/routing.lua") dofile(pipeworks.modpath.."/tubes/sorting.lua") dofile(pipeworks.modpath.."/tubes/signal.lua") -loadfile(pipeworks.modpath.."/tubes/embedded_tube.lua")(materials) +dofile(pipeworks.modpath.."/tubes/embedded_tube.lua") dofile(pipeworks.modpath.."/tubes/pane_embedded_tube.lua") if pipeworks.enable_teleport_tube then @@ -111,7 +108,7 @@ if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end -loadfile(pipeworks.modpath.."/crafts.lua")(materials) +dofile(pipeworks.modpath.."/crafts.lua") minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") diff --git a/materials.lua b/materials.lua deleted file mode 100644 index ca9adf5..0000000 --- a/materials.lua +++ /dev/null @@ -1,67 +0,0 @@ -local materials = { - stone = "default:stone", - desert_stone = "default:desert_stone", - desert_sand = "default:desert_sand", - chest = "default:chest", - copper_ingot = "default:copper_ingot", - steel_ingot = "default:steel_ingot", - gold_ingot = "default:gold_ingot", - mese = "default:mese", - mese_crystal = "default:mese_crystal", - mese_crystal_fragment = "default:mese_crystal_fragment", - teleporter = "default:mese", - glass = "default:glass" -} - -if minetest.get_modpath("mcl_core") then - materials = { - stone = "mcl_core:stone", - desert_stone = "mcl_core:redsandstone", - desert_sand = "mcl_core:sand", - chest = "mcl_chests:chest", - steel_ingot = "mcl_core:iron_ingot", - gold_ingot = "mcl_core:gold_ingot", - mese = "mesecons_torch:redstoneblock", - mese_crystal = "mesecons:redstone", - mese_crystal_fragment = "mesecons:redstone", - teleporter = "mesecons_torch:redstoneblock", - copper_ingot = "mcl_copper:copper_ingot", - glass = "mcl_core:glass", - } -elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then - materials = { - stone = "fl_stone:stone", - desert_stone = "fl_stone:desert_stone", - desert_sand = "fl_stone:desert_sand", - chest = "fl_storage:wood_chest", - steel_ingot = "fl_ores:iron_ingot", - gold_ingot = "fl_ores:gold_ingot", - mese = "fl_ores:iron_ingot", - mese_crystal = "fl_ores:iron_ingot", - mese_crystal_fragment = "fl_ores:iron_ingot", - teleporter = "fl_ores:iron_ingot", - copper_ingot = "fl_ores:copper_ingot", - glass = "fl_glass:framed_glass", - } -elseif minetest.get_modpath("hades_core") then - materials = { - stone = "hades_core:stone", - desert_stone = "hades_core:stone_baked", - desert_sand = "hades_core:volcanic_sand", - chest = "hades_chests:chest"; - steel_ingot = "hades_core:steel_ingot", - gold_ingot = "hades_core:gold_ingot", - mese = "hades_core:mese", - mese_crystal = "hades_core:mese_crystal", - mese_crystal_fragment = "hades_core:mese_crystal_fragment", - teleporter = "hades_materials:teleporter_device", - copper_ingot = "hades_core:copper_ingot", - tin_ingot = "hades_core:tin_ingot", - glass = "hades_core:glass", - } - if minetest.get_modpath("hades_default") then - materials.desert_sand = "hades_default:desert_sand" - end -end - -return materials \ No newline at end of file diff --git a/mod.conf b/mod.conf index 3e57efe..479abc8 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. -depends = basic_materials +depends = basic_materials, xcompat optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience min_minetest_version = 5.5.0 diff --git a/tubes/embedded_tube.lua b/tubes/embedded_tube.lua index 05e0672..0ca6e36 100644 --- a/tubes/embedded_tube.lua +++ b/tubes/embedded_tube.lua @@ -1,4 +1,4 @@ -local materials = ... +local materials = xcompat.materials local S = minetest.get_translator("pipeworks") local straight = function(pos, node, velocity, stack) return {velocity} end From 6c66a2f43ce4430955df4233400c3e21dd8f07b8 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Sun, 3 Mar 2024 12:48:27 +0100 Subject: [PATCH 12/30] Tags support (#107) Signed-off-by: Slava Zanko Co-authored-by: Slava Zanko Co-authored-by: BuckarooBanzay Co-authored-by: OgelGames --- crafts.lua | 20 ++++ default_settings.lua | 2 + filter-injector.lua | 39 ++++++- init.lua | 1 + item_transport.lua | 54 +++++++-- textures/pipeworks_tag_tube_end.png | Bin 0 -> 875 bytes textures/pipeworks_tag_tube_inv.png | Bin 0 -> 496 bytes textures/pipeworks_tag_tube_noctr_1.png | Bin 0 -> 768 bytes textures/pipeworks_tag_tube_noctr_2.png | Bin 0 -> 744 bytes textures/pipeworks_tag_tube_noctr_3.png | Bin 0 -> 743 bytes textures/pipeworks_tag_tube_noctr_4.png | Bin 0 -> 747 bytes textures/pipeworks_tag_tube_noctr_5.png | Bin 0 -> 769 bytes textures/pipeworks_tag_tube_noctr_6.png | Bin 0 -> 753 bytes textures/pipeworks_tag_tube_plain_1.png | Bin 0 -> 864 bytes textures/pipeworks_tag_tube_plain_2.png | Bin 0 -> 865 bytes textures/pipeworks_tag_tube_plain_3.png | Bin 0 -> 863 bytes textures/pipeworks_tag_tube_plain_4.png | Bin 0 -> 864 bytes textures/pipeworks_tag_tube_plain_5.png | Bin 0 -> 871 bytes textures/pipeworks_tag_tube_plain_6.png | Bin 0 -> 860 bytes textures/pipeworks_tag_tube_short.png | Bin 0 -> 457 bytes tubes/lua.lua | 29 ++++- tubes/tags.lua | 139 ++++++++++++++++++++++++ 22 files changed, 266 insertions(+), 18 deletions(-) create mode 100644 textures/pipeworks_tag_tube_end.png create mode 100644 textures/pipeworks_tag_tube_inv.png create mode 100644 textures/pipeworks_tag_tube_noctr_1.png create mode 100644 textures/pipeworks_tag_tube_noctr_2.png create mode 100644 textures/pipeworks_tag_tube_noctr_3.png create mode 100644 textures/pipeworks_tag_tube_noctr_4.png create mode 100644 textures/pipeworks_tag_tube_noctr_5.png create mode 100644 textures/pipeworks_tag_tube_noctr_6.png create mode 100644 textures/pipeworks_tag_tube_plain_1.png create mode 100644 textures/pipeworks_tag_tube_plain_2.png create mode 100644 textures/pipeworks_tag_tube_plain_3.png create mode 100644 textures/pipeworks_tag_tube_plain_4.png create mode 100644 textures/pipeworks_tag_tube_plain_5.png create mode 100644 textures/pipeworks_tag_tube_plain_6.png create mode 100644 textures/pipeworks_tag_tube_short.png create mode 100644 tubes/tags.lua diff --git a/crafts.lua b/crafts.lua index 058cc8a..45f642c 100644 --- a/crafts.lua +++ b/crafts.lua @@ -223,6 +223,26 @@ if pipeworks.enable_mese_tube then }) end +if pipeworks.enable_item_tags and pipeworks.enable_tag_tube then + minetest.register_craft( { + output = "pipeworks:tag_tube_000000 2", + recipe = { + { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }, + { materials.book, materials.mese_crystal, materials.book }, + { "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 + if pipeworks.enable_sand_tube then minetest.register_craft( { output = "pipeworks:sand_tube_1 2", diff --git a/default_settings.lua b/default_settings.lua index 6bf0a67..c48d852 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -4,6 +4,8 @@ local prefix = "pipeworks_" local settings = { enable_pipes = true, + enable_item_tags = true, + enable_tag_tube = true, enable_lowpoly = false, enable_autocrafter = true, enable_deployer = true, diff --git a/filter-injector.lua b/filter-injector.lua index 908417d..6f38e60 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -14,20 +14,29 @@ local function set_filter_formspec(data, meta) local formspec if data.digiline then + local form_height = 3 + if pipeworks.enable_item_tags then + form_height = 4 + end formspec = - "size[8.5,3]".. + ("size[8.5,%f]"):format(form_height) .. "item_image[0.2,0;1,1;pipeworks:"..data.name.."]".. "label[1.2,0.2;"..minetest.formspec_escape(itemname).."]".. "field[0.5,1.6;4.6,1;channel;"..S("Channel")..";${channel}]".. "button[4.8,1.3;1.5,1;set_channel;"..S("Set").."]".. - fs_helpers.cycling_button(meta, "button[0.2,2.3;4.05,1", "slotseq_mode", + fs_helpers.cycling_button(meta, ("button[0.2,%f;4.05,1"):format(form_height - 0.7), "slotseq_mode", {S("Sequence slots by Priority"), S("Sequence slots Randomly"), S("Sequence slots by Rotation")}).. - fs_helpers.cycling_button(meta, "button[4.25,2.3;4.05,1", "exmatch_mode", + fs_helpers.cycling_button(meta, ("button[4.25,%f;4.05,1"):format(form_height - 0.7), "exmatch_mode", {S("Exact match - off"), S("Exact match - on")}).. - "button_exit[6.3,1.3;2,1;close;"..S("Close").."]" + ("button_exit[6.3,%f;2,1;close;" .. S("Close") .. "]"):format(form_height - 1.7) + if pipeworks.enable_item_tags then + formspec = formspec .. + ("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_item_tags;"):format(form_height - 1.7) .. S("Set") .. "]" + end else local exmatch_button = "" if data.stackwise then @@ -62,6 +71,11 @@ local function set_filter_formspec(data, meta) exmatch_button.. pipeworks.fs_helpers.get_inv(6).. "listring[]" + if pipeworks.enable_item_tags then + formspec = formspec .. + "field[5.8,0.5;3,0.8;item_tags;" .. S("Item Tags") .. ";${item_tags}]" .. + "button[9,0.3;1,1.1;set_item_tags;" .. S("Set") .. "]" + end end meta:set_string("formspec", formspec) end @@ -123,6 +137,7 @@ local function punch_filter(data, filtpos, filtnode, msg) local slotseq_mode local exmatch_mode + local item_tags = pipeworks.sanitize_tags(filtmeta:get_string("item_tags")) local filters = {} if data.digiline then local function add_filter(name, group, count, wear, metadata) @@ -186,6 +201,12 @@ local function punch_filter(data, filtpos, filtnode, msg) set_filter_formspec(data, filtmeta) end + if type(msg.tags) == "table" then + item_tags = pipeworks.sanitize_tags(msg.tags) + elseif type(msg.tag) == "string" then + item_tags = pipeworks.sanitize_tags({msg.tag}) + end + if msg.nofire then return end @@ -339,7 +360,7 @@ local function punch_filter(data, filtpos, filtnode, msg) local pos = vector.add(frompos, vector.multiply(dir, 1.4)) local start_pos = vector.add(frompos, dir) 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 end end @@ -457,6 +478,10 @@ for _, data in ipairs({ end local meta = minetest.get_meta(pos) + if pipeworks.enable_item_tags and fields.item_tags and (fields.key_enter_field == "item_tags" or fields.set_item_tags) then + local tags = pipeworks.sanitize_tags(fields.item_tags) + meta:set_string("item_tags", table.concat(tags, ",")) + end --meta:set_int("slotseq_index", 1) set_filter_formspec(data, meta) set_filter_infotext(data, meta) @@ -478,6 +503,10 @@ for _, data in ipairs({ fs_helpers.on_receive_fields(pos, fields) local meta = minetest.get_meta(pos) meta:set_int("slotseq_index", 1) + if pipeworks.enable_item_tags and fields.item_tags and (fields.key_enter_field == "item_tags" or fields.set_item_tags) then + local tags = pipeworks.sanitize_tags(fields.item_tags) + meta:set_string("item_tags", table.concat(tags, ",")) + end set_filter_formspec(data, meta) set_filter_infotext(data, meta) end diff --git a/init.lua b/init.lua index 42ad9b7..a7ef061 100644 --- a/init.lua +++ b/init.lua @@ -67,6 +67,7 @@ dofile(pipeworks.modpath.."/tubes/sorting.lua") dofile(pipeworks.modpath.."/tubes/signal.lua") dofile(pipeworks.modpath.."/tubes/embedded_tube.lua") dofile(pipeworks.modpath.."/tubes/pane_embedded_tube.lua") +dofile(pipeworks.modpath.."/tubes/tags.lua") if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/tubes/teleport.lua") diff --git a/item_transport.lua b/item_transport.lua index 7e83d95..7577741 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -3,11 +3,36 @@ local enable_max_limit = minetest.settings:get_bool("pipeworks_enable_items_per_ local max_tube_limit = tonumber(minetest.settings:get("pipeworks_max_items_per_tube")) or 30 if enable_max_limit == nil then enable_max_limit = true end +if pipeworks.enable_item_tags then + local max_tag_length = tonumber(minetest.settings:get("pipeworks_max_item_tag_length")) or 32 + local max_tags = tonumber(minetest.settings:get("pipeworks_max_item_tags")) or 16 + + function pipeworks.sanitize_tags(tags) + if type(tags) == "string" then + tags = tags:split(",") + end + local sanitized = {} + for i, tag in ipairs(tags) do + if type(tag) == "string" then + tag = tag:gsub("[%s,]", "") -- Remove whitespace and commas + tag = tag:gsub("%$%b%{%}", "") -- Remove special ${key} values + if tag ~= "" then + table.insert(sanitized, tag:sub(1, max_tag_length)) + end + end + if #sanitized >= max_tags then + break + end + end + return sanitized + end +end + function pipeworks.tube_item(pos, item) error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead") 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 local stack = ItemStack(item) local obj = luaentity.add_entity(pos, "pipeworks:tubed_item") @@ -15,6 +40,7 @@ function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner) obj.start_pos = vector.new(start_pos) obj:set_velocity(velocity) obj.owner = owner + obj.tags = tags --obj:set_color("red") -- todo: this is test-only code return obj end @@ -79,13 +105,14 @@ end -- compatibility behaviour for the existing can_go() callbacks, -- 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 max_priority = 0 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 - can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack) + local def = minetest.registered_nodes[cnode.name] + if def and def.tube and def.tube.can_go then + can_go = def.tube.can_go(pos, cnode, vel, stack, tags) else 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 @@ -144,7 +171,7 @@ end -- * 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, -- 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 cmeta = minetest.get_meta(pos) local speed = math.abs(velocity.x + velocity.y + velocity.z) @@ -172,7 +199,7 @@ local function go_next(pos, velocity, stack, owner) -- n is the new value of the cycle counter. -- XXX: this probably needs cleaning up after being split out, -- 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, -- don't update the field so it stays the same for the next item. @@ -276,6 +303,7 @@ luaentity.register_entity("pipeworks:tubed_item", { color_entity = nil, color = nil, start_pos = nil, + tags = nil, set_item = function(self, item) local itemstring = ItemStack(item):to_string() -- Accept any input format @@ -337,8 +365,9 @@ luaentity.register_entity("pipeworks:tubed_item", { local node = minetest.get_node(self.start_pos) if minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then local leftover - if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then - leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel, self.owner) + local def = minetest.registered_nodes[node.name] + if def.tube and def.tube.insert_object then + leftover = def.tube.insert_object(self.start_pos, node, stack, vel, self.owner) else leftover = stack end @@ -353,7 +382,14 @@ luaentity.register_entity("pipeworks:tubed_item", { return end - local found_next, new_velocity, multimode = go_next(self.start_pos, velocity, stack, self.owner) -- todo: color + local tags + 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_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))) diff --git a/textures/pipeworks_tag_tube_end.png b/textures/pipeworks_tag_tube_end.png new file mode 100644 index 0000000000000000000000000000000000000000..db131bc951c12307cc9be0d2c3770e8036f3a63e GIT binary patch literal 875 zcmV-x1C;!UP)kO^htra6sRbH;h?4n z)=eNE5t$;;FT4l+)?khl!KBDVW^^{mlZ+r9hWw*h=-Jhyx++hcTJLS^6Uu zWC@7UA0jBM=QJ>s(mn+FN;H+b3g3S)SBgMqEoD4%fcuaCjqN9XV0JzBOu?BWcpA!; z!=W=tP$K~}=?5ke5KnrdAp+n(X|T*mopY?EMye`xEt@v~a5LwH(NtAUhZ}WFRkP_f zsB3Cbj>*OMv|&SalIES}7h?2pgsyH^u)dKsC*75kz`^VM=Zv-f% zDxZb9kFUkT*!09NeksREjdLTxr|j-PxfK%T*moP)_I>FTDgR(;?TK$-zX^t)dwbVS zu(mH8V%^(&ox7p5EskP*EeQ-K7WcV*BMRpM_x)|;+~?LPL(IW15pkm^6%hfrJdJrg>bbk}v66kkY6QeQ zMWBZG>PqsEtIRN_J;Qw5seuleQ5+J*ff0IkQOiwC+!Wn*Y48RHAjD zYmUIqXg()%8W?-*R-k87cpg-H5obpxQqW{0XFLB{RJTEoT4#002ovPDHLkV1l=@ Buj&8* literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tag_tube_inv.png b/textures/pipeworks_tag_tube_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..7fd2c314ae2b2d7f5c0aacacc3523795bde69a7c GIT binary patch literal 496 zcmV#w+#m)Z2%>Tg3{l3orzR3T%%>KB`|G35fx5WRl#{aCt|E9pc-@I-B z0004WQchCsm82l?LY?z-QpxxByX{d!f+$b?(Akcu|fOz=AmS0=!^2vl@aMgXu`a6$F}pPD}s= zi|NDyZ~>MBS>yV*My=}R1#MpgFp9vmF91B+fU@s`Bv`aY**97F0S_A5wiy5l2BvKR zKtQ4G%9Z)P`HbYf7zl0G1ArA4Za;P{07UcPX`50&1>qLBZ5qI82&TZto(7}Af~k=6 zeca%MX-fhC3s_jTGyn(#KU zL+mPF!j0Ru%a=hA+m9lGyeMZ>%jlm7z=Zp#lM080000z^% z|Ns8k+W*ee|HaMz>j3}1$^W^_|G35fv%>$f$N#Lu{-nPDpuPT`y8oBA|B|}@i?%o4 zJOBUyPBQz-00001bW%=J06^y0W&i*Ja!Eu%RCwB*)`3pMI1B{P_G+B8u{|#Q|GysB zCaYS7a$ZYtq0|o=c!-f;Ip$O93kU8H7b8 z1^DQoyqjR}z&biWOLo9x<#7g|?3x2?0Nc3{mKj#b2cBx*muH709Ids90@#mjN>tlb66yq zKxza?@cvbPtAhYMejn_BnE>K0FclFMcYq>5A|~zl1E?4PG!=(TY65jN6E$hpRG?}< zjVBY>e5F)e=gb3vipk4qOK%FmBpMkiC4$SQWv}fR}+<=k0cOicO+r?=E zm_v|fAa)Ufxjq7M))OcJkVl~Y5Mkm3Py*2U7J^Wox6u9s=JgSf5P?si#12IC<@iiY%OvpK0Ryz{?l4in^$tMHOdOl;YHsQBAk=D7qq>Kni&IUwG|n!ZS8 z+j;@k4@v?qyp0wQfRQXwsb8Y*6!G*`ZhdKgOqx7K9xrKoD}m@Zg&u@dlgC&FP|u%8 y9;0?(L}2%H2O$C_OTP){L z|Ns8k+W*tm|IE?<#m)Zf0RO+q|GCEgxXb^u$N#Is{-nPDp1S{;zWM3)m;FH2*e%w7Z8C|1Ei`5poR)@l}S()4nP2@s3Ho$riX|DF!A-3xGKy9is`~R z6EhJPX5yJM(=Cqx&%Avf&6yJQ@U+~*%R?T4e=YUjm`9+z2g-3Z-+`rk4-6yJ4&(!n zKLGg|kd7VFTVU*v@4!+IKz$DkBX9?D@Bal*4o>aBG7Rz_7zY`FC4CL_Nv1pi@)pPg zkQ%^ahX7FT6$T-{uTVb%OL+^(FakFq4?unkq{m&H5;HOXM|=y>Wqq}N<`GywO_^>f zG+&r#d!8qOxv9Yn)!hvOHNzu-3P216KLQ6_p;|HNkBLD6z~vSQOaV>TA>>$NfB@zY zcQJwB^}jeHFuP8X0BHmm76JscE-O3W5(3P(3VRQNhX9dQA@6&D5CEfXUFtyeA5Gv7 zKw`l?Sb@Hce0xT`!VaVr@DSj_4d_LvNDLTnVhUd*pp*kpt^|u#xC5oVVng^CxdUsm z1UJ$7TCa!8$cRtSJ2W78kz_xGHc0eQo9#eqMNC5gI?zX8i~m9yMxbZ~-+_~-z$1`e a0sjL{*G?Sl;nt)80000?P)Hq)$I1|?I00001bW%=J06^y0W&i*JSxH1eRCwB**N2wsFbo9H@QCE1kwp3be|-ew zlX$7hY%jh?V|xqJ>qyPlAp}g3sL%)$Xb7lwyswiEFgyep+5~lP1@sDCm?0s+JHR_9 zkkbPweGjyT00sAzjUkU!06I{bLV_4zcc3R$l)5I`!bhyt+bDPjOje0e3V3NwLXI&#j$ zOvHtmc;?J>%QL_;-@lLMOo@7UI^V+Qr#u6fmUW0Ok;P zF@fOyzc?c>yH1e+X#^M+0tB=yD=Xj<0?h9f)*b{80V1tJUiSbY07mz9sRPk}G=V<= zi3Rsy0s1!b?HTb3E07kzLx2l6pckPcF<`ujDSVNDQZ_(25G-2Z0hIQN4dG+t4lKzM z+(hR?J!~!`BR)az(174YlJykYAkjx{wgRaYF%1FeKp%lE{tIOofua?B1$LeSk3f0{ Z{0F#~SgZ95&vO6(002ovPDHLkV1kDlJShMG literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tag_tube_noctr_4.png b/textures/pipeworks_tag_tube_noctr_4.png new file mode 100644 index 0000000000000000000000000000000000000000..014303373ade9851b3b28ed91e7fd06154bbfcb9 GIT binary patch literal 747 zcmVsqGyB*qn*^uqrzBvU*+kJS7#gn%g$6&is84FS~-w{_A1hKB${o1pHkfL@^sGb99f z2YBZM@_PqL-vg~7K*4=wW5{C_fDV+VkRS%w4d}@~$%30$X}m`>5Ux-*08<#C4&2@d zp@e~-+<{#;k^3!dZ%91^h^7v-5y))!G3H$ruq@kFu$@1Ry~8XT1kwnQ#4pki4pvam zx4%>!28e2P7XTsxafki|L?G1wsVV}fp+a0`5>$l)5I`!bhyt+bAz}bbe0e3V3NwLX zI&jX!OvHtmc;?J>%_G1w-@cFLOo@7UI$gu3hdcu3mUJ}}Ykd7cF3rUo-qcQ**s437XR05KFC1rE4EwPMm=6N3VP%QX;~0-7#E$g#u# z0n8!pVgkYIe{n`&cAX*t(g-jt1PEwZR#w0z1eo6{tUU-G0z_JcyzT))0E}+yQU{{{ zXaau#5)1CZ0`zU<>oejNRv;~ahX5CDKrcc?V!(J4Q}`kQrEGw5Ay~A+9VqP;8^XuP z9axejxQWh}df8k?Mtp+ap#i~*BfwbK9q002ovPDHLkV1n$$JQ@H1 literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tag_tube_noctr_5.png b/textures/pipeworks_tag_tube_noctr_5.png new file mode 100644 index 0000000000000000000000000000000000000000..d4c33ba4d07fecba08f8ccea660a697a9f0cce29 GIT binary patch literal 769 zcmV+c1OEJpP)x=$o{y?|G35fv&jFm!vCwo{-nPDp1S{;zW@!Uk3vjv-2so##q=om50r2&}20L`Uo zf)Gj=m{T*z_?F1$R(M+h^$;MMx0Ocyv(#2xw-5P?(!q^by@h6-_&K~NPAKme(zA_~BUZy^T2#Fu~K zsxT8Mh6|@e%tTz6X&R?A(IdVCJo5TI8WUwYf`|Jfru(<}4t#D=Kl@k#ZkLw7f!wa< z9k`d*fzMk5+zuc$KzahC2B-&++ZyuUKxu18J8-WJaQhSJQ{V$gP5t!=kQ?W=08P~A zWBi&(58U%hK--KVb%6W{qz=d%zVIe?3%d+wxa0vnC)3R(j z0fNUekgbIDzX#E)G+Ni?1BhN|0$%_U3-(|EjyCe+7ts=0ATNN20GDP%S^&xt12A1X zVS+`s#L@ueO0Z}NJ5aWNYzU8$+d(D?HqobRy*3*oBc4IIHYu<~_r`OKxAlMYuFV#p z%^;bE04zY80$com(xpI<_|DWudx=$p5*<{=AtAs!z&}nP ze>b4^9cT*y3hpO2hCEgQ=s?{R62t&ofu3^87F=SZ@p?1^!3t>|zK1CcPzTm8La1Tj zR66j}HIe(ZaQi~)AwV>DU>kwVe!dvXPZh8n+gGq3Z;idfEE)vz2#_FrTNuK@3JUu6 zPSs(6s5W;2AR-WV=>LESq!}PhMF2H4h^tJ3rf>iPNJA4*05&~D41kFPCgQ3v6DXzw zmqN@$T$w4&sU*7Q5#X8E|D(B3rXHRy*QCos9)a_gb{?|=ygyps19g9zZ@{H~4U8kS z4wM~GJ^sxwF8OPqPcoGO zkhee?fV=@bb_f9NR$&mz`wHzNaH($r8Ajj@C<9R50{L-^Q)VXS1ErLh=)j3+`OPCh z%ijxKQ)xah(fU450&`P?8JfEr1Zsvy01bc`D*glxxI(pI(mxY}0)Wdk5SRj*k3-0@ z!~g-zA?{)V!Rx0uBQSgLaRGS*7#0Eqv>dB?*JZ~K(-3yz5|2+7_H}W z2cl0jf&Ty!3+`Y6`WpHAj(CMTkQcy1fD3OxFG5vf0Mc;~5-hmHT6aJ_5-eKb2Gs2n z8^RYOcVJ18;1WF@+i`bgWW*=v9X3Fsx5j=k-Uf-jYO_0#w<4w?03GNfu*L6Ch7kx7 jzA+79AY5Tceg*sk2y8oHJ|ChJ_lDq$k zwm08A0002c60$M?0004WQchC0n{)duF?ck;p=A;Q$zvS089V@ zY<(hzs2)XJ6=niOdvWi?OvK}=d~jzXGSERh;)~9&xWEpME78&Eq!hQ`E^(AiVrScQ z7`}gMe((A_U_>!+*!ly&0*ojr4nUeV0OSbUY$=ij*jktg=;_Wiq_?dFf-F=2C%~ER zd?TP1;smhH?|;b90}z_&UTe{19SHy)(<4qm&-@E8Edh7Q2-!k%W&)OGE<}zSkdq*_ z1Z<7$fM*zQ=j=W-8#~guchdR>kaacN0B1X(Tl!1q4d8#wV9H^8MDV`?=8CWpdV-`! z^hX^tJ^u;FJ!v@d7T#jf>({ciz&BtYLQepYba#V5%`jp)MF4>bVle@TVc;!rz!jz zVNgIZJ)D39+omIAfB@zYcL^~5{SoKKro**W1e`m7VI_co!Zsd&O9^1kVS92Ayw-u- z5&AO&lmIaL={plpeb5AG2as5C1_8)1^7TSJ!UH%1;3a@d-hc(5AvM6h6VLKS0>-_G zG6=z{5f)(Fg$?D~$O#B_DGt&3$6VHRnCcy5h8rN&)0lT*HFBVM8Xv$qRi?EF3CI@M q>VGI(3j`@2rcDf#BWybV4e%#tSy)?jX`~|n000080000`Jgjs80004WQchCnoS#J!e_&Asqih(!qiI}&iUAnqS;#`aMJPTSWA{^8M>8Fp9^aI649eMefP z#Rx|EuP4=@lQ0_*APInopwWIh=_Cmf=jX#o3s*TLO%6%v_WLcJWfA2S9=j&XqwD&dwiTkYO|%-0X+LX(SnV zYZ{C+j+o99;PerkauTEm5rGNj-{0bVU$lp96_LjZPd;K$HN1+yFN~I%$`Gs_d zlMxj3e}7ab3=q{ZrvMNU$ed8~}MFx*8&05uHAR4Ia?nCrHIA))}R1LofV zw!RUA*XiYUD$E3m^3JUhGZFW@a^=QEWS~mi{X*k+Kfo&ck*GGhD8%LK7JE4)c9lcb z@cp~S_o=@Ex)%ext!)4npnD0i1HyCwAk}T7gh&?PXki4Pg*(n6tsE^7WSQFE0j_Yz z2LTlq2Y@yH^O2!Bz%|0X&PA8C2LRZnEe=3i`2#R)1H43pXdyVm0b9Efky^Ie4Nwcf z*~kVQ!}ypS-MdENiPImQly(4Q9nB8FRVp<8Y3OIuYg#ShU&xLV$u6L7-;nemX<|feHL%01!jRhhPFzp*m3X!^EJtHRYBY z6wn*zPC%S(W5Q+r88#tvii7dbuQ+dq>eP}EaGd~#r2qnQTi<{wDS%CO+s;9lxenxs z(Dn?nZ)x=Ax&n}W(FFbkAhF~O91vq8`6)F1K?_s9OC4+v8-z|DKfp2!!)a3sEWH z+wT8bCya9XI6GZG&|Y{#;c_Cge;p#=sz`-Sz<`zj(_UX8NdUu30K=+aerf?}Aqfpq z0(b)W!wTfv28`^1&JsYunYl3JH48uj#-fm*2CxO#>R-1Nn>gv*M-3=jh~iUBWdLo! z8iX*)fUll_k9H#GE?fhtmjI%70#*rR_VF_Ik1QZBl(b+Up2qahM2mp?1d!A>(jhKd zP|*LqR2>G0>U0+XA_8%TLcbg0H$VV+1et~>s0g5j32~K6FcrT4HZesMfDORn8^HEA zVu(J90BpdBkm3Mj(gA?9NSjxRWC6|+W&(O<=N!_nqXdHNr2cn+JG1kH zfUXcHfHj|dc<2EL&CK3&(VaRH0KAjl;so^czX8({utHkM5|T3$@aQN+q%A;pg47al z7V-uh&G_b=)vwiH$C;m%T>SvZ9?cHGeKlx4G<7ck|E&j8j#boe+A^8G_DHeVHEk_Bw0A~|=0{A-AfwX;g@w%Cb`8VQ6M6U?U1kj{LOi!RY zW`_8w)1yJ{#S}j>wM$@bYB0lecY{F9Fk(7I0D%c&G69HT;G4h!SEx>0`pv|kc;xaZ z5){w}7ny(r+omIA>ymPay95~j{EGAIP;)I_>-Py@SP3AYNE>f}O9^1kk@ogM@LC13 zEcAB|s&8rZD|9EI`l1QY2_Ugz4+4;F;`z zX@p=^3mY(2U_*HsIRT+A#U?ucnmctLrg{bGVF9Fi8gmtPAq~aTn1I~P-Lz&Q0a*fD q{X#iPAV~Qz9b%wt;n4k0fZqWOt6=Or#1X9k0000x=$p5*<{@%KV+Uz>zHGE&G6xTz^Xx5t+Y0jL})fN@sP-?hN75QLLR0Y(7o zn-$=50q*F5_7p%_BXeS8jEhdIeyXAZBkLV|&X2+e!}$_U1H(hZC9vTsuI(^ek+uNefE( zzdx#jMnbiZ0g?cSF{so}BaI|M;whpViLL;t#!d{y0e0nBAM5OZlC+yNkRWZn0;9*_ z0YjB$pz?Us)}&UEdOu@1ODiH`lvC>MZ?y98g?3h7Mb0LdgzEAARPnG0b{(5elR17k~?Jdk9qrMA8NzPEYGcNU#7~2|WNUvSUxQV=F<3mDK(Ya7A`J z0p)Pj091`{-aIr1xO!x-J#?ks3sA^c(n~b}E&MM)w*br#7NUgU^aXHjg#hOSL?=Wo z0DB=Xz}Aeme&Jze#==0OqN~jaCH=zZf9Ge;$w)ZX`SM@1Fh~NMK literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tag_tube_plain_6.png b/textures/pipeworks_tag_tube_plain_6.png new file mode 100644 index 0000000000000000000000000000000000000000..458fe5d27ec90b82c596635423338d0e37ea801b GIT binary patch literal 860 zcmV-i1Ec(jP)j3}0$p5*<{sqoY zN4vS0t|{y}`VEcm^0}nf*F^-Bj8td^G-wLY?Rokn01Qt73}*-Z(FlkLLD(QEfCqpd z>_A>FK#Lh@PXQDh&J#nPivR?mofHz}02Y9$`np?kh@IB`Xamv_+6Mqr8bAS<3n8>L z;I#(ep*@jfFFY5do&t#O0XSPAvxhfheJBEk?PCOc@Mw$-n`jcSuK<$#j> zld8i2QSI&mKtv$!Q0R*R1^@!c{Ja|=T}1#jbcm}IL0901m7m4}w((dJZIyNkad|()qbw5J%c9NjHr3x& z{SRoP7u%TzxD?BR|#0-8P! z0Be8yBtsp5p+4)qE_zv80D#+civv(2{{`q4fU`t|XdyT~0Ed=FM7DCP9ssoftc~1& zWf(8c(fv>_>{$KLNvR7!uBF)m*vkfuKMn0CfIrP(%ENYx;Qs>p6=5ON07)IuZ&md0 zd<%$u(y)!;-(u0@*Rr(0Ctw{y4FH!#6^PjD6wA&`%+JJ!h@M7aCV)C^#B>ze$C_b$ zRq0Tp?U{+@YbyeCQ-c}0yBh>*hBj8a2p}-QSm^-7(C{K~z!j<;MPEz|3IHyLhCu;E z_u-rXgLTJ{0Rosq++~3A^)1eyMVo8M2-sHu!%_eN4O_bbE-8TdjBw{5c&-CEBh-5a zNC99peR}}1H=4jd01`{iU;tu_e7um4a0B)M@D#u$Hoyg-CON>mC+_JT31}_cGYG-5 z5n6a>VMBT|asY;^B!}qyr(f1t8Tk$(!wE?4NOEt5K5O==%>od6b2ZIH2tc&JmOr5^ mEf6GqFfC#r9bwV_72q%S1!0AG{OC^r0000#z-#m)b~%KyH||GCEgxXb^t$N#Lu|Et3Ns=@xGzW<)O|Czr3m$(0v zy!u&k;Q#;t0d!JMQvg8b*k%9#0X|7YK~#9!?U7fa+b|3SZHo{@EO%k${)bJZ^gyrt zrEy%vGHAESpU7k~nTV+nNC2Y7uJIv50SJT+C_&@^^;8i+2{9>!asZiIs4Fuu06isX zXomzaSp~V;fj4V?yPMmmUvs-RU%Q8|Zq0gMt!He;|{|WHR{(^wAIy39)Ef00000NkvXXu0mjfkp0)Q literal 0 HcmV?d00001 diff --git a/tubes/lua.lua b/tubes/lua.lua index 7c02e9e..50782bf 100644 --- a/tubes/lua.lua +++ b/tubes/lua.lua @@ -945,7 +945,7 @@ for white = 0, 1 do tube = { connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}, priority = 50, - can_go = function(pos, node, velocity, stack) + can_go = function(pos, node, velocity, stack, tags) local src = {name = nil} -- add color of the incoming tube explicitly; referring to rules, in case they change later for _, rule in pairs(rules) do @@ -960,12 +960,33 @@ for white = 0, 1 do itemstring = stack:to_string(), item = stack:to_table(), velocity = velocity, + tags = table.copy(tags), + side = src.name, }) - if not succ or type(msg) ~= "string" then + if not succ then return go_back(velocity) end - local r = rules[msg] - return r and {r} or go_back(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, }, after_place_node = pipeworks.after_place, diff --git a/tubes/tags.lua b/tubes/tags.lua new file mode 100644 index 0000000..ffd7ec7 --- /dev/null +++ b/tubes/tags.lua @@ -0,0 +1,139 @@ +local S = minetest.get_translator("pipeworks") +local fs_helpers = pipeworks.fs_helpers + +if not pipeworks.enable_item_tags or not pipeworks.enable_tag_tube then return end + +local help_text = minetest.formspec_escape( + S("Separate multiple tags using commas.").."\n".. + S("Use \"\" to match items without tags.") +) + +local update_formspec = function(pos) + local meta = minetest.get_meta(pos) + local buttons_formspec = "" + for i = 0, 5 do + buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta, + "image_button[9," .. (i + (i * 0.25) + 0.5) .. ";1,0.6", "l" .. (i + 1) .. "s", + { + pipeworks.button_off, + pipeworks.button_on + } + ) + end + local size = "10.2,9" + meta:set_string("formspec", + "formspec_version[2]" .. + "size[" .. size .. "]" .. + pipeworks.fs_helpers.get_prepends(size) .. + "field[1.5,0.25;7.25,1;tags1;;${tags1}]" .. + "field[1.5,1.5;7.25,1;tags2;;${tags2}]" .. + "field[1.5,2.75;7.25,1;tags3;;${tags3}]" .. + "field[1.5,4.0;7.25,1;tags4;;${tags4}]" .. + "field[1.5,5.25;7.25,1;tags5;;${tags5}]" .. + "field[1.5,6.5;7.25,1;tags6;;${tags6}]" .. + + "image[0.22,0.25;1,1;pipeworks_white.png]" .. + "image[0.22,1.50;1,1;pipeworks_black.png]" .. + "image[0.22,2.75;1,1;pipeworks_green.png]" .. + "image[0.22,4.00;1,1;pipeworks_yellow.png]" .. + "image[0.22,5.25;1,1;pipeworks_blue.png]" .. + "image[0.22,6.50;1,1;pipeworks_red.png]" .. + buttons_formspec .. + "label[0.22,7.9;"..help_text.."]".. + "button[7.25,7.8;1.5,0.8;set_item_tags;" .. S("Set") .. "]" + ) +end + +pipeworks.register_tube("pipeworks:tag_tube", { + description = S("Tag Sorting Pneumatic Tube Segment"), + 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", + "pipeworks_tag_tube_noctr_4.png", "pipeworks_tag_tube_noctr_5.png", "pipeworks_tag_tube_noctr_6.png" }, + plain = { "pipeworks_tag_tube_plain_1.png", "pipeworks_tag_tube_plain_2.png", "pipeworks_tag_tube_plain_3.png", + "pipeworks_tag_tube_plain_4.png", "pipeworks_tag_tube_plain_5.png", "pipeworks_tag_tube_plain_6.png" }, + ends = { "pipeworks_tag_tube_end.png" }, + short = "pipeworks_tag_tube_short.png", + no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones + node_def = { + tube = { + can_go = function(pos, node, velocity, stack, tags) + local tbl, tbln = {}, 0 + local found, foundn = {}, 0 + local meta = minetest.get_meta(pos) + local tag_hash = {} + if #tags > 0 then + for _,tag in ipairs(tags) do + tag_hash[tag] = true + end + else + tag_hash[""] = true -- Matches items without tags + end + for i, vect in ipairs(pipeworks.meseadjlist) do + local npos = vector.add(pos, vect) + local node = minetest.get_node(npos) + local reg_node = minetest.registered_nodes[node.name] + if meta:get_int("l" .. i .. "s") == 1 and reg_node then + local tube_def = reg_node.tube + if not tube_def or not tube_def.can_insert or + tube_def.can_insert(npos, node, stack, vect) then + local side_tags = meta:get_string("tags" .. i) + if side_tags ~= "" then + side_tags = pipeworks.sanitize_tags(side_tags) + for _,tag in ipairs(side_tags) do + if tag_hash[tag] then + foundn = foundn + 1 + found[foundn] = vect + break + end + end + else + tbln = tbln + 1 + tbl[tbln] = vect + end + end + end + end + return (foundn > 0) and found or tbl + end + }, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + for i = 1, 6 do + meta:set_int("l" .. tostring(i) .. "s", 1) + end + update_formspec(pos) + meta:set_string("infotext", S("Tag sorting pneumatic tube")) + end, + after_place_node = function(pos, placer, itemstack, pointed_thing) + if placer and placer:is_player() and placer:get_player_control().aux1 then + local meta = minetest.get_meta(pos) + for i = 1, 6 do + meta:set_int("l" .. tostring(i) .. "s", 0) + end + update_formspec(pos) + end + return pipeworks.after_place(pos, placer, itemstack, pointed_thing) + end, + on_receive_fields = function(pos, formname, fields, sender) + if (fields.quit and not fields.key_enter_field) + or not pipeworks.may_configure(pos, sender) then + return + end + + local meta = minetest.get_meta(pos) + for i = 1, 6 do + local field_name = "tags" .. tostring(i) + if fields[field_name] then + local tags = pipeworks.sanitize_tags(fields[field_name]) + meta:set_string(field_name, table.concat(tags, ",")) + end + end + + fs_helpers.on_receive_fields(pos, fields) + update_formspec(pos) + end, + can_dig = function(pos, player) + return true + end, + }, +}) From ce263da6d51f143e98aaf09f849956e69cec3a8e Mon Sep 17 00:00:00 2001 From: OgelGames Date: Thu, 7 Mar 2024 14:56:19 +1100 Subject: [PATCH 13/30] also accept strings of tags in digilines and lua fixes #116 --- filter-injector.lua | 2 +- item_transport.lua | 2 +- tubes/lua.lua | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/filter-injector.lua b/filter-injector.lua index 6f38e60..e605c9e 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -201,7 +201,7 @@ local function punch_filter(data, filtpos, filtnode, msg) set_filter_formspec(data, filtmeta) end - if type(msg.tags) == "table" then + if type(msg.tags) == "table" or type(msg.tags) == "string" then item_tags = pipeworks.sanitize_tags(msg.tags) elseif type(msg.tag) == "string" then item_tags = pipeworks.sanitize_tags({msg.tag}) diff --git a/item_transport.lua b/item_transport.lua index 7577741..ddf2a08 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -388,7 +388,7 @@ luaentity.register_entity("pipeworks:tubed_item", { 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 + self.tags = #tags > 0 and tags or nil end local rev_vel = vector.multiply(velocity, -1) local rev_dir = vector.direction(self.start_pos,vector.add(self.start_pos,rev_vel)) diff --git a/tubes/lua.lua b/tubes/lua.lua index 50782bf..1fc9208 100644 --- a/tubes/lua.lua +++ b/tubes/lua.lua @@ -972,10 +972,10 @@ for white = 0, 1 do elseif type(msg) == "table" then if pipeworks.enable_item_tags then local new_tags - if type(msg.tags) == "table" then - new_tags = msg.tags + if type(msg.tags) == "table" or type(msg.tags) == "string" then + new_tags = pipeworks.sanitize_tags(msg.tags) elseif type(msg.tag) == "string" then - new_tags = {msg.tag} + new_tags = pipeworks.sanitize_tags({msg.tag}) end if new_tags then for i=1, math.max(#tags, #new_tags) do From 8828183befafdf1bf3a26e3b6303cc824da36b81 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Tue, 12 Mar 2024 14:17:29 +1100 Subject: [PATCH 14/30] remove nan values from digiline messages --- tubes/lua.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tubes/lua.lua b/tubes/lua.lua index 1fc9208..7a76fe9 100644 --- a/tubes/lua.lua +++ b/tubes/lua.lua @@ -370,7 +370,10 @@ local function clean_and_weigh_digiline_message(msg, back_references) return msg, #msg + 25 elseif t == "number" then -- Numbers are passed by value so need not be touched, and cost 8 bytes - -- as all numbers in Lua are doubles. + -- as all numbers in Lua are doubles. NaN values are removed. + if msg ~= msg then + return nil, 0 + end return msg, 8 elseif t == "boolean" then -- Booleans are passed by value so need not be touched, and cost 1 From 1577af738fe2f57df2194ea76ecfa515a4a3e714 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Wed, 13 Mar 2024 17:31:38 +0100 Subject: [PATCH 15/30] Autocrafter multi group ingredient (#115) * check for non-zero group value in theory groups can have negative values too. * fix #114 multi group recipe items Fix the bug that prevented crafting with recipes that had ingredients that need to match multiple groups. * comments and whitespace changes * fix faulty empty table check --- autocrafter.lua | 65 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/autocrafter.lua b/autocrafter.lua index bd9a669..014c4a5 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -4,6 +4,7 @@ local S = minetest.get_translator("pipeworks") local autocrafterCache = {} local craft_time = 1 +local next = next local function count_index(invlist) local index = {} @@ -48,7 +49,9 @@ local function get_matching_craft(output_name, example_recipe) elseif recipe_item_name:sub(1, 6) == "group:" then group = recipe_item_name:sub(7) for example_item_name, _ in pairs(index_example) do - if minetest.get_item_group(example_item_name, group) > 0 then + if minetest.get_item_group( + example_item_name, group) ~= 0 + then score = score + 1 break end @@ -89,22 +92,27 @@ local function get_craft(pos, inventory, hash) return craft end --- From a consumption table with groups and an inventory index, build --- a consumption table without groups +-- From a consumption table with groups and an inventory index, +-- build a consumption table without groups local function calculate_consumption(inv_index, consumption_with_groups) inv_index = table.copy(inv_index) consumption_with_groups = table.copy(consumption_with_groups) + -- table of items to actually consume local consumption = {} - local groups = {} + -- table of ingredients defined as one or more groups each + local grouped_ingredients = {} -- First consume all non-group requirements - -- This is done to avoid consuming a non-group item which is also - -- in a group + -- This is done to avoid consuming a non-group item which + -- is also in a group for key, count in pairs(consumption_with_groups) do if key:sub(1, 6) == "group:" then - groups[#groups + 1] = key:sub(7, #key) + -- build table with group recipe items while looping + grouped_ingredients[key] = key:sub(7):split(',') else + -- if the item to consume doesn't exist in inventory + -- or not enough of them, abort crafting if not inv_index[key] or inv_index[key] < count then return nil end @@ -118,28 +126,45 @@ local function calculate_consumption(inv_index, consumption_with_groups) end end + -- helper function to resolve matching ingredients with multiple group + -- requirements + local function ingredient_groups_match_item(ingredient_groups, name) + local found = 0 + local count_ingredient_groups = #ingredient_groups + for i = 1, count_ingredient_groups do + if minetest.get_item_group(name, + ingredient_groups[i]) ~= 0 + then + found = found + 1 + end + end + return found == count_ingredient_groups + end + -- Next, resolve groups using the remaining items in the inventory - local take - if #groups > 0 then + if next(grouped_ingredients) ~= nil then + local take for itemname, count in pairs(inv_index) do if count > 0 then - local def = minetest.registered_items[itemname] - local item_groups = def and def.groups or {} - for i = 1, #groups do - local group = groups[i] - local groupname = "group:" .. group - if item_groups[group] and item_groups[group] >= 1 - and consumption_with_groups[groupname] > 0 + -- groupname is the string as defined by recipe. + -- e.g. group:dye,color_blue + -- groups holds the group names split into a list + -- ready to be passed to core.get_item_group() + for groupname, groups in pairs(grouped_ingredients) do + if consumption_with_groups[groupname] > 0 + and ingredient_groups_match_item(groups, itemname) then - take = math.min(count, consumption_with_groups[groupname]) + take = math.min(count, + consumption_with_groups[groupname]) consumption_with_groups[groupname] = - consumption_with_groups[groupname] - take + consumption_with_groups[groupname] - take assert(consumption_with_groups[groupname] >= 0) consumption[itemname] = - (consumption[itemname] or 0) + take + (consumption[itemname] or 0) + take - inv_index[itemname] = inv_index[itemname] - take + inv_index[itemname] = + inv_index[itemname] - take assert(inv_index[itemname] >= 0) end end From 1b79084e6bbbcbc02229f3136b87cca98f14e829 Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:21:43 +0100 Subject: [PATCH 16/30] fix chest duplication bug (#119) closes #118 Co-authored-by: BuckarooBanzay --- compat-chests.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compat-chests.lua b/compat-chests.lua index 0448660..eef3a5a 100644 --- a/compat-chests.lua +++ b/compat-chests.lua @@ -111,6 +111,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end minetest.after(0.2, function() if minetest.get_modpath("default") then + local current_node = minetest.get_node(pos) + if current_node.name ~= "default:" .. swap .. "_open" then + -- the chest has already been replaced, don't try to replace what's there. + -- see: https://github.com/minetest/minetest_game/pull/3046 + return + end minetest.swap_node(pos, { name = "default:" .. swap, param2 = node.param2 }) end From 21dbae9962d728637add4fdea05916e4e9b51ebe Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sat, 30 Mar 2024 15:55:35 +1100 Subject: [PATCH 17/30] fix missing check for `pipeworks.enable_item_tags` fixes #117 closes #121 --- filter-injector.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/filter-injector.lua b/filter-injector.lua index e605c9e..21b3aca 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -201,10 +201,12 @@ local function punch_filter(data, filtpos, filtnode, msg) set_filter_formspec(data, filtmeta) end - if type(msg.tags) == "table" or type(msg.tags) == "string" then - item_tags = pipeworks.sanitize_tags(msg.tags) - elseif type(msg.tag) == "string" then - item_tags = pipeworks.sanitize_tags({msg.tag}) + if pipeworks.enable_item_tags then + if type(msg.tags) == "table" or type(msg.tags) == "string" then + 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 From 1169cff163f9b0131c41a11d146d111ff065b476 Mon Sep 17 00:00:00 2001 From: tour <129965577+a-tour-ist@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:25:13 +0200 Subject: [PATCH 18/30] de-duplicate chest code (#123) * rewrite compat-chests.lua add pipeworks.override_chest() to make a existing chest connecting to pipeworks * move pipeworks.override_chest() to a new file fix crash with after_place_node() there let mcl_barrels make use of the new function * some comments --- chests.lua | 90 +++++++++ compat-chests.lua | 457 +++++++++++++++++----------------------------- init.lua | 8 +- mcl_barrels.lua | 72 -------- 4 files changed, 257 insertions(+), 370 deletions(-) create mode 100644 chests.lua delete mode 100644 mcl_barrels.lua diff --git a/chests.lua b/chests.lua new file mode 100644 index 0000000..ed7b061 --- /dev/null +++ b/chests.lua @@ -0,0 +1,90 @@ +pipeworks.chests = {} + +-- register a chest to connect with pipeworks tubes. +-- will autoconnect to tubes and add tube inlets to the textures +-- it is highly recommended to allow the user to change the "splitstacks" int (1 to enable) in the node meta +-- but that can't be done by this function + +-- @param override: additional overrides, such as stuff to modify the node formspec +-- @param connect_sides: which directions the chests shall connect to +function pipeworks.override_chest(chestname, override, connect_sides) + local old_def = minetest.registered_nodes[chestname] + + local tube_entry = "^pipeworks_tube_connection_wooden.png" + override.tiles = override.tiles or old_def.tiles + -- expand the tiles table if it has been shortened + if #override.tiles < 6 then + for i = #override.tiles, 6 do + override.tiles[i] = override.tiles[#override.tiles] + end + end + -- add inlets to the sides that connect to tubes + local tile_directions = {"top", "bottom", "right", "left", "back", "front"} + for i, direction in ipairs(tile_directions) do + if connect_sides[direction] then + if type(override.tiles[i]) == "string" then + override.tiles[i] = override.tiles[i] .. tube_entry + elseif type(override.tiles[i]) == "table" and not override.tiles[i].animation then + override.tiles[i].name = override.tiles[i].name .. tube_entry + end + end + end + + local old_after_place_node = override.after_place_node or old_def.after_place_node or function() end + override.after_place_node = function(pos, placer, itemstack, pointed_thing) + old_after_place_node(pos, placer, itemstack, pointed_thing) + pipeworks.after_place(pos) + end + + local old_after_dig = override.after_dig or old_def.after_dig or function() end + override.after_dig_node = function(pos, oldnode, oldmetadata, digger) + old_after_dig(pos, oldnode, oldmetadata, digger) + pipeworks.after_dig(pos, oldnode, oldmetadata, digger) + end + + local old_on_rotate + if override.on_rotate ~= nil then + old_on_rotate = override.on_rotate + elseif old_def.on_rotate ~= nil then + old_on_rotate = old_def.on_rotate + else + old_on_rotate = function() end + end + -- on_rotate = false -> rotation disabled, no need to update tubes + -- everything else: undefined by the most common screwdriver mods + if type(old_on_rotate) == "function" then + override.on_rotate = function(pos, node, user, mode, new_param2) + if old_on_rotate(pos, node, user, mode, new_param2) ~= false then + return pipeworks.on_rotate(pos, node, user, mode, new_param2) + else + return false + end + end + end + + override.tube = { + insert_object = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:add_item("main", stack) + end, + can_insert = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if meta:get_int("splitstacks") == 1 then + stack = stack:peek_item(1) + end + return inv:room_for_item("main", stack) + end, + input_inventory = "main", + connect_sides = connect_sides + } + + -- Add the extra groups + override.groups = override.groups or old_def.groups or {} + override.groups.tubedevice = 1 + override.groups.tubedevice_receiver = 1 + + minetest.override_item(chestname, override) + pipeworks.chests[chestname] = true +end \ No newline at end of file diff --git a/compat-chests.lua b/compat-chests.lua index eef3a5a..a53d9f3 100644 --- a/compat-chests.lua +++ b/compat-chests.lua @@ -1,309 +1,178 @@ --- this bit of code modifies the default chests and furnaces to be compatible --- with pipeworks. --- --- the formspecs found here are basically copies of the ones from minetest_game --- plus bits from pipeworks' sorting tubes +-- this bit of code overrides the default chests from common games (mtg, hades, minclone*) to be +-- compatible with pipeworks. Where possible, it overrides their formspec to add a splitstacks switch --- Pipeworks Specific local fs_helpers = pipeworks.fs_helpers -local tube_entry = "^pipeworks_tube_connection_wooden.png" --- Chest Locals -local open_chests = {} +-- formspec helper to add the splitstacks switch +local function add_pipeworks_switch(formspec, pos) + -- based on the sorting tubes + formspec = formspec .. + fs_helpers.cycling_button( + minetest.get_meta(pos), + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + return formspec +end + +-- helper to add the splitstacks switch to a node-formspec +local function update_node_formspec(pos) + local meta = minetest.get_meta(pos) + local old_fs = meta:get_string("formspec") + local new_fs = add_pipeworks_switch(old_fs, pos) + meta:set_string("formspec", new_fs) +end -local get_chest_formspec if minetest.get_modpath("default") then - function get_chest_formspec(pos) - local spos = pos.x .. "," .. pos.y .. "," .. pos.z - local formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[nodemeta:" .. spos .. ";main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) - - -- Pipeworks Switch - formspec = formspec .. - fs_helpers.cycling_button( - minetest.get_meta(pos), - pipeworks.button_base, - "splitstacks", - { - pipeworks.button_off, - pipeworks.button_on - } - )..pipeworks.button_label - - return formspec - end -else - local function get_hotbar_bg(x,y) - local out = "" - for i=0,7,1 do - out = out .."image["..x+i..","..y..";1,1;gui_hb_bg.png]" + -- add the pipeworks switch into the default chest formspec + local old_get_chest_formspec = default.chest.get_chest_formspec + -- luacheck: ignore 122 + default.chest.get_chest_formspec = function(pos) + local old_fs = old_get_chest_formspec(pos) + local node = minetest.get_node(pos) + -- not all chests using this formspec necessary connect to pipeworks + if pipeworks.chests[node.name] then + local new_fs = add_pipeworks_switch(old_fs, pos) + return new_fs + else + return old_fs end - return out end - function get_chest_formspec(pos) - local spos = pos.x .. "," .. pos.y .. "," .. pos.z - local formspec = - "size[10,9]" .. - "background9[8,8;8,9;hades_chests_chestui.png;true;8]".. - "list[nodemeta:" .. spos .. ";main;0,0.3;10,4;]" .. - "list[current_player;main;0,4.85;10,1;]" .. - "list[current_player;main;0,6.08;10,3;10]" .. - "listring[nodemeta:" .. spos .. ";main]" .. - "listring[current_player;main]" .. - get_hotbar_bg(0,4.85) - - -- Pipeworks Switch - formspec = formspec .. - fs_helpers.cycling_button( - minetest.get_meta(pos), - pipeworks.button_base, - "splitstacks", - { - pipeworks.button_off, - pipeworks.button_on - } - )..pipeworks.button_label - - return formspec - end -end - -local function chest_lid_obstructed(pos) - local above = { x = pos.x, y = pos.y + 1, z = pos.z } - local def = minetest.registered_nodes[minetest.get_node(above).name] - -- allow ladders, signs, wallmounted things and torches to not obstruct - if not def then return true end - if def.drawtype == "airlike" or - def.drawtype == "signlike" or - def.drawtype == "torchlike" or - (def.drawtype == "nodebox" and def.paramtype2 == "wallmounted") then - return false - end - return true -end - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "pipeworks:chest_formspec" and player then - local pn = player:get_player_name() - if open_chests[pn] then - local pos = open_chests[pn].pos - if fields.quit then - local sound = open_chests[pn].sound - local swap = open_chests[pn].swap - local node = minetest.get_node(pos) - - open_chests[pn] = nil - for _, v in pairs(open_chests) do - if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then - return true - end - end - minetest.after(0.2, function() - if minetest.get_modpath("default") then - local current_node = minetest.get_node(pos) - if current_node.name ~= "default:" .. swap .. "_open" then - -- the chest has already been replaced, don't try to replace what's there. - -- see: https://github.com/minetest/minetest_game/pull/3046 - return - end - minetest.swap_node(pos, { name = "default:" .. swap, param2 = node.param2 }) - end - - -- Pipeworks notification - pipeworks.after_place(pos) - end) - minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10}) - elseif pipeworks.may_configure(pos, player) then + -- get the fields from the chest formspec, we can do this bc. newest functions are called first + -- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840 + minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "default:chest" then + local pn = player:get_player_name() + local pos = default.chest.open_chests[pn].pos + local chest = pos and minetest.get_node(pos) + local is_pipeworks_chest = chest and pipeworks.chests[chest] + if is_pipeworks_chest and not fields.quit and pipeworks.may_configure(pos, player) then -- Pipeworks Switch fs_helpers.on_receive_fields(pos, fields) - minetest.show_formspec(player:get_player_name(), "pipeworks:chest_formspec", get_chest_formspec(pos)) + minetest.show_formspec(player:get_player_name(), + "default:chest", + default.chest.get_chest_formspec(pos)) + end + -- Do NOT return true here, the callback from default still needs to run + return false + end + end) + + local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} + local connect_sides_open = {left = 1, right = 1, back = 1, bottom = 1} + + pipeworks.override_chest("default:chest", {}, connect_sides) + pipeworks.override_chest("default:chest_open", {}, connect_sides_open) + pipeworks.override_chest("default:chest_locked", {}, connect_sides) + pipeworks.override_chest("default:chest_locked_open", {}, connect_sides_open) +elseif minetest.get_modpath("hades_chests") then + local chest_colors = {"", "white", "grey", "dark_grey", "black", "blue", "cyan", "dark_green", "green", "magenta", + "orange", "pink", "red", "violet", "yellow"} + for _, color in ipairs(chest_colors) do + local chestname = (color == "" and "hades_chests:chest") + or "hades_chests:chest_" .. color + local chestname_protected = (color == "" and "hades_chests:chest_locked") + or "hades_chests:chest_" .. color .. "_locked" + local old_def = minetest.registered_nodes[chestname] + + -- chest formspec-creation functions are local, we need to find other ways + -- normal chests use node formspecs, we can hack into these + local old_on_construct = old_def.on_construct + local override = { + on_construct = function(pos) + old_on_construct(pos) + update_node_formspec(pos) + end, + on_receive_fields = function(pos, formname, fields, player) + if not fields.quit and pipeworks.may_configure(pos, player) then + -- Pipeworks Switch + fs_helpers.on_receive_fields(pos, fields) + update_node_formspec(pos) + end + end, + -- chest's on_rotate is "simple", but we assumed the api from the mtg screwdriver mod + -- this will keep the same behavior, but supports the code above + on_rotate = screwdriver.rotate_simple + } + + -- locked chests uses local functions to create their formspec - we need to copy these + -- https://codeberg.org/Wuzzy/Hades_Revisited/src/branch/master/mods/hades_chests/init.lua + local function get_locked_chest_formspec(pos) + local spos = pos.x .. "," .. pos.y .. "," ..pos.z + local formspec = + "size[10,9]".. + "list[nodemeta:".. spos .. ";main;0,0;10,4;]".. + "list[current_player;main;0,5;10,4;]".. + "listring[]".. + "background9[8,8;10,9;hades_chests_chestui.png;true;8]" + + -- change from pipeworks + local new_fs = add_pipeworks_switch(formspec, pos) + return new_fs + end + + local function has_locked_chest_privilege(meta, player) + local name = player:get_player_name() + if name ~= meta:get_string("owner") and not minetest.check_player_privs(name, "protection_bypass") then + return false end return true end + + -- store, which chest a formspec submission belongs to + -- {player1 = pos1, player2 = pos2, ...} + local open_chests = {} + minetest.register_on_leaveplayer(function(player) + open_chests[player:get_player_name()] = nil + end) + + local override_protected = { + on_rightclick = function(pos, node, clicker) + local meta = minetest.get_meta(pos) + if has_locked_chest_privilege(meta, clicker) then + minetest.show_formspec( + clicker:get_player_name(), + "hades_chests:chest_locked", + get_locked_chest_formspec(pos) + ) + open_chests[clicker:get_player_name()] = pos + else + minetest.sound_play({ name = "hades_chests_locked", gain = 0.3 }, { max_hear_distance = 10 }, true) + end + end, + on_rotate = screwdriver.rotate_simple + } + + -- get the fields from the chest formspec, we can do this bc. newest functions are called first + -- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840 + minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "hades_chests:chest_locked" then + local pn = player:get_player_name() + local pos = open_chests[pn] + if not fields.quit and pos and pipeworks.may_configure(pos, player) then + -- Pipeworks Switch + fs_helpers.on_receive_fields(pos, fields) + minetest.show_formspec(pn, "hades_chests:chest_locked", get_locked_chest_formspec(pos)) + end + -- Do NOT return true here, the callback from hades still needs to run (if they add one) + return false + end + end) + + local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} + pipeworks.override_chest(chestname, override, connect_sides) + pipeworks.override_chest(chestname_protected, override_protected, connect_sides) end -end) - --- Original Definitions -local old_chest_def, old_chest_open_def, old_chest_locked_def, old_chest_locked_open_def -if minetest.get_modpath("default") then - old_chest_def = table.copy(minetest.registered_items["default:chest"]) - old_chest_open_def = table.copy(minetest.registered_items["default:chest_open"]) - old_chest_locked_def = table.copy(minetest.registered_items["default:chest_locked"]) - old_chest_locked_open_def = table.copy(minetest.registered_items["default:chest_locked_open"]) -elseif minetest.get_modpath("hades_chests") then - old_chest_def = table.copy(minetest.registered_items["hades_chests:chest"]) - old_chest_open_def = table.copy(minetest.registered_items["hades_chests:chest"]) - old_chest_locked_def = table.copy(minetest.registered_items["hades_chests:chest_locked"]) - old_chest_locked_open_def = table.copy(minetest.registered_items["hades_chests:chest_locked"]) -end - --- Override Construction -local override_protected, override, override_open, override_protected_open -override_protected = { - tiles = { - "default_chest_top.png"..tube_entry, - "default_chest_top.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_lock.png", - "default_chest_inside.png" - }, - after_place_node = function(pos, placer) - old_chest_locked_def.after_place_node(pos, placer) - pipeworks.after_place(pos) - end, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - if not default.can_interact_with_node(clicker, pos) then - return itemstack - end - - minetest.sound_play(old_chest_locked_def.sound_open, {gain = 0.3, - pos = pos, max_hear_distance = 10}) - if not chest_lid_obstructed(pos) then - if minetest.get_modpath("default") then - minetest.swap_node(pos, - { name = "default:" .. "chest_locked" .. "_open", - param2 = node.param2 }) - end - end - minetest.after(0.2, minetest.show_formspec, - clicker:get_player_name(), - "pipeworks:chest_formspec", get_chest_formspec(pos)) - open_chests[clicker:get_player_name()] = { pos = pos, - sound = old_chest_locked_def.sound_close, swap = "chest_locked" } - end, - groups = table.copy(old_chest_locked_def.groups), - tube = { - insert_object = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item("main", stack) - end, - can_insert = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if meta:get_int("splitstacks") == 1 then - stack = stack:peek_item(1) - end - return inv:room_for_item("main", stack) - end, - input_inventory = "main", - connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} - }, - after_dig_node = pipeworks.after_dig, - on_rotate = pipeworks.on_rotate -} -override = { - tiles = { - "default_chest_top.png"..tube_entry, - "default_chest_top.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_front.png", - "default_chest_inside.png" - }, - on_rightclick = function(pos, node, clicker) - minetest.sound_play(old_chest_def.sound_open, {gain = 0.3, pos = pos, - max_hear_distance = 10}) - if not chest_lid_obstructed(pos) then - if minetest.get_modpath("default") then - minetest.swap_node(pos, { - name = "default:" .. "chest" .. "_open", - param2 = node.param2 }) - end - end - minetest.after(0.2, minetest.show_formspec, - clicker:get_player_name(), - "pipeworks:chest_formspec", get_chest_formspec(pos)) - open_chests[clicker:get_player_name()] = { pos = pos, - sound = old_chest_def.sound_close, swap = "chest" } - end, - groups = table.copy(old_chest_def.groups), - tube = { - insert_object = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item("main", stack) - end, - can_insert = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if meta:get_int("splitstacks") == 1 then - stack = stack:peek_item(1) - end - return inv:room_for_item("main", stack) - end, - input_inventory = "main", - connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} - }, - after_place_node = pipeworks.after_place, - after_dig_node = pipeworks.after_dig, - on_rotate = pipeworks.on_rotate -} ---[[local override_common = { - -} -for k,v in pairs(override_common) do - override_protected[k] = v - override[k] = v -end]] - -override_open = table.copy(override) -override_open.groups = table.copy(old_chest_open_def.groups) -override_open.tube = table.copy(override.tube) -override_open.tube.connect_sides = table.copy(override.tube.connect_sides) -override_open.tube.connect_sides.top = nil - -override_protected_open = table.copy(override_protected) -override_protected_open.groups = table.copy(old_chest_locked_open_def.groups) -override_protected_open.tube = table.copy(override_protected.tube) -override_protected_open.tube.connect_sides = table.copy(override_protected.tube.connect_sides) -override_protected_open.tube.connect_sides.top = nil - -override_protected.tiles = { -- Rearranged according to the chest registration in Minetest_Game. - "default_chest_top.png"..tube_entry, - "default_chest_top.png"..tube_entry, - "default_chest_side.png"..tube_entry.."^[transformFX", - "default_chest_side.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_lock.png", -} -override.tiles = { - "default_chest_top.png"..tube_entry, - "default_chest_top.png"..tube_entry, - "default_chest_side.png"..tube_entry.."^[transformFX", - "default_chest_side.png"..tube_entry, - "default_chest_side.png"..tube_entry, - "default_chest_front.png", -} - --- Add the extra groups -for _,v in ipairs({override_protected, override, override_open, override_protected_open}) do - v.groups.tubedevice = 1 - v.groups.tubedevice_receiver = 1 -end - --- Override with the new modifications. -if minetest.get_modpath("default") then - minetest.override_item("default:chest", override) - minetest.override_item("default:chest_open", override_open) - minetest.override_item("default:chest_locked", override_protected) - minetest.override_item("default:chest_locked_open", override_protected_open) -elseif minetest.get_modpath("hades_chests") then - minetest.override_item("hades_chests:chest", override) - --minetest.override_item("hades_chests:chest_open", override_open) - minetest.override_item("hades_chests:chest_locked", override_protected) - --minetest.override_item("hades_chests:chest_locked_open", override_protected_open) -end - +elseif minetest.get_modpath("mcl_barrels") then + -- TODO: bring splitstacks switch in the formspec + -- with the current implementation of mcl_barrels this would mean to duplicate a lot of code from there... + local connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1} + pipeworks.override_chest("mcl_barrels:barrel_closed", {}, connect_sides) + pipeworks.override_chest("mcl_barrels:barrel_open", {}, connect_sides) +end \ No newline at end of file diff --git a/init.lua b/init.lua index a7ef061..6d85a06 100644 --- a/init.lua +++ b/init.lua @@ -59,6 +59,7 @@ dofile(pipeworks.modpath.."/luaentity.lua") dofile(pipeworks.modpath.."/item_transport.lua") dofile(pipeworks.modpath.."/flowing_logic.lua") dofile(pipeworks.modpath.."/filter-injector.lua") +dofile(pipeworks.modpath.."/chests.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") dofile(pipeworks.modpath.."/tubes/registration.lua") @@ -95,12 +96,11 @@ end if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end -if pipeworks.enable_redefines and (minetest.get_modpath("default") or minetest.get_modpath("hades_core")) then +if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat-chests.lua") - dofile(pipeworks.modpath.."/compat-furnaces.lua") end -if pipeworks.enable_redefines and minetest.get_modpath("mcl_barrels") then - dofile(pipeworks.modpath.."/mcl_barrels.lua") +if pipeworks.enable_redefines and (minetest.get_modpath("default") or minetest.get_modpath("hades_core")) then + dofile(pipeworks.modpath.."/compat-furnaces.lua") end if pipeworks.enable_redefines and minetest.get_modpath("mcl_furnaces") then dofile(pipeworks.modpath.."/mcl_furnaces.lua") diff --git a/mcl_barrels.lua b/mcl_barrels.lua deleted file mode 100644 index 423dab3..0000000 --- a/mcl_barrels.lua +++ /dev/null @@ -1,72 +0,0 @@ --- this bit of code modifies the mcl barrels to be compatible with --- pipeworks. - --- Pipeworks Specific -local tube_entry = "^pipeworks_tube_connection_wooden.png" - --- Original Definitions -local old_barrel = table.copy(minetest.registered_items["mcl_barrels:barrel_closed"]) - -local groups = old_barrel.groups -groups["tubedevice"] = 1 -groups["tubedevice_receiver"] = 1 -local groups_open = table.copy(groups) -groups_open["not_in_creative_inventory"] = 1 - - --- Override Construction -local override_barrel = {} - -override_barrel.tiles = { - "mcl_barrels_barrel_top.png^[transformR270", - "mcl_barrels_barrel_bottom.png"..tube_entry, - "mcl_barrels_barrel_side.png"..tube_entry -} - -override_barrel.after_place_node = function(pos, placer, itemstack, pointed_thing) - old_barrel.after_place_node(pos, placer, itemstack, pointed_thing) - pipeworks.after_place(pos, placer, itemstack, pointed_thing) -end - -override_barrel.tube = { - insert_object = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item("main", stack) - end, - can_insert = function(pos, node, stack, direction) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if meta:get_int("splitstacks") == 1 then - stack = stack:peek_item(1) - end - return inv:room_for_item("main", stack) - end, - input_inventory = "main", - connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1} -} - -override_barrel.after_dig_node = function(pos, oldnode, oldmetadata, digger) - old_barrel.after_dig_node(pos, oldnode, oldmetadata, digger) - pipeworks.after_dig(pos) -end - -override_barrel.groups = table.copy(old_barrel.groups) - -override_barrel.on_rotate = pipeworks.on_rotate - - -local override_barrel_open = table.copy(override_barrel) - -override_barrel_open.tiles = { - "mcl_barrels_barrel_top_open.png", - "mcl_barrels_barrel_bottom.png"..tube_entry, - "mcl_barrels_barrel_side.png"..tube_entry -} - -override_barrel_open.groups = groups_open - - --- Override with the new modifications. -minetest.override_item("mcl_barrels:barrel_closed", override_barrel) -minetest.override_item("mcl_barrels:barrel_open", override_barrel_open) From 94442e87bb31c3d2cf1a9968aa9d047515db7f20 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Mon, 13 May 2024 12:00:17 +0200 Subject: [PATCH 19/30] patch for #124 (#125) async race condition fix * restructure avoiding excessive indentation * possibly fix #124 * async race condition fix --- compat-chests.lua | 57 ++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/compat-chests.lua b/compat-chests.lua index a53d9f3..b996871 100644 --- a/compat-chests.lua +++ b/compat-chests.lua @@ -47,21 +47,27 @@ if minetest.get_modpath("default") then -- get the fields from the chest formspec, we can do this bc. newest functions are called first -- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840 minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "default:chest" then - local pn = player:get_player_name() - local pos = default.chest.open_chests[pn].pos - local chest = pos and minetest.get_node(pos) - local is_pipeworks_chest = chest and pipeworks.chests[chest] - if is_pipeworks_chest and not fields.quit and pipeworks.may_configure(pos, player) then - -- Pipeworks Switch - fs_helpers.on_receive_fields(pos, fields) - minetest.show_formspec(player:get_player_name(), - "default:chest", - default.chest.get_chest_formspec(pos)) - end - -- Do NOT return true here, the callback from default still needs to run - return false + if fields.quit or formname ~= "default:chest" then + return end + local pn = player:get_player_name() + local chest_open = default.chest.open_chests[pn] + if not chest_open then + -- chest already closed before formspec + return + end + local pos = chest_open.pos + local chest = pos and minetest.get_node(pos) + local is_pipeworks_chest = chest and pipeworks.chests[chest] + if is_pipeworks_chest and pipeworks.may_configure(pos, player) then + -- Pipeworks Switch + fs_helpers.on_receive_fields(pos, fields) + minetest.show_formspec(pn, + "default:chest", + default.chest.get_chest_formspec(pos)) + end + -- Do NOT return true here, the callback from default still needs to run + return false end) local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} @@ -152,17 +158,18 @@ elseif minetest.get_modpath("hades_chests") then -- get the fields from the chest formspec, we can do this bc. newest functions are called first -- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840 minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "hades_chests:chest_locked" then - local pn = player:get_player_name() - local pos = open_chests[pn] - if not fields.quit and pos and pipeworks.may_configure(pos, player) then - -- Pipeworks Switch - fs_helpers.on_receive_fields(pos, fields) - minetest.show_formspec(pn, "hades_chests:chest_locked", get_locked_chest_formspec(pos)) - end - -- Do NOT return true here, the callback from hades still needs to run (if they add one) - return false + if fields.quit or formname ~= "hades_chests:chest_locked" then + return end + local pn = player:get_player_name() + local pos = open_chests[pn] + if pos and pipeworks.may_configure(pos, player) then + -- Pipeworks Switch + fs_helpers.on_receive_fields(pos, fields) + minetest.show_formspec(pn, "hades_chests:chest_locked", get_locked_chest_formspec(pos)) + end + -- Do NOT return true here, the callback from hades still needs to run (if they add one) + return false end) local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1} @@ -175,4 +182,4 @@ elseif minetest.get_modpath("mcl_barrels") then local connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1} pipeworks.override_chest("mcl_barrels:barrel_closed", {}, connect_sides) pipeworks.override_chest("mcl_barrels:barrel_open", {}, connect_sides) -end \ No newline at end of file +end From 1225e4168bd09b07f1978006640a681e6fc0a4b0 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Wed, 15 May 2024 21:18:26 +1000 Subject: [PATCH 20/30] fix splitstacks toggle in default chests --- compat-chests.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compat-chests.lua b/compat-chests.lua index b996871..5465bfb 100644 --- a/compat-chests.lua +++ b/compat-chests.lua @@ -52,14 +52,13 @@ if minetest.get_modpath("default") then end local pn = player:get_player_name() local chest_open = default.chest.open_chests[pn] - if not chest_open then + if not chest_open or not chest_open.pos then -- chest already closed before formspec return end local pos = chest_open.pos - local chest = pos and minetest.get_node(pos) - local is_pipeworks_chest = chest and pipeworks.chests[chest] - if is_pipeworks_chest and pipeworks.may_configure(pos, player) then + local node = minetest.get_node(pos) + if pipeworks.chests[node.name] and pipeworks.may_configure(pos, player) then -- Pipeworks Switch fs_helpers.on_receive_fields(pos, fields) minetest.show_formspec(pn, From 223c90e68424109fb8f3e49a847327135e675907 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Mon, 27 May 2024 00:31:04 +1000 Subject: [PATCH 21/30] Fake player and wielder improvements (#126) --- .luacheckrc | 2 +- autoplace_tubes.lua | 6 +- common.lua | 318 +---------------------- filter-injector.lua | 10 +- legacy.lua | 62 ----- mod.conf | 2 +- wielder.lua | 614 ++++++++++++++++++-------------------------- 7 files changed, 262 insertions(+), 752 deletions(-) delete mode 100644 legacy.lua diff --git a/.luacheckrc b/.luacheckrc index 215a236..6d2f92f 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -21,6 +21,6 @@ read_globals = { "default", "mesecon", "digiline", "screwdriver", "unified_inventory", "i3", "mcl_experience", "awards", - "xcompat", + "xcompat", "fakelib", } diff --git a/autoplace_tubes.lua b/autoplace_tubes.lua index 8348430..9f4e112 100644 --- a/autoplace_tubes.lua +++ b/autoplace_tubes.lua @@ -11,7 +11,7 @@ local function nodeside(node, tubedir) end local backdir = minetest.facedir_to_dir(node.param2) - local back = pipeworks.vector_dot(backdir, tubedir) + local back = vector.dot(backdir, tubedir) if back == 1 then return "back" elseif back == -1 then @@ -19,7 +19,7 @@ local function nodeside(node, tubedir) end local topdir = pipeworks.facedir_to_top_dir(node.param2) - local top = pipeworks.vector_dot(topdir, tubedir) + local top = vector.dot(topdir, tubedir) if top == 1 then return "top" elseif top == -1 then @@ -27,7 +27,7 @@ local function nodeside(node, tubedir) end local rightdir = pipeworks.facedir_to_right_dir(node.param2) - local right = pipeworks.vector_dot(rightdir, tubedir) + local right = vector.dot(rightdir, tubedir) if right == 1 then return "right" else diff --git a/common.lua b/common.lua index 5db3feb..dcf2c7f 100644 --- a/common.lua +++ b/common.lua @@ -91,22 +91,6 @@ function pipeworks.replace_name(tbl,tr,name) return ntbl end ----------------------- --- Vector functions -- ----------------------- - -function pipeworks.vector_cross(a, b) - return { - x = a.y * b.z - a.z * b.y, - y = a.z * b.x - a.x * b.z, - z = a.x * b.y - a.y * b.x - } -end - -function pipeworks.vector_dot(a, b) - return a.x * b.x + a.y * b.y + a.z * b.z -end - ----------------------- -- Facedir functions -- ----------------------- @@ -122,7 +106,7 @@ function pipeworks.facedir_to_top_dir(facedir) end function pipeworks.facedir_to_right_dir(facedir) - return pipeworks.vector_cross( + return vector.cross( pipeworks.facedir_to_top_dir(facedir), minetest.facedir_to_dir(facedir) ) @@ -142,29 +126,10 @@ function directions.side_to_dir(side) end function directions.dir_to_side(dir) - local c = pipeworks.vector_dot(dir, vector.new(1, 2, 3)) + 4 + local c = vector.dot(dir, vector.new(1, 2, 3)) + 4 return ({6, 2, 4, 0, 3, 1, 5})[c] end ----------------------- --- String functions -- ----------------------- - ---[[function pipeworks.string_split(str, sep) - local fields = {} - local index = 1 - local expr = "([^"..sep.."])+" - string.gsub(str, expr, function(substring) - fields[index] = substring - index = index + 1 - end) - return fields -end]] - -function pipeworks.string_startswith(str, substr) - return str:sub(1, substr:len()) == substr -end - --------------------- -- Table functions -- --------------------- @@ -208,7 +173,7 @@ pipeworks.fs_helpers = fs_helpers function fs_helpers.on_receive_fields(pos, fields) local meta = minetest.get_meta(pos) for field in pairs(fields) do - if pipeworks.string_startswith(field, "fs_helpers_cycling:") then + if field:match("^fs_helpers_cycling:") then local l = field:split(":") local new_value = tonumber(l[2]) local meta_name = l[3] @@ -325,278 +290,5 @@ function pipeworks.load_position(pos) vm:read_from_map(pos, pos) end -local function delay(...) - local args = {...} - return (function() return unpack(args) end) -end - -local function get_set_wrap(name, is_dynamic) - return (function(self) - return self["_" .. name] - end), (function(self, value) - if is_dynamic then - self["_" .. name] = type(value) == "table" - and table.copy(value) or value - end - end) -end - -local fake_player_metatable = { - is_player = delay(true), - is_fake_player = true, - - -- dummy implementation of the rest of the player API: - add_player_velocity = delay(), -- deprecated - add_velocity = delay(), - get_acceleration = delay(), -- no-op for players - get_animation = delay({x = 0, y = 0}, 0, 0, false), - get_armor_groups = delay({}), - get_attach = delay(), - get_attribute = delay(), -- deprecated - get_bone_position = delay(vector.zero(), vector.zero()), - get_children = delay({}), - get_clouds = delay({ - ambient = { r = 0, b = 0, g = 0, a = 0 }, - color = { r = 0, b = 0, g = 0, a = 0 }, - density = 0, - height = 120, - thickness = 10, - speed = vector.zero(), - }), - get_day_night_ratio = delay(), - get_entity_name = delay(), - get_formspec_prepend = delay(""), - get_fov = delay(0, false, 0), - get_lighting = delay({ - exposure = { - center_weight_power = 1, - exposure_correction = 0, - luminance_max = -3, - luminance_min = -3, - speed_bright_dark = 1000, - speed_dark_bright = 1000, - }, - saturation = 1, - shadows = { - intensity = .6212, - }, - }), - get_local_animation = delay({x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, 30), - get_luaentity = delay(), - get_meta = delay({ - contains = delay(false), - get = delay(), - set_string = delay(), - get_string = delay(""), - set_int = delay(), - get_int = delay(0), - set_float = delay(), - get_float = delay(0), - get_keys = delay({}), - to_table = delay({fields = {}}), - from_table = delay(false), - equals = delay(false), - }), - get_moon = delay({ - scale = 1, - texture = "", - tonemap = "", - visible = false, - }), - get_physics_override = delay({ - acceleration_air = 1, - acceleration_default = 1, - gravity = 1, - jump = 1, - liquid_fluidity = 1, - liquid_fluidity_smooth = 1, - liquid_sink = 1, - new_move = true, - sneak = true, - sneak_glitch = false, - speed = 1, - speed_climb = 1, - speed_crouch = 1, - }), - get_player_velocity = vector.zero, -- deprecated - get_rotation = delay(), -- no-op for players - get_sky = delay({ r = 0, g = 0, b = 0, a = 0 }, "regular", {}, true), - get_sky_color = delay({ - dawn_horizon = { r = 0, g = 0, b = 0, a = 0 }, - dawn_sky = { r = 0, g = 0, b = 0, a = 0 }, - day_horizon = { r = 0, g = 0, b = 0, a = 0 }, - day_sky = { r = 0, g = 0, b = 0, a = 0 }, - fog_moon_tint = { r = 0, g = 0, b = 0, a = 0 }, - fog_sun_tint = { r = 0, g = 0, b = 0, a = 0 }, - fog_tint_type = "default", - indoors = { r = 0, g = 0, b = 0, a = 0 }, - night_horizon = { r = 0, g = 0, b = 0, a = 0 }, - night_sky = { r = 0, g = 0, b = 0, a = 0 }, - }), - get_stars = delay({ - count = 1000, - day_opacity = 0, - scale = 1, - star_color = { r = 0, g = 0, b = 0, a = 0 }, - visible = true, - }), - get_sun = delay({ - scale = 1, - sunrise = "", - sunrise_visible = true, - texture = "", - tonemap = "", - visible = true, - }), - get_texture_mod = delay(), -- no-op for players - get_velocity = vector.zero, - get_yaw = delay(), -- no-op for players - getacceleration = delay(), -- backward compatibility - getvelocity = vector.zero, -- backward compatibility - getyaw = delay(), -- backward compatibility - hud_add = delay(), - hud_change = delay(), - hud_get = delay(), - hud_get_flags = delay({ - basic_debug = false, - breathbar = false, - chat = false, - crosshair = false, - healthbar = false, - hotbar = false, - minimap = false, - minimap_radar = false, - wielditem = false, - }), - hud_get_hotbar_image = delay(""), - hud_get_hotbar_itemcount = delay(1), - hud_get_hotbar_selected_image = delay(""), - hud_remove = delay(), - hud_set_flags = delay(), - hud_set_hotbar_image = delay(), - hud_set_hotbar_itemcount = delay(), - hud_set_hotbar_selected_image = delay(), - override_day_night_ratio = delay(), - punch = delay(), - remove = delay(), - respawn = delay(), - right_click = delay(), - send_mapblock = delay(), - set_acceleration = delay(), - set_animation = delay(), - set_animation_frame_speed = delay(), - set_armor_groups = delay(), - set_attach = delay(), - set_attribute = delay(), -- deprecated - set_bone_position = delay(), - set_clouds = delay(), - set_detach = delay(), - set_formspec_prepend = delay(), - set_fov = delay(), - set_lighting = delay(), - set_local_animation = delay(), - set_look_horizontal = delay(), - set_look_pitch = delay(), - set_look_vertical = delay(), - set_look_yaw = delay(), - set_minimap_modes = delay(), - set_moon = delay(), - set_nametag_attributes = delay(), - set_physics_override = delay(), - set_rotation = delay(), -- no-op for players - set_sky = delay(), - set_sprite = delay(), -- no-op for players - set_stars = delay(), - set_sun = delay(), - set_texture_mod = delay(), -- no-op for players - set_velocity = delay(), -- no-op for players - set_yaw = delay(), -- no-op for players - setacceleration = delay(), -- backward compatibility - setsprite = delay(), -- backward compatibility - settexturemod = delay(), -- backward compatibility - setvelocity = delay(), -- backward compatibility - setyaw = delay(), -- backward compatibility -} - -function pipeworks.create_fake_player(def, is_dynamic) - local wielded_item = ItemStack("") - if def.inventory and def.wield_list then - wielded_item = def.inventory:get_stack(def.wield_list, def.wield_index or 1) - end - local p = { - get_player_name = delay(def.name), - - _formspec = def.formspec or "", - _hp = def.hp or 20, - _breath = 11, - _pos = def.position and table.copy(def.position) or vector.new(), - _properties = def.properties or { eye_height = def.eye_height or 1.47 }, - _inventory = def.inventory, - _wield_index = def.wield_index or 1, - _wielded_item = wielded_item, - - -- Model and view - _eye_offset1 = vector.new(), - _eye_offset3 = vector.new(), - set_eye_offset = function(self, first, third) - self._eye_offset1 = table.copy(first) - self._eye_offset3 = table.copy(third) - end, - get_eye_offset = function(self) - return self._eye_offset1, self._eye_offset3 - end, - get_look_dir = delay(def.look_dir or vector.new()), - get_look_pitch = delay(def.look_pitch or 0), - get_look_yaw = delay(def.look_yaw or 0), - get_look_horizontal = delay(def.look_yaw or 0), - get_look_vertical = delay(-(def.look_pitch or 0)), - - -- Controls - get_player_control = delay({ - jump=false, right=false, left=false, LMB=false, RMB=false, - sneak=def.sneak, aux1=false, down=false, up=false - }), - get_player_control_bits = delay(def.sneak and 64 or 0), - - -- Inventory and ItemStacks - get_inventory = delay(def.inventory), - set_wielded_item = function(self, item) - if self._inventory and def.wield_list then - return self._inventory:set_stack(def.wield_list, - self._wield_index, item) - end - self._wielded_item = ItemStack(item) - end, - get_wielded_item = function(self, item) - if self._inventory and def.wield_list then - return self._inventory:get_stack(def.wield_list, - self._wield_index) - end - return ItemStack(self._wielded_item) - end, - get_wield_list = delay(def.wield_list), - get_nametag_attributes = delay({ - bgcolor = false, - color = { r = 0, g = 0, b = 0, a = 0 }, - text = def.name, - }), - } - -- Getter & setter functions - p.get_inventory_formspec, p.set_inventory_formspec - = get_set_wrap("formspec", is_dynamic) - p.get_breath, p.set_breath = get_set_wrap("breath", is_dynamic) - p.get_hp, p.set_hp = get_set_wrap("hp", is_dynamic) - p.get_pos, p.set_pos = get_set_wrap("pos", is_dynamic) - p.get_wield_index, p.set_wield_index = get_set_wrap("wield_index", true) - p.get_properties, p.set_properties = get_set_wrap("properties", false) - - -- For players, move_to and get_pos do the same - p.move_to = p.get_pos - - -- Backwards compatibility - p.getpos = p.get_pos - p.setpos = p.set_pos - p.moveto = p.move_to - setmetatable(p, { __index = fake_player_metatable }) - return p -end +-- Kept for compatibility with old mods +pipeworks.create_fake_player = fakelib.create_player diff --git a/filter-injector.lua b/filter-injector.lua index 21b3aca..293a066 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -84,9 +84,7 @@ local function punch_filter(data, filtpos, filtnode, msg) local filtmeta = minetest.get_meta(filtpos) local filtinv = filtmeta:get_inventory() local owner = filtmeta:get_string("owner") - local fakePlayer = pipeworks.create_fake_player({ - name = owner - }) + local fakeplayer = fakelib.create_player(owner) local dir = pipeworks.facedir_to_right_dir(filtnode.param2) local frompos = vector.subtract(filtpos, dir) local fromnode = minetest.get_node(frompos) @@ -322,7 +320,7 @@ local function punch_filter(data, filtpos, filtnode, msg) if fromtube.can_remove then doRemove = fromtube.can_remove(frompos, fromnode, stack, dir, frominvname, spos) elseif fromdef.allow_metadata_inventory_take then - doRemove = fromdef.allow_metadata_inventory_take(frompos, frominvname,spos, stack, fakePlayer) + doRemove = fromdef.allow_metadata_inventory_take(frompos, frominvname, spos, stack, fakeplayer) end -- stupid lack of continue statements grumble if doRemove > 0 then @@ -356,13 +354,13 @@ local function punch_filter(data, filtpos, filtnode, msg) item = stack:take_item(count) frominv:set_stack(frominvname, spos, stack) if fromdef.on_metadata_inventory_take then - fromdef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakePlayer) + fromdef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakeplayer) end end local pos = vector.add(frompos, vector.multiply(dir, 1.4)) local start_pos = vector.add(frompos, dir) pipeworks.tube_inject_item(pos, start_pos, dir, item, - fakePlayer:get_player_name(), item_tags) + fakeplayer:get_player_name(), item_tags) return true -- only fire one item, please end end diff --git a/legacy.lua b/legacy.lua deleted file mode 100644 index 743d6f1..0000000 --- a/legacy.lua +++ /dev/null @@ -1,62 +0,0 @@ -local S = minetest.get_translator("pipeworks") - -if not minetest.get_modpath("auto_tree_tap") and - minetest.get_modpath("technic") then - - minetest.register_abm({ - nodenames = { "auto_tree_tap:off", "auto_tree_tap:on" }, - chance = 1, - interval = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local fdir = node.param2 - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("pick", 1) - inv:set_size("ghost_pick", 1) - inv:set_size("main", 100) - minetest.set_node(pos, {name = "pipeworks:nodebreaker_off", param2 = fdir}) - minetest.registered_nodes["pipeworks:nodebreaker_off"].on_punch(pos, node) - inv:set_stack("pick", 1, ItemStack("technic:treetap")) - end - }) - - minetest.register_node(":auto_tree_tap:off", { - description = S("Auto-Tap"), - tiles = {"pipeworks_nodebreaker_top_off.png","pipeworks_nodebreaker_bottom_off.png","pipeworks_nodebreaker_side2_off.png","pipeworks_nodebreaker_side1_off.png", - "pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_off.png"}, - is_ground_content = false, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, not_in_creative_inventory=1, axey=1, handy=1, pickaxey=1}, - _mcl_hardness=0.8, - _sound_def = { - key = "node_sound_stone_defaults", - }, - tube = {connect_sides={back=1}}, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("pick", 1) - inv:set_stack("pick", 1, ItemStack("default:pick_mese")) - end, - after_place_node = function (pos, placer) - pipeworks.scan_for_tube_objects(pos, placer) - local placer_pos = placer:get_pos() - - --correct for the player's height - if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end - - --correct for 6d facedir - if placer_pos then - local dir = { - x = pos.x - placer_pos.x, - y = pos.y - placer_pos.y, - z = pos.z - placer_pos.z - } - local node = minetest.get_node(pos) - node.param2 = minetest.dir_to_facedir(dir, true) - minetest.set_node(pos, node) - end - end, - after_dig_node = pipeworks.scan_for_tube_objects, - }) -end diff --git a/mod.conf b/mod.conf index 479abc8..ea1a06d 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. -depends = basic_materials, xcompat +depends = basic_materials, xcompat, fakelib optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience min_minetest_version = 5.5.0 diff --git a/wielder.lua b/wielder.lua index 44121ba..9050490 100644 --- a/wielder.lua +++ b/wielder.lua @@ -1,247 +1,201 @@ local S = minetest.get_translator("pipeworks") -local assumed_eye_pos = vector.new(0, 1.5, 0) +local has_digilines = minetest.get_modpath("digilines") -local function delay(x) - return (function() return x end) -end - -local function set_wielder_formspec(data, meta) - local size = "10.2,"..(7+data.wield_inv_height) - local list_background = "" +local function set_wielder_formspec(def, meta) + local width, height = def.wield_inv.width, def.wield_inv.height + local offset = 5.22 - width * 0.625 + local size = "10.2,"..(6.5 + height * 1.25 + (has_digilines and 1.25 or 0)) + local list_bg = "" if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then - list_background = "style_type[box;colors=#666]" - for i=0, data.wield_inv_height-1 do - for j=0, data.wield_inv_width-1 do - list_background = list_background .. "box[".. ((10-data.wield_inv_width)*0.5)+(i*1.25) ..",".. 1+(j*1.25) ..";1,1;]" + list_bg = "style_type[box;colors=#666]" + for i=0, height-1 do + for j=0, width-1 do + list_bg = list_bg.."box["..offset+(i*1.25)..","..1.25+(j*1.25)..";1,1;]" end end end - meta:set_string("formspec", - "formspec_version[2]" .. - "size["..size.."]".. - pipeworks.fs_helpers.get_prepends(size).. - "item_image[0.5,0.5;1,1;"..data.name_base.."_off]".. - "label[1.5,1;"..minetest.formspec_escape(data.description).."]".. - list_background .. - "list[context;"..minetest.formspec_escape(data.wield_inv_name)..";"..((10-data.wield_inv_width)*0.5)..",1;"..data.wield_inv_width..","..data.wield_inv_height..";]".. - pipeworks.fs_helpers.get_inv((2+data.wield_inv_height)) .. - "listring[context;"..minetest.formspec_escape(data.wield_inv_name).."]" .. - "listring[current_player;main]" - ) - meta:set_string("infotext", data.description) -end - -local can_tool_dig_node = function(nodename, toolcaps, toolname) - --pipeworks.logger("can_tool_dig_node() STUB nodename="..tostring(nodename).." toolname="..tostring(toolname).." toolcaps: "..dump(toolcaps)) - -- brief documentation of minetest.get_dig_params() as it's not yet documented in lua_api.txt: - -- takes two arguments, a node's block groups and a tool's capabilities, - -- both as they appear in their respective definitions. - -- returns a table with the following fields: - -- diggable: boolean, can this tool dig this node at all - -- time: float, time needed to dig with this tool - -- wear: int, number of wear points to inflict on the item - local nodedef = minetest.registered_nodes[nodename] - -- don't explode due to nil def in event of unknown node! - if (nodedef == nil) then return false end - - local nodegroups = nodedef.groups - local diggable = minetest.get_dig_params(nodegroups, toolcaps).diggable - if not diggable then - -- a pickaxe can't actually dig leaves based on it's groups alone, - -- but a player holding one can - the game seems to fall back to the hand. - -- fall back to checking the hand's properties if the tool isn't the correct one. - local hand_caps = minetest.registered_items[""].tool_capabilities - diggable = minetest.get_dig_params(nodegroups, hand_caps).diggable + local inv_offset = 1.5 + height * 1.25 + local fs = "formspec_version[2]size["..size.."]".. + pipeworks.fs_helpers.get_prepends(size)..list_bg.. + "item_image[0.5,0.3;1,1;"..def.name.."_off]".. + "label[1.75,0.8;"..minetest.formspec_escape(def.description).."]".. + "list[context;"..def.wield_inv.name..";"..offset..",1.25;"..width..","..height..";]" + if has_digilines then + fs = fs.."field[1.5,"..inv_offset..";5,0.8;channel;"..S("Channel")..";${channel}]".. + "button_exit[6.5,"..inv_offset..";2,0.8;save;"..S("Save").."]".. + pipeworks.fs_helpers.get_inv(inv_offset + 1.25).."listring[]" + else + fs = fs..pipeworks.fs_helpers.get_inv(inv_offset).."listring[]" end - return diggable + meta:set_string("formspec", fs) + meta:set_string("infotext", def.description) end -local function wielder_on(data, wielder_pos, wielder_node) - data.fixup_node(wielder_pos, wielder_node) - if wielder_node.name ~= data.name_base.."_off" then return end - wielder_node.name = data.name_base.."_on" - minetest.swap_node(wielder_pos, wielder_node) - minetest.check_for_falling(wielder_pos) - local wielder_meta = minetest.get_meta(wielder_pos) - local inv = wielder_meta:get_inventory() - local wield_inv_name = data.wield_inv_name - local wieldindex - for i, stack in ipairs(inv:get_list(wield_inv_name)) do - if not stack:is_empty() then - wieldindex = i - break +local function wielder_action(def, pos, node, index) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local list = inv:get_list(def.wield_inv.name) + local wield_index + if index then + if list[index] and (def.wield_hand or not list[index]:is_empty()) then + wield_index = index + end + else + for i, stack in ipairs(list) do + if not stack:is_empty() then + wield_index = i + break + end end end - if not wieldindex then - if not data.ghost_inv_name then return end - wield_inv_name = data.ghost_inv_name - inv:set_stack(wield_inv_name, 1, ItemStack(data.ghost_tool)) - wieldindex = 1 + if not wield_index and not def.wield_hand then + return end - local dir = minetest.facedir_to_dir(wielder_node.param2) - -- under/above is currently intentionally left switched - -- even though this causes some problems with deployers and e.g. seeds - -- as there are some issues related to nodebreakers otherwise breaking 2 nodes afar. - -- solidity would have to be checked as well, - -- but would open a whole can of worms related to difference in nodebreaker/deployer behavior - -- and the problems of wielders acting on themselves if below is solid - local under_pos = vector.subtract(wielder_pos, dir) - local above_pos = vector.subtract(under_pos, dir) - local pitch - local yaw - if dir.z < 0 then - yaw = 0 - pitch = 0 - elseif dir.z > 0 then - yaw = math.pi - pitch = 0 - elseif dir.x < 0 then - yaw = 3*math.pi/2 - pitch = 0 - elseif dir.x > 0 then - yaw = math.pi/2 - pitch = 0 - elseif dir.y > 0 then - yaw = 0 - pitch = -math.pi/2 - else - yaw = 0 - pitch = math.pi/2 - end - local virtplayer = pipeworks.create_fake_player({ - name = data.masquerade_as_owner and wielder_meta:get_string("owner") - or ":pipeworks:" .. minetest.pos_to_string(wielder_pos), - formspec = wielder_meta:get_string("formspec"), - look_dir = vector.multiply(dir, -1), - look_pitch = pitch, - look_yaw = yaw, - sneak = data.sneak, - position = vector.subtract(wielder_pos, assumed_eye_pos), + local dir = minetest.facedir_to_dir(node.param2) + local fakeplayer = fakelib.create_player({ + name = meta:get_string("owner"), + direction = vector.multiply(dir, -1), + position = pos, inventory = inv, - wield_index = wieldindex, - wield_list = wield_inv_name + wield_index = wield_index or 1, + wield_list = def.wield_inv.name, }) - - local pointed_thing = { type="node", under=under_pos, above=above_pos } - data.act(virtplayer, pointed_thing) - if data.eject_drops then + -- Under and above positions are intentionally switched. + local pointed = { + type = "node", + under = vector.subtract(pos, dir), + above = vector.subtract(pos, vector.multiply(dir, 2)), + } + def.action(fakeplayer, pointed) + if def.eject_drops then for i, stack in ipairs(inv:get_list("main")) do if not stack:is_empty() then - pipeworks.tube_inject_item(wielder_pos, wielder_pos, dir, stack) + pipeworks.tube_inject_item(pos, pos, dir, stack) inv:set_stack("main", i, ItemStack("")) end end end end -local function wielder_off(data, pos, node) - if node.name == data.name_base.."_on" then - node.name = data.name_base.."_off" +local function wielder_on(def, pos, node) + if node.name ~= def.name.."_off" then + return + end + node.name = def.name.."_on" + minetest.swap_node(pos, node) + wielder_action(def, pos, node) +end + +local function wielder_off(def, pos, node) + if node.name == def.name.."_on" then + node.name = def.name.."_off" minetest.swap_node(pos, node) - minetest.check_for_falling(pos) end end -local function register_wielder(data) - data.fixup_node = data.fixup_node or function (pos, node) end - data.fixup_oldmetadata = data.fixup_oldmetadata or function (m) return m end - for _, state in ipairs({ "off", "on" }) do - local groups = { snappy=2, choppy=2, oddly_breakable_by_hand=2, mesecon=2, tubedevice=1, tubedevice_receiver=1, axey=1, handy=1, pickaxey=1 } - if state == "on" then groups.not_in_creative_inventory = 1 end - local tile_images = {} - for _, face in ipairs({ "top", "bottom", "side2", "side1", "back", "front" }) do - table.insert(tile_images, data.texture_base.."_"..face..(data.texture_stateful[face] and "_"..state or "")..".png") +local function wielder_digiline_action(def, pos, channel, msg) + local meta = minetest.get_meta(pos) + local set_channel = meta:get_string("channel") + if channel ~= set_channel then + return + end + if type(msg) ~= "table" then + if type(msg) == "string" then + if msg:sub(1, 8) == "activate" then + msg = {command = "activate", slot = tonumber(msg:sub(9))} + end + else + return end - minetest.register_node(data.name_base.."_"..state, { - description = data.description, - tiles = tile_images, + end + if msg.command == "activate" then + local node = minetest.get_node(pos) + local index = type(msg.slot) == "number" and msg.slot or nil + wielder_action(def, pos, node, index) + end +end + +function pipeworks.register_wielder(def) + for _,state in ipairs({"off", "on"}) do + local groups = { + snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, + mesecon = 2, tubedevice = 1, tubedevice_receiver = 1, + axey = 1, handy = 1, pickaxey = 1, + not_in_creative_inventory = state == "on" and 1 or nil + } + minetest.register_node(def.name.."_"..state, { + description = def.description, + tiles = def.tiles[state], + paramtype2 = "facedir", + groups = groups, + is_ground_content = false, + _mcl_hardness = 0.6, + _sound_def = { + key = "node_sound_stone_defaults", + }, + drop = def.name.."_off", mesecons = { effector = { rules = pipeworks.rules_all, - action_on = function (pos, node) - wielder_on(data, pos, node) + action_on = function(pos, node) + wielder_on(def, pos, node) end, - action_off = function (pos, node) - wielder_off(data, pos, node) + action_off = function(pos, node) + wielder_off(def, pos, node) + end, + }, + }, + digilines = { + receptor = {}, + effector = { + action = function(pos, _, channel, msg) + wielder_digiline_action(def, pos, channel, msg) end, }, }, tube = { - can_insert = function(pos, node, stack, tubedir) - if not data.tube_permit_anteroposterior_insert then - local nodedir = minetest.facedir_to_dir(node.param2) - if vector.equals(tubedir, nodedir) or vector.equals(tubedir, vector.multiply(nodedir, -1)) then + can_insert = function(pos, node, stack, direction) + if def.eject_drops then + -- Prevent ejected items from being inserted + local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) + if vector.equals(direction, dir) then return false end end - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:room_for_item(data.wield_inv_name, stack) + local inv = minetest.get_meta(pos):get_inventory() + return inv:room_for_item(def.wield_inv.name, stack) end, - insert_object = function(pos, node, stack, tubedir) - if not data.tube_permit_anteroposterior_insert then - local nodedir = minetest.facedir_to_dir(node.param2) - if vector.equals(tubedir, nodedir) or vector.equals(tubedir, vector.multiply(nodedir, -1)) then - return stack - end - end - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:add_item(data.wield_inv_name, stack) + insert_object = function(pos, node, stack) + local inv = minetest.get_meta(pos):get_inventory() + return inv:add_item(def.wield_inv.name, stack) end, - input_inventory = data.wield_inv_name, - connect_sides = data.tube_connect_sides, - can_remove = function(pos, node, stack, tubedir) + input_inventory = "main", + connect_sides = def.connect_sides, + can_remove = function(pos, node, stack) return stack:get_count() end, }, - is_ground_content = false, - paramtype2 = "facedir", - tubelike = 1, - groups = groups, - _mcl_hardness=0.6, - _sound_def = { - key = "node_sound_stone_defaults", - }, - drop = data.name_base.."_off", on_construct = function(pos) local meta = minetest.get_meta(pos) - set_wielder_formspec(data, meta) local inv = meta:get_inventory() - inv:set_size(data.wield_inv_name, data.wield_inv_width*data.wield_inv_height) - if data.ghost_inv_name then - inv:set_size(data.ghost_inv_name, 1) - end - if data.eject_drops then - inv:set_size("main", 100) + inv:set_size(def.wield_inv.name, def.wield_inv.width * def.wield_inv.height) + if def.eject_drops then + inv:set_size("main", 32) end + set_wielder_formspec(def, meta) end, - after_place_node = function (pos, placer) + after_place_node = function(pos, placer) pipeworks.scan_for_tube_objects(pos) - local placer_pos = placer:get_pos() - if placer_pos and placer:is_player() then placer_pos = vector.add(placer_pos, assumed_eye_pos) end - if placer_pos then - local dir = vector.subtract(pos, placer_pos) - local node = minetest.get_node(pos) - node.param2 = minetest.dir_to_facedir(dir, true) - minetest.set_node(pos, node) + if not placer then + return end + local node = minetest.get_node(pos) + node.param2 = minetest.dir_to_facedir(placer:get_look_dir(), true) + minetest.set_node(pos, node) minetest.get_meta(pos):set_string("owner", placer:get_player_name()) end, - can_dig = (data.can_dig_nonempty_wield_inv and delay(true) or function(pos, player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:is_empty(data.wield_inv_name) - end), after_dig_node = function(pos, oldnode, oldmetadata, digger) - -- The legacy-node fixup is done here in a - -- different form from the standard fixup, - -- rather than relying on a standard fixup - -- in an on_dig callback, because some - -- non-standard diggers (such as technic's - -- mining drill) don't respect on_dig. - oldmetadata = data.fixup_oldmetadata(oldmetadata) - for _, stack in ipairs(oldmetadata.inventory[data.wield_inv_name] or {}) do + for _,stack in ipairs(oldmetadata.inventory.main or {}) do if not stack:is_empty() then minetest.add_item(pos, stack) end @@ -249,7 +203,6 @@ local function register_wielder(data) pipeworks.scan_for_tube_objects(pos) end, on_rotate = pipeworks.on_rotate, - on_punch = data.fixup_node, allow_metadata_inventory_put = function(pos, listname, index, stack, player) if not pipeworks.may_configure(pos, player) then return 0 end return stack:get_count() @@ -261,212 +214,141 @@ local function register_wielder(data) allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) if not pipeworks.may_configure(pos, player) then return 0 end return count - end + end, + on_receive_fields = function(pos, _, fields, sender) + if not fields.channel or not pipeworks.may_configure(pos, sender) then + return + end + minetest.get_meta(pos):set_string("channel", fields.channel) + end, }) end + table.insert(pipeworks.ui_cat_tube_list, def.name.."_off") +end + +local function get_tiles(name, stateful) + local tiles = {on = {}, off = {}} + for _,state in ipairs({"off", "on"}) do + for _,side in ipairs({"top", "bottom", "side2", "side1", "back", "front"}) do + local suffix = stateful[side] and "_"..state or "" + table.insert(tiles[state], "pipeworks_"..name.."_"..side..suffix..".png") + end + end + return tiles end if pipeworks.enable_node_breaker then - local data - -- see after end of data table for other use of these variables - local name_base = "pipeworks:nodebreaker" - local wield_inv_name = "pick" - data = { - name_base = name_base, + pipeworks.register_wielder({ + name = "pipeworks:nodebreaker", description = S("Node Breaker"), - texture_base = "pipeworks_nodebreaker", - texture_stateful = { top = true, bottom = true, side2 = true, side1 = true, front = true }, - tube_connect_sides = { top=1, bottom=1, left=1, right=1, back=1 }, - tube_permit_anteroposterior_insert = false, - wield_inv_name = wield_inv_name, - wield_inv_width = 1, - wield_inv_height = 1, - can_dig_nonempty_wield_inv = true, - ghost_inv_name = "ghost_pick", - ghost_tool = ":", -- hand by default - fixup_node = function (pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - -- Node breakers predating the visible pick slot - -- may have been partially updated. This code - -- fully updates them. Some have been observed - -- to have no pick slot at all; first add one. - if inv:get_size("pick") ~= 1 then - inv:set_size("pick", 1) - end - -- Originally, they had a ghost pick in a "pick" - -- inventory, no other inventory, and no form. - -- The partial update of early with-form node - -- breaker code gives them "ghost_pick" and "main" - -- inventories, but leaves the old ghost pick in - -- the "pick" inventory, and doesn't add a form. - -- First perform that partial update. - if inv:get_size("ghost_pick") ~= 1 then - inv:set_size("ghost_pick", 1) - inv:set_size("main", 100) - end - -- If the node breaker predates the visible pick - -- slot, which we can detect by it not having a - -- form, then the pick slot needs to be cleared - -- of the old ghost pick. - if (meta:get_string("formspec") or "") == "" then - inv:set_stack("pick", 1, ItemStack("")) - end - -- Finally, unconditionally set the formspec - -- and infotext. This not only makes the - -- pick slot visible for node breakers where - -- it wasn't before; it also updates the form - -- for node breakers that had an older version - -- of the form, and sets infotext where it was - -- missing for early with-form node breakers. - set_wielder_formspec(data, meta) - end, - fixup_oldmetadata = function (oldmetadata) - -- Node breakers predating the visible pick slot, - -- with node form, kept their ghost pick in an - -- inventory named "pick", the same name as the - -- later visible pick slot. The pick must be - -- removed to avoid spilling it. - if not oldmetadata.fields.formspec then - return { inventory = { pick = {} }, fields = oldmetadata.fields } + tiles = get_tiles("nodebreaker", {top = 1, bottom = 1, side2 = 1, side1 = 1, front = 1}), + connect_sides = {top = 1, bottom = 1, left = 1, right = 1, back = 1}, + wield_inv = {name = "pick", width = 1, height = 1}, + wield_hand = true, + eject_drops = true, + action = function(fakeplayer, pointed) + local stack = fakeplayer:get_wielded_item() + local old_stack = ItemStack(stack) + local item_def = minetest.registered_items[stack:get_name()] + if item_def.on_use then + fakeplayer:set_wielded_item(item_def.on_use(stack, fakeplayer, pointed) or stack) else - return oldmetadata - end - end, - masquerade_as_owner = true, - sneak = false, - act = function(virtplayer, pointed_thing) - if minetest.is_protected(vector.add(virtplayer:get_pos(), assumed_eye_pos), virtplayer:get_player_name()) then - return - end - - --local dname = "nodebreaker.act() " - local wieldstack = virtplayer:get_wielded_item() - local oldwieldstack = ItemStack(wieldstack) - local on_use = (minetest.registered_items[wieldstack:get_name()] or {}).on_use - if on_use then - --pipeworks.logger(dname.."invoking on_use "..tostring(on_use)) - wieldstack = on_use(wieldstack, virtplayer, pointed_thing) or wieldstack - virtplayer:set_wielded_item(wieldstack) - else - local under_node = minetest.get_node(pointed_thing.under) - local def = minetest.registered_nodes[under_node.name] - if not def then - -- do not dig an unknown node + local node = minetest.get_node(pointed.under) + local node_def = minetest.registered_nodes[node.name] + if not node_def or not node_def.on_dig then return end - -- check that the current tool is capable of destroying the - -- target node. - -- if we can't, don't dig, and leave the wield stack unchanged. - -- note that wieldstack:get_tool_capabilities() returns hand - -- properties if the item has none of it's own. - if can_tool_dig_node(under_node.name, - wieldstack:get_tool_capabilities(), - wieldstack:get_name()) then - def.on_dig(pointed_thing.under, under_node, virtplayer) - local sound = def.sounds and def.sounds.dug - if sound then - minetest.sound_play(sound.name, - {pos=pointed_thing.under, gain=sound.gain}) + -- Check if the tool can dig the node + local tool = stack:get_tool_capabilities() + if not minetest.get_dig_params(node_def.groups, tool).diggable then + -- Try using hand if tool can't dig the node + local hand = ItemStack():get_tool_capabilities() + if not minetest.get_dig_params(node_def.groups, hand).diggable then + return end - wieldstack = virtplayer:get_wielded_item() - --~ else - --pipeworks.logger(dname.."couldn't dig node!") end + -- This must only check for false, because `on_dig` returning nil is the same as returning true. + if node_def.on_dig(pointed.under, node, fakeplayer) == false then + return + end + local sound = node_def.sounds and node_def.sounds.dug + if sound then + minetest.sound_play(sound, {pos = pointed.under}, true) + end + stack = fakeplayer:get_wielded_item() end - local wieldname = wieldstack:get_name() - if wieldname == oldwieldstack:get_name() then - -- don't mechanically wear out tool - if wieldstack:get_count() == oldwieldstack:get_count() and - wieldstack:get_metadata() == oldwieldstack:get_metadata() and - ((minetest.registered_items[wieldstack:get_name()] or {}).wear_represents or "mechanical_wear") == "mechanical_wear" then - virtplayer:set_wielded_item(oldwieldstack) + if stack:get_name() == old_stack:get_name() then + -- Don't mechanically wear out tool + if stack:get_wear() ~= old_stack:get_wear() and stack:get_count() == old_stack:get_count() + and (item_def.wear_represents == nil or item_def.wear_represents == "mechanical_wear") then + print("replaced") + fakeplayer:set_wielded_item(old_stack) end - elseif wieldname ~= "" then - -- tool got replaced by something else: - -- treat it as a drop - virtplayer:get_inventory():add_item("main", wieldstack) - virtplayer:set_wielded_item(ItemStack("")) + elseif not stack:is_empty() then + -- Tool got replaced by something else, treat it as a drop. + fakeplayer:get_inventory():add_item("main", stack) + fakeplayer:set_wielded_item("") end end, - eject_drops = true, - } - register_wielder(data) - pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:nodebreaker_off" - -- aliases for when someone had technic installed, but then uninstalled it but not pipeworks + }) minetest.register_alias("technic:nodebreaker_off", "pipeworks:nodebreaker_off") minetest.register_alias("technic:nodebreaker_on", "pipeworks:nodebreaker_on") minetest.register_alias("technic:node_breaker_off", "pipeworks:nodebreaker_off") minetest.register_alias("technic:node_breaker_on", "pipeworks:nodebreaker_on") - -- turn legacy auto-tree-taps into node breakers - dofile(pipeworks.modpath.."/legacy.lua") - - -- register LBM for transition to cheaper node breakers - local lbm_id = "pipeworks:refund_node_breaker_pick" - minetest.register_lbm({ - name = lbm_id, - label = "Give back mese pick for pre-transition node breakers", - run_at_every_load = false, - nodenames = { name_base.."_on", name_base.."_off" }, - action = function(pos, node) - pipeworks.logger(lbm_id.." entry, nodename="..node.name) - local invref = minetest.get_meta(pos):get_inventory() - invref:add_item(wield_inv_name, ItemStack("default:pick_mese")) - end - }) + minetest.register_alias("auto_tree_tap:off", "pipeworks:nodebreaker_off") + minetest.register_alias("auto_tree_tap:on", "pipeworks:nodebreaker_on") end if pipeworks.enable_deployer then - register_wielder({ - name_base = "pipeworks:deployer", + pipeworks.register_wielder({ + name = "pipeworks:deployer", description = S("Deployer"), - texture_base = "pipeworks_deployer", - texture_stateful = { front = true }, - tube_connect_sides = { back=1 }, - tube_permit_anteroposterior_insert = true, - wield_inv_name = "main", - wield_inv_width = 3, - wield_inv_height = 3, - can_dig_nonempty_wield_inv = false, - masquerade_as_owner = true, - sneak = false, - act = function(virtplayer, pointed_thing) - if minetest.is_protected(vector.add(virtplayer:get_pos(), assumed_eye_pos), virtplayer:get_player_name()) then - return + tiles = get_tiles("deployer", {front = 1}), + connect_sides = {back = 1}, + wield_inv = {name = "main", width = 3, height = 3}, + action = function(fakeplayer, pointed) + local stack = fakeplayer:get_wielded_item() + local def = minetest.registered_items[stack:get_name()] + if def and def.on_place then + local new_stack, placed_pos = def.on_place(stack, fakeplayer, pointed) + fakeplayer:set_wielded_item(new_stack or stack) + -- minetest.item_place_node doesn't play sound to the placer + local sound = placed_pos and def.sounds and def.sounds.place + local name = fakeplayer:get_player_name() + if sound and name ~= "" then + minetest.sound_play(sound, {pos = placed_pos, to_player = name}, true) + end end - - local wieldstack = virtplayer:get_wielded_item() - virtplayer:set_wielded_item((minetest.registered_items[wieldstack:get_name()] or {on_place=minetest.item_place}).on_place(wieldstack, virtplayer, pointed_thing) or wieldstack) end, - eject_drops = false, }) - pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:deployer_off" - -- aliases for when someone had technic installed, but then uninstalled it but not pipeworks minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off") minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on") end if pipeworks.enable_dispenser then - register_wielder({ - name_base = "pipeworks:dispenser", + -- Override minetest.item_drop to negate its hardcoded offset + -- when the dropper is a fake player. + local item_drop = minetest.item_drop + -- luacheck: ignore 122 + function minetest.item_drop(stack, dropper, pos) + if dropper and dropper.is_fake_player then + pos = vector.new(pos.x, pos.y - 1.2, pos.z) + end + return item_drop(stack, dropper, pos) + end + pipeworks.register_wielder({ + name = "pipeworks:dispenser", description = S("Dispenser"), - texture_base = "pipeworks_dispenser", - texture_stateful = { front = true }, - tube_connect_sides = { back=1 }, - tube_permit_anteroposterior_insert = true, - wield_inv_name = "main", - wield_inv_width = 3, - wield_inv_height = 3, - can_dig_nonempty_wield_inv = false, - masquerade_as_owner = false, - sneak = true, - act = function(virtplayer, pointed_thing) - local wieldstack = virtplayer:get_wielded_item() - virtplayer:set_wielded_item((minetest.registered_items[wieldstack:get_name()] or - {on_drop=minetest.item_drop}).on_drop(wieldstack, virtplayer, virtplayer:get_pos()) or - wieldstack) + tiles = get_tiles("dispenser", {front = 1}), + connect_sides = {back = 1}, + wield_inv = {name = "main", width = 3, height = 3}, + action = function(fakeplayer) + local stack = fakeplayer:get_wielded_item() + local def = minetest.registered_items[stack:get_name()] + if def and def.on_drop then + local pos = fakeplayer:get_pos() + fakeplayer:set_wielded_item(def.on_drop(stack, fakeplayer, pos) or stack) + end end, - eject_drops = false, }) - pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:dispenser_off" end From 71fe60014f17d694b4767e41d87b8ae6b050bbb3 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Mon, 27 May 2024 23:19:46 +1000 Subject: [PATCH 22/30] fix hard-coded inventory name in wielders --- wielder.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wielder.lua b/wielder.lua index 9050490..ef26a97 100644 --- a/wielder.lua +++ b/wielder.lua @@ -169,7 +169,7 @@ function pipeworks.register_wielder(def) local inv = minetest.get_meta(pos):get_inventory() return inv:add_item(def.wield_inv.name, stack) end, - input_inventory = "main", + input_inventory = def.wield_inv.name, connect_sides = def.connect_sides, can_remove = function(pos, node, stack) return stack:get_count() @@ -195,7 +195,7 @@ function pipeworks.register_wielder(def) minetest.get_meta(pos):set_string("owner", placer:get_player_name()) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - for _,stack in ipairs(oldmetadata.inventory.main or {}) do + for _,stack in ipairs(oldmetadata.inventory[def.wield_inv.name] or {}) do if not stack:is_empty() then minetest.add_item(pos, stack) end From 5919f432aee78178d61551881e1644b48b561202 Mon Sep 17 00:00:00 2001 From: 1F616EMO~nya Date: Wed, 3 Jul 2024 13:34:18 +0800 Subject: [PATCH 23/30] Remove extra `print()` calls and copy Luacontroller's print behavior (#127) --- autoplace_pipes.lua | 2 +- settingtypes.txt | 4 ++++ tubes/lua.lua | 14 ++++++++------ wielder.lua | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/autoplace_pipes.lua b/autoplace_pipes.lua index ec4b27e..fc3d7d0 100644 --- a/autoplace_pipes.lua +++ b/autoplace_pipes.lua @@ -211,7 +211,7 @@ function pipeworks.scan_pipe_surroundings(pos) pzm = 1 end - print("stage 2 returns "..pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp.. + minetest.log("info", "stage 2 returns "..pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp.. " for nodes surrounding "..minetest.get_node(pos).name.." at "..minetest.pos_to_string(pos)) return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp end diff --git a/settingtypes.txt b/settingtypes.txt index 6d8e3ad..8508892 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -87,3 +87,7 @@ pipeworks_entity_update_interval (Entity Update Interval) float 0 0 0.8 # if set to true, items passing through teleport tubes will log log where they came from and where they went. pipeworks_log_teleport_tubes (Log Teleport Tubes) bool false + +# Behavior of print() inside a lua tube. By default, this emits a message into actionstream. +# Set it to noop if you wish to disable that behavior. +pipeworks_lua_tube_print_behavior (Behavior of print in Lua Tube) enum log log,noop diff --git a/tubes/lua.lua b/tubes/lua.lua index 7a76fe9..ec09829 100644 --- a/tubes/lua.lua +++ b/tubes/lua.lua @@ -229,11 +229,13 @@ end ------------------------- local function safe_print(param) - local string_meta = getmetatable("") - local sandbox = string_meta.__index - string_meta.__index = string -- Leave string sandbox temporarily - print(dump(param)) - string_meta.__index = sandbox -- Restore string sandbox + if (minetest.settings:get("pipeworks_lua_tube_print_behavior") or "log") == "log" then + local string_meta = getmetatable("") + local sandbox = string_meta.__index + string_meta.__index = string -- Leave string sandbox temporarily + minetest.log("action", string.format("[pipeworks.tubes.lua] print(%s)", dump(param))) + string_meta.__index = sandbox -- Restore string sandbox + end end local function safe_date() @@ -603,7 +605,7 @@ local function save_memory(pos, meta, mem) meta:set_string("lc_memory", memstring) meta:mark_as_private("lc_memory") else - print("Error: lua_tube memory overflow. "..memsize_max.." bytes available, " + minetest.log("info", "lua_tube memory overflow. "..memsize_max.." bytes available, " ..#memstring.." required. Controller overheats.") burn_controller(pos) end diff --git a/wielder.lua b/wielder.lua index ef26a97..00dc6b7 100644 --- a/wielder.lua +++ b/wielder.lua @@ -281,7 +281,6 @@ if pipeworks.enable_node_breaker then -- Don't mechanically wear out tool if stack:get_wear() ~= old_stack:get_wear() and stack:get_count() == old_stack:get_count() and (item_def.wear_represents == nil or item_def.wear_represents == "mechanical_wear") then - print("replaced") fakeplayer:set_wielded_item(old_stack) end elseif not stack:is_empty() then From 720f6003ba4e23981044fa986d6e8ec73e0686b0 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Fri, 5 Jul 2024 11:17:19 +1000 Subject: [PATCH 24/30] Add vacuum tube visualizations using `vizlib` (#128) --- .luacheckrc | 2 +- mod.conf | 2 +- tubes/vacuum.lua | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 6d2f92f..ef7e76b 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -21,6 +21,6 @@ read_globals = { "default", "mesecon", "digiline", "screwdriver", "unified_inventory", "i3", "mcl_experience", "awards", - "xcompat", "fakelib", + "xcompat", "fakelib", "vizlib", } diff --git a/mod.conf b/mod.conf index ea1a06d..3f8158a 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. depends = basic_materials, xcompat, fakelib -optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience +optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience, vizlib min_minetest_version = 5.5.0 diff --git a/tubes/vacuum.lua b/tubes/vacuum.lua index 8298cc5..d78d837 100644 --- a/tubes/vacuum.lua +++ b/tubes/vacuum.lua @@ -1,6 +1,8 @@ local S = minetest.get_translator("pipeworks") +local has_vislib = minetest.get_modpath("vizlib") + local enable_max = minetest.settings:get_bool("pipeworks_enable_items_per_tube_limit", true) local max_items = tonumber(minetest.settings:get("pipeworks_max_items_per_tube")) or 30 max_items = math.ceil(max_items / 2) -- Limit vacuuming to half the max limit @@ -38,6 +40,15 @@ local function repair_tube(pos, was_node) set_timer(pos) end +local function show_area(pos, node, player) + if not player or player:get_wielded_item():get_name() ~= "" then + -- Only show area when using an empty hand + return + end + local radius = tonumber(minetest.get_meta(pos):get("dist")) or 2 + vizlib.draw_cube(pos, radius + 0.5, {player = player}) +end + if pipeworks.enable_sand_tube then pipeworks.register_tube("pipeworks:sand_tube", { description = S("Vacuuming Pneumatic Tube Segment"), @@ -56,6 +67,7 @@ if pipeworks.enable_sand_tube then vacuum(pos, 2) set_timer(pos) end, + on_punch = has_vislib and show_area or nil, }, }) end @@ -101,6 +113,7 @@ if pipeworks.enable_mese_sand_tube then meta:set_int("dist", dist) meta:set_string("infotext", S("Adjustable Vacuuming Tube (@1m)", dist)) end, + on_punch = has_vislib and show_area or nil, }, }) end From e9a9bd711ecef35b36d319e3ff9c9f81e17084a6 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sun, 7 Jul 2024 11:09:37 +1000 Subject: [PATCH 25/30] fix typo in `pipeworks.override_chest` fixes #129 --- chests.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chests.lua b/chests.lua index ed7b061..74b658e 100644 --- a/chests.lua +++ b/chests.lua @@ -36,7 +36,7 @@ function pipeworks.override_chest(chestname, override, connect_sides) pipeworks.after_place(pos) end - local old_after_dig = override.after_dig or old_def.after_dig or function() end + local old_after_dig = override.after_dig or old_def.after_dig_node or function() end override.after_dig_node = function(pos, oldnode, oldmetadata, digger) old_after_dig(pos, oldnode, oldmetadata, digger) pipeworks.after_dig(pos, oldnode, oldmetadata, digger) @@ -87,4 +87,4 @@ function pipeworks.override_chest(chestname, override, connect_sides) minetest.override_item(chestname, override) pipeworks.chests[chestname] = true -end \ No newline at end of file +end From 171faec7e9f98151259f3f5d6b9d1cb8e26c1846 Mon Sep 17 00:00:00 2001 From: 1F616EMO~nya Date: Sun, 25 Aug 2024 00:05:27 +0800 Subject: [PATCH 26/30] Optimize move_entities_globalstep_part1 (#134) --- luaentity.lua | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/luaentity.lua b/luaentity.lua index ef6d552..cc7d170 100644 --- a/luaentity.lua +++ b/luaentity.lua @@ -67,36 +67,41 @@ end minetest.register_on_shutdown(write_entities) luaentity.entities_index = 0 -local function get_blockpos(pos) - return {x = math.floor(pos.x / 16), - y = math.floor(pos.y / 16), - z = math.floor(pos.z / 16)} -end - local move_entities_globalstep_part1 local is_active if pipeworks.use_real_entities then local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones) + local function get_blockpos(pos) + return {x = math.floor(pos.x / 16), + y = math.floor(pos.y / 16), + z = math.floor(pos.z / 16)} + end + move_entities_globalstep_part1 = function(dtime) local active_block_range = tonumber(minetest.settings:get("active_block_range")) or 2 - local new_active_blocks = {} + for key in pairs(active_blocks) do + active_blocks[key] = nil + end for _, player in ipairs(minetest.get_connected_players()) do local blockpos = get_blockpos(player:get_pos()) - local minp = vector.subtract(blockpos, active_block_range) - local maxp = vector.add(blockpos, active_block_range) + local minpx = blockpos.x - active_block_range + local minpy = blockpos.y - active_block_range + local minpz = blockpos.z - active_block_range + local maxpx = blockpos.x + active_block_range + local maxpy = blockpos.y + active_block_range + local maxpz = blockpos.z + active_block_range - for x = minp.x, maxp.x do - for y = minp.y, maxp.y do - for z = minp.z, maxp.z do - local pos = {x = x, y = y, z = z} - new_active_blocks[minetest.hash_node_position(pos)] = pos - end - end + for x = minpx, maxpx do + for y = minpy, maxpy do + for z = minpz, maxpz do + local pos = {x = x, y = y, z = z} + active_blocks[minetest.hash_node_position(pos)] = true + end + end end end - active_blocks = new_active_blocks -- todo: callbacks on block load/unload end From 63bc754889d270dea5ced6f4d57425db51f38358 Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:35:45 +0200 Subject: [PATCH 27/30] luacheck with builtin minetest (#109) * [PoC] luacheck with builtin minetest * switch to `minetest+max` std for luacheck * use branch in action * use SX's docker image * disable tty * Update .github/workflows/luacheck.yml Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> * go back to upstream luacheck * fix globals listing --------- Co-authored-by: BuckarooBanzay Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> --- .github/workflows/luacheck.yml | 2 +- .luacheckrc | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index b501650..3c99a99 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -7,4 +7,4 @@ jobs: - name: Checkout uses: actions/checkout@master - name: Luacheck - uses: lunarmodules/luacheck@master \ No newline at end of file + uses: lunarmodules/luacheck@master diff --git a/.luacheckrc b/.luacheckrc index ef7e76b..79d6ae7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,6 +1,7 @@ unused_args = false max_line_length= 240 redefined = false +std = "minetest+max" globals = { "pipeworks", @@ -8,19 +9,9 @@ globals = { } read_globals = { - -- Stdlib - string = {fields = {"split"}}, - table = {fields = {"copy", "getn"}}, - - -- Minetest - "vector", "ItemStack", - "dump", "minetest", - "VoxelManip", "VoxelArea", - -- mods "default", "mesecon", "digiline", "screwdriver", "unified_inventory", "i3", "mcl_experience", "awards", - "xcompat", "fakelib", "vizlib", - + "xcompat", "fakelib", "vizlib" } From a2ffaa9dc363e5b8f5cb21089358d50351013f98 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Thu, 5 Sep 2024 12:56:33 +1000 Subject: [PATCH 28/30] fix nodebreaker not ejecting replacement items fixes #137 --- wielder.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wielder.lua b/wielder.lua index 00dc6b7..0850e5a 100644 --- a/wielder.lua +++ b/wielder.lua @@ -251,7 +251,8 @@ if pipeworks.enable_node_breaker then local old_stack = ItemStack(stack) local item_def = minetest.registered_items[stack:get_name()] if item_def.on_use then - fakeplayer:set_wielded_item(item_def.on_use(stack, fakeplayer, pointed) or stack) + stack = item_def.on_use(stack, fakeplayer, pointed) or stack + fakeplayer:set_wielded_item(stack) else local node = minetest.get_node(pointed.under) local node_def = minetest.registered_nodes[node.name] From 3189da7c9b1c9198382084e3bec35d7d918d6f24 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 6 Sep 2024 09:21:42 +0500 Subject: [PATCH 29/30] add Russian locale (#136) --- locale/pipeworks.ru.tr | 121 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 locale/pipeworks.ru.tr diff --git a/locale/pipeworks.ru.tr b/locale/pipeworks.ru.tr new file mode 100644 index 0000000..942ee90 --- /dev/null +++ b/locale/pipeworks.ru.tr @@ -0,0 +1,121 @@ +# textdomain: pipeworks + +# License: CC-by-SA 4.0 +# Author: VinAdmin ovvitalik@gmail.com + +## generic interaction +Set=Установить +Cancel=Отмена + +## digilines interfacing +Channel=Канал + +## init +Allow splitting incoming stacks from tubes=Разрешить разделение входящих стопок из трубок + +## autocrafter +Unknown item=Неизвестный предмет +unconfigured Autocrafter: unknown recipe=ненастроенный автокрафтер: неизвестный рецепт +unconfigured Autocrafter=ненастроенный автокрафтер +'@1' Autocrafter (@2)='@1' Автокрафтер (@2) +Save=Сохранить +paused '@1' Autocrafter=приостановлено '@1' Автокрафтер +Autocrafter=Автокрафтер + +## compat-furnaces +Allow splitting incoming material (not fuel) stacks from tubes=Разрешить разделение стопок поступающего материала (не топлива) из трубок. + +## decorative tubes +Airtight steelblock embedded tube=Герметичная встроенная трубка из стального блока +Airtight panel embedded tube=Герметичная встроенная в панель трубка + +## devices +Pump/Intake Module=Модуль насоса/впуска +Valve=Клапан +Decorative grating=Декоративная решетка +Spigot outlet=Выходной патрубок +Airtight Pipe entry/exit=Вход/выход герметичной трубы +Flow Sensor=Датчик потока +Flow sensor (on)=Датчик расхода (вкл.) +empty=пустой +@1% full=@1% заполнено +Expansion Tank (@1)=Расширительный бак (@1) +Fluid Storage Tank (@1)=Резервуар для хранения жидкости (@1) +Fountainhead=Источник +Straight-only Pipe=Только прямая труба + +## filter-injector +(slot #@1 next)=(слот #@1 следующий) +@1 Filter-Injector=@1 фильтр-инжектор +Sequence slots by Priority=Последовательность слотов по приоритету +Sequence slots Randomly=Слоты последовательности Случайный +Sequence slots by Rotation=Последовательность слотов по вращению +Exact match - off=Точное совпадение – выключено +Exact match - on=Точное совпадение - включено +Prefer item types:=Предпочитаете типы предметов: +Itemwise=По пунктам +Stackwise=Стекообразно +Digiline=Диджилайн + +## legacy +Auto-Tap=Авто-нажатие + +## pipes +Pipe Segment=Сегмент трубы +Pipe Segment (legacy)=Сегмент трубы (устаревший) + + +## routing tubes +Pneumatic tube segment=Сегмент пневматической трубки +Broken Tube=Сломанная трубка +High Priority Tube Segment=Сегмент трубы с высоким приоритетом +Accelerating Pneumatic Tube Segment=Ускорительный сегмент пневматической трубки +Crossing Pneumatic Tube Segment=Пересечение сегмента пневматической трубы +One way tube=Односторонняя трубка + +## signal tubes +Detecting Pneumatic Tube Segment on=Обнаружение сегмента пневматической трубки включено +Detecting Pneumatic Tube Segment=Обнаружение сегмента пневматической трубки +Digiline Detecting Pneumatic Tube Segment=Digiline обнаруживает сегмент пневматической трубки +Digiline Detecting Tube=Детекторная трубка Digiline +Conducting Pneumatic Tube Segment=Проводящий сегмент пневматической трубки +Conducting Pneumatic Tube Segment on=Проводящий сегмент пневматической трубки на +Digiline Conducting Pneumatic Tube Segment=Сегмент проводящей пневматической трубки Digiline +Mesecon and Digiline Conducting Pneumatic Tube Segment=Сегмент токопроводящей пневматической трубки Mesecon и Digiline +Mesecon and Digiline Conducting Pneumatic Tube Segment on=Сегмент проводящей пневматической трубки Mesecon и Digiline на +Tag Sorting Pneumatic Tube Segment=Сегмент пневматической трубки для сортировки тегов +Lua controlled Tube=Трубка, управляемая Lua + +## sorting tubes +Sorting Pneumatic Tube Segment=Сортировка сегментов пневматической трубки +Sorting pneumatic tube=Сортировочная пневматическая труба + +## teleport tube +Receive=Получить +Channels are public by default=По умолчанию каналы являются общедоступными +Use : for fully private channels=Используйте <игрок>:<канал> для полностью приватных каналов +Use ; for private receivers=Используйте <игрок>;<канал> для частных приемников +Teleporting Pneumatic Tube Segment=Сегмент пневматической трубы для телепортации +Teleporting Tube=Телепортационная труба +Unconfigured Teleportation Tube=Неконфигурированная телепортационная труба +Sorry, channel '@1' is reserved for exclusive use by @2=Извините, канал '@1' зарезервирован исключительно для использования @2 +Sorry, receiving from channel '@1' is reserved for @2=Извините, прием с канала '@1' зарезервирован для @2 +Teleportation Tube @1 on '@2'=Трубка телепортации @1 на '@2' + +## trashcan +Trash Can=Мусорное ведро + +## tube registration +Pneumatic tube segment (legacy)=Сегмент пневматической трубы (устаревший) + +## vacuum tubes +Radius=Радиус +Vacuuming Pneumatic Tube Segment=Сегмент пневматической трубки для вакуумирования +Adjustable Vacuuming Tube=Регулируемая вакуумная трубка +Adjustable Vacuuming Pneumatic Tube Segment=Регулируемый сегмент вакуумной пневматической трубки +Adjustable Vacuuming Pneumatic Tube Segment (@1m)=Регулируемый сегмент вакуумной пневматической трубки (@1m) + +## wielder +Node Breaker=Разрушитель узла +Deployer=Развертыватель +Dispenser=Распылитель From 7079fff85f571e0d22e4a6c7164054926e5a8a96 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sat, 7 Sep 2024 20:19:46 +1000 Subject: [PATCH 30/30] remove hardcoded `stack_max` in tube registration fixes #138 --- tubes/registration.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/tubes/registration.lua b/tubes/registration.lua index 14a5df5..cbfc150 100644 --- a/tubes/registration.lua +++ b/tubes/registration.lua @@ -112,7 +112,6 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e key = "node_sound_wood_defaults", }, walkable = true, - stack_max = 99, basename = name, style = style, drop = string.format("%s_%s", name, dropname),