From c497b36e606440631b8e149dbc8e64cfce1c7487 Mon Sep 17 00:00:00 2001 From: jp Date: Sun, 2 Aug 2015 02:00:29 +0200 Subject: [PATCH] Fix ndef error and prepare enchanting table --- crafts.lua | 9 +++++++ enchanting.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 1 + textures/bg.png | Bin 0 -> 231 bytes worktable.lua | 34 +++++++++++++------------ 5 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 enchanting.lua create mode 100644 textures/bg.png diff --git a/crafts.lua b/crafts.lua index c584885..9e26ac6 100644 --- a/crafts.lua +++ b/crafts.lua @@ -131,6 +131,15 @@ minetest.register_craft({ } }) +minetest.register_craft({ + output = "xdecor:enchantment_table", + recipe = { + {"", "default:book", ""}, + {"default:diamond", "default:obsidian", "default:diamond"}, + {"default:obsidian", "default:obsidian", "default:obsidian"} + } +}) + minetest.register_craft({ output = "xdecor:fence_wrought_iron 2", recipe = { diff --git a/enchanting.lua b/enchanting.lua new file mode 100644 index 0000000..119c02f --- /dev/null +++ b/enchanting.lua @@ -0,0 +1,65 @@ +local function enchconstruct(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", "size[8,7;]"..xdecor.fancy_gui.. + "label[0.65,-0.15;Enchant]".. + "image[0.4,0.2;2,2;default_book.png]".. + "list[current_name;tool;0.3,2;1,1;]".. + "list[current_name;mese;1.3,2;1,1;]".. + "image_button[2.5,0;5.3,1.1;bg.png;durable;Durable]".. + "image_button[2.5,1;5.3,1.1;bg.png;fast;Fast]".. + "image_button[2.5,2;5.3,1.1;bg.png;luck;Luck]".. + "list[current_player;main;0,3.3;8,4;]") + meta:set_string("infotext", "Enchantment Table") + + local inv = meta:get_inventory() + inv:set_size("tool", 1) + inv:set_size("mese", 1) +end + +local function enchdig(pos, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + if not inv:is_empty("tool") or not inv:is_empty("mese") then + return false + end + return true +end + +local function enchput(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + if listname == "mese" then + if stack:get_name() == "default:mese_crystal" then + return stack:get_count() + else + return 0 + end + end + if listname == "tool" then + local tname = stack:get_name() + local tdef = minetest.registered_tools[tname] + + if tdef then return 1 else return 0 end + end + + return stack:get_count() +end + +xdecor.register("enchantment_table", { + description = "Enchantment Table", + tiles = { + "xdecor_enchantment_top.png", + "xdecor_enchantment_bottom.png", + "xdecor_enchantment_side.png", + "xdecor_enchantment_side.png", + "xdecor_enchantment_side.png", + "xdecor_enchantment_side.png", + }, + groups = {cracky=1}, + sounds = xdecor.stone, + on_construct = enchconstruct, + can_dig = enchdig, + allow_metadata_inventory_put = enchput +}) diff --git a/init.lua b/init.lua index 95b37b2..0dbbf05 100644 --- a/init.lua +++ b/init.lua @@ -4,6 +4,7 @@ modpath = minetest.get_modpath("xdecor") dofile(modpath.."/handlers/nodeboxes.lua") dofile(modpath.."/handlers/registration.lua") dofile(modpath.."/crafts.lua") +--dofile(modpath.."/enchanting.lua") -- In development. dofile(modpath.."/hive.lua") dofile(modpath.."/itemframe.lua") dofile(modpath.."/mailbox.lua") diff --git a/textures/bg.png b/textures/bg.png new file mode 100644 index 0000000000000000000000000000000000000000..d025195530e5ed9775c22a43276f95b873d86107 GIT binary patch literal 231 zcmV++4N h7A2xX`X=8Wtv)QyBu23vaNz&|002ovPDHLkV1n