From 0721c30f0c0138427efc4deb051933b453e67f6c Mon Sep 17 00:00:00 2001 From: Evert Date: Thu, 5 Apr 2018 08:34:53 +0300 Subject: [PATCH] Rework the registration, add pattern textures --- tinkering/init.lua | 6 +- tinkering/register.lua | 107 +++++++++--------- .../textures/tinkering_axe_head_pattern.png | Bin 0 -> 689 bytes .../textures/tinkering_blank_pattern.png | Bin 0 -> 580 bytes .../tinkering_pickaxe_head_pattern.png | Bin 0 -> 674 bytes .../tinkering_shovel_head_pattern.png | Bin 0 -> 696 bytes .../tinkering_sword_blade_pattern.png | Bin 0 -> 752 bytes .../tinkering_tool_binding_pattern.png | Bin 0 -> 796 bytes .../textures/tinkering_tool_rod_pattern.png | Bin 0 -> 721 bytes 9 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 tinkering/textures/tinkering_axe_head_pattern.png create mode 100644 tinkering/textures/tinkering_blank_pattern.png create mode 100644 tinkering/textures/tinkering_pickaxe_head_pattern.png create mode 100644 tinkering/textures/tinkering_shovel_head_pattern.png create mode 100644 tinkering/textures/tinkering_sword_blade_pattern.png create mode 100644 tinkering/textures/tinkering_tool_binding_pattern.png create mode 100644 tinkering/textures/tinkering_tool_rod_pattern.png diff --git a/tinkering/init.lua b/tinkering/init.lua index fd5eaff..36207ed 100644 --- a/tinkering/init.lua +++ b/tinkering/init.lua @@ -12,12 +12,12 @@ tinkering.modpath = modpath -- Utilities dofile(modpath.."/util.lua") --- Pattern Library -dofile(modpath.."/pattern.lua") - -- Material Database dofile(modpath.."/materials.lua") +-- Pattern Library +dofile(modpath.."/pattern.lua") + -- Registration dofile(modpath.."/register.lua") diff --git a/tinkering/register.lua b/tinkering/register.lua index be7434b..bd47e24 100644 --- a/tinkering/register.lua +++ b/tinkering/register.lua @@ -1,6 +1,6 @@ -local tools = { +tinkering.tools = { pick = { - name = "Pickaxe", + description = "Pickaxe", groups = {"cracky"}, fleshy_decrement = 1, components = { @@ -15,7 +15,7 @@ local tools = { } }, axe = { - name = "Axe", + description = "Axe", groups = {"choppy"}, fleshy_increment = 1, components = { @@ -30,7 +30,7 @@ local tools = { } }, sword = { - name = "Sword", + description = "Sword", groups = {"snappy"}, fleshy_decrement = 0, components = { @@ -45,7 +45,7 @@ local tools = { } }, shovel = { - name = "Shovel", + description = "Shovel", groups = {"crumbly"}, fleshy_decrement = 1, components = { @@ -61,31 +61,57 @@ local tools = { }, } -local components = { - pickaxe_head = {description = "%s Pickaxe Head", materials = 1, image = tools.pick.textures.main}, - axe_head = {description = "%s Axe Head", materials = 1, image = tools.axe.textures.main}, - sword_blade = {description = "%s Sword Blade", materials = 1, image = tools.sword.textures.main}, - shovel_head = {description = "%s Shovel Head", materials = 1, image = tools.shovel.textures.main}, +tinkering.components = { + pickaxe_head = {description = "%s Pickaxe Head", materials = 1, image = tinkering.tools.pick.textures.main}, + axe_head = {description = "%s Axe Head", materials = 1, image = tinkering.tools.axe.textures.main}, + sword_blade = {description = "%s Sword Blade", materials = 1, image = tinkering.tools.sword.textures.main}, + shovel_head = {description = "%s Shovel Head", materials = 1, image = tinkering.tools.shovel.textures.main}, tool_rod = {description = "%s Tool Rod", materials = 1, image = "tinkering_tool_rod.png"}, tool_binding = {description = "%s Tool Binding", materials = 1, image = "tinkering_tool_binding.png"} } --- Register a tool component -function tinkering.register_component(data) +-- Create component for material +local function create_material_component(data) local desc = data.description local name = data.name - local mod = data.mod_name or "tinkering" + local mod = data.mod_name minetest.register_craftitem(mod..":"..name, { - description = desc, - groups = {tinker_component = 1}, + description = desc, + groups = {tinker_component = 1}, inventory_image = data.image }) end +-- Register a new tool component +function tinkering.register_component(name, data) + local mod = data.mod_name or "tinkering" + + if not tinkering.components[name] then + tinkering.components[name] = data + end + + -- Register components for all materials + for m, s in pairs(tinkering.materials) do + local component = m.."_"..name + + create_material_component({ + name = component, + mod_name = mod, + description = data.description:format(s.name), + image = tinkering.color_filter(data.image, s.color) + }) + + -- Make all components meltable + metal_melter.set_spec(name, metal_caster.spec.cast) + metal_melter.register_melt(mod..":"..component, m, name) + end +end + -- Register a tool type -- --- name = "Pickaxe", -- Name (description) of the tool +--data = { +-- description = "Pickaxe", -- Name (description) of the tool -- groups = {"cracky"}, -- Group caps that apply -- mod = "tinkering", -- The mod you're registering this tool from -- fleshy_decrement = 1, -- Amount removed from base damage group "fleshy". Negative value adds. @@ -99,9 +125,10 @@ end -- second = "tinkering_overlay_handle_pickaxe.png", -- Overlay (typically a handle) -- offset = "1,-1" -- Head's offset on the texture -- } +--} -- function tinkering.register_tool_type(name, data) - tools[name] = data + tinkering.tools[name] = data end -- Create groups based on materials @@ -175,7 +202,7 @@ function tinkering.compose_tool_texture(tooltype, main, rod) local mat_main = tinkering.materials[main] local mat_rod = tinkering.materials[rod] - local tool_data = tools[tooltype] + local tool_data = tinkering.tools[tooltype] local main_tex = tool_data.textures.main .."\\^[multiply\\:".. mat_main.color local rod_tex = tool_data.textures.second .."\\^[multiply\\:".. mat_rod.color @@ -203,16 +230,16 @@ function tinkering.get_tool_capabilities(tool_type, materials) if not main then return nil end -- Tool data - local tool_data = tools[tool_type] + local tool_data = tinkering.tools[tool_type] -- Name of the tool - local name = tool_data.name or "Tool" + local name = tool_data.description or "Tool" -- Group copies local groups = {} local dgroups = {} - -- Copy the groups + -- Copy the damage groups for g,v in pairs(main.modifier.damagegroups) do -- Decrement/increment damage group if tool wants it if tool_data[g.."_decrement"] then @@ -290,8 +317,8 @@ function tinkering.create_tool(tool_type, materials, want_tool, custom_name, ove -- TODO: Add texture as metadata (https://github.com/minetest/minetest/issues/5686) -- Not a valid tool type - if not tools[tool_type] then return false end - local tool_data = tools[tool_type] + if not tinkering.tools[tool_type] then return false end + local tool_data = tinkering.tools[tool_type] -- Check if the components are correct if not compare_components_required(tool_data.components, materials) then return false end @@ -337,43 +364,21 @@ end -- Register components and base tools local start_load = os.clock() -local tools = {"pick", "axe", "shovel", "sword"} local num_components = 0 local num_tools = 0 +-- Create base tools for m, s in pairs(tinkering.materials) do - for i, v in pairs(components) do - if v.materials == 1 then - local component = m.."_"..i - - tinkering.register_component({ - name = component, - description = v.description:format(s.name), - image = tinkering.color_filter(v.image, s.color) - }) - - -- Make all components meltable - metal_melter.register_melt("tinkering:"..component, m, i) - num_components = num_components + 1 - end - end - - for _,t in pairs(tools) do + for t,_ in pairs(tinkering.tools) do tinkering.create_tool(t, {main=m,binding="wood",rod="wood"}, false, nil, {groups={not_in_creative_inventory=1}}) num_tools = num_tools + 1 end end --- Add casts to metal_melter -for i,v in pairs(components) do - metal_melter.set_spec(i, metal_caster.spec.cast) - metal_caster.register_cast(i.."_cast", { - name = v.description:sub(4).." Cast", - mod = "tinkering", - result = i, - cost = metal_caster.spec.cast, - typenames = {i} - }) +-- Register tool components +for i, v in pairs(tinkering.components) do + tinkering.register_component(i, v) + num_components = num_components + 1 end print(("[tinkering] Added %d components and %d base tools in %f seconds."):format(num_components, num_tools, os.clock() - start_load)) diff --git a/tinkering/textures/tinkering_axe_head_pattern.png b/tinkering/textures/tinkering_axe_head_pattern.png new file mode 100644 index 0000000000000000000000000000000000000000..8d5d5aa4e67764304813a87c3173152f627dcad6 GIT binary patch literal 689 zcmV;i0#5yjP)q z0L1Tk%~1dV010qNS#tmY3ljhU3ljkVnw%H_000McNliru;sgZ+2`IO^mxBNR03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00I?BL_t(I%XO1YPg7A4 zhM#lKx&5Sx6{s{-pe$$%F~ps}!5FtD#-(meNZf;oTf+}v@5euJYa$zBiM6$bN`Mw_ zdwY6&#s%%grZCAQ=gef@nfINHdi!))(n$?~h~WDg#jFVsjRZvE*uai3*|ect%5j@H zcU|ClYASZvxWF4l4rd4a_<4q}^^7Nd6T7nmoE?z#4MY}1@YERfab*F3$c8NDQ$#kT z);yK!WOlL@@Gx1w_3L{QfU0L8)?Ice8JqtNHi`e;kr~p2`-jL18{0zNnql3{# zQ$G&Ssr1zZA~f3p+n)|%EiZy0)p~bE13Pqh+JkZ_7yD&kr-}h~J|C!Fe@MBMi);{-@){8pVLV#vp>&a0*##MPWWoxs+o!>&w>O zzS@1WA&=IlH&Of3y`r$XvJg|4SQI&$#{qZdl6-hok%!}{Cb?F-hqWV2BB5!udp8QF zwW3(aP%LC5pYvpM3FCVV`aKc}jj@qqF6(pJ31<-^s5LL*Z>gB0-VX2-C_hOz z=wWce$w_D2(PR1k-Iz|;kNEceDDGNsoH80YCNidc54H7dMY3sg>&Z^mg<|H^gMP$6 XGBob8s`}OK00000NkvXXu0mjfLPju3 literal 0 HcmV?d00001 diff --git a/tinkering/textures/tinkering_blank_pattern.png b/tinkering/textures/tinkering_blank_pattern.png new file mode 100644 index 0000000000000000000000000000000000000000..8d116b442d2788c2e5dbf7fee950b27b5bd73af2 GIT binary patch literal 580 zcmV-K0=xZ*P)q z0L1Tk%~1dV010qNS#tmY3ljhU3ljkVnw%H_000McNliru;sgZ+3IwiCsG|S?03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00F2;L_t(I%Y~CqZxb;P z#ecSE|0Pri2vMU#Q%)QaH$DU6vmo&;d#%KgB0@sahNvZNlk6I=%^}S;&2Gz+MzY8D z%zJNS_4(sr$PxoU2!SXvDC!7+D+7d3R#^q=o(!*kGBP1 zzg-d;Q;Q^$D!eW5wjhZFoP`k3>bC0pw;ceS&3XAO#o3%KHF>9_Iby^xJYQhaY|UWHBmiqYgUL;!2llT=jOI}j zcj26`*b)L_ZOL$ab2pkD-A&l|pmc!%^t!D|W4=l`J~^YmpCWPkXrbT(f>M>njn4k- zr;UE>!bAok1cJ>gTKvcPZ47>0ttA}wJGINsdB*1p$}-dnI_H^8msndOacr1On~gI@ z(d(|6O{PmufBxaayL}|m6ssk1Y!K@_PudX|^SohZFc@D~+k@U7!|4L8Kt%~xizR{& z%x3f3j+(<)&$lMxI6gV6x(-Jdl%;25Z5nCRmrwoB&g8)_yBQaX+E-t!9RC0dD8>|* SjL$Ft0000q z0L1Tk%~1dV010qNS#tmY3ljhU3ljkVnw%H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E@cM*00LA=L_t(I%XO2@ZqrZ@ zg}>{29mn}0Ep3`Vl@vCJ1&e~jqUsa$Vfu`$0I>lILa1sHk=vwB(^e!-Vmmh;7NLPC zFw$&hbTntq%u&ZjkHq&h03w3xY82}sfSn77ENe+R#}s|T<5rpfMV9>mT-{7*RtxIB z_Wfcc&fI2XX~LJYJ6x^T(sK=-Yv|v`)GJzLX@ch(uqlY(C}%-<|LHaWHjSxn=CNr^ zGMxYrgb};7lJfilo?igK^9v|PVI&jw+S~l-43>@SyBL$pV}Of(#H;5!${1&5wUg5u zagBq~MiYc%blzVu_)DbAFrrZ{s!lHg!1>MgGK{2AEpl}|!Dxqnig3oF2jwIffZJir!G2uj9aa~CDD+bq$n6#;nr@k%yJ z9^G(^wb>GAZAQ?INYgn^E~k0_xlhoI*erRx`EVscH=@^{&~B8~?J#C%%cs|$@cP{a z@zgGSFrARgX`JDB#=V literal 0 HcmV?d00001 diff --git a/tinkering/textures/tinkering_tool_binding_pattern.png b/tinkering/textures/tinkering_tool_binding_pattern.png new file mode 100644 index 0000000000000000000000000000000000000000..1812568d58d14c622e5fb84e2e4250968b5d470b GIT binary patch literal 796 zcmV+%1LOROP)q z0L1Tk%~1dV010qNS#tmY3ljhU3ljkVnw%H_000McNliru;sgZ+4=m=5^c(;H03B&m zSad^gZEa<4bN~PV002XBWnpw>WFU8GbZ8()Nlj2>E@cM*00MwXL_t(I%XO1oZyHw+ zhM%+N>=&3C8ZV!r#JQ*xMXE2NHo55^sQOzf^*2^ZQ&qm8YUMhK9S9CK9|;&11IyW+ zUIbHFRz{keSDJUE_nA?@{Pc~4z6L-SO$QyC3FIj>3^l=ua#U_LN#LZ+KYUSMApyF|Dqd}9*7tCYgQJb6St~G#MRX8iMJONS)Wv9l6`^xEC-99r>& zlG5wP0PF=WFOM&zT=Wz`t*F)8vmpS(X(HvKN2fc+4|4!0XN>`bp3}}$_VXTpvWkb zIiFx{Mz0@}Bq_%8G{^sps7HBq8)kpBkb0B{;MvoN)6P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