From 71e0b3a61ef3e03f282b72b5d05341e5ebdb7962 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sat, 25 Feb 2017 19:55:21 -0700 Subject: [PATCH] Initial commit This was split out of the venerable Castle mod, https://github.com/minetest-mods/castle, which has been maintained by a long line of distinguished modders. --- .gitattributes | 17 ++ .gitignore | 47 ++++++ LICENSE | 21 +++ README.txt | 16 ++ depends.txt | 3 + description.txt | 1 + init.lua | 157 +++++++++++++++++++ intllib.lua | 45 ++++++ locale/template.pot | 33 ++++ mod.conf | 1 + textures/LICENSE.txt | 20 +++ textures/crafting_bench_workbench_back.png | Bin 0 -> 383 bytes textures/crafting_bench_workbench_bottom.png | Bin 0 -> 369 bytes textures/crafting_bench_workbench_front.png | Bin 0 -> 391 bytes textures/crafting_bench_workbench_side.png | Bin 0 -> 342 bytes textures/crafting_bench_workbench_top.png | Bin 0 -> 336 bytes 16 files changed, 361 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.txt create mode 100644 depends.txt create mode 100644 description.txt create mode 100644 init.lua create mode 100644 intllib.lua create mode 100644 locale/template.pot create mode 100644 mod.conf create mode 100644 textures/LICENSE.txt create mode 100644 textures/crafting_bench_workbench_back.png create mode 100644 textures/crafting_bench_workbench_bottom.png create mode 100644 textures/crafting_bench_workbench_front.png create mode 100644 textures/crafting_bench_workbench_side.png create mode 100644 textures/crafting_bench_workbench_top.png diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd2946a --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..456d091 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Minetest Mods Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..c2dedda --- /dev/null +++ b/README.txt @@ -0,0 +1,16 @@ +=-=-=-=-=-=-=-=-=-= + +Crafting Bench +by: Philipbenr And DanDuncombe + +=-=-=-=-=-=-=-=-=-= + +Licence: MIT + +see: LICENSE + +=-=-=-=-=-=-=-=-=-= + +An auto-crafting bench + +=-=-=-=-=-=-=-=-=-= diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..9dd7d9b --- /dev/null +++ b/depends.txt @@ -0,0 +1,3 @@ +default +intllib? +hopper? diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..728c836 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +An auto-crafting bench diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a390f54 --- /dev/null +++ b/init.lua @@ -0,0 +1,157 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +minetest.register_alias("castle:workbench", "crafting_bench:workbench") + +minetest.register_node("crafting_bench:workbench",{ + description = S("Workbench"), + tiles = { + "crafting_bench_workbench_top.png", + "crafting_bench_workbench_bottom.png", + "crafting_bench_workbench_side.png", + "crafting_bench_workbench_side.png", + "crafting_bench_workbench_back.png", + "crafting_bench_workbench_front.png" + }, + paramtype2 = "facedir", + paramtype = "light", + groups = {choppy=2,oddly_breakable_by_hand=2,flammable=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "normal", + on_construct = function ( pos ) + local meta = minetest.get_meta( pos ) + meta:set_string( 'formspec', + 'size[10,10;]' .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + 'label[1,0;'..S('Source Material')..']' .. + 'list[context;src;1,1;2,4;]' .. + 'label[4,0;'..S('Recipe to Use')..']' .. + 'list[context;rec;4,1;3,3;]' .. + 'label[7.5,0;'..S('Craft Output')..']' .. + 'list[context;dst;8,1;1,4;]' .. + 'list[current_player;main;1,6;8,4;]' ) + meta:set_string( 'infotext', S('Workbench')) + local inv = meta:get_inventory() + inv:set_size( 'src', 2 * 4 ) + inv:set_size( 'rec', 3 * 3 ) + inv:set_size( 'dst', 1 * 4 ) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + minetest.log("action", S("@1 moves stuff in workbench at @2", player:get_player_name(), minetest.pos_to_string(pos))) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", S("@1 moves stuff to workbench at @2", player:get_player_name(), minetest.pos_to_string(pos))) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", S("@1 takes stuff from workbench at @2", player:get_player_name(), minetest.pos_to_string(pos))) + end, +}) +local get_recipe = function ( inv ) + local result, needed, input + needed = inv:get_list( 'rec' ) + + result, input = minetest.get_craft_result( { + method = 'normal', + width = 3, + items = needed + }) + + local totalneed = {} + + if result.item:is_empty() then + result = nil + else + result = result.item + for _, item in ipairs( needed ) do + if item ~= nil and not item:is_empty() and not inv:contains_item( 'src', item ) then + result = nil + break + end + if item ~= nil and not item:is_empty() then + if totalneed[item:get_name()] == nil then + totalneed[item:get_name()] = 1 + else + totalneed[item:get_name()] = totalneed[item:get_name()] + 1 + end + end + end + for name, number in pairs( totalneed ) do + local totallist = inv:get_list( 'src' ) + for i, srcitem in pairs( totallist ) do + if srcitem:get_name() == name then + local taken = srcitem:take_item( number ) + number = number - taken:get_count() + totallist[i] = srcitem + end + if number <= 0 then + break + end + end + if number > 0 then + result = nil + break + end + end + end + + return needed, input, result +end + +minetest.register_abm( { + nodenames = { 'crafting_bench:workbench' }, + interval = 5, + chance = 1, + action = function ( pos, node ) + local meta = minetest.get_meta( pos ) + local inv = meta:get_inventory() + local result, newinput, needed + if not inv:is_empty( 'src' ) then + -- Check for a valid recipe and sufficient resources to craft it + needed, newinput, result = get_recipe( inv ) + if result ~= nil and inv:room_for_item( 'dst', result ) then + inv:add_item( 'dst', result ) + for i, item in pairs( needed ) do + if item ~= nil and item ~= '' then + inv:remove_item( 'src', ItemStack( item ) ) + end + if newinput[i] ~= nil and not newinput[i]:is_empty() then + inv:add_item( 'src', newinput[i] ) + end + end + end + end + end +} ) + +local function has_locked_chest_privilege(meta, player) + if player:get_player_name() ~= meta:get_string("owner") then + return false + end + return true +end + +minetest.register_craft({ + output = "crafting_bench:workbench", + recipe = { + {"default:steel_ingot","default:steel_ingot","default:steel_ingot"}, + {"default:wood", "default:wood","default:steel_ingot"}, + {"default:tree", "default:tree","default:steel_ingot"}, + } +}) + +-- Hopper compatibility +if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then + hopper:add_container({ + {"top", "crafting_bench:workbench", "dst"}, + {"side", "crafting_bench:workbench", "src"}, + {"bottom", "crafting_bench:workbench", "src"}, + }) +end diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..4c87ae1 --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,33 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-02-25 19:50-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: init.lua:8 +msgid "Workbench" +msgstr "" + +#: init.lua:48 +msgid "@1 moves stuff in workbench at @2" +msgstr "" + +#: init.lua:51 +msgid "@1 moves stuff to workbench at @2" +msgstr "" + +#: init.lua:54 +msgid "@1 takes stuff from workbench at @2" +msgstr "" diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..9d51c80 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = crafting_bench diff --git a/textures/LICENSE.txt b/textures/LICENSE.txt new file mode 100644 index 0000000..bd7ca92 --- /dev/null +++ b/textures/LICENSE.txt @@ -0,0 +1,20 @@ +-------------------------------------------- + +License Textures: Philipner - CC-BY-SA 3.0 + +-crafting_bench_workbench_back.png +-crafting_bench_workbench_front.png +-crafting_bench_workbench_side.png +-crafting_bench_workbench_top.png + + +-------------------------------------------- + +16 px textures based on crafting_bench mod +original textures by Philipner + +License Textures: Napiophelios - CC-BY-SA 3.0 + +-crafting_bench_workbench_bottom.png + +-------------------------------------------- diff --git a/textures/crafting_bench_workbench_back.png b/textures/crafting_bench_workbench_back.png new file mode 100644 index 0000000000000000000000000000000000000000..174d941d1b5de14f0ce6883d312d59e9624849c0 GIT binary patch literal 383 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbMfzSWT$5`P^*&8|b{{o-U3d6}N2rUkWuD@U#Rk zxFxLdUGqWh>)-ZsGq2XwZ`wTbuFnHq28ZvB2z_QXN`ti zXSQEIn$xrM+4q|o6&e!L86O+yD6df0IJU_q`Hi^rl!*CCp8W;V8=aP&n_?!kyF^QMWmM*RmwgPUH#i4)Sw6p9`Dn$8hC}<_ b3m#?n&EWi(a6?fP=wt>@S3j3^P6fXrd-xV8S{7%>N%o ze7xPhJm+_-%U_|5X2EM)uKozk0_m<=xwZ&>I|`gw4GE>Cq!mbeU)4q$0o~b=H%;8L zNx*Y5a%N*`phUxCRWyRbreGVI=r){BgR6OTy@=srs*=!s+N>J^=6qMgff$FDVWfnH zH6`hYZJD-^aL5!}+y%b-tKo<>>hEHbYf2H2}7AOjX7 zzn7s483_4McE+kL4TfXja4fV_!V*(6p%EbKiYbjkx3xrQ{o~A^I!UE*pD25l`dDbE zM21ib4M_$lDU?^2nhe}0GN9g91uiv*`}MBOd9vpFSGA_TeDAL}|GM6vCHH0Jfw3iO P00000NkvXXu0mjf*Yv04 literal 0 HcmV?d00001 diff --git a/textures/crafting_bench_workbench_front.png b/textures/crafting_bench_workbench_front.png new file mode 100644 index 0000000000000000000000000000000000000000..27a1f1f8f42242cf70c0fe4f14a01d8a5fadb62d GIT binary patch literal 391 zcmV;20eJq2P)k4FVJn1RWI!QA9FrS}-RZ40&TFn1n`bSud-QKd_){4haLFj8hH? z022-dP((6>Z!?j6Je7h;q>@<<3Ir1j0u>JhBpM4P8w*nr6^?m13I+fT2?7%g0}>4d z91{f`6bMof6HyTqO+hhhRU2zn9Bf%9a9%5jb2X5AJfMqEr<7f%mR~zx7j6Im0IW$w zK~#9!J&)%SgCG!uPmd@dNbEhP_xk=Xmpdos`@^z3yA1GD01&T^t5Zxum7qK(CMH2K zu7e+K8z6v1AuxCDlL*GbXsHT`F@{e&f}N`7a(zsKV!34Qw=Bzc8`=QTbc>lrkRcDc z-|pQzBsw;{H1&OFqQoaWGLRBy>MBaK){-k))4i_P8Mq?C@KqE=MDzo{;`uW)MjHwd lrIh(Om!wcZ$>0B@$}ii}3URBpECK)k002ovPDHLkV1gLbf&Ksh literal 0 HcmV?d00001 diff --git a/textures/crafting_bench_workbench_side.png b/textures/crafting_bench_workbench_side.png new file mode 100644 index 0000000000000000000000000000000000000000..b6418acba534863a6092316bd6a55f11ff03a245 GIT binary patch literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}b%0NZtG&L0tSE;77o(4Zfw~Nj zzmuW2gFYuavj{JfpOZnLi&1WrfvPmOzq3(Jr2gs&_I#WSa$+14Yi#(qScG|)Mfq8! zg;-RixB~@60$hyxDlOSq7&+OPWQ18|L^whOgo6b|LIp*_ghYKE4Sk*T{hbX%Jk2Bg zY$jCO{CK|U0?--LJY5_^DsK7qh4URY;BkIxk(FJkdd~0ryTASsCtaKO=r^%w9z4$E zuqP%zIVDjzLifmLiOmlrxQ`xL5prLfh2w|OvrIX+ir);y4Wfx{3(U1mj&F&zcvHz- zbNTH*lX<*WQ=O|rX8Q5Oh8}H7W42rw`?Gn8(xIz2OM*V`jI~~V>)=Vzy*wWz@*`YS l7QM6+)ZQ}T&9Bng`}SJ0{|L-D{SD|s22WQ%mvv4FO#rYbY~TO@ literal 0 HcmV?d00001 diff --git a/textures/crafting_bench_workbench_top.png b/textures/crafting_bench_workbench_top.png new file mode 100644 index 0000000000000000000000000000000000000000..fef4827774d1a4cdec3c9b64036aa10c618768ae GIT binary patch literal 336 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}a)3{W>*@*iaZ*wVQZliUlJ@!v z^P7wlrDfx!WD=yLa-$4lC8gt~rIVy&ydCu8B_-n}rTv@?5~Zd4t85ZMQnJa?(!Ngm zF%lASAS9J2DH$s*oh&VzBqNh7E9>K6&|6`>$M(u&pmi%eT^vIyZn^eH<{ft6ah|`V zGwpN5$!lhwv+w<%GPRM3?Td2&zl!DcDF)k*woZ99(~2!?=Zbq$$sw2KzOnM1^tm+6 zSLF-K|8S=wO^;<9ds(=Zx>C11IJT)~;Uzv7v(EJnT=T`m-tle}|8&HvEHUVLVv&Nq z(c|k*uOD8NJzopr0J1oF`2YX_ literal 0 HcmV?d00001