Shortening some naming

This commit is contained in:
kilbith 2015-08-24 22:50:29 +02:00
parent 4a9636649b
commit 0137f17e6c
4 changed files with 30 additions and 52 deletions

View File

@ -3,16 +3,14 @@ local enchanting = {}
function enchanting.construct(pos)
local meta = minetest.get_meta(pos)
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
local concat = table.concat
local f = {"size[8,7;]"..xbg..
local formspec = "size[8,7;]"..xbg..
"label[0.85,-0.15;Enchant]".."image[0.6,0.2;2,2;xdecor_enchbook.png]"..
"list[current_name;tool;0.5,2;1,1;]"..
"list[current_name;mese;1.5,2;1,1;]".."image[1.5,2;1,1;mese_layout.png]"..
"image_button[2.75,0;5,1.5;ench_bg.png;durable;Durable]"..
"image_button[2.75,1.5;5,1.5;ench_bg.png;fast;Fast]"..
"list[current_player;main;0,3.3;8,4;]"}
local formspec = concat(f)
"list[current_player;main;0,3.3;8,4;]"
meta:set_string("formspec", formspec)
meta:set_string("infotext", "Enchantment Table")
@ -31,8 +29,7 @@ function enchanting.is_allowed(toolname)
end
function enchanting.fields(pos, _, fields, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
local toolstack = inv:get_stack("tool", 1)
local mesestack = inv:get_stack("mese", 1)
local toolname = toolstack:get_name()
@ -51,9 +48,7 @@ function enchanting.fields(pos, _, fields, _)
end
function enchanting.dig(pos, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
if not inv:is_empty("tool") or not inv:is_empty("mese") then
return false
end
@ -68,9 +63,7 @@ function enchanting.put(_, listname, _, stack, _)
if toolname == "default:mese_crystal" then return count
else return 0 end
end
if listname == "tool" then
return enchanting.is_allowed(toolname)
end
if listname == "tool" then return enchanting.is_allowed(toolname) end
return count
end
@ -90,7 +83,7 @@ xdecor.register("enchantment_table", {
allow_metadata_inventory_move = function(...) return 0 end
})
local function capitalize(str) return str:gsub("^%l", string.upper) end
local function cap(str) return str:gsub("^%l", string.upper) end
-- Higher number = stronger enchant.
local use_factor = 1.2
@ -101,27 +94,23 @@ function enchanting.register_enchtools()
local tools = { {"axe", "choppy"}, {"pick", "cracky"}, {"shovel", "crumbly"} }
local chants = {"durable", "fast"}
for j = 1, #materials do
for t = 1, #tools do
for i = 1, #chants do
local chant = chants[i]
local material = materials[j]
local tool_name = tools[t][1]
local main_groupcap = tools[t][2]
local original_tool = minetest.registered_tools["default:"..tool_name.."_"..material]
for _, m in pairs(materials) do
for _, t in pairs(tools) do
for _, c in pairs(chants) do
local original_tool = minetest.registered_tools["default:"..t[1].."_"..m]
local original_groupcaps = original_tool.tool_capabilities.groupcaps
local groupcaps = table.copy(original_groupcaps)
if chant == "durable" then
groupcaps[main_groupcap].uses = original_groupcaps[main_groupcap].uses * use_factor
elseif chant == "fast" then
if c == "durable" then
groupcaps[t[2]].uses = original_groupcaps[t[2]].uses * use_factor
elseif c == "fast" then
for i = 1, 3 do
groupcaps[main_groupcap].times[i] = original_groupcaps[main_groupcap].times[i] - times_subtractor
groupcaps[t[2]].times[i] = original_groupcaps[t[2]].times[i] - times_subtractor
end
end
minetest.register_tool(string.format("xdecor:enchanted_%s_%s_%s", tool_name, material, chant), {
description = string.format("Enchanted %s %s (%s)", capitalize(material), capitalize(tool_name), capitalize(chant)),
minetest.register_tool(string.format("xdecor:enchanted_%s_%s_%s", t[1], m, c), {
description = string.format("Enchanted %s %s (%s)", cap(m), cap(t[1]), cap(c)),
inventory_image = original_tool.inventory_image,
wield_image = original_tool.wield_image,
groups = {not_in_creative_inventory=1},

View File

@ -2,28 +2,24 @@ local hive = {}
function hive.construct(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
local concat = table.concat
local f = {"size[8,5;]"..xbg..
local formspec = "size[8,5;]"..xbg..
"label[1.35,0;Bees are making honey\nwith pollen around...]"..
"image[0.2,-0.1;1,1;flowers_dandelion_white.png]"..
"image[7,0.1;1,1;flowers_viola.png]"..
"image[6,0;1,1;xdecor_bee.png]"..
"list[current_name;honey;5,0;1,1;]"..
"list[current_player;main;0,1.35;8,4;]"}
local formspec = concat(f)
"list[current_player;main;0,1.35;8,4;]"
meta:set_string("formspec", formspec)
meta:set_string("infotext", "Artificial Hive")
local inv = meta:get_inventory()
inv:set_size("honey", 1)
end
function hive.dig(pos, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
if not inv:is_empty("honey") then return false end
return true
end
@ -52,8 +48,7 @@ minetest.register_abm({
nodenames = {"xdecor:hive"},
interval = 10, chance = 5,
action = function(pos, _, _, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
local honeystack = inv:get_stack("honey", 1)
local honey = honeystack:get_count()

View File

@ -1,5 +1,4 @@
local mailbox = {}
local concat = table.concat
local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
xdecor.register("mailbox", {
@ -9,7 +8,7 @@ xdecor.register("mailbox", {
"xdecor_mailbox_side.png", "xdecor_mailbox_side.png",
"xdecor_mailbox.png", "xdecor_mailbox.png",
},
groups = {cracky=2},
groups = {cracky=3},
after_place_node = function(pos, placer, _)
local meta = minetest.get_meta(pos)
local owner = placer:get_player_name()
@ -41,9 +40,7 @@ xdecor.register("mailbox", {
return player:get_player_name() == owner
end,
on_metadata_inventory_put = function(pos, listname, _, stack, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
if listname == "drop" and inv:room_for_item("main", stack) then
inv:remove_item("drop", stack)
inv:add_item("main", stack)
@ -62,20 +59,18 @@ xdecor.register("mailbox", {
function mailbox.get_formspec(pos)
local spos = pos.x..","..pos.y..","..pos.z
local f = {"size[8,9]"..xbg..
local formspec = "size[8,9]"..xbg..
"label[0,0;You received...]"..
"list[nodemeta:"..spos..";main;0,0.75;8,4;]"..
"list[current_player;main;0,5.25;8,4;]"}
local formspec = concat(f)
"list[current_player;main;0,5.25;8,4;]"
return formspec
end
function mailbox.get_insert_formspec(pos, owner)
local spos = pos.x..","..pos.y..","..pos.z
local f = {"size[8,5]"..xbg..
local formspec = "size[8,5]"..xbg..
"label[0.5,0;Send your goods\nto "..owner.." :]"..
"list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
"list[current_player;main;0,1.25;8,4;]"}
local formspec = concat(f)
"list[current_player;main;0,1.25;8,4;]"
return formspec
end

View File

@ -141,8 +141,8 @@ local function update_form_inventory(inv, input_stack)
for _, form in pairs(def) do
local material_name = input_stack:get_name():match("%a+:(.+)")
local form_name = form[1]
local count = math.min(worktable.anz(form_name) * inv:get_stack("input", 1):get_count(), input_stack:get_stack_max())
form_inv_list[#form_inv_list+1] = string.format("xdecor:%s_%s %d", form_name, material_name, count)
end
inv:set_list("forms", form_inv_list)
@ -162,9 +162,9 @@ function worktable.on_take(pos, listname, index, stack, player)
elseif listname == "forms" then
local form_name = stack:get_name():match("%a+:(%a+)_%a+")
local input_stack = inv:get_stack("input", 1)
input_stack:take_item(math.ceil(stack:get_count() / worktable.anz(form_name)))
inv:set_stack("input", 1, input_stack)
update_form_inventory(inv, input_stack)
end
end
@ -229,8 +229,7 @@ minetest.register_abm({
nodenames = {"xdecor:worktable"},
interval = 3, chance = 1,
action = function(pos, _, _, _)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
local tool = inv:get_stack("tool", 1)
local hammer = inv:get_stack("hammer", 1)
local wear = tool:get_wear()