diff options
28 files changed, 858 insertions, 417 deletions
diff --git a/blox/init.lua b/blox/init.lua index 95d087a..30a9795 100644 --- a/blox/init.lua +++ b/blox/init.lua @@ -221,19 +221,19 @@ table.insert(blox.old_89_color_nodes, "blox:stone_tinted") minetest.override_item("default:stone_block", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:stone_square",
+ airbrush_replacement_node = "blox:stone_square",
groups = {cracky = 3, stone = 1, ud_param2_colorable = 1},
})
minetest.override_item("default:stone", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:stone_tinted",
+ airbrush_replacement_node = "blox:stone_tinted",
groups = {cracky = 3, stone = 1, ud_param2_colorable = 1},
})
minetest.override_item("default:cobble", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:cobble_tinted",
+ airbrush_replacement_node = "blox:cobble_tinted",
groups = {cracky = 3, stone = 2, ud_param2_colorable = 1},
})
@@ -242,7 +242,7 @@ minetest.override_item("default:cobble", { if moreblocks then
minetest.override_item("moreblocks:circle_stone_bricks", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:stone_loop",
+ airbrush_replacement_node = "blox:stone_loop",
groups = {cracky = 3, ud_param2_colorable = 1},
})
@@ -259,7 +259,7 @@ if moreblocks then minetest.override_item("moreblocks:iron_checker", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:stone_checker",
+ airbrush_replacement_node = "blox:stone_checker",
groups = {cracky = 3, ud_param2_colorable = 1},
})
@@ -276,7 +276,7 @@ if moreblocks then minetest.override_item("moreblocks:wood_tile", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:wood_quarter",
+ airbrush_replacement_node = "blox:wood_quarter",
groups = {wood = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, ud_param2_colorable = 1},
})
@@ -293,7 +293,7 @@ if moreblocks then minetest.override_item("moreblocks:wood_tile_flipped", {
palette = "unifieddyes_palette_extended.png",
- ud_replacement_node = "blox:wood_quarter",
+ airbrush_replacement_node = "blox:wood_quarter",
groups = {wood = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, ud_param2_colorable = 1},
})
@@ -334,7 +334,7 @@ if minetest.get_modpath("coloredwood") then else
minetest.override_item("default:wood", {
- ud_replacement_node = "blox:wood_tinted",
+ airbrush_replacement_node = "blox:wood_tinted",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1, ud_param2_colorable = 1},
})
diff --git a/coloredwood/init.lua b/coloredwood/init.lua index e139c31..09f466a 100644 --- a/coloredwood/init.lua +++ b/coloredwood/init.lua @@ -234,6 +234,7 @@ end minetest.override_item("default:wood", { palette = "unifieddyes_palette_extended.png", + airbrush_replacement_node = "coloredwood:wood_block", groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1, ud_param2_colorable = 1}, }) diff --git a/extranodes/init.lua b/extranodes/init.lua index 4e2e335..a4e51bd 100644 --- a/extranodes/init.lua +++ b/extranodes/init.lua @@ -103,7 +103,7 @@ if minetest.get_modpath("moreblocks") then end local iclip_def = { - description = "Insulator/cable clip", + description = S("Insulator/cable clip"), drawtype = "mesh", mesh = "technic_insulator_clip.obj", tiles = {"technic_insulator_clip.png"}, @@ -113,7 +113,7 @@ local iclip_def = { } local iclipfence_def = { - description = "Insulator/cable clip", + description = S("Insulator/cable clip"), tiles = {"technic_insulator_clip.png"}, is_ground_content = false, paramtype = "light", @@ -161,7 +161,7 @@ if minetest.registered_nodes["streets:steel_support"] then end local sclip_def = { - description = "Steel strut with insulator/cable clip", + description = S("Steel strut with insulator/cable clip"), drawtype = "mesh", mesh = "technic_steel_strut_with_insulator_clip.obj", tiles = sclip_tex, diff --git a/steel/README.md b/steel/README.md new file mode 100644 index 0000000..5c3dfe3 --- /dev/null +++ b/steel/README.md @@ -0,0 +1,14 @@ +minetest-steel +============== + +This mod adds a range of steel materials that are recyclable to +minetest. To recycle, simply craft anything into scrap, and turn the +scrap into an iron lump. Registered items: plate_hard, plate_soft, +plate_rusted, grate_hard, grate_soft, strut, roofing. + +Optional dependencies: +* Homedecor for better roofing. +* Compatible with streets mod (no duplicates). + +License: GPL-2.0 for code, CC-BY-SA-4.0 for textures. +Original mod by minetesting (João Matos), changes by Zeg9. diff --git a/steel/description.txt b/steel/description.txt new file mode 100644 index 0000000..f08f6d8 --- /dev/null +++ b/steel/description.txt @@ -0,0 +1 @@ +Adds a range of steel materials that are recyclable. diff --git a/steel/init.lua b/steel/init.lua index 72aa92b..fa9dfdd 100644 --- a/steel/init.lua +++ b/steel/init.lua @@ -21,11 +21,11 @@ function steel_node_is_owned(pos, placer) end end - elseif type(isprotect)=="function" then -- glomie's protection mod + elseif type(isprotect)=="function" then -- glomie's protection mod if not isprotect(5, pos, placer) then ownername = "someone" end - elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod + elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod if not protector.can_dig(5, pos, placer) then ownername = "someone" end @@ -58,7 +58,7 @@ function steel_rotate_and_place(itemstack, placer, pointed_thing) local iswall = (above.x ~= under.x) or (above.z ~= under.z) local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0) - if iswall then + if iswall then local dirs = { 2, 3, 0, 1 } minetest.add_node(above, {name = wield_name.."_wall", param2 = dirs[fdir+1] }) -- place wall variant elseif isceiling then @@ -217,15 +217,15 @@ minetest.register_node("steel:roofing_wall", { }) if homedecor_register_slope and homedecor_register_roof then - homedecor_register_slope("steel", "roofing", - "steel:roofing", - {bendy=2,snappy=1,dig_immediate=2}, - {"corrugated_steel.png"}, + homedecor_register_slope("steel", "roofing", + "steel:roofing", + {bendy=2,snappy=1,dig_immediate=2}, + {"corrugated_steel.png"}, "Corrugated steel roofing" ) - homedecor_register_roof("steel", "roofing", - {bendy=2,snappy=1,dig_immediate=2}, - {"corrugated_steel.png"}, + homedecor_register_roof("steel", "roofing", + {bendy=2,snappy=1,dig_immediate=2}, + {"corrugated_steel.png"}, "Corrugated steel roofing" ) end @@ -276,9 +276,9 @@ if not minetest.registered_nodes["streets:steel_support"] then minetest.register_craft({ output = 'steel:strut 5', recipe = { - {'default:steel_ingot', '', 'default:steel_ingot'}, {'', 'default:steel_ingot', ''}, - {'default:steel_ingot', '', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, + {'', 'default:steel_ingot', ''}, } }) end diff --git a/steel/mod.conf b/steel/mod.conf new file mode 100644 index 0000000..2d42e84 --- /dev/null +++ b/steel/mod.conf @@ -0,0 +1 @@ +name = steel diff --git a/technic/config.lua b/technic/config.lua index 331e102..bb748ec 100644 --- a/technic/config.lua +++ b/technic/config.lua @@ -13,8 +13,6 @@ local defaults = { enable_entity_radiation_damage = "true", enable_longterm_radiation_damage = "true", enable_nuclear_reactor_digiline_selfdestruct = "false", - creative_mode = "false", - enable_producers = "true", } for k, v in pairs(defaults) do diff --git a/technic/machines/HV/init.lua b/technic/machines/HV/init.lua index 468932d..d7136b4 100644 --- a/technic/machines/HV/init.lua +++ b/technic/machines/HV/init.lua @@ -8,11 +8,9 @@ dofile(path.."/cables.lua") dofile(path.."/battery_box.lua") -- Generators -if technic.config:get_bool("enable_producers") then - dofile(path.."/solar_array.lua") - dofile(path.."/nuclear_reactor.lua") - dofile(path.."/generator.lua") -end +dofile(path.."/solar_array.lua") +dofile(path.."/nuclear_reactor.lua") +dofile(path.."/generator.lua") -- Machines dofile(path.."/quarry.lua") diff --git a/technic/machines/LV/init.lua b/technic/machines/LV/init.lua index aeb6ce3..30523c9 100644 --- a/technic/machines/LV/init.lua +++ b/technic/machines/LV/init.lua @@ -8,13 +8,11 @@ dofile(path.."/cables.lua") dofile(path.."/battery_box.lua") -- Generators -if technic.config:get_bool("enable_producers") then - dofile(path.."/solar_panel.lua") - dofile(path.."/solar_array.lua") - dofile(path.."/geothermal.lua") - dofile(path.."/water_mill.lua") - dofile(path.."/generator.lua") -end +dofile(path.."/solar_panel.lua") +dofile(path.."/solar_array.lua") +dofile(path.."/geothermal.lua") +dofile(path.."/water_mill.lua") +dofile(path.."/generator.lua") -- Machines dofile(path.."/alloy_furnace.lua") diff --git a/technic/machines/LV/water_mill.lua b/technic/machines/LV/water_mill.lua index 5d871f0..33834ec 100644 --- a/technic/machines/LV/water_mill.lua +++ b/technic/machines/LV/water_mill.lua @@ -1,6 +1,6 @@ -- A water mill produces LV EUs by exploiting flowing water across it --- It is a LV EU supplyer and fairly low yield (max 120EUs) --- It is a little under half as good as the thermal generator. +-- It is a LV EU supplyer and fairly low yield (max 180EUs) +-- It is a little over half as good as the thermal generator. local S = technic.getter @@ -29,11 +29,9 @@ end local run = function(pos, node) local meta = minetest.get_meta(pos) local water_flow = 0 - local lava_nodes = 0 local production_level = 0 local eu_supply = 0 - local max_output = 35 * 45 -- four param2's at 15 makes 60, cap it lower for "overload protection" - -- (plus we want the gen to report 100% if three sides have full flow) + local max_output = 4 * 45 -- keeping it around 180, little more than previous 150 :) local positions = { {x=pos.x+1, y=pos.y, z=pos.z}, @@ -49,7 +47,7 @@ local run = function(pos, node) end end - eu_supply = math.min(35 * water_flow, max_output) + eu_supply = math.min(4 * water_flow, max_output) production_level = math.floor(100 * eu_supply / max_output) meta:set_int("LV_EU_supply", eu_supply) diff --git a/technic/machines/MV/hydro_turbine.lua b/technic/machines/MV/hydro_turbine.lua new file mode 100644 index 0000000..36aac91 --- /dev/null +++ b/technic/machines/MV/hydro_turbine.lua @@ -0,0 +1,105 @@ +-- A Hydro Turbine produces MV EUs by exploiting flowing water across it +-- It is a MV EU supplyer and fairly high yield (max 1800EUs) + +local S = technic.getter + +local cable_entry = "^technic_cable_connection_overlay.png" + +minetest.register_alias("hydro_turbine", "technic:hydro_turbine") + +minetest.register_craft({ + output = 'technic:hydro_turbine', + recipe = { + {'technic:stainless_steel_ingot', 'technic:water_mill', 'technic:stainless_steel_ingot'}, + {'technic:water_mill', 'technic:mv_transformer', 'technic:water_mill'}, + {'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'}, + } +}) + +local function get_water_flow(pos) + local node = minetest.get_node(pos) + if minetest.get_item_group(node.name, "water") == 3 then + return node.param2 -- returns approx. water flow, if any + end + return 0 +end + +--- +-- 10 times better than LV hydro because of 2 extra water mills and 4 stainless steel, a transformer and whatnot ;P. +-- Man hydro turbines are tough and long lasting. So, give it some value :) +local run = function(pos, node) + local meta = minetest.get_meta(pos) + local water_flow = 0 + local production_level = 0 + local eu_supply = 0 + local max_output = 40 * 45 -- Generates 1800EU/s + + local positions = { + {x=pos.x+1, y=pos.y, z=pos.z}, + {x=pos.x-1, y=pos.y, z=pos.z}, + {x=pos.x, y=pos.y, z=pos.z+1}, + {x=pos.x, y=pos.y, z=pos.z-1}, + } + + for _, p in pairs(positions) do + water_flow = water_flow + get_water_flow(p) + end + + eu_supply = math.min(40 * water_flow, max_output) + production_level = math.floor(100 * eu_supply / max_output) + + meta:set_int("MV_EU_supply", eu_supply) + + meta:set_string("infotext", + S("Hydro %s Generator"):format("MV").." ("..production_level.."%)") + if production_level > 0 and + minetest.get_node(pos).name == "technic:hydro_turbine" then + technic.swap_node(pos, "technic:hydro_turbine_active") + meta:set_int("MV_EU_supply", 0) + return + end + if production_level == 0 then + technic.swap_node(pos, "technic:hydro_turbine") + end +end + +minetest.register_node("technic:hydro_turbine", { + description = S("Hydro %s Generator"):format("MV"), + tiles = { + "technic_hydro_turbine_top.png", + "technic_machine_bottom.png"..cable_entry, + "technic_hydro_turbine_side.png", + "technic_hydro_turbine_side.png", + "technic_hydro_turbine_side.png", + "technic_hydro_turbine_side.png" + }, + paramtype2 = "facedir", + groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, + technic_machine=1, technic_mv=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", S("Hydro %s Generator"):format("MV")) + meta:set_int("MV_EU_supply", 0) + end, + technic_run = run, +}) + +minetest.register_node("technic:hydro_turbine_active", { + description = S("Hydro %s Generator"):format("MV"), + tiles = {"technic_hydro_turbine_top_active.png", "technic_machine_bottom.png", + "technic_hydro_turbine_side.png", "technic_hydro_turbine_side.png", + "technic_hydro_turbine_side.png", "technic_hydro_turbine_side.png"}, + paramtype2 = "facedir", + groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, + technic_machine=1, technic_mv=1, not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + drop = "technic:hydro_turbine", + technic_run = run, + technic_disabled_machine_name = "technic:hydro_turbine", +}) + +technic.register_machine("MV", "technic:hydro_turbine", technic.producer) +technic.register_machine("MV", "technic:hydro_turbine_active", technic.producer) diff --git a/technic/machines/MV/init.lua b/technic/machines/MV/init.lua index bb9542d..7092fda 100644 --- a/technic/machines/MV/init.lua +++ b/technic/machines/MV/init.lua @@ -8,13 +8,12 @@ dofile(path.."/cables.lua") dofile(path.."/battery_box.lua") -- Generators -if technic.config:get_bool("enable_producers") then - if technic.config:get_bool("enable_wind_mill") then - dofile(path.."/wind_mill.lua") - end - dofile(path.."/generator.lua") - dofile(path.."/solar_array.lua") +if technic.config:get_bool("enable_wind_mill") then + dofile(path.."/wind_mill.lua") end +dofile(path.."/generator.lua") +dofile(path.."/solar_array.lua") +dofile(path.."/hydro_turbine.lua") -- Machines dofile(path.."/alloy_furnace.lua") diff --git a/technic/machines/creative.lua b/technic/machines/creative.lua deleted file mode 100644 index 39abe74..0000000 --- a/technic/machines/creative.lua +++ /dev/null @@ -1,41 +0,0 @@ -local S = technic.getter - -minetest.register_abm({ - nodenames = {"group:technic_lv", "group:technic_mv", "group:technic_hv"}, - label = "Run Machines", - interval = 1, - chance = 1, - action = function(pos,node) - local meta = minetest.get_meta(pos) - local pos1 = {x=pos.x, y=pos.y-1, z=pos.z} - local tier = technic.get_cable_tier(minetest.get_node(pos1).name) - local meta = minetest.get_meta(pos) - if not tier then - meta:set_int("active", 0) - return - end - meta:set_int("active", 1) - meta:set_int("LV_EU_input", meta:get_int("LV_EU_demand")) - meta:set_int("MV_EU_input", meta:get_int("MV_EU_demand")) - meta:set_int("HV_EU_input", meta:get_int("HV_EU_demand")) - local nodedef = minetest.registered_nodes[node.name] - if nodedef and nodedef.technic_run then - nodedef.technic_run(pos, node) - end - end, -}) - -minetest.register_lbm({ - nodenames = {"technic:switching_station", "technic:power_monitor"}, - name = "technic:update_infotext", - label = "Update switching station / power monitor infotext", - run_at_every_load = true, - action = function(pos, node) - local meta = minetest.get_meta(pos) - if node.name == "technic:switching_station" then - meta:set_string("infotext", S("Switching Station")) - elseif node.name == "technic:power_monitor" then - meta:set_string("infotext", S("Power Monitor")) - end - end, -}) diff --git a/technic/machines/init.lua b/technic/machines/init.lua index 00ea158..f2e31c9 100644 --- a/technic/machines/init.lua +++ b/technic/machines/init.lua @@ -13,8 +13,3 @@ dofile(path.."/supply_converter.lua") dofile(path.."/other/init.lua") -if technic.config:get_bool("creative_mode") then - --The switching station does not handle running machines - --in this mode, so alternative means are used to do so. - dofile(path.."/creative.lua") -end diff --git a/technic/machines/other/frames.lua b/technic/machines/other/frames.lua index 5459289..d5c60a3 100644 --- a/technic/machines/other/frames.lua +++ b/technic/machines/other/frames.lua @@ -1,56 +1,71 @@ - local S = technic.getter frames = {} -local infinite_stacks = minetest.settings:get_bool("creative_mode") and minetest.get_modpath("unified_inventory") == nil +local infinite_stacks = minetest.settings:get_bool("creative_mode") + and minetest.get_modpath("unified_inventory") == nil local frames_pos = {} -- Helpers -local function get_face(pos,ppos,pvect) +local function get_face(pos, ppos, pvect) -- Raytracer to get which face has been clicked - ppos={x=ppos.x-pos.x,y=ppos.y-pos.y+1.5,z=ppos.z-pos.z} - if pvect.x>0 then - local t=(-0.5-ppos.x)/pvect.x - local y_int=ppos.y+t*pvect.y - local z_int=ppos.z+t*pvect.z - if y_int>-0.45 and y_int<0.45 and z_int>-0.45 and z_int<0.45 then return 1 end - elseif pvect.x<0 then - local t=(0.5-ppos.x)/pvect.x - local y_int=ppos.y+t*pvect.y - local z_int=ppos.z+t*pvect.z - if y_int>-0.45 and y_int<0.45 and z_int>-0.45 and z_int<0.45 then return 2 end - end - if pvect.y>0 then - local t=(-0.5-ppos.y)/pvect.y - local x_int=ppos.x+t*pvect.x - local z_int=ppos.z+t*pvect.z - if x_int>-0.45 and x_int<0.45 and z_int>-0.45 and z_int<0.45 then return 3 end - elseif pvect.y<0 then - local t=(0.5-ppos.y)/pvect.y - local x_int=ppos.x+t*pvect.x - local z_int=ppos.z+t*pvect.z - if x_int>-0.45 and x_int<0.45 and z_int>-0.45 and z_int<0.45 then return 4 end - end - if pvect.z>0 then - local t=(-0.5-ppos.z)/pvect.z - local x_int=ppos.x+t*pvect.x - local y_int=ppos.y+t*pvect.y - if x_int>-0.45 and x_int<0.45 and y_int>-0.45 and y_int<0.45 then return 5 end - elseif pvect.z<0 then - local t=(0.5-ppos.z)/pvect.z - local x_int=ppos.x+t*pvect.x - local y_int=ppos.y+t*pvect.y - if x_int>-0.45 and x_int<0.45 and y_int>-0.45 and y_int<0.45 then return 6 end + ppos = { x = ppos.x - pos.x, y = ppos.y - pos.y + 1.5, z = ppos.z - pos.z } + + if pvect.x > 0 then + local t = (-0.5 - ppos.x) / pvect.x + local y_int = ppos.y + t * pvect.y + local z_int = ppos.z + t * pvect.z + if y_int > -0.45 and y_int < 0.45 and z_int > -0.45 and z_int < 0.45 then + return 1 + end + elseif pvect.x < 0 then + local t = (0.5 - ppos.x) / pvect.x + local y_int = ppos.y + t * pvect.y + local z_int = ppos.z + t * pvect.z + if y_int > -0.45 and y_int < 0.45 and z_int > -0.45 and z_int < 0.45 then + return 2 + end + end + + if pvect.y > 0 then + local t = (-0.5 - ppos.y) / pvect.y + local x_int = ppos.x + t * pvect.x + local z_int = ppos.z + t * pvect.z + if x_int > -0.45 and x_int < 0.45 and z_int > -0.45 and z_int < 0.45 then + return 3 + end + elseif pvect.y < 0 then + local t = (0.5 - ppos.y) / pvect.y + local x_int = ppos.x + t * pvect.x + local z_int = ppos.z + t * pvect.z + if x_int > -0.45 and x_int < 0.45 and z_int > -0.45 and z_int < 0.45 then + return 4 + end + end + + if pvect.z > 0 then + local t = (-0.5 - ppos.z) / pvect.z + local x_int = ppos.x + t * pvect.x + local y_int = ppos.y + t * pvect.y + if x_int > -0.45 and x_int < 0.45 and y_int > -0.45 and y_int < 0.45 then + return 5 + end + elseif pvect.z < 0 then + local t = (0.5 - ppos.z) / pvect.z + local x_int = ppos.x + t * pvect.x + local y_int = ppos.y + t * pvect.y + if x_int > -0.45 and x_int < 0.45 and y_int > -0.45 and y_int < 0.45 then + return 6 + end end end local function lines(str) local t = {} local function helper(line) table.insert(t, line) return "" end - helper((str:gsub("(.-)\r?\n", helper))) + helper(str:gsub("(.-)\r?\n", helper)) return t end @@ -63,12 +78,14 @@ end local function pos_from_string(str) local l = lines(str) - return {x = tonumber(l[1]), y = tonumber(l[2]), z = tonumber(l[3])} + return { x = tonumber(l[1]), y = tonumber(l[2]), z = tonumber(l[3]) } end -local function pos_in_list(l,pos) - for _,p in ipairs(l) do - if p.x==pos.x and p.y==pos.y and p.z==pos.z then return true end +local function pos_in_list(l, pos) + for _, p in ipairs(l) do + if p.x == pos.x and p.y == pos.y and p.z == pos.z then + return true + end end return false end @@ -80,176 +97,206 @@ local function table_empty(table) return true end -local function add_table(table,toadd) +local function add_table(table, toadd) local i = 1 while true do o = table[i] if o == toadd then return end if o == nil then break end - i = i+1 + i = i + 1 end table[i] = toadd end -local function move_nodes_vect(poslist,vect,must_not_move,owner) +local function move_nodes_vect(poslist, vect, must_not_move, owner) if minetest.is_protected then - for _,pos in ipairs(poslist) do - local npos=vector.add(pos,vect) + for _, pos in ipairs(poslist) do + local npos = vector.add(pos, vect) if minetest.is_protected(pos, owner) or minetest.is_protected(npos, owner) then return end end end - for _,pos in ipairs(poslist) do - local npos=vector.add(pos,vect) + + for _, pos in ipairs(poslist) do + local npos = vector.add(pos, vect) local name = minetest.get_node(npos).name - if ((name~="air" and minetest.registered_nodes[name].liquidtype=="none") or frames_pos[pos_to_string(npos)]) and not(pos_in_list(poslist,npos)) then + if (name ~= "air" and minetest.registered_nodes[name].liquidtype == "none" or + frames_pos[pos_to_string(npos)]) and not pos_in_list(poslist, npos) then return end - --[[if pos.x==must_not_move.x and pos.y==must_not_move.y and pos.z==must_not_move.z then - return - end]] end + local nodelist = {} for _, pos in ipairs(poslist) do local node = minetest.get_node(pos) local meta = minetest.get_meta(pos):to_table() - nodelist[#(nodelist)+1] = {oldpos = pos, pos = vector.add(pos, vect), node = node, meta = meta} + local timer = minetest.get_node_timer(pos) + nodelist[#nodelist + 1] = { + oldpos = pos, + pos = vector.add(pos, vect), + node = node, + meta = meta, + timer = { + timeout = timer:get_timeout(), + elapsed = timer:get_elapsed() + } + } end + local objects = {} for _, pos in ipairs(poslist) do - for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do + for _, object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do local entity = object:get_luaentity() if not entity or not mesecon.is_mvps_unmov(entity.name) then add_table(objects, object) end end end + for _, obj in ipairs(objects) do obj:setpos(vector.add(obj:getpos(), vect)) end - for _,n in ipairs(nodelist) do + + for _, n in ipairs(nodelist) do local npos = n.pos minetest.set_node(npos, n.node) local meta = minetest.get_meta(npos) meta:from_table(n.meta) - for __,pos in ipairs(poslist) do + local timer = minetest.get_node_timer(npos) + if n.timer.timeout ~= 0 or n.timer.elapsed ~= 0 then + timer:set(n.timer.timeout, n.timer.elapsed) + end + for __, pos in ipairs(poslist) do if npos.x == pos.x and npos.y == pos.y and npos.z == pos.z then table.remove(poslist, __) break end end end + for __, pos in ipairs(poslist) do minetest.remove_node(pos) end + for _, callback in ipairs(mesecon.on_mvps_move) do callback(nodelist) end end local function is_supported_node(name) - return ((string.find(name, "tube") ~= nil) and (string.find(name, "pipeworks") ~= nil)) + return string.find(name, "tube") and string.find(name, "pipeworks") end - -- Frames -for xm=0,1 do -for xp=0,1 do -for ym=0,1 do -for yp=0,1 do -for zm=0,1 do -for zp=0,1 do - -local a=8/16 -local b=7/16 -local nodeboxes= { - { -a, -a, -a, -b, a, -b }, - { -a, -a, b, -b, a, a }, - { b, -a, b, a, a, a }, - { b, -a, -a, a, a, -b }, - - { -b, b, -a, b, a, -b }, - { -b, -a, -a, b, -b, -b }, - - { -b, b, b, b, a, a }, - { -b, -a, b, b, -b, a }, - - { b, b, -b, a, a, b }, - { b, -a, -b, a, -b, b }, - - { -a, b, -b, -b, a, b }, - { -a, -a, -b, -b, -b, b }, +for xm = 0, 1 do +for xp = 0, 1 do +for ym = 0, 1 do +for yp = 0, 1 do +for zm = 0, 1 do +for zp = 0, 1 do + + local a = 8 / 16 + local b = 7 / 16 + local nodeboxes = { + { -a, -a, -a, -b, a, -b }, + { -a, -a, b, -b, a, a }, + + { b, -a, b, a, a, a }, + { b, -a, -a, a, a, -b }, + + { -b, b, -a, b, a, -b }, + { -b, -a, -a, b, -b, -b }, + + { -b, b, b, b, a, a }, + { -b, -a, b, b, -b, a }, + + { b, b, -b, a, a, b }, + { b, -a, -b, a, -b, b }, + + { -a, b, -b, -b, a, b }, + { -a, -a, -b, -b, -b, b }, } - - if yp==0 then - table.insert(nodeboxes, {-b,b,-b, b,a,b}) + + if yp == 0 then + table.insert(nodeboxes, { -b, b, -b, b, a, b }) end - if ym==0 then - table.insert(nodeboxes, {-b,-a,-b, b,-b,b}) + if ym == 0 then + table.insert(nodeboxes, { -b, -a, -b, b, -b, b }) end - if xp==0 then - table.insert(nodeboxes, {b,b,b,a,-b,-b}) + if xp == 0 then + table.insert(nodeboxes, { b, b, b, a, -b, -b }) end - if xm==0 then - table.insert(nodeboxes, {-a,-b,-b,-b,b,b}) + if xm == 0 then + table.insert(nodeboxes, { -a, -b, -b, -b, b, b }) end - if zp==0 then - table.insert(nodeboxes, {-b,-b,b, b,b,a}) + if zp == 0 then + table.insert(nodeboxes, { -b, -b, b, b, b, a }) end - if zm==0 then - table.insert(nodeboxes, {-b,-b,-a, b,b,-b}) + if zm == 0 then + table.insert(nodeboxes, { -b, -b, -a, b, b, -b }) end - - local nameext=tostring(xm)..tostring(xp)..tostring(ym)..tostring(yp)..tostring(zm)..tostring(zp) - local groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2} - if nameext~="111111" then groups.not_in_creative_inventory=1 end - - minetest.register_node("technic:frame_"..nameext,{ + local nameext = string.format("%d%d%d%d%d%d", xm, xp, ym, yp, zm, zp) + local groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2 } + if nameext ~= "111111" then groups.not_in_creative_inventory = 1 end + + + minetest.register_node("technic:frame_"..nameext, { description = S("Frame"), - tiles = {"technic_frame.png"}, - groups=groups, + tiles = { "technic_frame.png" }, + groups = groups, drawtype = "nodebox", node_box = { type = "fixed", - fixed=nodeboxes, + fixed = nodeboxes, }, selection_box = { - type="fixed", - fixed={-0.5,-0.5,-0.5,0.5,0.5,0.5} + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 } }, paramtype = "light", - frame=1, - drop="technic:frame_111111", + frame = 1, + drop = "technic:frame_111111", sunlight_propagates = true, - frame_connect_all=function(nodename) - l2={} - l1={{x=-1,y=0,z=0},{x=1,y=0,z=0},{x=0,y=-1,z=0},{x=0,y=1,z=0},{x=0,y=0,z=-1},{x=0,y=0,z=1}} - for i,dir in ipairs(l1) do - if string.sub(nodename,-7+i,-7+i)=="1" then - l2[#(l2)+1]=dir + + frame_connect_all = function(nodename) + l2 = {} + l1 = { + { x = -1, y = 0, z = 0 }, { x = 1, y = 0, z = 0 }, + { x = 0, y = -1, z = 0 }, { x = 0, y = 1, z = 0 }, + { x = 0, y = 0, z = -1 }, { x = 0, y = 0, z = 1 } + } + for i, dir in ipairs(l1) do + if string.sub(nodename, -7 + i, -7 + i) == "1" then + l2[#l2 + 1] = dir end end return l2 end, - on_punch=function(pos,node,puncher) - local ppos=puncher:getpos() - local pvect=puncher:get_look_dir() - local pface=get_face(pos,ppos,pvect) - if pface==nil then return end - local nodename=node.name - local newstate=tostring(1-tonumber(string.sub(nodename,-7+pface,-7+pface))) - if pface<=5 then - nodename=string.sub(nodename,1,-7+pface-1)..newstate..string.sub(nodename,-7+pface+1) + + on_punch = function(pos, node, puncher) + local ppos = puncher:getpos() + local pvect = puncher:get_look_dir() + local pface = get_face(pos, ppos, pvect) + + if pface == nil then return end + + local nodename = node.name + local newstate = tostring(1 - tonumber(string.sub(nodename, pface - 7, pface - 7))) + if pface <= 5 then + nodename = string.sub(nodename, 1, pface - 7 - 1)..newstate..string.sub(nodename, pface - 7 + 1) else - nodename=string.sub(nodename,1,-2)..newstate + nodename = string.sub(nodename, 1, -2)..newstate end - node.name=nodename - minetest.set_node(pos,node) + + node.name = nodename + minetest.set_node(pos, node) end, + on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above + if minetest.is_protected(pos, placer:get_player_name()) then minetest.log("action", placer:get_player_name() .. " tried to place " .. itemstack:get_name() @@ -258,21 +305,25 @@ local nodeboxes= { minetest.record_protection_violation(pos, placer:get_player_name()) return itemstack end + if pos == nil then return end + local node = minetest.get_node(pos) if node.name ~= "air" then if is_supported_node(node.name) then obj = minetest.add_entity(pos, "technic:frame_entity") - obj:get_luaentity():set_node({name=itemstack:get_name()}) + obj:get_luaentity():set_node({ name = itemstack:get_name() }) end else - minetest.set_node(pos, {name = itemstack:get_name()}) + minetest.set_node(pos, { name = itemstack:get_name() }) end + if not infinite_stacks then itemstack:take_item() end return itemstack end, + on_rightclick = function(pos, node, placer, itemstack, pointed_thing) if is_supported_node(itemstack:get_name()) then if minetest.is_protected(pos, placer:get_player_name()) then @@ -283,15 +334,15 @@ local nodeboxes= { minetest.record_protection_violation(pos, placer:get_player_name()) return itemstack end - - minetest.set_node(pos, {name = itemstack:get_name()}) - + + minetest.set_node(pos, { name = itemstack:get_name() }) + local take_item = true local def = minetest.registered_items[itemstack:get_name()] -- Run callback if def.after_place_node then -- Copy place_to because callback can modify it - local pos_copy = {x=pos.x, y=pos.y, z=pos.z} + local pos_copy = vector.new(pos) if def.after_place_node(pos_copy, placer, itemstack) then take_item = false end @@ -301,9 +352,9 @@ local nodeboxes= { local _, callback for _, callback in ipairs(minetest.registered_on_placenodes) do -- Copy pos and node because callback can modify them - local pos_copy = {x=pos.x, y=pos.y, z=pos.z} - local newnode_copy = {name=def.name, param1=0, param2=0} - local oldnode_copy = {name="air", param1=0, param2=0} + local pos_copy = { x = pos.x, y = pos.y, z = pos.z } + local newnode_copy = { name = def.name, param1 = 0, param2 = 0 } + local oldnode_copy = { name = "air", param1 = 0, param2 = 0 } if callback(pos_copy, newnode_copy, placer, oldnode_copy, itemstack) then take_item = false end @@ -312,13 +363,13 @@ local nodeboxes= { if take_item then itemstack:take_item() end - + obj = minetest.add_entity(pos, "technic:frame_entity") - obj:get_luaentity():set_node({name=node.name}) - + obj:get_luaentity():set_node({ name = node.name }) + return itemstack else - --local pointed_thing = {type = "node", under = pos} + --local pointed_thing = { type = "node", under = pos } if pointed_thing then return minetest.item_place_node(itemstack, placer, pointed_thing) end @@ -336,25 +387,27 @@ end minetest.register_entity("technic:frame_entity", { initial_properties = { physical = true, - collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, + collisionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }, visual = "wielditem", textures = {}, - visual_size = {x=0.667, y=0.667}, + visual_size = { x = 0.667, y = 0.667 }, }, node = {}, set_node = function(self, node) self.node = node - local pos = self.object:getpos() - pos = {x = math.floor(pos.x+0.5), y = math.floor(pos.y+0.5), z = math.floor(pos.z+0.5)} + local pos = vector.round(self.object:getpos()) frames_pos[pos_to_string(pos)] = node.name + local stack = ItemStack(node.name) local itemtable = stack:to_table() local itemname = nil + if itemtable then itemname = stack:to_table().name end + local item_texture = nil local item_type = "" if minetest.registered_items[itemname] then @@ -363,7 +416,7 @@ minetest.register_entity("technic:frame_entity", { end prop = { is_visible = true, - textures = {node.name}, + textures = { node.name }, } self.object:set_properties(prop) end, @@ -373,18 +426,17 @@ minetest.register_entity("technic:frame_entity", { end, on_activate = function(self, staticdata) - self.object:set_armor_groups({immortal=1}) - self:set_node({name=staticdata}) + self.object:set_armor_groups({ immortal = 1 }) + self:set_node({ name = staticdata }) end, - + dig = function(self) - minetest.handle_node_drops(self.object:getpos(), {ItemStack("technic:frame_111111")}, self.last_puncher) - local pos = self.object:getpos() - pos = {x = math.floor(pos.x+0.5), y = math.floor(pos.y+0.5), z = math.floor(pos.z+0.5)} + minetest.handle_node_drops(self.object:getpos(), { ItemStack("technic:frame_111111") }, self.last_puncher) + local pos = vector.round(self.object:getpos()) frames_pos[pos_to_string(pos)] = nil self.object:remove() end, - + on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) local pos = self.object:getpos() if self.damage_object == nil then @@ -396,35 +448,43 @@ minetest.register_entity("technic:frame_entity", { else self.damage_object:get_luaentity().remaining_time = 0.25 end + self.last_puncher = puncher local ppos = puncher:getpos() local pvect = puncher:get_look_dir() - local pface = get_face(pos,ppos,pvect) + local pface = get_face(pos, ppos, pvect) if pface == nil then return end local nodename = self.node.name - local newstate = tostring(1-tonumber(string.sub(nodename, -7+pface, -7+pface))) + local newstate = tostring(1 - tonumber(string.sub(nodename, pface - 7, pface - 7))) + if pface <= 5 then - nodename = string.sub(nodename, 1, -7+pface-1)..newstate..string.sub(nodename, -7+pface+1) + nodename = string.sub(nodename, 1, pface - 7 - 1)..newstate..string.sub(nodename, pface - 7 + 1) else nodename = string.sub(nodename, 1, -2)..newstate end + self.node.name = nodename self:set_node(self.node) end, - + on_rightclick = function(self, clicker) local pos = self.object:getpos() local ppos = clicker:getpos() local pvect = clicker:get_look_dir() local pface = get_face(pos, ppos, pvect) - if pface == nil then return end - local pos_under = {x = math.floor(pos.x+0.5), y = math.floor(pos.y+0.5), z = math.floor(pos.z+0.5)} - local pos_above = {x = pos_under.x, y = pos_under.y, z = pos_under.z} - local index = ({"x", "y", "z"})[math.floor((pface+1)/2)] - pos_above[index] = pos_above[index] + 2*((pface+1)%2) - 1 - local pointed_thing = {type = "node", under = pos_under, above = pos_above} + + if pface == nil then + return + end + + local pos_under = vector.round(pos) + local pos_above = { x = pos_under.x, y = pos_under.y, z = pos_under.z } + local index = ({ "x", "y", "z" })[math.floor((pface + 1) / 2)] + pos_above[index] = pos_above[index] + 2 * ((pface + 1)%2) - 1 + local pointed_thing = { type = "node", under = pos_under, above = pos_above } local itemstack = clicker:get_wielded_item() local itemdef = minetest.registered_items[itemstack:get_name()] + if itemdef ~= nil then itemdef.on_place(itemstack, clicker, pointed_thing) end @@ -435,9 +495,9 @@ local crack = "crack_anylength.png^[verticalframe:5:0" minetest.register_entity("technic:damage_entity", { initial_properties = { visual = "cube", - visual_size = {x=1.01, y=1.01}, - textures = {crack, crack, crack, crack, crack, crack}, - collisionbox = {0, 0, 0, 0, 0, 0}, + visual_size = { x = 1.01, y = 1.01 }, + textures = { crack, crack, crack, crack, crack, crack }, + collisionbox = { 0, 0, 0, 0, 0, 0 }, physical = false, }, on_step = function(self, dtime) @@ -460,7 +520,7 @@ minetest.register_entity("technic:damage_entity", { self.frame_object:dig() end local ct = "crack_anylength.png^[verticalframe:5:"..self.texture_index - self.object:set_properties({textures = {ct, ct, ct, ct, ct, ct}}) + self.object:set_properties({ textures = { ct, ct, ct, ct, ct, ct } }) end end, }) @@ -471,7 +531,11 @@ mesecon.register_on_mvps_move(function(moved_nodes) local to_move = {} for _, n in ipairs(moved_nodes) do if frames_pos[pos_to_string(n.oldpos)] ~= nil then - to_move[#to_move+1] = {pos = n.pos, oldpos = n.oldpos, name = frames_pos[pos_to_string(n.oldpos)]} + to_move[#to_move + 1] = { + pos = n.pos, + oldpos = n.oldpos, + name = frames_pos[pos_to_string(n.oldpos)] + } frames_pos[pos_to_string(n.oldpos)] = nil end end @@ -481,7 +545,8 @@ mesecon.register_on_mvps_move(function(moved_nodes) local objects = minetest.get_objects_inside_radius(t.oldpos, 0.1) for _, obj in ipairs(objects) do local entity = obj:get_luaentity() - if entity and (entity.name == "technic:frame_entity" or entity.name == "technic:damage_entity") then + if entity and (entity.name == "technic:frame_entity" or + entity.name == "technic:damage_entity") then obj:setpos(t.pos) end end @@ -491,7 +556,7 @@ end) minetest.register_on_dignode(function(pos, node) if frames_pos[pos_to_string(pos)] ~= nil then - minetest.set_node(pos, {name = frames_pos[pos_to_string(pos)]}) + minetest.set_node(pos, { name = frames_pos[pos_to_string(pos)] }) frames_pos[pos_to_string(pos)] = nil local objects = minetest.get_objects_inside_radius(pos, 0.1) for _, obj in ipairs(objects) do @@ -504,87 +569,109 @@ minetest.register_on_dignode(function(pos, node) end) -- Frame motor -local function connected(pos,c,adj) - for _,vect in ipairs(adj) do - local pos1=vector.add(pos,vect) - local nodename=minetest.get_node(pos1).name +local function connected(pos, c, adj) + for _, vect in ipairs(adj) do + local pos1 = vector.add(pos, vect) + local nodename = minetest.get_node(pos1).name if frames_pos[pos_to_string(pos1)] then nodename = frames_pos[pos_to_string(pos1)] end - if not(pos_in_list(c,pos1)) and nodename~="air" and - (minetest.registered_nodes[nodename].frames_can_connect==nil or - minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then - c[#(c)+1]=pos1 - if minetest.registered_nodes[nodename].frame==1 then - local adj=minetest.registered_nodes[nodename].frame_connect_all(nodename) - connected(pos1,c,adj) + if not pos_in_list(c, pos1) and nodename ~= "air" and + (minetest.registered_nodes[nodename].frames_can_connect == nil or + minetest.registered_nodes[nodename].frames_can_connect(pos1, vect)) then + c[#c + 1] = pos1 + if minetest.registered_nodes[nodename].frame == 1 then + local adj = minetest.registered_nodes[nodename].frame_connect_all(nodename) + connected(pos1, c, adj) end end end end local function get_connected_nodes(pos) - c={pos} - local nodename=minetest.get_node(pos).name + c = { pos } + local nodename = minetest.get_node(pos).name if frames_pos[pos_to_string(pos)] then nodename = frames_pos[pos_to_string(pos)] end - connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(nodename)) + connected(pos, c, minetest.registered_nodes[nodename].frame_connect_all(nodename)) return c end local function frame_motor_on(pos, node) - local dirs = {{x=0,y=1,z=0},{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}} - local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1]) + local dirs = { + { x = 0, y = 1, z = 0 }, { 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 } + } + local nnodepos = vector.add(pos, dirs[math.floor(node.param2 / 4) + 1]) local dir = minetest.facedir_to_dir(node.param2) - local nnode=minetest.get_node(nnodepos) + local nnode = minetest.get_node(nnodepos) + if frames_pos[pos_to_string(nnodepos)] then nnode.name = frames_pos[pos_to_string(nnodepos)] end + local meta = minetest.get_meta(pos) if meta:get_int("last_moved") == minetest.get_gametime() then return end + local owner = meta:get_string("owner") - if minetest.registered_nodes[nnode.name].frame==1 then - local connected_nodes=get_connected_nodes(nnodepos) - move_nodes_vect(connected_nodes,dir,pos,owner) + if minetest.registered_nodes[nnode.name].frame == 1 then + local connected_nodes = get_connected_nodes(nnodepos) + move_nodes_vect(connected_nodes, dir, pos, owner) end + minetest.get_meta(vector.add(pos, dir)):set_int("last_moved", minetest.get_gametime()) end -minetest.register_node("technic:frame_motor",{ +minetest.register_node("technic:frame_motor", { description = S("Frame Motor"), - tiles = {"pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", - "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2}, + tiles = { + "pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", + "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png" + }, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2 }, paramtype2 = "facedir", - mesecons={effector={action_on=frame_motor_on}}, + mesecons = { effector = { action_on = frame_motor_on } }, + after_place_node = function(pos, placer, itemstack) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name()) end, - frames_can_connect=function(pos,dir) + + frames_can_connect = function(pos, dir) local node = minetest.get_node(pos) - local dir2 = ({{x=0,y=1,z=0},{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}})[math.floor(node.param2/4)+1] - return dir2.x~=-dir.x or dir2.y~=-dir.y or dir2.z~=-dir.z + local dir2 = ({ + { x= 0 , y = 1, z = 0 }, { 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 } + })[math.floor(node.param2 / 4) + 1] + return dir2.x ~= -dir.x or dir2.y ~= -dir.y or dir2.z ~= -dir.z end }) -- Templates -local function template_connected(pos,c,connectors) - for _,vect in ipairs({{x=0,y=1,z=0},{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}}) do - local pos1=vector.add(pos,vect) - local nodename=minetest.get_node(pos1).name - if not(pos_in_list(c,pos1)) and (nodename=="technic:template" or nodename == "technic:template_connector")then +local function template_connected(pos, c, connectors) + local vects = { + { x = 0, y = 1, z = 0 }, { 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 } + } + for _, vect in ipairs(vects) do + local pos1 = vector.add(pos, vect) + local nodename = minetest.get_node(pos1).name + if not pos_in_list(c, pos1) and (nodename == "technic:template" or + nodename == "technic:template_connector") then local meta = minetest.get_meta(pos1) if meta:get_string("connected") == "" then - c[#(c)+1]=pos1 - template_connected(pos1,c,connectors) + c[#c + 1] = pos1 + template_connected(pos1, c, connectors) if nodename == "technic:template_connector" then - connectors[#connectors+1] = pos1 + connectors[#connectors + 1] = pos1 end end end @@ -592,14 +679,14 @@ local function template_connected(pos,c,connectors) end local function get_templates(pos) - local c = {pos} + local c = { pos } local connectors if minetest.get_node(pos).name == "technic:template_connector" then - connectors = {pos} + connectors = { pos } else connectors = {} end - template_connected(pos,c,connectors) + template_connected(pos, c, connectors) return c, connectors end @@ -615,7 +702,7 @@ end local function save_node(pos) local node = minetest.get_node(pos) if node.name == "air" then - minetest.set_node(pos, {name="technic:template"}) + minetest.set_node(pos, { name = "technic:template" }) return end if node.name == "technic:template" then @@ -624,6 +711,7 @@ local function save_node(pos) meta:set_string("connected", "") return end + local meta = minetest.get_meta(pos) local meta0 = meta:to_table() for _, list in pairs(meta0.inventory) do @@ -631,8 +719,9 @@ local function save_node(pos) list[key] = stack:to_string() end end + node.meta = meta0 - minetest.set_node(pos, {name="technic:template"}) + minetest.set_node(pos, { name = "technic:template" }) return node end @@ -650,38 +739,40 @@ end local function expand_template(pos) local meta = minetest.get_meta(pos) local c = meta:get_string("connected") + if c == "" then return end c = minetest.deserialize(c) + for _, vect in ipairs(c) do local pos1 = vector.add(pos, vect) local saved_node = save_node(pos1) local meta1 = minetest.get_meta(pos1) if saved_node ~= nil then meta1:set_string("saved_node", minetest.serialize(saved_node)) - else - --meta1:set_string("saved_node", "") end end end local function compress_templates(pos) local templates, connectors = get_templates(pos) + if #connectors == 0 then - connectors = {pos} + connectors = { pos } end + for _, cn in ipairs(connectors) do local meta = minetest.get_meta(cn) local c = {} - for _,p in ipairs(templates) do + for _, p in ipairs(templates) do local np = vector.subtract(p, cn) - if not pos_in_list(c,np) then - c[#c+1] = np + if not pos_in_list(c, np) then + c[#c + 1] = np end end local cc = {} - for _,p in ipairs(connectors) do + for _, p in ipairs(connectors) do local np = vector.subtract(p, cn) - if (np.x ~= 0 or np.y ~= 0 or np.z ~= 0) then + if np.x ~= 0 or np.y ~= 0 or np.z ~= 0 then cc[pos_to_string(np)] = true end end @@ -689,10 +780,10 @@ local function compress_templates(pos) meta:set_string("connected", minetest.serialize(c)) meta:set_string("connectors_connected", minetest.serialize(cc)) end - - for _,p in ipairs(templates) do + + for _, p in ipairs(templates) do if not pos_in_list(connectors, p) then - minetest.set_node(p, {name = "air"}) + minetest.set_node(p, { name = "air" }) end end end @@ -701,11 +792,12 @@ local function template_drops(pos, node, oldmeta, digger) local c = oldmeta.fields.connected local cc = oldmeta.fields.connectors_connected local drops + if c == "" or c == nil then - drops = {"technic:template 1"} + drops = { "technic:template 1" } else if cc == "" or cc == nil then - drops = {"technic:template 1"} + drops = { "technic:template 1" } else local dcc = minetest.deserialize(cc) if not table_empty(dcc) then @@ -716,22 +808,23 @@ local function template_drops(pos, node, oldmeta, digger) local meta = minetest.get_meta(p) local d = minetest.deserialize(meta:get_string("connectors_connected")) if d ~= nil then - d[pos_to_string({x=-ssp.x, y=-ssp.y, z=-ssp.z})] = nil + d[pos_to_string({ x = -ssp.x, y = -ssp.y, z = -ssp.z })] = nil meta:set_string("connectors_connected", minetest.serialize(d)) end end else local stack_max = 99 - local num = #(minetest.deserialize(c)) + local num = #minetest.deserialize(c) drops = {} while num > stack_max do - drops[#drops+1] = "technic:template "..stack_max + drops[#drops + 1] = "technic:template "..stack_max num = num - stack_max end - drops[#drops+1] = "technic:template "..num + drops[#drops + 1] = "technic:template "..num end end end + minetest.handle_node_drops(pos, drops, digger) end @@ -744,44 +837,44 @@ local function template_on_destruct(pos, node) end end -minetest.register_node("technic:template",{ +minetest.register_node("technic:template", { description = S("Template"), - tiles = {"technic_mv_cable.png"}, + tiles = { "technic_mv_cable.png" }, drop = "", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2 }, on_destruct = template_on_destruct, after_dig_node = template_drops, - on_punch = function(pos,node,puncher) + on_punch = function(pos, node, puncher) swap_template(pos, "technic:template_disabled") end }) -minetest.register_node("technic:template_disabled",{ +minetest.register_node("technic:template_disabled", { description = S("Template"), - tiles = {"technic_hv_cable.png"}, + tiles = { "technic_hv_cable.png" }, drop = "", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, not_in_creative_inventory = 1 }, on_destruct = template_on_destruct, after_dig_node = template_drops, - on_punch = function(pos,node,puncher) + on_punch = function(pos, node, puncher) local meta = minetest.get_meta(pos) swap_template(pos, "technic:template_connector") end }) -minetest.register_node("technic:template_connector",{ +minetest.register_node("technic:template_connector", { description = S("Template"), - tiles = {"technic_lv_cable.png"}, + tiles = { "technic_lv_cable.png" }, drop = "", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, not_in_creative_inventory = 1 }, on_destruct = template_on_destruct, after_dig_node = template_drops, - on_punch = function(pos,node,puncher) + on_punch = function(pos, node, puncher) swap_template(pos, "technic:template") end }) -minetest.register_craftitem("technic:template_replacer",{ +minetest.register_craftitem("technic:template_replacer", { description = S("Template (replacing)"), inventory_image = "technic_template_replacer.png", on_place = function(itemstack, placer, pointed_thing) @@ -801,12 +894,12 @@ minetest.register_craftitem("technic:template_replacer",{ end }) -minetest.register_tool("technic:template_tool",{ +minetest.register_tool("technic:template_tool", { description = S("Template Tool"), inventory_image = "technic_template_tool.png", on_use = function(itemstack, puncher, pointed_thing) local pos = pointed_thing.under - if pos == nil or (minetest.is_protected and minetest.is_protected(pos, puncher:get_player_name())) then + if pos == nil or minetest.is_protected and minetest.is_protected(pos, puncher:get_player_name()) then return nil end local node = minetest.get_node(pos) @@ -818,7 +911,7 @@ minetest.register_tool("technic:template_tool",{ else compress_templates(pos) end - + end }) @@ -831,40 +924,50 @@ local function get_template_nodes(pos) if connected == "" then return {} end local adj = minetest.deserialize(connected) local c = {} - for _,vect in ipairs(adj) do - local pos1=vector.add(pos,vect) - local nodename=minetest.get_node(pos1).name - if not(pos_in_list(c,pos1)) and nodename~="air" then - c[#(c)+1]=pos1 + for _, vect in ipairs(adj) do + local pos1 = vector.add(pos, vect) + local nodename = minetest.get_node(pos1).name + if not(pos_in_list(c, pos1)) and nodename ~= "air" then + c[#c + 1] = pos1 end end return c end local function template_motor_on(pos, node) - local dirs = {{x=0,y=1,z=0},{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}} - local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1]) + local dirs = { + { x = 0, y = 1, z = 0 }, { 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 } + } + local nnodepos = vector.add(pos, dirs[math.floor(node.param2 / 4) + 1]) local dir = minetest.facedir_to_dir(node.param2) - local nnode=minetest.get_node(nnodepos) + local nnode = minetest.get_node(nnodepos) local meta = minetest.get_meta(pos) if meta:get_int("last_moved") == minetest.get_gametime() then return end local owner = meta:get_string("owner") if nnode.name == "technic:template" then - local connected_nodes=get_template_nodes(nnodepos) - move_nodes_vect(connected_nodes,dir,pos,owner) + local connected_nodes = get_template_nodes(nnodepos) + move_nodes_vect(connected_nodes, dir, pos, owner) end minetest.get_meta(vector.add(pos, dir)):set_int("last_moved", minetest.get_gametime()) end -minetest.register_node("technic:template_motor",{ +minetest.register_node("technic:template_motor", { description = S("Template Motor"), - tiles = {"pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", - "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2}, + tiles = { + "pipeworks_filter_top.png^[transformR90", + "technic_lv_cable.png", + "technic_lv_cable.png", + "technic_lv_cable.png", + "technic_lv_cable.png", + "technic_lv_cable.png" + }, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2 }, paramtype2 = "facedir", - mesecons={effector={action_on=template_motor_on}}, + mesecons = { effector = { action_on = template_motor_on } }, after_place_node = function(pos, placer, itemstack) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name()) @@ -875,54 +978,54 @@ minetest.register_node("technic:template_motor",{ minetest.register_craft({ output = 'technic:frame_111111', recipe = { - {'', 'default:stick', ''}, - {'default:stick', 'technic:brass_ingot', 'default:stick'}, - {'', 'default:stick', ''}, + { '', 'default:stick', '' }, + { 'default:stick', 'technic:brass_ingot', 'default:stick' }, + { '', 'default:stick', '' }, } }) minetest.register_craft({ output = 'technic:frame_motor', recipe = { - {'', 'technic:frame_111111', ''}, - {'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable'}, - {'', 'technic:frame_111111', ''}, + { '', 'technic:frame_111111', '' }, + { 'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable' }, + { '', 'technic:frame_111111', '' }, } }) minetest.register_craft({ output = 'technic:template 10', recipe = { - {'', 'technic:brass_ingot', ''}, - {'technic:brass_ingot', 'default:mese_crystal', 'technic:brass_ingot'}, - {'', 'technic:brass_ingot', ''}, + { '', 'technic:brass_ingot', '' }, + { 'technic:brass_ingot', 'default:mese_crystal', 'technic:brass_ingot' }, + { '', 'technic:brass_ingot', '' }, } }) minetest.register_craft({ output = 'technic:template_replacer', - recipe = {{'technic:template'}} + recipe = { { 'technic:template' } } }) minetest.register_craft({ output = 'technic:template', - recipe = {{'technic:template_replacer'}} + recipe = { { 'technic:template_replacer' } } }) minetest.register_craft({ output = 'technic:template_motor', recipe = { - {'', 'technic:template', ''}, - {'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable'}, - {'', 'technic:template', ''}, + { '', 'technic:template', '' }, + { 'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable' }, + { '', 'technic:template', '' }, } }) minetest.register_craft({ output = 'technic:template_tool', recipe = { - {'', 'technic:template', ''}, - {'default:mese_crystal', 'default:stick', 'default:mese_crystal'}, - {'', 'default:stick', ''}, + { '', 'technic:template', '' }, + { 'default:mese_crystal', 'default:stick', 'default:mese_crystal' }, + { '', 'default:stick', '' }, } }) diff --git a/technic/machines/power_monitor.lua b/technic/machines/power_monitor.lua index 0d709da..7e8b850 100644 --- a/technic/machines/power_monitor.lua +++ b/technic/machines/power_monitor.lua @@ -35,12 +35,6 @@ minetest.register_node("technic:power_monitor",{ end, }) -if technic.config:get_bool("creative_mode") then - --Power distribution is not used in this mode, - --so the power monitor is inert and never needs to run. - return -end - minetest.register_abm({ nodenames = {"technic:power_monitor"}, label = "Machines: run power monitor", diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua index 70765bf..d645847 100644 --- a/technic/machines/switching_station.lua +++ b/technic/machines/switching_station.lua @@ -88,13 +88,6 @@ minetest.register_node("technic:switching_station",{ }, }) -if technic.config:get_bool("creative_mode") then - --Power distribution is not used in this mode, - --so the switching station is inert and none of the - --network processing is needed. - return -end - -------------------------------------------------- -- Functions to traverse the electrical network -------------------------------------------------- diff --git a/technic/textures/technic_hydro_turbine_side.png b/technic/textures/technic_hydro_turbine_side.png Binary files differnew file mode 100644 index 0000000..eeb5ab2 --- /dev/null +++ b/technic/textures/technic_hydro_turbine_side.png diff --git a/technic/textures/technic_hydro_turbine_top.png b/technic/textures/technic_hydro_turbine_top.png Binary files differnew file mode 100644 index 0000000..e04533f --- /dev/null +++ b/technic/textures/technic_hydro_turbine_top.png diff --git a/technic/textures/technic_hydro_turbine_top_active.png b/technic/textures/technic_hydro_turbine_top_active.png Binary files differnew file mode 100644 index 0000000..54ff90f --- /dev/null +++ b/technic/textures/technic_hydro_turbine_top_active.png diff --git a/unifiedbricks/init.lua b/unifiedbricks/init.lua index 83b91b8..5c675f9 100644 --- a/unifiedbricks/init.lua +++ b/unifiedbricks/init.lua @@ -111,6 +111,7 @@ minetest.register_node("unifiedbricks:brickblock", { minetest.override_item("default:brick", { palette = "unifieddyes_palette_extended.png", + airbrush_replacement_node = "unifiedbricks:brickblock", groups = {cracky = 3, ud_param2_colorable = 1}, }) @@ -131,6 +132,7 @@ minetest.register_node("unifiedbricks:clayblock", { minetest.override_item("default:clay", { palette = "unifieddyes_palette_extended.png", + airbrush_replacement_node = "unifiedbricks:clayblock", groups = {crumbly = 3, ud_param2_colorable = 1}, }) diff --git a/unifieddyes/API.md b/unifieddyes/API.md index 63fab69..c42d5aa 100644 --- a/unifieddyes/API.md +++ b/unifieddyes/API.md @@ -13,6 +13,7 @@ minetest.register_node("mymod:colored_node", { palette = "unifieddyes_palette_extended.png", groups = {snappy = 1, cracky = 2, ud_param2_colorable = 1} on_construct = unifieddyes.on_construct, + airbrush_replacement_node = "mymod:my_other_colored_node" }) ``` @@ -31,6 +32,8 @@ minetest.register_node("mymod:colored_node", { `on_construct`: see below. +`airbrush_replacement_node`: The node to swap in when the airbrush is used on this node. For example, you could `minetest.override_item()` on some default node to add this field, pointing to a colorable node of your own, so that when the default node is painted, it's replaced with yours in the new color. + #### Function calls **`unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)` @@ -42,10 +45,6 @@ These two are used to re-orient `wallmounted` nodes after placing. The former al This serves the same purpose as the `fix_rotation_nsew`, but is used to restrict the node's rotation after it's been hit with the screwdriver. -**`unifieddyes.select_node(pointed_thing)`** - -Just what it says on the tin. :-) This function returns a position and node definition of whatever is being pointed at. - **`unifieddyes.is_buildable_to(placer_name, ...)`** Again, another obvious one, returns whether or not the pointed node is `buildable_to` (can be overwritten by another node). diff --git a/unifieddyes/init.lua b/unifieddyes/init.lua index 39923a2..5b08a10 100644 --- a/unifieddyes/init.lua +++ b/unifieddyes/init.lua @@ -153,6 +153,9 @@ local default_dyes = { "yellow" } +unifieddyes.player_current_dye = {} +unifieddyes.player_selected_dye = {} + -- if a node with a palette is placed in the world, -- but the itemstack used to place it has no palette_index (color byte), -- create something appropriate to make it officially white. @@ -160,26 +163,29 @@ local default_dyes = { minetest.register_on_placenode( function(pos, newnode, placer, oldnode, itemstack, pointed_thing) local def = minetest.registered_items[newnode.name] - if not def or not def.palette then return false end - if string.find(itemstack:to_string(), "palette_index") then - minetest.swap_node(pos, {name = newnode.name, param2 = newnode.param2}) - return + + if not def + or not def.palette + or def.after_place_node then + return false end - local param2 = 0 - local color = 0 + if not string.find(itemstack:to_string(), "palette_index") then + local param2 = 0 + local color = 0 + + if def.palette == "unifieddyes_palette_extended.png" then + param2 = 240 + color = 240 + elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then + param2 = newnode.param2 % 8 + elseif def.palette ~= "unifieddyes_palette.png" then -- it's a split palette + param2 = newnode.param2 % 32 + end - if def.palette == "unifieddyes_palette_extended.png" then - param2 = 240 - color = 240 - elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then - param2 = newnode.param2 % 8 - elseif def.palette ~= "unifieddyes_palette.png" then -- it's a split palette - param2 = newnode.param2 % 32 + minetest.swap_node(pos, {name = newnode.name, param2 = param2}) + minetest.get_meta(pos):set_int("palette_index", color) end - - minetest.swap_node(pos, {name = newnode.name, param2 = param2}) - minetest.get_meta(pos):set_int("palette_index", color) end ) @@ -341,19 +347,6 @@ function unifieddyes.fix_after_screwdriver_nsew(pos, node, user, mode, new_param end end -function unifieddyes.select_node(pointed_thing) - local pos = pointed_thing.under - local node = minetest.get_node_or_nil(pos) - local def = node and minetest.registered_nodes[node.name] - - if not def or not def.buildable_to then - pos = pointed_thing.above - node = minetest.get_node_or_nil(pos) - def = node and minetest.registered_nodes[node.name] - end - return def and pos, def -end - function unifieddyes.is_buildable_to(placer_name, ...) for _, pos in ipairs({...}) do local node = minetest.get_node_or_nil(pos) @@ -640,6 +633,294 @@ function unifieddyes.getpaletteidx(color, palette_type) end end +-- punch-to-recolor using the airbrush + +function unifieddyes.on_airbrush(itemstack, player, pointed_thing) + local player_name = player:get_player_name() + local painting_with = nil + + if unifieddyes.player_current_dye[player_name] and minetest.registered_items[unifieddyes.player_current_dye[player_name]] then + painting_with = unifieddyes.player_current_dye[player_name] + end + + local pos = minetest.get_pointed_thing_position(pointed_thing) + if not pos or player:get_player_control().sneak then + unifieddyes.show_airbrush_form(player) + return + end + + if not painting_with then return end + + local node = minetest.get_node(pos) + local def = minetest.registered_items[node.name] + if not def then return end + + if minetest.is_protected(pos, player_name) then + minetest.chat_send_player(player_name, "Sorry, someone else owns that node.") + return + end + + if not def.palette then + minetest.chat_send_player(player_name, "That node can't be colored.") + return + end + + local palette = nil + local fdir = 0 + if def.palette == "unifieddyes_palette_extended.png" then + palette = "extended" + elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then + palette = "wallmounted" + fdir = node.param2 % 8 + elseif def.palette ~= "unifieddyes_palette.png" then + palette = true + fdir = node.param2 % 32 + end + + local idx, hue = unifieddyes.getpaletteidx(painting_with, palette) + + local inv = player:get_inventory() + if (not creative or not creative.is_enabled_for(player_name)) and not inv:contains_item("main", painting_with) then + local suff = "" + if not idx then + suff = " Besides, "..string.sub(painting_with, 5).." can't be applied to that node." + end + minetest.chat_send_player(player_name, "You're in survival mode, and you're out of "..string.sub(painting_with, 5).."."..suff) + return + end + + if not idx then + minetest.chat_send_player(player_name, string.sub(painting_with, 5).." can't be applied to that node.") + return + end + + local oldidx = node.param2 - fdir + if idx == oldidx then + minetest.chat_send_player(player_name, "That node is already "..string.sub(painting_with, 5)..".") + return + end + + local name = def.airbrush_replacement_node or node.name + + minetest.swap_node(pos, {name = name, param2 = fdir + idx}) + if not creative or not creative.is_enabled_for(player_name) then + inv:remove_item("main", painting_with) + return + end +end + +function unifieddyes.show_airbrush_form(player) + if not player then return end + local player_name = player:get_player_name() + local creative = creative and creative.is_enabled_for(player_name) + local inv = player:get_inventory() + + local base_form = "size[15,8.5]label[7,-0.25;Select a color:]" + local size="0.75,0.75;" + local hps=0.6 + local vps=1.3 + local vs=0.3 + + for v = 0, 6 do + local val = unifieddyes.VALS_EXTENDED[v+1] + + local sat = "" + local v2=(v/2) + + for hi, h in ipairs(unifieddyes.HUES_EXTENDED) do + local hue = h[1] + local hp=hi-0.5 + + local r = h[2] + local g = h[3] + local b = h[4] + + local factor = 40 + if v > 3 then + factor = 75 + v2 = (v-2) + end + + local r2 = math.max(math.min(r + (4-v)*factor, 255), 0) + local g2 = math.max(math.min(g + (4-v)*factor, 255), 0) + local b2 = math.max(math.min(b + (4-v)*factor, 255), 0) + + local color = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2) + local dye = "dye:"..val..hue..sat + local overlay = "" + if not creative and inv:contains_item("main", dye) then + overlay = "^unifieddyes_available_overlay.png" + end + + if dye == unifieddyes.player_selected_dye[player_name] then + overlay = "^unifieddyes_select_overlay.png" + end + + local colorize = minetest.formspec_escape("^[colorize:#"..color..":255") + base_form = base_form.."image_button[".. + (hp*hps)..","..(v2*vps+vs)..";".. + size.. + "unifieddyes_white_square.png"..colorize..overlay..";".. + val..hue..sat..";]".. + "tooltip["..val..hue..sat..";"..val..hue..sat.."]" + + end + + if v > 3 then + sat = "_s50" + v2 = (v-1.5) + + for hi, h in ipairs(unifieddyes.HUES_EXTENDED) do + local hue = h[1] + local hp=hi-0.5 + + local r = h[2] + local g = h[3] + local b = h[4] + + local factor = 75 + + local pr = 0.299 + local pg = 0.587 + local pb = 0.114 + + local r2 = math.max(math.min(r + (4-v)*factor, 255), 0) + local g2 = math.max(math.min(g + (4-v)*factor, 255), 0) + local b2 = math.max(math.min(b + (4-v)*factor, 255), 0) + + local p = math.sqrt(r2*r2*pr + g2*g2*pg + b2*b2*pb) + local r3 = math.floor(p+(r2-p)*0.5) + local g3 = math.floor(p+(g2-p)*0.5) + local b3 = math.floor(p+(b2-p)*0.5) + + local color = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3) + local dye = "dye:"..val..hue..sat + + local overlay = "" + if not creative and inv:contains_item("main", dye) then + overlay = "^unifieddyes_available_overlay.png" + end + + if dye == unifieddyes.player_selected_dye[player_name] then + overlay = "^unifieddyes_select_overlay.png" + end + + local colorize = minetest.formspec_escape("^[colorize:#"..color..":255") + + base_form = base_form.."image_button[".. + (hp*hps)..","..(v2*vps+vs)..";".. + size.. + "unifieddyes_white_square.png"..colorize..overlay..";".. + val..hue..sat..";]".. + "tooltip["..val..hue..sat..";"..val..hue..sat.."]" + end + end + end + + local v2=5 + for y = 0, 15 do + + local hp=(15-y)+0.5 + + local grey = string.format("%02x", y*17)..string.format("%02x", y*17)..string.format("%02x", y*17) + local grey2 = "grey_"..y + + if y == 0 then grey2 = "black" + elseif y == 4 then grey2 = "dark_grey" + elseif y == 8 then grey2 = "grey" + elseif y == 11 then grey2 = "light_grey" + elseif y == 15 then grey2 = "white" + end + + local dye = "dye:"..grey2 + + local overlay = "" + if not creative and inv:contains_item("main", dye) then + overlay = "^unifieddyes_available_overlay.png" + end + + if dye == unifieddyes.player_selected_dye[player_name] then + overlay = "^unifieddyes_select_overlay.png" + end + + local colorize = minetest.formspec_escape("^[colorize:#"..grey..":255") + base_form = base_form.."image_button[".. + (hp*hps)..","..(v2*vps+vs)..";".. + size.. + "unifieddyes_white_square.png"..colorize..overlay..";".. + grey2..";]tooltip["..grey2..";"..grey2.."]" + + end + + if not creative then + base_form = base_form.. + "image[10.3,"..(vps*5+vs)..";"..size.. + "unifieddyes_available_overlay.png]".. + "label[11.0,"..(vps*5.1+vs)..";Dyes on hand]".. + "image[12.5,"..(vps*5+vs)..";"..size.. + "unifieddyes_select_overlay.png]".. + "label[13.2,"..(vps*5.1+vs)..";Your selection]" + end + + base_form = base_form.. + "button_exit[11,8;2,1;cancel;Cancel]".. + "button_exit[13,8;2,1;accept;Accept]" + + if unifieddyes.player_selected_dye[player_name] then + base_form = base_form.. + "label[1,"..(7.5+vs)..";Selected dye: ".. + unifieddyes.player_selected_dye[player_name].."]" + end + + minetest.show_formspec(player_name, "unifieddyes:dye_select_form", base_form) +end + +minetest.register_tool("unifieddyes:airbrush", { + description = S("Dye Airbrush"), + inventory_image = "unifieddyes_airbrush.png", + use_texture_alpha = true, + tool_capabilities = { + full_punch_interval=0.1, + }, + range = 12, + on_use = unifieddyes.on_airbrush +}) + +minetest.register_craft( { + output = "unifieddyes:airbrush", + recipe = { + { "default:gold_ingot", "", "bucket:bucket_empty" }, + { "", "default:steel_ingot", "" }, + { "", "", "default:steel_ingot" } + }, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "unifieddyes:dye_select_form" then + local player_name = player:get_player_name() + local s1 = string.sub(minetest.serialize(fields), 11) + local s3 = string.sub(s1,1, string.find(s1, '"')-1) + if s3 == "cancel" then + unifieddyes.player_selected_dye[player_name] = nil + return + elseif s3 == "accept" and unifieddyes.player_selected_dye[player_name] then + local dye = unifieddyes.player_selected_dye[player_name] + unifieddyes.player_current_dye[player_name] = dye + unifieddyes.player_selected_dye[player_name] = nil + minetest.chat_send_player(player_name, "Selected "..string.sub(dye, 5).." for the airbrush.") + return + else + local inv = player:get_inventory() + local creative = creative and creative.is_enabled_for(player_name) + local dye = "dye:"..s3 + if minetest.registered_items[dye] and (creative or inv:contains_item("main", dye)) then + unifieddyes.player_selected_dye[player_name] = dye + unifieddyes.show_airbrush_form(player) + end + end + end +end) + -- build a table to convert from classic/89-color palette to extended palette -- the first five entries are for the old greyscale - white, light, grey, dark, black @@ -925,6 +1206,8 @@ minetest.register_craft( { }, }) +-- aliases + minetest.register_alias("dye:light_red", "dye:pink") minetest.register_alias("dye:medium_orange", "dye:brown") diff --git a/unifieddyes/textures/unifieddyes_airbrush.png b/unifieddyes/textures/unifieddyes_airbrush.png Binary files differnew file mode 100644 index 0000000..3cb768c --- /dev/null +++ b/unifieddyes/textures/unifieddyes_airbrush.png diff --git a/unifieddyes/textures/unifieddyes_available_overlay.png b/unifieddyes/textures/unifieddyes_available_overlay.png Binary files differnew file mode 100644 index 0000000..02c8cbd --- /dev/null +++ b/unifieddyes/textures/unifieddyes_available_overlay.png diff --git a/unifieddyes/textures/unifieddyes_select_overlay.png b/unifieddyes/textures/unifieddyes_select_overlay.png Binary files differnew file mode 100644 index 0000000..20beb95 --- /dev/null +++ b/unifieddyes/textures/unifieddyes_select_overlay.png diff --git a/unifieddyes/textures/unifieddyes_white_square.png b/unifieddyes/textures/unifieddyes_white_square.png Binary files differnew file mode 100644 index 0000000..28658b7 --- /dev/null +++ b/unifieddyes/textures/unifieddyes_white_square.png |