Get rid of minetest.serialize in cooking code + cleaning of ench. table

This commit is contained in:
kilbith 2016-01-06 17:33:47 +01:00
parent 696d84e871
commit 9c34c83912
2 changed files with 36 additions and 32 deletions

View File

@ -117,9 +117,14 @@ minetest.register_abm({
for _, obj in pairs(objs) do for _, obj in pairs(objs) do
if obj and obj:get_luaentity() then if obj and obj:get_luaentity() then
local itemstring = obj:get_luaentity().itemstring:match("[%w_]+:([%w_]+)") local itemstring = obj:get_luaentity().itemstring:match("[%w_]+:([%w_]+)")
if not next(ingredients) then
for _, rep in pairs(ingredients) do
if itemstring == rep then return end
end
end
for _, ing in pairs(ingredients_list) do for _, ing in pairs(ingredients_list) do
if itemstring and itemstring:match(ing) if itemstring and itemstring:match(ing) then
and not minetest.serialize(ingredients):find(itemstring) then
ingredients[#ingredients+1] = itemstring ingredients[#ingredients+1] = itemstring
end end
end end

View File

@ -10,9 +10,9 @@ function enchanting.formspec(pos, tooltype)
list[context;mese;2,2.9;1,1;] list[context;mese;2,2.9;1,1;]
list[current_player;main;0.5,4.5;8,4;] list[current_player;main;0.5,4.5;8,4;]
image[2,2.9;1,1;mese_layout.png] image[2,2.9;1,1;mese_layout.png]
tooltip[sharp;Your sword kills faster] tooltip[sharp;Your sword inflicts more damage]
tooltip[durable;Your tool lasts longer] tooltip[durable;Your tool is more resistant]
tooltip[fast;Your tool digs faster] tooltip[fast;Your tool is more powerful]
tooltip[strong;Your armor is more resistant] tooltip[strong;Your armor is more resistant]
tooltip[speed;Your speed is increased] ]] tooltip[speed;Your speed is increased] ]]
..default.gui_slots..default.get_hotbar_bg(0.5,4.5) ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
@ -30,22 +30,19 @@ function enchanting.formspec(pos, tooltype)
end end
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)
return formspec
end end
function enchanting.on_put(pos, listname, _, stack, _) function enchanting.on_put(pos, listname, _, stack, _)
local stn = stack:get_name()
local meta = minetest.get_meta(pos)
if listname == "tool" then if listname == "tool" then
local stn = stack:get_name()
if stn:find("pick") or stn:find("axe") or stn:find("shovel") then if stn:find("pick") or stn:find("axe") or stn:find("shovel") then
meta:set_string("formspec", enchanting.formspec(pos, "tool")) enchanting.formspec(pos, "tool")
elseif stn:find("sword") then elseif stn:find("sword") then
meta:set_string("formspec", enchanting.formspec(pos, "sword")) enchanting.formspec(pos, "sword")
elseif stn:find("chestplate") or stn:find("leggings") or stn:find("helmet") then elseif stn:find("chestplate") or stn:find("leggings") or stn:find("helmet") then
meta:set_string("formspec", enchanting.formspec(pos, "armor")) enchanting.formspec(pos, "armor")
elseif stn:find("boots") then elseif stn:find("boots") then
meta:set_string("formspec", enchanting.formspec(pos, "boots")) enchanting.formspec(pos, "boots")
end end
end end
end end
@ -59,11 +56,10 @@ function enchanting.fields(pos, _, fields, _)
local mod, tool = toolstack_name:match("([%w_]+):([%w_]+)") local mod, tool = toolstack_name:match("([%w_]+):([%w_]+)")
local toolwear = toolstack:get_wear() local toolwear = toolstack:get_wear()
local mese = mesestack:get_count() local mese = mesestack:get_count()
local ench = dump(fields):match("%w+") local ench = next(fields)
local enchanted_tool = mod..":enchanted_"..tool.."_"..ench local enchanted_tool = mod..":enchanted_"..tool.."_"..ench
if mese > 0 and fields[ench] and if mese > 0 and minetest.registered_tools[enchanted_tool] then
minetest.registered_tools[enchanted_tool] then
toolstack:replace(enchanted_tool) toolstack:replace(enchanted_tool)
toolstack:add_wear(toolwear) toolstack:add_wear(toolwear)
mesestack:take_item() mesestack:take_item()
@ -99,6 +95,22 @@ function enchanting.put(_, listname, _, stack, _)
return 0 return 0
end 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)
end
xdecor.register("enchantment_table", { xdecor.register("enchantment_table", {
description = "Enchantment Table", description = "Enchantment Table",
tiles = { tiles = {
@ -110,25 +122,12 @@ xdecor.register("enchantment_table", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_rotate = screwdriver.rotate_simple, on_rotate = screwdriver.rotate_simple,
can_dig = enchanting.dig, can_dig = enchanting.dig,
on_construct = function(pos) on_construct = enchanting.construct,
local meta = minetest.get_meta(pos)
enchanting.formspec(pos, nil)
meta:set_string("infotext", "Enchantment Table")
local inv = meta:get_inventory()
inv:set_size("tool", 1)
inv:set_size("mese", 1)
end,
enchanting.formspec,
on_receive_fields = enchanting.fields, on_receive_fields = enchanting.fields,
on_metadata_inventory_put = enchanting.on_put, on_metadata_inventory_put = enchanting.on_put,
on_metadata_inventory_take = enchanting.on_take,
allow_metadata_inventory_put = enchanting.put, allow_metadata_inventory_put = enchanting.put,
allow_metadata_inventory_move = function() return 0 end, allow_metadata_inventory_move = function() return 0 end
on_metadata_inventory_take = function(pos, listname, _, _, _)
if listname == "tool" then
enchanting.formspec(pos, nil)
end
end
}) })
local function cap(str) local function cap(str)