]> git.lizzy.rs Git - xdecor.git/blobdiff - enchanting.lua
Add Trampoline
[xdecor.git] / enchanting.lua
index 416a6f59e0b0e184cd96fec634d15b485ef60b56..a3c8e5a9734f2c19cd8b8584249b9f8824319177 100644 (file)
@@ -58,7 +58,7 @@ function enchanting.on_put(pos, listname, _, stack)
        end
 end
 
-function enchanting.fields(pos, _, fields)
+function enchanting.fields(pos, _, fields, sender)
        if fields.quit then return end
        local inv = minetest.get_meta(pos):get_inventory()
        local tool = inv:get_stack("tool", 1)
@@ -68,6 +68,7 @@ function enchanting.fields(pos, _, fields)
        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)
@@ -146,11 +147,11 @@ function enchanting.timer(pos)
        if tostring(x..z):find(2) then
                minetest.add_particle({
                        pos = bookshelf_pos,
-                       velocity = {x=x, y=1.7-y, z=z},
-                       acceleration = {x=-0.6, y=-1.5, z=0},
+                       velocity = {x=x, y=2-y, z=z},
+                       acceleration = {x=0, y=-2.2, z=0},
                        expirationtime = 1,
                        size = 2,
-                       texture = "xdecor_glyph"..math.random(1,14)..".png"
+                       texture = "xdecor_glyph"..math.random(1,18)..".png"
                })
        end
        return true
@@ -180,7 +181,15 @@ minetest.register_entity("xdecor:book_open", {
        visual_size = {x=0.75, y=0.75},
        collisionbox = {0},
        physical = false,
-       textures = {"xdecor_book_open.png"}
+       textures = {"xdecor_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
 })
 
 local function cap(S) return S:gsub("^%l", string.upper) end
@@ -190,7 +199,7 @@ function enchanting:register_tools(mod, def)
        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 return end
+               if not original_tool then break end
 
                if original_tool.tool_capabilities then
                        local original_damage_groups = original_tool.tool_capabilities.damage_groups