+++ /dev/null
-## Files related to minetest development cycle
-/*.patch
-# GNU Patch reject file
-*.rej
-
-## Editors and Development environments
-*~
-*.swp
-*.bak*
-*.orig
-# Vim
-*.vim
-# Kate
-.*.kate-swp
-.swp.*
-# Eclipse (LDT)
-.project
-.settings/
-.buildpath
-.metadata
-# Idea IDE
-.idea/*
+++ /dev/null
-unused_args = false
-allow_defined_top = true
-
-read_globals = {
- "minetest",
- "default",
-}
-+----------------------------------------------------------------------+
-| Copyright (c) 2015-2016 kilbith <jeanpatrick.guerrero@gmail.com> |
-| |
-| Code: GPL version 3 |
-| Textures: WTFPL (credits: Gambit) |
-| Sounds: |
-| - xdecor_enchanting.ogg - by Timbre - CC BY-SA-NC |
-| freesound.org/people/Timbre/sounds/221683/ |
-+----------------------------------------------------------------------+
-
-
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
--- /dev/null
+Enchanting for MineClone2
+--------------------------
+
+This is a rewrite of the mtg enchanting mod. Beta Version, more features coming soon.
+The textures look absolutely shit, but as far as I know I have to use the textures from Pixel Perfection so I dont get trouble with Mocrisoft. There is a version with original textures and sounds, but I can't publish that one. If you'd like to advice me how I can somehow do that anyway, please open an issue or contact me via email (eliasfleckenstein@web.de).
+++ /dev/null
-## Enchanting ##
-
-##### A mod adding a Minecraft-inspired Enchantment Table to Minetest. #####
-##### 3 enchants are proposed for the default tools, and 2 enchants for the armors from [3d_armor](https://github.com/stujones11/minetest-3d_armor). #####
-
-##### This mod is originating from [X-Decor](https://github.com/kilbith/xdecor). #####
-
-![Preview](https://lut.im/oWfKNfxAA4/n9jqwFpJOdUdo8yT.png)
-![Preview2](http://i.imgur.com/X9MkQzV.png)
--- /dev/null
+local book_animations = {["close"] = 1, ["opening"] = 2, ["open"] = 3, ["closing"] = 4}
+local book_animation_steps = {0, 640, 680, 700, 740}
+local book_animation_speed = 40
+
+function mcl_enchanting.schedule_book_animation(self, anim)
+ self.scheduled_anim = {timer = self.anim_length, anim = anim}
+end
+
+function mcl_enchanting.set_book_animation(self, anim)
+ local anim_index = book_animations[anim]
+ local start, stop = book_animation_steps[anim_index], book_animation_steps[anim_index + 1]
+ self.object:set_animation({x = start, y = stop}, book_animation_speed)
+ self.scheduled_anim = nil
+ self.anim_length = (stop - start) / 40
+end
+
+function mcl_enchanting.check_animation_schedule(self, dtime)
+ local schedanim = self.scheduled_anim
+ if schedanim then
+ schedanim.timer = schedanim.timer - dtime
+ if schedanim.timer <= 0 then
+ mcl_enchanting.set_book_animation(self, schedanim.anim)local pos1=self.object:get_pos()
+ end
+ end
+end
+
+function mcl_enchanting.look_at(self, pos2)
+ local pos1 = self.object:get_pos()
+ local vec = vector.subtract(pos1, pos2)
+ local yaw = math.atan(vec.z / vec.x) - math.pi/2
+ yaw = yaw + (pos1.x >= pos2.x and math.pi or 0)
+ self.object:set_yaw(yaw + math.pi)
+end
+
+function mcl_enchanting.check_book(pos)
+ obj_pos = vector.add(pos, mcl_enchanting.book_offset)
+ for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.1)) do
+ local luaentity = obj:get_luaentity()
+ if luaentity and luaentity.name == "mcl_enchanting:book" then
+ if minetest.get_node(pos).name ~= "mcl_enchanting:table" then
+ obj:remove()
+ end
+ return
+ end
+ end
+ minetest.add_entity(obj_pos, "mcl_enchanting:book")
+end
+
+minetest.register_entity("mcl_enchanting:book", {
+ initial_properties = {
+ visual = "mesh",
+ mesh = "mcl_enchanting_book.b3d",
+ visual_size = {x = 12.5, y = 12.5},
+ collisionbox = {0, 0, 0},
+ physical = false,
+ textures = {"mcl_enchanting_book_entity.png"},
+ },
+ player_near = false,
+ on_activate = function(self)
+ self.object:set_armor_groups({immortal = 1})
+ mcl_enchanting.set_book_animation(self, "close")
+ mcl_enchanting.check_book(vector.subtract(self.object:get_pos(), mcl_enchanting.book_offset))
+ end,
+ on_step = function(self, dtime)
+ local old_player_near = self.player_near
+ local player_near = false
+ local player
+ for _, obj in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 2.5)) do
+ if obj:is_player() then
+ player_near = true
+ player = obj
+ end
+ end
+ if player_near and not old_player_near then
+ mcl_enchanting.set_book_animation(self, "opening")
+ mcl_enchanting.schedule_book_animation(self, "open")
+ elseif old_player_near and not player_near then
+ mcl_enchanting.set_book_animation(self, "closing")
+ mcl_enchanting.schedule_book_animation(self, "close")
+ end
+ if player then
+ mcl_enchanting.look_at(self, player:get_pos())
+ end
+ self.player_near = player_near
+ mcl_enchanting.check_animation_schedule(self, dtime)
+ end,
+})
--- /dev/null
+local bookshelf_positions = {{x = 1}, {x = -1}, {z = 1}, {z = -1}}
+
+for _, p in pairs(bookshelf_positions) do
+ for _, d in pairs({"x", "y", "z"}) do
+ p[d] = p[d] or 0
+ end
+end
+
+minetest.register_abm({
+ name = "Enchanting table bookshelf particles",
+ interval = 0.1,
+ chance = 1,
+ nodenames = "mcl_books:bookshelf",
+ action = function(pos)
+ for _, relative_pos in pairs(bookshelf_positions) do
+ if minetest.get_node(vector.add(pos, vector.multiply(relative_pos, 2))).name == "mcl_enchanting:table" and minetest.get_node(vector.add(pos, relative_pos, 2)).name == "air" then
+ minetest.add_particle({
+ pos = pos,
+ velocity = vector.subtract(relative_pos, vector.new(0, -2, 0)),
+ acceleration = {x = 0, y = -2, z = 0},
+ expirationtime = 2,
+ size = 2,
+ texture = "mcl_enchanting_glyph_" .. math.random(18) .. ".png"
+ })
+ end
+ end
+ end
+})
+++ /dev/null
-default
-3d_armor?
-xdecor?
+++ /dev/null
-A mod adding a Minecraft-inspired Enchantment Table to Minetest.
--- /dev/null
+local C = minetest.get_color_escape_sequence
+
+local enchanting_table_formspec = ""
+ .. "size[9.07,8.6;]"
+ .. "formspec_version[3]"
+ .. "label[0,0;" .. minetest.formspec_escape(minetest.colorize("#313131", "Enchant")) .. "]"
+ .. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1)
+ .. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]"
+ .. "list[context;lapis;1.1,2.4;1,1;]"
+ .. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1)
+ .. "list[context;tool;0.2,2.4;1,1;]"
+ .. "label[0,4;" .. minetest.formspec_escape(minetest.colorize("#313131", "Inventory")) .. "]"
+ .. mcl_formspec.get_itemslot_bg(0,4.5,9,3)
+ .. mcl_formspec.get_itemslot_bg(0,7.74,9,1)
+ .. "list[current_player;main;0,4.5;9,3;9]"
+ .. "listring[]"
+ .. "list[current_player;main;0,7.74;9,1;]"
+ .. "real_coordinates[true]"
+ .. "image[3.15,0.6;7.6,4.1;mcl_enchanting_button_background.png]"
+
+
+local roman_numbers = {"I", "II", "III", "IV", "V"}
+
+function mcl_enchanting.get_enchantment_description(enchantment, level)
+ local enchantment_def = mcl_enchanting.enchantments[enchantment]
+ return enchantment_def.name .. " " .. (enchantment_def.max_level == 1 and "" or roman_numbers[level])
+end
+
+function mcl_enchanting.update_formspec(pos)
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ local full_tool_name = inv:get_stack("tool", 1):get_name()
+ local shortened_tool_name = mcl_enchanting.all_tools[full_tool_name]
+ local supported_enchantments = (shortened_tool_name and mcl_enchanting.tools[shortened_tool_name].enchantments or {})
+ local sup_ench = false
+ local formspec = enchanting_table_formspec
+ local e_list = minetest.deserialize(meta:get_string("enchantments"))
+ local y = 0.65
+ for i, e in pairs(e_list) do
+ local enchantment_supported = table.indexof(supported_enchantments, e.enchantment) ~= -1
+ sup_ench = sup_ench or enchantment_supported
+ local enough_lapis = inv:contains_item("lapis", ItemStack(mcl_enchanting.lapis_itemstring .. " " .. e.cost))
+ local ending = (enough_lapis and enchantment_supported and "" or "_off")
+ local hover_ending = (enough_lapis and enchantment_supported and "_hovered" or "_off")
+ formspec = formspec
+ .. "container[3.2," .. y .. "]"
+ .. (enchantment_supported and "tooltip[button_" .. i .. ";" .. C("#818181") .. mcl_enchanting.get_enchantment_description(e.enchantment, e.level) .. " " .. C("#FFFFFF") .. " . . . ?\n\n" .. C(enough_lapis and "#818181" or "#FC5454") .. e.cost .. " Lapis Lazuli" .. "]" or "")
+ .. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]"
+ .. "button[0,0;7.5,1.3;button_" .. i .. ";]"
+ .. (enchantment_supported and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "")
+ .. (enchantment_supported and e.glyphs or "")
+ .. "container_end[]"
+ y = y + 1.35
+ end
+ formspec = formspec
+ .. "image[" .. (sup_ench and 0.58 or 1.15) .. ",1.2;" .. (sup_ench and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (sup_ench and "open" or "closed") .. ".png]"
+ meta:set_string("formspec", formspec)
+end
+
+function mcl_enchanting.progress_formspec_input(pos, _, fields, player)
+ if fields.quit then
+ return
+ end
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ local e_list = minetest.deserialize(meta:get_string("enchantments"))
+ local button_pressed
+ for i = 1, 3 do
+ if fields["button_" .. i] then
+ button_pressed = i
+ end
+ end
+ if not button_pressed then return end
+ local e = e_list[button_pressed]
+ local lapis_cost = ItemStack(mcl_enchanting.lapis_itemstring .. " " .. e.cost)
+ if not inv:contains_item("lapis", lapis_cost) then return end
+ local tool_stack = inv:get_stack("tool", 1)
+ local full_tool_name = tool_stack:get_name()
+ local shortened_tool_name = mcl_enchanting.all_tools[full_tool_name]
+ if not shortened_tool_name then return end
+ if table.indexof(mcl_enchanting.tools[shortened_tool_name].enchantments, e.enchantment) == -1 then return end
+ local wear = tool_stack:get_wear()
+ inv:remove_item("lapis", lapis_cost)
+ local enchanted_tool_stack = ItemStack(full_tool_name .. "_enchanted_" .. e.enchantment .. "_" .. e.level)
+ enchanted_tool_stack:add_wear(tool_stack:get_wear())
+ inv:set_stack("tool", 1, enchanted_tool_stack)
+ minetest.sound_play("mcl_enchanting_enchant", {to_player = player:get_player_name(), gain = 5.0})
+ mcl_enchanting.add_enchantments(pos)
+end
+
+function mcl_enchanting.add_enchantments(pos)
+ local meta = minetest.get_meta(pos)
+ local e_list = {}
+ for i = 1, 3 do
+ local e = {}
+ e.cost = math.random(mcl_enchanting.max_cost)
+ e.enchantment = mcl_enchanting.enchantment_name_list[math.random(#mcl_enchanting.enchantment_name_list)]
+ local max_level = mcl_enchanting.enchantments[e.enchantment].max_level
+ e.level = max_level + 1 - math.ceil(math.pow(math.random(math.pow(max_level, mcl_enchanting.level_rarity_grade)), 1 / mcl_enchanting.level_rarity_grade))
+ e.glyphs = ""
+ local x = 1.3
+ for i = 1, 9 do
+ e.glyphs = e.glyphs .. "image[".. x .. ",0.1;0.5,0.5;mcl_enchanting_glyph_" .. math.random(18) .. ".png^[colorize:#675D49:255]"
+ x = x + 0.6
+ end
+ e_list[i] = e
+ end
+ meta:set_string("enchantments", minetest.serialize(e_list))
+ mcl_enchanting.update_formspec(pos)
+end
+
+function mcl_enchanting.drop_inventory(pos)
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ for _, listname in pairs({"tool", "lapis"}) do
+ local stack = inv:get_stack(listname, 1)
+ if not stack:is_empty() then
+ minetest.add_item(vector.add(pos, {x = math.random(0, 10) / 10 - 0.5, y = 0, z = math.random(0, 10) / 10 - 0.5}), stack)
+ end
+ end
+end
+
+function mcl_enchanting.init_table(pos)
+ local inv = minetest.get_meta(pos):get_inventory()
+ inv:set_size("tool", 1)
+ inv:set_size("lapis", 1)
+ mcl_enchanting.add_enchantments(pos)
+ minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
+end
+
+-- Ugly hack to run enchanted tool registration before HELP/tt is run
+table.insert(minetest.registered_on_mods_loaded, 1, function()
+ for toolname, tooldef in pairs(mcl_enchanting.tools) do
+ for _, material in pairs(tooldef.materials) do
+ local full_name = toolname .. ((material == "") and "" or "_" .. material)
+ local old_def = minetest.registered_tools[full_name]
+ if not old_def then break end
+ mcl_enchanting.all_tools[full_name] = toolname
+ for _, enchantment in pairs(tooldef.enchantments) do
+ local enchantment_def = mcl_enchanting.enchantments[enchantment]
+ for lvl = 1, enchantment_def.max_level do
+ local new_def = table.copy(old_def)
+ new_def.description = minetest.colorize("#54FCFC", old_def.description) .. "\n" .. mcl_enchanting.get_enchantment_description(enchantment, lvl)
+ new_def.inventory_image = old_def.inventory_image .. "^[colorize:violet:50"
+ new_def.groups.not_in_creative_inventory = 1
+ new_def.texture = old_def.texture or full_name:gsub("%:", "_")
+ new_def._original_tool = full_name
+ enchantment_def.create_itemdef(new_def, lvl)
+ minetest.register_tool(":" .. full_name .. "_enchanted_" .. enchantment .. "_" .. lvl, new_def)
+ end
+ end
+ end
+ end
+end)
-screwdriver = screwdriver or {}
-local ceil, abs, random = math.ceil, math.abs, math.random
-
--- Cost in Mese crystal(s) for enchanting.
-local mese_cost = 1
-
--- Force of the enchantments.
-local enchanting = {
- uses = 1.2, -- Durability
- times = 0.1, -- Efficiency
- damages = 1, -- Sharpness
- strength = 1.2, -- Armor strength (3d_armor only)
- speed = 0.2, -- Player speed (3d_armor only)
- jump = 0.2 -- Player jumping (3d_armor only)
-}
-
-local function cap(S) return S:gsub("^%l", string.upper) end
-local function to_percent(orig_value, final_value)
- return abs(ceil(((final_value - orig_value) / orig_value) * 100))
-end
-
-function enchanting:get_tooltip(enchant, orig_caps, fleshy)
- local bonus = {durable=0, efficiency=0, damages=0}
- if orig_caps then
- bonus.durable = to_percent(orig_caps.uses, orig_caps.uses * enchanting.uses)
- local sum_caps_times = 0
- for i=1, #orig_caps.times do
- sum_caps_times = sum_caps_times + orig_caps.times[i]
- end
- local average_caps_time = sum_caps_times / #orig_caps.times
- bonus.efficiency = to_percent(average_caps_time, average_caps_time - enchanting.times)
- end
- if fleshy then
- bonus.damages = to_percent(fleshy, fleshy + enchanting.damages)
- end
-
- local specs = { -- not finished, to complete
- durable = {"#00baff", " (+"..bonus.durable.."%)"},
- fast = {"#74ff49", " (+"..bonus.efficiency.."%)"},
- sharp = {"#ffff00", " (+"..bonus.damages.."%)"},
- strong = {"#ff3d3d", ""},
- speed = {"#fd5eff", ""}
- }
- return minetest.colorize and
- minetest.colorize(specs[enchant][1],
- "\n"..cap(enchant)..specs[enchant][2]) or
- "\n"..cap(enchant)..specs[enchant][2]
-end
-
-
-function enchanting.formspec(pos, num)
- local meta = minetest.get_meta(pos)
- local formspec = [[ size[9,9;]
- bgcolor[#080808BB;true]
- background[0,0;9,9;ench_ui.png]
- list[context;tool;0.9,2.9;1,1;]
- list[context;mese;2,2.9;1,1;]
- list[current_player;main;0.5,4.5;8,4;]
- image[2,2.9;1,1;mese_layout.png]
- tooltip[sharp;Your weapon inflicts more damages]
- tooltip[durable;Your tool last longer]
- tooltip[fast;Your tool digs faster]
- tooltip[strong;Your armor is more resistant]
- tooltip[speed;Your speed is increased] ]]
- ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
-
- local enchant_buttons = {
- [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
- image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]],
- "image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]",
- "image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]",
- [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
- image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
- }
-
- formspec = formspec..(enchant_buttons[num] or "")
- meta:set_string("formspec", formspec)
-end
-
-function enchanting.on_put(pos, listname, _, stack)
- if listname == "tool" then
- local stackname = stack:get_name()
- local tool_groups = {
- "axe, pick, shovel",
- "chestplate, leggings, helmet",
- "sword", "boots"
- }
-
- for idx, tools in pairs(tool_groups) do
- if tools:find(stackname:match(":(%w+)")) then
- enchanting.formspec(pos, idx)
+local default_tool_enchantments = {"efficiency", "unbreaking", "silk_touch"}
+local default_tool_materials = {"wood", "stone", "iron", "gold", "diamond"}
+local default_tool = {enchantments = default_tool_enchantments, materials = default_tool_materials}
+local default_armor_enchantments = {"unbreaking"}--, "protection"}
+local default_armor_materials = {"leather", "chain", "iron", "gold", "diamond"}
+local default_armor = {enchantments = default_armor_enchantments, materials = default_armor_materials}
+
+mcl_enchanting = {
+ lapis_itemstring = "mcl_dye:blue",
+ max_cost = 24,
+ level_rarity_grade = 3,
+ enchantment_name_list = {},
+ all_tools = {},
+ book_offset = vector.new(0, 0.75, 0),
+ enchantments = {
+ silk_touch = {
+ name = "Silk Touch",
+ max_level = 1,
+ create_itemdef = function(def)
+ def.tool_capabilities.max_drop_level = -5000
+ def._silk_touch = true
end
- end
- end
-end
-
-function enchanting.fields(pos, _, fields, sender)
- if not next(fields) or fields.quit then
- return
- end
- local inv = minetest.get_meta(pos):get_inventory()
- local tool = inv:get_stack("tool", 1)
- local mese = inv:get_stack("mese", 1)
- local orig_wear = tool:get_wear()
- local mod, name = tool:get_name():match("(.*):(.*)")
- local enchanted_tool = (mod or "")..":enchanted_"..(name or "").."_"..next(fields)
-
- if mese:get_count() >= mese_cost and minetest.registered_tools[enchanted_tool] then
- minetest.sound_play("xdecor_enchanting", {to_player=sender:get_player_name(), gain=0.8})
- tool:replace(enchanted_tool)
- tool:add_wear(orig_wear)
- mese:take_item(mese_cost)
- inv:set_stack("mese", 1, mese)
- inv:set_stack("tool", 1, tool)
- end
-end
-
-function enchanting.dig(pos)
- local inv = minetest.get_meta(pos):get_inventory()
- return inv:is_empty("tool") and inv:is_empty("mese")
-end
-
-local function allowed(tool)
- if not tool then return false end
- for item in pairs(minetest.registered_tools) do
- if item:find("enchanted_"..tool) then return true end
- end
- return false
-end
-
-function enchanting.put(_, listname, _, stack)
- local item = stack:get_name():match("[^:]+$")
- if listname == "mese" and item == "mese_crystal" then
- return stack:get_count()
- elseif listname == "tool" and allowed(item) then
- return 1
- end
- return 0
-end
-
-function enchanting.on_take(pos, listname)
- if listname == "tool" then enchanting.formspec(pos, nil) end
-end
-
-function enchanting.construct(pos)
- local meta = minetest.get_meta(pos)
- meta:set_string("infotext", "Enchantment Table")
- enchanting.formspec(pos, nil)
-
- local inv = meta:get_inventory()
- inv:set_size("tool", 1)
- inv:set_size("mese", 1)
-
- minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open")
- local timer = minetest.get_node_timer(pos)
- timer:start(5.0)
-end
-
-function enchanting.destruct(pos)
- for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do
- if obj and obj:get_luaentity() and
- obj:get_luaentity().name == "xdecor:book_open" then
- obj:remove() break
- end
- end
-end
-
-function enchanting.timer(pos)
- local num = #minetest.get_objects_inside_radius(pos, 0.9)
- if num == 0 then
- minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open")
- end
-
- local minp = {x=pos.x-2, y=pos.y, z=pos.z-2}
- local maxp = {x=pos.x+2, y=pos.y+1, z=pos.z+2}
- local bookshelves = minetest.find_nodes_in_area(minp, maxp, "default:bookshelf")
- if #bookshelves == 0 then return true end
-
- local bookshelf_pos = bookshelves[random(1, #bookshelves)]
- local x = pos.x - bookshelf_pos.x
- local y = bookshelf_pos.y - pos.y
- local z = pos.z - bookshelf_pos.z
-
- if tostring(x..z):find(2) then
- minetest.add_particle({
- pos = bookshelf_pos,
- velocity = {x=x, y=2-y, z=z},
- acceleration = {x=0, y=-2.2, z=0},
- expirationtime = 1,
- size = 2,
- texture = "xdecor_glyph"..random(1,18)..".png"
- })
- end
- return true
-end
-
-minetest.register_node(":xdecor:enchantment_table", {
- description = "Enchantment Table",
- paramtype = "light",
- paramtype2 = "facedir",
- tiles = {"enchtable_top.png", "enchtable_bottom.png",
- "enchtable_side.png", "enchtable_side.png",
- "enchtable_side.png", "enchtable_side.png"},
- groups = {cracky=1, level=1},
- sounds = default.node_sound_stone_defaults(),
- on_rotate = screwdriver.rotate_simple,
- can_dig = enchanting.dig,
- on_timer = enchanting.timer,
- on_construct = enchanting.construct,
- on_destruct = enchanting.destruct,
- on_receive_fields = enchanting.fields,
- on_metadata_inventory_put = enchanting.on_put,
- on_metadata_inventory_take = enchanting.on_take,
- allow_metadata_inventory_put = enchanting.put,
- allow_metadata_inventory_move = function() return 0 end
-})
-
-minetest.register_entity(":xdecor:book_open", {
- visual = "sprite",
- visual_size = {x=0.75, y=0.75},
- collisionbox = {0},
- physical = false,
- textures = {"book_open.png"},
- on_activate = function(self)
- local pos = self.object:getpos()
- local pos_under = {x=pos.x, y=pos.y-1, z=pos.z}
-
- if minetest.get_node(pos_under).name ~= "xdecor:enchantment_table" then
- self.object:remove()
- end
- end
-})
-
-minetest.register_craft({
- output = "xdecor:enchantment_table",
- recipe = {
- {"", "default:book", ""},
- {"default:diamond", "default:obsidian", "default:diamond"},
- {"default:obsidian", "default:obsidian", "default:obsidian"}
- }
-})
-
-function enchanting:register_tools(mod, def)
- for tool in pairs(def.tools) do
- for material in def.materials:gmatch("[%w_]+") do
- for enchant in def.tools[tool].enchants:gmatch("[%w_]+") do
- local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
- if not original_tool then break end
-
- if original_tool.tool_capabilities then
- local original_damage_groups = original_tool.tool_capabilities.damage_groups
- local original_groupcaps = original_tool.tool_capabilities.groupcaps
- local groupcaps = table.copy(original_groupcaps)
- local fleshy = original_damage_groups.fleshy
- local full_punch_interval = original_tool.tool_capabilities.full_punch_interval
- local max_drop_level = original_tool.tool_capabilities.max_drop_level
- local group = next(original_groupcaps)
-
- if enchant == "durable" then
- groupcaps[group].uses = ceil(original_groupcaps[group].uses * enchanting.uses)
- elseif enchant == "fast" then
- for i, time in pairs(original_groupcaps[group].times) do
- groupcaps[group].times[i] = time - enchanting.times
+ },
+ sharpness = {
+ name = "Sharpness",
+ max_level = 5,
+ create_itemdef = function(def, level)
+ def.tool_capabilities.damage_groups.fleshy = def.tool_capabilities.damage_groups.fleshy + (level + 1) / 2
+ end,
+ },
+ efficiency = {
+ name = "Efficiency",
+ max_level = 5,
+ create_itemdef = function(def, level)
+ local groupcaps = def.tool_capabilities.groupcaps
+ for _, groupcap in pairs(groupcaps) do
+ for i, t in pairs(groupcap.times) do
+ local m = 1 / t
+ m = m + math.pow(level, 2) + 1
+ groupcap.times[i] = 1 / m
+ end
end
- elseif enchant == "sharp" then
- fleshy = fleshy + enchanting.damages
- end
-
- minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
- description = "Enchanted "..cap(material).." "..cap(tool)..
- self:get_tooltip(enchant, original_groupcaps[group], fleshy),
- inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
- wield_image = original_tool.wield_image,
- groups = {not_in_creative_inventory=1},
- tool_capabilities = {
- groupcaps = groupcaps, damage_groups = {fleshy = fleshy},
- full_punch_interval = full_punch_interval, max_drop_level = max_drop_level
- }
- })
- end
-
- if mod == "3d_armor" then
- local original_armor_groups = original_tool.groups
- local armorcaps = {}
- armorcaps.not_in_creative_inventory = 1
-
- for armor_group, value in pairs(original_armor_groups) do
- if enchant == "strong" then
- armorcaps[armor_group] = ceil(value * enchanting.strength)
- elseif enchant == "speed" then
- armorcaps[armor_group] = value
- armorcaps.physics_speed = enchanting.speed
- armorcaps.physics_jump = enchanting.jump
+ end,
+ },
+ unbreaking = {
+ name = "Unbreaking",
+ max_level = 3,
+ create_itemdef = function(def, level)
+ local toolcaps = def.tool_capabilities
+ local armor_uses = def.groups.mcl_armor_uses
+ local factor = 0.5
+ if toolcaps then
+ local groupcaps = toolcaps.groupcaps
+ for _, groupcap in pairs(groupcaps) do
+ groupcap.uses = math.floor(groupcap.uses * (1 + level))
+ end
+ def.tool_capabilities.punch_attack_uses = math.floor(def.tool_capabilities.punch_attack_uses * (1 + level))
+ elseif armor_uses then
+ def.groups.mcl_armor_uses = math.floor(armor_uses / (0.6 + (0.4 / (level + 1))))
end
end
-
- minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
- description = "Enchanted "..cap(material).." "..cap(tool)..
- self:get_tooltip(enchant),
- inventory_image = original_tool.inventory_image,
- texture = "3d_armor_"..tool.."_"..material,
- wield_image = original_tool.wield_image,
- groups = armorcaps,
- wear = 0
- })
- end
- end
- end
- end
-end
-
-enchanting:register_tools("default", {
- materials = "steel, bronze, mese, diamond",
+ },
+ --[[
+ protection = {
+ name = "Protection",
+ max_level = 4,
+ create_itemdef = function(def, level)
+ local groups = def.groups
+ groups.mcl_armor_points = groups.mcl_armor_points + (0.04 * level)
+ end,
+ },
+ --]]
+ },
tools = {
- axe = {enchants = "durable, fast"},
- pick = {enchants = "durable, fast"},
- shovel = {enchants = "durable, fast"},
- sword = {enchants = "sharp"}
+ ["mcl_tools:pick"] = default_tool,
+ ["mcl_tools:axe"] = {materials = default_tool_materials, enchantments = {"efficiency", "unbreaking", "sharpness", "silk_touch"}},
+ ["mcl_tools:shovel"] = default_tool,
+ ["mcl_tools:sword"] = {materials = default_tool_materials, enchantments = {"unbreaking", "sharpness"}},
+ ["mcl_tools:hoe"] = {materials = default_tool_materials, enchantments = {"unbreaking", "silk_touch"}},
+ ["mcl_armor:helmet"] = default_armor,
+ ["mcl_armor:chestplate"] = default_armor,
+ ["mcl_armor:leggings"] = default_armor,
+ ["mcl_armor:boots"] = default_armor,
}
-})
+}
-enchanting:register_tools("3d_armor", {
- materials = "steel, bronze, gold, diamond",
- tools = {
- boots = {enchants = "strong, speed"},
- chestplate = {enchants = "strong"},
- helmet = {enchants = "strong"},
- leggings = {enchants = "strong"}
- }
-})
+for k in pairs(mcl_enchanting.enchantments) do
+ table.insert(mcl_enchanting.enchantment_name_list, k)
+end
+
+local modpath = minetest.get_modpath("mcl_enchanting")
+for _, f in pairs({"engine", "book", "table", "bookshelf_particles", "silk_touch"}) do
+ dofile(modpath .. "/" .. f .. ".lua")
+end
-name = enchanting
+name = mcl_enchanting
+description = The rewrite of the Enchanting mod for MineClone2
+depends = mcl_sounds, mcl_formspec, mcl_dye
+optional_depends = screwdriver
+author = Fleckenstein
--- /dev/null
+local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
+local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
+local pickaxes_better_than_stone = {"mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
+local shovels = {"mcl_tools:shovel_wood", "mcl_tools:shovel_stone", "mcl_tools:shovel_gold", "mcl_tools:shovel_iron", "mcl_tools:shovel_diamond"}
+
+local silk_touch_tool_lists = {
+ ["mcl_books:bookshelf"] = true,
+ ["mcl_core:clay"] = true,
+ ["mcl_core:stone_with_coal"] = pickaxes,
+ ["group:coral_block"] = pickaxes,
+ ["group:coral"] = true,
+ ["group:coral_fan"] = true,
+ ["mcl_core:stone_with_diamond"] = pickaxes_better_than_iron,
+ ["mcl_core:stone_with_emerald"] = pickaxes_better_than_iron,
+ ["mcl_chests:ender_chest"] = pickaxes,
+ ["group:glass"] = true,
+ ["mcl_nether:glowstone"] = true,
+ ["mcl_core:dirt_with_grass"] = true,
+ ["mcl_core:gravel"] = true,
+ ["mcl_core:ice"] = true,
+ ["mcl_core:stone_with_lapis"] = pickaxes_better_than_stone,
+ ["group:leaves"] = true,
+ ["mcl_farming:melon"] = true,
+ ["group:huge_mushroom"] = true,
+ ["mcl_core:mycelium"] = true,
+ ["mcl_nether:quartz_ore"] = pickaxes,
+ ["mcl_core:packed_ice"] = true,
+ ["mcl_core:podzol"] = true,
+ ["mcl_core:stone_with_redstone"] = pickaxes_better_than_iron,
+ ["mcl_ocean:sea_lantern"] = true,
+ ["group:top_snow"] = shovels,
+ ["mcl_core:snowblock"] = shovels,
+ ["mcl_core:stone"] = pickaxes,
+}
+
+minetest.register_on_mods_loaded(function()
+ local old_handle_node_drops = minetest.handle_node_drops
+ function minetest.handle_node_drops(pos, drops, digger)
+ if digger and digger:is_player() then
+ local wielditem = digger:get_wielded_item()
+ local tooldef = wielditem:get_definition()
+ if tooldef._silk_touch then
+ local nodename = minetest.get_node(pos).name
+ local nodedef = minetest.registered_nodes[nodename]
+ local silk_touch_spec = silk_touch_tool_lists[nodename]
+ local suitable_tool = false
+ local tool_list
+ if silk_touch_spec == true then
+ suitable_tool = true
+ elseif silk_touch_spec then
+ tool_list = silk_touch_spec
+ else
+ for k, v in pairs(nodedef.groups) do
+ if v > 0 then
+ local group_spec = silk_touch_tool_lists["group:" .. k]
+ if group_spec == true then
+ suitable_tool = true
+ elseif group_spec then
+ toollist = group_spec
+ break
+ end
+ end
+ end
+ end
+ if tool_list and not suitable_tool then
+ suitable_tool = (table.indexof(tool_list, tooldef._original_tool) ~= -1)
+ end
+ if suitable_tool then
+ drops = {nodename}
+ end
+ end
+ end
+ old_handle_node_drops(pos, drops, digger)
+ end
+end)
--- /dev/null
+minetest.register_node("mcl_enchanting:table", {
+ description = "Enchanting Table",
+ drawtype = "nodebox",
+ tiles = {"mcl_enchanting_table_top.png", "mcl_enchanting_table_bottom.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {-0.5, -0.5, -0.5, 0.5, 0.25, 0.5},
+ },
+ sounds = mcl_sounds.node_sound_stone_defaults(),
+ groups = {pickaxey = 2},
+ _mcl_blast_resistance = 1200,
+ _mcl_hardness = 5,
+ on_rotate = (screwdriver or {}).rotate_simple,
+ on_construct = mcl_enchanting.init_table,
+ on_destruct = mcl_enchanting.drop_inventory,
+ after_destruct = mcl_enchanting.check_book,
+ on_receive_fields = mcl_enchanting.progress_formspec_input,
+ on_metadata_inventory_put = mcl_enchanting.update_formspec,
+ on_metadata_inventory_take = mcl_enchanting.update_formspec,
+ allow_metadata_inventory_put = function(_, listname, _, stack)
+ if listname == "lapis" then
+ return (stack:get_name() == mcl_enchanting.lapis_itemstring) and stack:get_count() or 0
+ end
+ return 1
+ end,
+ allow_metadata_inventory_move = function()
+ return 0
+ end,
+})