Finish and enable the Enchantment Table (yay!)
This commit is contained in:
parent
6e52bc628c
commit
28c397044a
143
enchanting.lua
143
enchanting.lua
@ -6,9 +6,8 @@ local function enchconstruct(pos)
|
||||
"image[1.3,2;1,1;ench_mese_layout.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;ench_bg.png;durable;Durable]"..
|
||||
"image_button[2.5,1;5.3,1.1;ench_bg.png;fast;Fast]"..
|
||||
"image_button[2.5,2;5.3,1.1;ench_bg.png;luck;Luck]"..
|
||||
"image_button[2.5,0;5.3,1.5;ench_bg.png;durable;Durable]"..
|
||||
"image_button[2.5,1.5;5.3,1.5;ench_bg.png;fast;Fast]"..
|
||||
"list[current_player;main;0,3.3;8,4;]")
|
||||
meta:set_string("infotext", "Enchantment Table")
|
||||
|
||||
@ -17,6 +16,25 @@ local function enchconstruct(pos)
|
||||
inv:set_size("mese", 1)
|
||||
end
|
||||
|
||||
local function enchfields(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local toolstack = inv:get_stack("tool", 1)
|
||||
local mesestack = inv:get_stack("mese", 1)
|
||||
local enchs = {"durable", "fast"}
|
||||
|
||||
for _, e in pairs(enchs) do
|
||||
if string.find(toolstack:get_name(), "default:") and
|
||||
mesestack:get_count() > 0 and fields[e] then
|
||||
|
||||
toolstack:replace("xdecor:enchanted_"..string.sub(toolstack:get_name(), 9).."_"..e)
|
||||
mesestack:take_item()
|
||||
inv:set_stack("mese", 1, mesestack)
|
||||
inv:set_stack("tool", 1, toolstack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function enchdig(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
@ -42,7 +60,11 @@ local function enchput(pos, listname, index, stack, player)
|
||||
local tname = stack:get_name()
|
||||
local tdef = minetest.registered_tools[tname]
|
||||
|
||||
if tdef then return 1 else return 0 end
|
||||
if tdef and not string.find(stack:get_name(), "sword") and not
|
||||
string.find(stack:get_name(), "stone") and not
|
||||
string.find(stack:get_name(), "wood") then
|
||||
return 1
|
||||
else return 0 end
|
||||
end
|
||||
|
||||
return stack:get_count()
|
||||
@ -56,11 +78,120 @@ xdecor.register("enchantment_table", {
|
||||
"xdecor_enchantment_side.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
|
||||
allow_metadata_inventory_put = enchput,
|
||||
on_receive_fields = enchfields
|
||||
})
|
||||
|
||||
local tools = {
|
||||
{"axe", "choppy"},
|
||||
{"pick", "cracky"},
|
||||
{"shovel", "crumbly"}
|
||||
}
|
||||
local materials = {"steel", "bronze", "mese", "diamond"}
|
||||
local groups = {"cracky", "crumbly", "choppy"}
|
||||
|
||||
for _, t in pairs(tools) do
|
||||
for _, m in pairs(materials) do
|
||||
local tool = t[1]
|
||||
local group = t[2]
|
||||
local toolname = tool.."_"..m
|
||||
|
||||
local registered_tool = {}
|
||||
registered_tool = minetest.registered_tools["default:"..toolname]["tool_capabilities"]["groupcaps"][group]
|
||||
|
||||
local times = registered_tool["times"]
|
||||
local uses = registered_tool["uses"]
|
||||
local dmg = registered_tool["damage_groups"]
|
||||
local maxlvl = registered_tool["maxlevel"]
|
||||
|
||||
local dig_faster, use_longer = {}, {}
|
||||
use_longer = registered_tool["uses"] * 1.1 -- Wearing factor for enchanted tools (higher in positive means longer use).
|
||||
for i = 1, 3 do
|
||||
dig_faster[i] = registered_tool["times"][i] - 0.1 -- Digging factor for enchanted tools (higher in negative means faster dig).
|
||||
end
|
||||
|
||||
--- Pickaxes ---
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_pick_"..m.."_durable", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Pickaxe (Durable)",
|
||||
inventory_image = minetest.registered_tools["default:pick_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
cracky = {times=times, uses=use_longer, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_pick_"..m.."_fast", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Pickaxe (Fast)",
|
||||
inventory_image = minetest.registered_tools["default:pick_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
cracky = {times=dig_faster, uses=uses, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
|
||||
--- Axe ---
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_axe_"..m.."_durable", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Durable)",
|
||||
inventory_image = minetest.registered_tools["default:axe_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
choppy = {times=times, uses=use_longer, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_axe_"..m.."_fast", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Axe (Fast)",
|
||||
inventory_image = minetest.registered_tools["default:axe_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
choppy = {times=dig_faster, uses=uses, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
|
||||
--- Shovels ---
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_shovel_"..m.."_durable", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Shovel (Durable)",
|
||||
inventory_image = minetest.registered_tools["default:shovel_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
crumbly = {times=times, uses=use_longer, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_tool("xdecor:enchanted_shovel_"..m.."_fast", {
|
||||
description = "Enchanted "..string.sub(string.upper(m), 0, 1)..string.sub(m, 2).." Shovel (Fast)",
|
||||
inventory_image = minetest.registered_tools["default:shovel_"..m]["inventory_image"],
|
||||
groups = {not_in_creative_inventory=1},
|
||||
tool_capabilities = {
|
||||
groupcaps = {
|
||||
crumbly = {times=dig_faster, uses=uses, maxlevel=maxlvl}
|
||||
},
|
||||
damage_groups = dmg
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
2
init.lua
2
init.lua
@ -4,7 +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.."/enchanting.lua")
|
||||
dofile(modpath.."/hive.lua")
|
||||
dofile(modpath.."/itemframe.lua")
|
||||
dofile(modpath.."/mailbox.lua")
|
||||
|
@ -5,9 +5,9 @@ local material = {
|
||||
"cobble", "mossycobble", "desert_cobble",
|
||||
"stone", "sandstone", "desert_stone", "obsidian",
|
||||
"stonebrick", "sandstonebrick", "desert_stonebrick", "obsidianbrick",
|
||||
"coalblock", "copperblock", "steelblock", "goldblock",
|
||||
"snowblock", "coalblock", "copperblock", "steelblock", "goldblock",
|
||||
"bronzeblock", "mese", "diamondblock",
|
||||
"brick", "clay", "ice", "meselamp",
|
||||
"brick", "cactus", "clay", "ice", "meselamp",
|
||||
"glass", "obsidian_glass"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user