Merge pull request #48 from kaadmy/newcrafting

Newcrafting
This commit is contained in:
KaadmY 2017-05-14 17:31:18 -07:00 committed by GitHub
commit fce9574528
32 changed files with 1050 additions and 869 deletions

View File

@ -174,10 +174,10 @@ minetest.register_on_placenode(on_place)
-- Formspecs
local form = default.ui.get_page("core")
local form = default.ui.get_page("default:default")
form = form .. "tableoptions[background=#DDDDDD30]"
form = form .. "tablecolumns[text,align=left,width=11;text,align=left,width=28;text,align=left,width=5]"
default.ui.register_page("core_achievements", form)
default.ui.register_page("achievements:achievements", form)
function achievements.get_formspec(name, row)
if not row then row = 1 end
@ -212,7 +212,7 @@ function achievements.get_formspec(name, row)
achievement_list = achievement_list .. progress
end
local form = default.ui.get_page("core_achievements")
local form = default.ui.get_page("achievements:achievements")
form = form .. "table[0.25,2.5;7.75,5.5;achievement_list;" .. achievement_list .. ";" .. row .. "]"
@ -243,7 +243,7 @@ end
local function receive_fields(player, form_name, fields)
local name = player:get_player_name()
if form_name ~= "core_achievements" then return end
if form_name ~= "achievements:achievements" then return end
if fields.quit then return end
@ -257,7 +257,7 @@ local function receive_fields(player, form_name, fields)
end
end
minetest.show_formspec(name, "core_achievements", achievements.get_formspec(name, selected))
minetest.show_formspec(name, "achievements:achievements", achievements.get_formspec(name, selected))
end
minetest.register_on_player_receive_fields(receive_fields)

View File

@ -18,8 +18,8 @@ armor.materials = {
armor.slots = {"helmet", "chestplate", "boots"}
local form_armor = default.ui.get_page("core_2part")
default.ui.register_page("core_armor", form_armor)
local form_armor = default.ui.get_page("default:2part")
default.ui.register_page("armor:armor", form_armor)
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
@ -87,7 +87,7 @@ function armor.get_groups(player)
if armor.is_armor(itemname) then
local item = minetest.registered_items[itemname]
for mat_index, _ in ipairs(armor.materials) do
local mat = armor.materials[mat_index][1]
@ -158,7 +158,7 @@ local function on_die(player)
}
local drop = minetest.add_item(rpos, item)
if drop then
drop:setvelocity(
{
@ -190,7 +190,7 @@ minetest.register_craftitem(
description = "Chainmail sheet",
inventory_image = "armor_chainmail.png",
wield_image = "armor_chainmail.png",
wield_image = "armor_chainmail.png",
stack_max = 20,
})
@ -264,12 +264,14 @@ end
minetest.register_on_newplayer(on_newplayer)
minetest.register_on_joinplayer(on_joinplayer)
if enable_drop then
minetest.register_on_dieplayer(on_die)
end
minetest.register_globalstep(step)
local form_armor = default.ui.get_page("core_2part")
local form_armor = default.ui.get_page("default:2part")
form_armor = form_armor .. "list[current_player;main;0.25,4.75;8,4;]"
form_armor = form_armor .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
form_armor = form_armor .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
@ -290,7 +292,7 @@ form_armor = form_armor .. "list[current_player;armor_helmet;2.25,0.75;1,1;]"
form_armor = form_armor .. "listring[current_player;armor_helmet]"
form_armor = form_armor .. default.ui.get_itemslot_bg(2.25, 0.75, 1, 1)
default.ui.register_page("core_armor", form_armor)
default.ui.register_page("armor:armor", form_armor)
-- Achievements
@ -312,4 +314,4 @@ achievements.register_achievement(
craftitem = "group:is_armor",
})
default.log("mod:armor", "loaded")
default.log("mod:armor", "loaded")

View File

@ -22,7 +22,7 @@ minetest.register_craftitem(
title = data.title
end
local form = default.ui.get_page("core_notabs")
local form = default.ui.get_page("default:notabs")
form = form .. "field[0.5,1.25;8,0;title;Title:;"..minetest.formspec_escape(title).."]"
form = form .. "textarea[0.5,1.75;8,6.75;text;Contents:;"..minetest.formspec_escape(text).."]"
form = form .. default.ui.button_exit(2.75, 7.75, 3, 1, "write", "Write")
@ -41,7 +41,7 @@ minetest.register_on_player_receive_fields(
if not data then data = {} end
data.text = fields.text
data.title = fields.title
itemstack:set_metadata(minetest.serialize(data))
player:set_wielded_item(itemstack)
end)
@ -57,4 +57,4 @@ achievements.register_achievement(
craftitem = "default:book",
})
default.log("mod:book", "loaded")
default.log("mod:book", "loaded")

8
mods/crafting/README.txt Normal file
View File

@ -0,0 +1,8 @@
Cratfing mod
============
By Kaadmy, for Pixture
Custom crafting method, uses a list of possible items to craft instead of a grid
recipe.
Source license: LGPLv2.1

365
mods/crafting/api.lua Normal file
View File

@ -0,0 +1,365 @@
-- API
crafting = {}
crafting.registered_crafts = {}
-- User table of last selected row etc.
crafting.userdata = {}
-- Crafting can only take 4 itemstacks as input for sanity/interface reasons
crafting.max_inputs = 4
-- Default crafting definition values
crafting.default_craftdef = {
output = nil,
items = {},
groups = {},
}
function crafting.register_craft(def)
if def.output == nil then
minetest.log("warning",
"No output for craft recipe")
return
end
local itemstack = ItemStack(def.output)
local itemkey = itemstack:to_string()
if crafting.registered_crafts[itemkey] ~= nil then
minetest.log("warning",
"Tried to register an existing craft " .. itemkey .. ", allowing")
end
local craftdef = {
output = itemstack,
items = def.items or crafting.default_craftdef.items,
groups = def.groups or crafting.default_craftdef.groups,
}
if #craftdef.items > 4 then
minetest.log("warning",
"Attempting to register craft " .. itemkey .." with more than "
.. crafting.max_inputs .. " inputs, allowing")
end
for i = 1, crafting.max_inputs do
craftdef.items[i] = ItemStack(craftdef.items[i])
end
crafting.registered_crafts[itemkey] = craftdef
minetest.log("info", "Registered recipe for " .. itemkey)
end
function crafting.get_crafts(filter)
local results = {}
local function get_filter()
for craftname, craftdef in pairs(crafting.registered_crafts) do
for filtername, filtervalue in pairs(filter) do
if craftdef.groups[filtername] ~= nil
and filtervalue >= craftdef.groups[filtername] then
table.insert(results, craftname)
break
end
end
end
end
local function get_all()
for craftname, _ in pairs(crafting.registered_crafts) do
table.insert(results, craftname)
end
end
if filter == nil then
get_all()
else
get_filter()
end
local function sort_function(a, b)
local a_itemn = ItemStack(a):get_name()
local b_itemn = ItemStack(b):get_name()
local a_name = minetest.registered_items[a_itemn].description
local b_name = minetest.registered_items[b_itemn].description
return a_name < b_name
end
table.sort(results, sort_function)
return results
end
function crafting.craft(wanted, output, items)
-- `output` can be any ItemStack value
-- Duplicate items in `items` should work correctly
local craftdef = crafting.registered_crafts[wanted:get_name()]
if craftdef == nil then
minetest.log("warning",
"Tried to craft an unregistered item " .. wanted:get_name())
return nil
end
-- Check for validity
local craft_count = wanted:get_count()
for i = 1, crafting.max_inputs do
local required_itemstack = ItemStack(craftdef.items[i])
local itemc = 0
local group = string.match(required_itemstack:get_name(), "group:(.*)")
if required_itemstack ~= nil and required_itemstack:get_count() ~= 0 then
for j = 1, crafting.max_inputs do
local input_itemstack = ItemStack(items[j])
if (group ~= nil
and minetest.get_item_group(input_itemstack:get_name(), group) ~= 0)
or (input_itemstack ~= nil
and input_itemstack:get_name() == required_itemstack:get_name()) then
itemc = itemc + input_itemstack:get_count()
end
end
craft_count = math.min(craft_count,
math.floor(itemc / required_itemstack:get_count()))
if craft_count < 1 then
return nil -- Not enough items to craft
end
end
end
-- Put stuff in output stack
if output:get_free_space() < (craft_count * craftdef.output:get_count()) then
craft_count = math.floor(output:get_free_space() / craftdef.output:get_count())
end
if craft_count < 1 then
return nil -- Can't hold any output
end
output:add_item(ItemStack({
name = craftdef.output:get_name(),
count = craftdef.output:get_count() * craft_count}))
-- Iterate through second time to take items used for crafting
local function remove_used_item(itemn, count)
local items_required = count
local group = string.match(itemn, "group:(.*)")
for i = 1, crafting.max_inputs do
local input_itemstack = ItemStack(items[i])
if (group ~= nil
and minetest.get_item_group(input_itemstack:get_name(), group) ~= 0)
or (items[i] ~= nil
and input_itemstack:get_name() == itemn) then
local items_left = items_required - input_itemstack:get_count()
input_itemstack:take_item(items_required)
if items_left > 0 then
items_required = items_required - (items_required - items_left)
else
items[i] = input_itemstack:to_table()
break
end
items[i] = input_itemstack:to_table()
end
end
end
for i = 1, crafting.max_inputs do
local required_itemstack = ItemStack(craftdef.items[i])
if craftdef.items[i] ~= nil then
remove_used_item(required_itemstack:get_name(),
required_itemstack:get_count() * craft_count)
end
end
return {items = items, output = output}
end
local form = default.ui.get_page("default:2part")
form = form .. "field[-1,-1;0,0;crafting_tracker;;]"
form = form .. "list[current_player;main;0.25,4.75;8,4;]"
form = form .. "listring[current_player;main]"
form = form .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
form = form .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
form = form .. "list[current_player;craft_in;0.25,0.25;1,4;]"
form = form .. "listring[current_player;craft_in]"
form = form .. "list[current_player;craft_out;7.25,3.25;1,1;]"
form = form .. default.ui.get_itemslot_bg(0.25, 0.25, 1, 4)
form = form .. default.ui.get_itemslot_bg(7.25, 3.25, 1, 1)
form = form .. "image[5.25,3.25;1,1;ui_arrow_bg.png^[transformR270]"
form = form .. default.ui.button(7.25, 0.25, 1, 1, "do_craft_1", "1")
form = form .. default.ui.button(7.25, 1.25, 1, 1, "do_craft_10", "10")
form = form .. "tableoptions[background=#DDDDDD30]"
form = form .. "tablecolumns[text,align=left,width=2;text,align=left,width=40]"
default.ui.register_page("crafting:crafting", form)
function crafting.get_formspec(name)
local row = 1
if crafting.userdata[name] ~= nil then
row = crafting.userdata[name].row
end
local craft_list = ""
local craftitems = crafting.get_crafts(nil)
local selected_craftdef = nil
for i, itemn in ipairs(craftitems) do
local itemstack = ItemStack(itemn)
local itemdef = minetest.registered_items[itemstack:get_name()]
if i == row then
selected_craftdef = crafting.registered_crafts[itemn]
end
if itemdef ~= nil then
if craft_list ~= "" then
craft_list = craft_list .. ","
end
if itemstack:get_count() ~= 1 then
craft_list = craft_list .. minetest.formspec_escape( itemstack:get_count())
end
craft_list = craft_list .. "," .. minetest.formspec_escape(itemdef.description)
end
end
local form = default.ui.get_page("crafting:crafting")
form = form .. "table[1.25,0.25;5.75,2.75;craft_list;" .. craft_list
.. ";" .. row .. "]"
if selected_craftdef ~= nil then
if selected_craftdef.items[1] ~= nil then
form = form .. default.ui.fake_itemstack_any(
4.25, 3.25, selected_craftdef.items[1])
end
if selected_craftdef.items[2] ~= nil then
form = form .. default.ui.fake_itemstack_any(
3.25, 3.25, selected_craftdef.items[2])
end
if selected_craftdef.items[3] ~= nil then
form = form .. default.ui.fake_itemstack_any(
2.25, 3.25, selected_craftdef.items[3])
end
if selected_craftdef.items[4] ~= nil then
form = form .. default.ui.fake_itemstack_any(
1.25, 3.25, selected_craftdef.items[4])
end
if selected_craftdef.items[4] ~= nil then
form = form .. default.ui.fake_itemstack_any(
6.25, 3.25, selected_craftdef.output)
end
end
return form
end
local function on_joinplayer(player)
local name = player:get_player_name()
local inv = player:get_inventory()
if crafting.userdata[name] == nil then
crafting.userdata[name] = {row = 1}
end
if inv:get_size("craft_in") ~= 4 then
inv:set_size("craft_in", 4)
end
if inv:get_size("craft_out") ~= 1 then
inv:set_size("craft_out", 1)
end
end
local function on_player_receive_fields(player, form_name, fields)
if fields.crafting_tracker == nil then
return
end
local name = player:get_player_name()
local inv = player:get_inventory()
if fields.do_craft_1 or fields.do_craft_10 then
local craftitems = crafting.get_crafts(nil)
local wanted_itemstack = ItemStack(craftitems[crafting.userdata[name].row])
local output_itemstack = inv:get_stack("craft_out", 1)
if output_itemstack:get_name() ~= wanted_itemstack:get_name()
and output_itemstack:get_count() ~= 0 then
return -- Different item type in output already
end
if fields.do_craft_1 then
wanted_itemstack:set_count(1)
elseif fields.do_craft_10 then
wanted_itemstack:set_count(10)
else
return
end
local crafted = crafting.craft(wanted_itemstack,
output_itemstack,
inv:get_list("craft_in"))
if crafted then
inv:set_stack("craft_out", 1, "")
if inv:room_for_item("craft_out", crafted.output) then
inv:set_stack("craft_out", 1, crafted.output)
inv:set_list("craft_in", crafted.items)
end
end
elseif fields.craft_list then
local selection = minetest.explode_table_event(fields.craft_list)
if selection.type == "CHG" or selection.type == "DCL" then
crafting.userdata[name].row = selection.row
minetest.show_formspec(name, "crafting:crafting",
crafting.get_formspec(name, crafting.userdata[name].row))
end
end
end
minetest.register_on_joinplayer(on_joinplayer)
minetest.register_on_player_receive_fields(on_player_receive_fields)
default.log("api", "loaded")

10
mods/crafting/init.lua Normal file
View File

@ -0,0 +1,10 @@
--
-- Crafting mod
-- By Kaadmy, for Pixture
--
dofile(minetest.get_modpath("crafting").."/api.lua")
dofile(minetest.get_modpath("crafting").."/recipes.lua")
default.log("mod:crafting", "loaded")

529
mods/crafting/recipes.lua Normal file
View File

@ -0,0 +1,529 @@
--
-- Recipes
--
-- Pickaxes
crafting.register_craft(
{
output = "default:pick_wood",
items = {
"group:planks 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:pick_stone",
items = {
"group:stone 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:pick_steel",
items = {
"default:ingot_steel 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:pick_carbonsteel",
items = {
"default:ingot_carbonsteel 2",
"default:fiber 4",
"default:stick 3",
}
})
-- Shovels
crafting.register_craft(
{
output = "default:shovel_wood",
items = {
"group:planks 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:shovel_stone",
items = {
"group:stone 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:shovel_steel",
items = {
"default:ingot_steel 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:shovel_carbonsteel",
items = {
"default:ingot_carbonsteel 2",
"default:fiber 4",
"default:stick 3",
}
})
-- Axes
crafting.register_craft(
{
output = "default:axe_wood",
items = {
"group:planks 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:axe_stone",
items = {
"group:stone 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:axe_steel",
items = {
"default:ingot_steel 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:axe_carbonsteel",
items = {
"default:ingot_carbonsteel 2",
"default:fiber 4",
"default:stick 3",
}
})
-- Spears
crafting.register_craft(
{
output = "default:spear_wood",
items = {
"group:planks 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:spear_stone",
items = {
"group:stone 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:spear_steel",
items = {
"default:ingot_steel 2",
"default:fiber 4",
"default:stick 3",
}
})
crafting.register_craft(
{
output = "default:spear_carbonsteel",
items = {
"default:ingot_carbonsteel 2",
"default:fiber 4",
"default:stick 3",
}
})
-- Broadsword
crafting.register_craft(
{
output = "default:broadsword",
items = {
"default:ingot_steel 4",
"default:fiber 5",
"default:stick 2",
}
})
-- Items
crafting.register_craft(
{
output = "default:dust_carbonsteel",
items = {
"default:lump_coal",
"default:lump_iron 2",
}
})
crafting.register_craft(
{
output = "default:rope 2",
items = {
"default:dry_grass 3",
}
})
crafting.register_craft(
{
output = "default:fiber 3",
items = {
"default:leaves 4",
}
})
crafting.register_craft(
{
output = "default:fiber",
items = {
"default:grass",
}
})
crafting.register_craft(
{
output = "default:stick 4",
items = {
"group:planks",
}
})
crafting.register_craft(
{
output = "default:flint 2",
items = {
"default:gravel",
}
})
crafting.register_craft(
{
output = "default:paper",
items = {
"default:papyrus 3",
}
})
crafting.register_craft(
{
output = "default:book",
items = {
"default:paper 3",
"default:stick",
"default:fiber",
}
})
crafting.register_craft(
{
output = "default:flint_and_steel",
items = {
"default:ingot_steel",
"default:fiber",
"default:flint",
}
})
crafting.register_craft(
{
output = "default:bucket",
items = {
"default:stick 2",
"default:fiber 4",
"group:planks 5",
}
})
-- Stone nodes
crafting.register_craft(
{
output = "default:gravel",
items = {
"default:cobble",
}
})
crafting.register_craft(
{
output = "default:brick 2",
items = {
"group:soil 5",
"default:gravel 4",
}
})
-- Block nodes
crafting.register_craft(
{
output = "default:block_steel",
items = {
"default:ingot_steel 9",
}
})
crafting.register_craft(
{
output = "default:block_coal",
items = {
"default:lump_coal 9",
}
})
-- Path nodes
crafting.register_craft(
{
output = "default:dirt_path 8",
items = {
"group:soil 3",
"default:gravel 6",
}
})
crafting.register_craft(
{
output = "default:path_slab",
items = {
"group:soil_path",
}
})
crafting.register_craft(
{
output = "default:heated_dirt_path",
items = {
"group:soil_path",
"default:ingot_steel",
}
})
-- Wood nodes
crafting.register_craft(
{
output = "default:planks 4",
items = {
"default:tree",
}
})
crafting.register_craft(
{
output = "default:planks_oak 4",
items = {
"default:tree_oak",
}
})
crafting.register_craft(
{
output = "default:planks_birch 4",
items = {
"default:tree_birch",
}
})
-- Frame nodes
crafting.register_craft(
{
output = "default:frame",
items = {
"default:fiber 8",
"default:stick 6",
"group:planks",
}
})
crafting.register_craft(
{
output = "default:reinforced_frame",
items = {
"default:fiber 8",
"default:stick 6",
"default:frame",
}
})
crafting.register_craft(
{
output = "default:reinforced_cobble",
items = {
"default:fiber 8",
"default:stick 6",
"default:cobble",
}
})
-- Fence nodes
crafting.register_craft(
{
output = "default:fence 4",
items = {
"default:planks",
"default:stick 4",
"default:fiber 4",
}
})
crafting.register_craft(
{
output = "default:fence_oak 4",
items = {
"default:planks_oak",
"default:stick 4",
"default:fiber 4",
}
})
crafting.register_craft(
{
output = "default:fence_birch 4",
items = {
"default:planks_birch",
"default:stick 4",
"default:fiber 4",
}
})
-- Misc nodes
crafting.register_craft(
{
output = "default:sign 2",
items = {
"group:planks",
"default:fiber 2",
"default:stick 2",
}
})
crafting.register_craft(
{
output = "default:torch 2",
items = {
"default:lump_coal",
"default:stick",
"default:fiber",
}
})
crafting.register_craft(
{
output = "default:torch_weak 2",
items = {
"default:stick",
"default:fiber",
}
})
crafting.register_craft(
{
output = "default:ladder 2",
items = {
"default:stick 5",
"default:fiber 2",
}
})
-- Tool nodes (chests, furnaces, bookshelves)
crafting.register_craft(
{
output = "default:chest",
items = {
"default:stick 12",
"default:fiber 8",
"group:planks 6",
}
})
crafting.register_craft(
{
output = "default:furnace",
items = {
"default:torch",
"group:stone 6",
}
})
crafting.register_craft(
{
output = "default:bookshelf",
items = {
"default:book 3",
"group:planks 6",
}
})
-- Sand nodes
crafting.register_craft(
{
output = "default:sandstone",
items = {
"default:sand 2",
}
})
crafting.register_craft(
{
output = "default:compressed_sandstone",
items = {
"default:sandstone 2",
}
})
-- Agriculture nodes
crafting.register_craft(
{
output = "default:fertilizer",
items = {
"default:fern 3",
"default:fiber",
}
})
default.log("recipes", "loaded")

View File

@ -1,9 +0,0 @@
Crafting guide mod
==================
By Kaadmy, for Pixture
This mod adds a crafting guide in your inventory.
Asset license: CC BY-SA 4.0
Source license: LGPLv2.1

View File

@ -1,183 +0,0 @@
--
-- Crafting guide mod
-- By Kaadmy, for Pixture
--
craftingguide = {}
craftingguide.items = {}
craftingguide.itemlist = {}
craftingguide.users = {} -- {item = selected item, itemno = recipe no., page = page no.}
local page_size = 8 * 4
function craftingguide.get_formspec(name)
local user = craftingguide.users[name]
local page = user.page
local max_pages = math.floor(#craftingguide.itemlist / page_size) + 1
local form = ""
form = form .. default.ui.get_page("core_craftingguide")
form = form .. "label[0.41,1.74;"..user.itemno.."/"..#craftingguide.items[user.item].."]" -- itemno
form = form .. "label[3.9,8.15;"..page.."/"..max_pages.."]" -- page
form = form .. "label[4.4,2.5;"..minetest.formspec_escape(minetest.registered_items[user.item].description).."]" -- itemname
local method = craftingguide.items[user.item][user.itemno].type
if method == "normal" or method == "crafting" then
form = form .. "image[4.25,1.5;1,1;craftingguide_method_crafting.png]"
elseif method == "cooking" then
form = form .. "image[4.25,1.5;1,1;craftingguide_method_cooking.png]"
-- fuel recipes are different
-- elseif method == "fuel" then
-- form = form .. "image[4.25,1.5;1,1;craftingguide_method_fuel.png]"
else
form = form .. "image[4.25,1.5;1,1;craftingguide_method_unknown.png]"
form = form .. "label[4.1,1.73;"..method.."]"
end
local recipes = craftingguide.items[user.item]
local recipe = recipes[user.itemno]
form = form .. default.ui.fake_itemstack(6.25, 1.5, ItemStack(recipe.output), "guide_craftresult")
-- print(dump(recipe))
for slot_index, itemname in pairs(recipe.items) do
local x = slot_index - 1
local group = string.match(itemname, "group:(.*)")
local w = 3
if recipe.width ~= 0 then
w = recipe.width
end
if group == nil then
form = form .. default.ui.fake_simple_itemstack(1.25 + (x % w), 0.5 + math.floor(x / w), itemname, "guide_craftgrid_"..itemname)
else
form = form .. default.ui.item_group(1.25 + (x % w), 0.5 + math.floor(x / w), group, "guide_craftgrid_"..itemname)
end
end
local page_start = ((page * page_size) - page_size) + 1
local inv_x = 0
local inv_y = 0
for item_index = page_start, (page_start + page_size) - 1 do
local recipes = craftingguide.items[craftingguide.itemlist[item_index]]
if recipes ~= nil then
local itemname = ItemStack(recipes[1].output):get_name()
form = form .. default.ui.fake_simple_itemstack(0.25 + inv_x, 4 + inv_y, itemname, "guide_item_"..itemname)
inv_x = inv_x + 1
if inv_x >= 8 then
inv_x = 0
inv_y = inv_y + 1
end
else
break
end
end
return form
end
local function receive_fields(player, form_name, fields)
if form_name == "core_craftingguide" and not fields.quit then
local name = player:get_player_name()
local user = craftingguide.users[name]
local page = user.page
local recipes = craftingguide.items[user.item]
local itemno = user.itemno
local max_pages = math.floor(#craftingguide.itemlist / page_size) + 1
if fields.guide_next_recipe then
if itemno < #recipes then
itemno = itemno + 1
else
itemno = 1
end
elseif fields.guide_prev_recipe then
if itemno <= 1 then
itemno = #recipes
else
itemno = itemno - 1
end
end
if fields.guide_next and page < max_pages then
page = page + 1
elseif fields.guide_prev and page > 1 then
page = page - 1
end
for fieldname, val in pairs(fields) do
local itemname = string.match(fieldname, "guide_item_(.*)")
if itemname ~= nil then
itemno = 1
craftingguide.users[name].item = itemname
end
end
craftingguide.users[name].page = page
craftingguide.users[name].itemno = itemno
minetest.show_formspec(name, "core_craftingguide", craftingguide.get_formspec(name))
end
end
local function on_joinplayer(player)
local name = player:get_player_name()
craftingguide.users[name] = {page = 1, item = craftingguide.itemlist[1], itemno = 1}
end
local function on_leaveplayer(player)
local name = player:get_player_name()
craftingguide.users[name] = nil
end
local function load_recipes()
for itemname, itemdef in pairs(minetest.registered_items) do
local recipes = minetest.get_all_craft_recipes(itemname)
if recipes ~= nil and itemname ~= "" then
-- print(dump(recipes))
craftingguide.items[itemname] = recipes
table.insert(craftingguide.itemlist, itemname)
end
end
table.sort(craftingguide.itemlist)
print("Got "..#craftingguide.itemlist.." craftable items")
end
minetest.after(0, load_recipes)
minetest.register_on_joinplayer(on_joinplayer)
minetest.register_on_leaveplayer(on_leaveplayer)
minetest.register_on_player_receive_fields(receive_fields)
local form_craftingguide = default.ui.get_page("core")
form_craftingguide = form_craftingguide .. default.ui.get_itemslot_bg(0.25, 4, 8, 4)
form_craftingguide = form_craftingguide .. default.ui.image_button(2.5, 7.9, 1, 1, "guide_prev", "ui_arrow_bg.png^[transformR90")
form_craftingguide = form_craftingguide .. default.ui.image_button(5, 7.9, 1, 1, "guide_next", "ui_arrow_bg.png^[transformR270")
form_craftingguide = form_craftingguide .. default.ui.image_button(0.25, 0.5, 1, 1, "guide_next_recipe", "ui_arrow_bg.png")
form_craftingguide = form_craftingguide .. default.ui.image_button(0.25, 2.5, 1, 1, "guide_prev_recipe", "ui_arrow_bg.png^[transformFY")
form_craftingguide = form_craftingguide .. default.ui.get_itemslot_bg(1.25, 0.5, 3, 3)
form_craftingguide = form_craftingguide .. default.ui.get_itemslot_bg(6.25, 1.5, 1, 1)
form_craftingguide = form_craftingguide .. "image[5.25,1.5;1,1;"..minetest.formspec_escape("ui_arrow.png^[transformR270").."]"
default.ui.register_page("core_craftingguide", form_craftingguide)
default.log("mod:craftingguide", "loaded")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

View File

@ -1,555 +1,3 @@
--
-- Crafting
--
-- Pickaxes
minetest.register_craft(
{
output = "default:pick_wood",
recipe = {
{"", "group:planks", "default:fiber"},
{"", "default:stick", "group:planks"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:pick_stone",
recipe = {
{"", "group:stone", "default:fiber"},
{"", "default:stick", "group:stone"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:pick_steel",
recipe = {
{"", "default:ingot_steel", "default:fiber"},
{"", "default:stick", "default:ingot_steel"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:pick_carbonsteel",
recipe = {
{"", "default:ingot_carbonsteel", "default:fiber"},
{"", "default:stick", "default:ingot_carbonsteel"},
{"default:stick", "", ""},
}
})
-- Shovels
minetest.register_craft(
{
output = "default:shovel_wood",
recipe = {
{"", "group:planks", "group:planks"},
{"", "default:fiber", "group:planks"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:shovel_stone",
recipe = {
{"", "group:stone", "group:stone"},
{"", "default:fiber", "group:stone"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:shovel_steel",
recipe = {
{"", "default:ingot_steel", "default:ingot_steel"},
{"", "default:fiber", "default:ingot_steel"},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:shovel_carbonsteel",
recipe = {
{"", "default:ingot_carbonsteel", "default:ingot_carbonsteel"},
{"", "default:fiber", "default:ingot_carbonsteel"},
{"default:stick", "", ""},
}
})
-- Axes
minetest.register_craft(
{
output = "default:axe_wood",
recipe = {
{"group:planks", "default:fiber"},
{"group:planks", "default:stick"},
{"", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:axe_stone",
recipe = {
{"group:stone", "default:fiber"},
{"group:stone", "default:stick"},
{"", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:axe_steel",
recipe = {
{"default:ingot_steel", "default:fiber"},
{"default:ingot_steel", "default:stick"},
{"", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:axe_carbonsteel",
recipe = {
{"default:ingot_carbonsteel", "default:fiber"},
{"default:ingot_carbonsteel", "default:stick"},
{"", "default:stick"},
}
})
-- Spears
minetest.register_craft(
{
output = "default:spear_wood",
recipe = {
{"", "", "group:planks"},
{"", "default:fiber", ""},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:spear_stone",
recipe = {
{"", "", "group:stone"},
{"", "default:fiber", ""},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:spear_steel",
recipe = {
{"", "", "default:ingot_steel"},
{"", "default:fiber", ""},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:spear_carbonsteel",
recipe = {
{"", "", "default:ingot_carbonsteel"},
{"", "default:fiber", ""},
{"default:stick", "", ""},
}
})
minetest.register_craft(
{
output = "default:shears",
recipe = {
{"default:ingot_steel", ""},
{"group:stick", "default:ingot_steel"},
}
})
-- Broadsword
minetest.register_craft(
{
output = "default:broadsword",
recipe = {
{"", "", "default:ingot_steel"},
{"default:fiber", "default:ingot_steel", ""},
{"default:stick", "default:fiber", ""},
}
})
-- Nodes/Items
minetest.register_craft(
{
output = "default:dust_carbonsteel",
type = "shapeless",
recipe = {"default:lump_coal", "default:lump_iron", "default:lump_iron"}
})
minetest.register_craft(
{
output = "default:rope",
recipe = {
{"default:dry_grass"},
{"default:dry_grass"},
{"default:dry_grass"},
}
})
minetest.register_craft(
{
output = "default:fiber",
type = "shapeless",
recipe = {
"default:grass"
}
})
minetest.register_craft(
{
output = "default:fiber 3",
type = "shapeless",
recipe = {
"group:leaves", "group:leaves", "group:leaves", "group:leaves"
}
})
minetest.register_craft(
{
output = "default:gravel",
recipe = {
{"default:cobble"},
}
})
minetest.register_craft(
{
output = "default:bucket",
recipe = {
{"default:fiber", "default:stick", "default:fiber"},
{"group:planks", "", "group:planks"},
{"group:planks", "group:planks", "group:planks"},
}
})
minetest.register_craft(
{
output = "default:brick",
recipe = {
{"group:soil", "default:gravel", "group:soil"},
{"default:gravel", "group:soil", "default:gravel"},
{"group:soil", "default:gravel", "group:soil"},
}
})
minetest.register_craft(
{
output = "default:block_steel",
recipe = {
{"default:ingot_steel", "default:ingot_steel", "default:ingot_steel"},
{"default:ingot_steel", "default:ingot_steel", "default:ingot_steel"},
{"default:ingot_steel", "default:ingot_steel", "default:ingot_steel"},
}
})
minetest.register_craft(
{
output = "default:block_coal",
recipe = {
{"default:lump_coal", "default:lump_coal", "default:lump_coal"},
{"default:lump_coal", "default:lump_coal", "default:lump_coal"},
{"default:lump_coal", "default:lump_coal", "default:lump_coal"},
}
})
minetest.register_craft(
{
output = "default:dirt_path 8",
recipe = {
{"group:soil", "group:soil", "group:soil"},
{"default:gravel", "default:gravel", "default:gravel"},
{"default:gravel", "default:gravel", "default:gravel"},
}
})
minetest.register_craft(
{
output = "default:path_slab 3",
recipe = {
{"group:soil_path", "group:soil_path", "group:soil_path"},
}
})
minetest.register_craft(
{
output = "default:heated_dirt_path",
recipe = {
{"group:soil_path"},
{"default:ingot_steel"},
}
})
minetest.register_craft(
{
output = "default:planks 4",
recipe = {
{"default:tree"},
}
})
minetest.register_craft(
{
output = "default:planks_oak 4",
recipe = {
{"default:tree_oak"},
}
})
minetest.register_craft(
{
output = "default:planks_birch 4",
recipe = {
{"default:tree_birch"},
}
})
minetest.register_craft(
{
output = "default:frame",
recipe = {
{"default:fiber", "default:stick", "default:fiber"},
{"default:stick", "group:planks", "default:stick"},
{"default:fiber", "default:stick", "default:fiber"},
}
})
minetest.register_craft(
{
output = "default:reinforced_frame",
recipe = {
{"default:fiber", "default:stick", "default:fiber"},
{"default:stick", "default:frame", "default:stick"},
{"default:fiber", "default:stick", "default:fiber"},
}
})
minetest.register_craft(
{
output = "default:stick 4",
recipe = {
{"group:planks"},
}
})
minetest.register_craft(
{
output = "default:fence 4",
recipe = {
{"default:stick", "", "default:stick"},
{"default:fiber", "default:planks", "default:fiber"},
{"default:stick", "", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:fence_oak 4",
recipe = {
{"default:stick", "", "default:stick"},
{"default:fiber", "default:planks_oak", "default:fiber"},
{"default:stick", "", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:fence_birch 4",
recipe = {
{"default:stick", "", "default:stick"},
{"default:fiber", "default:planks_birch", "default:fiber"},
{"default:stick", "", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:sign 2",
recipe = {
{"group:planks", "default:fiber", "group:planks"},
{"group:planks", "group:planks", "group:planks"},
{"", "default:stick", ""},
}
})
minetest.register_craft(
{
output = "default:reinforced_cobble",
recipe = {
{"default:fiber", "default:stick", "default:fiber"},
{"default:stick", "default:cobble", "default:stick"},
{"default:fiber", "default:stick", "default:fiber"},
}
})
minetest.register_craft(
{
output = "default:torch 2",
recipe = {
{"default:lump_coal"},
{"default:fiber"},
{"default:stick"},
}
})
minetest.register_craft(
{
output = "default:torch_weak 2",
recipe = {
{"default:fiber"},
{"default:stick"},
}
})
minetest.register_craft(
{
output = "default:flint 2",
type = "shapeless",
recipe = {"default:gravel"},
})
minetest.register_craft(
{
output = "default:flint_and_steel",
recipe = {
{"default:ingot_steel", ""},
{"default:fiber", "default:flint"},
},
})
minetest.register_craft(
{
output = "default:chest",
recipe = {
{"group:planks", "group:planks", "group:planks"},
{"group:planks", "default:fiber", "group:planks"},
{"group:planks", "group:planks", "group:planks"},
}
})
minetest.register_craft(
{
output = "default:chest_locked",
recipe = {
{"default:fiber", "default:stick", "default:fiber"},
{"default:stick", "default:chest", "default:stick"},
{"default:fiber", "default:ingot_steel", "default:fiber"},
}
})
minetest.register_craft(
{
output = "default:furnace",
recipe = {
{"group:stone", "group:stone", "group:stone"},
{"group:stone", "", "group:stone"},
{"group:stone", "group:stone", "group:stone"},
}
})
minetest.register_craft(
{
output = "default:sandstone 2",
recipe = {
{"default:sand", "default:sand"},
{"default:sand", "default:sand"},
}
})
minetest.register_craft(
{
output = "default:sandstone 2",
type = "shapeless",
recipe = {"default:compressed_sandstone"},
})
minetest.register_craft(
{
output = "default:compressed_sandstone",
type = "shapeless",
recipe = {"default:sandstone", "default:sandstone"},
})
minetest.register_craft(
{
output = "default:paper",
recipe = {
{"default:papyrus", "default:papyrus", "default:papyrus"},
}
})
minetest.register_craft(
{
output = "default:book",
recipe = {
{"default:fiber", "default:stick", "default:paper"},
{"default:fiber", "default:stick", "default:paper"},
{"default:fiber", "default:stick", "default:paper"},
}
})
minetest.register_craft(
{
output = "default:bookshelf",
recipe = {
{"group:planks", "group:planks", "group:planks"},
{"default:book", "default:book", "default:book"},
{"group:planks", "group:planks", "group:planks"},
}
})
minetest.register_craft(
{
output = "default:ladder 2",
recipe = {
{"default:stick", "", "default:stick"},
{"default:fiber", "default:stick", "default:fiber"},
{"default:stick", "", "default:stick"},
}
})
minetest.register_craft(
{
output = "default:fertilizer 3",
recipe = {
{"", "default:fiber", ""},
{"default:fern", "default:fern", "default:fern"},
{"default:fern", "default:fern", "default:fern"},
},
})
--
-- Tool repair
--
minetest.register_craft(
{
type = "toolrepair",
additional_wear = -0.1,
})
--
-- Cooking

View File

@ -1,9 +1,22 @@
default.ui = {}
default.ui.core = {}
-- UI defaults
default.ui.core.colors = "listcolors[#00000000;#00000010;#00000000;#68B259;#FFF]"
default.ui.core.bg = "bgcolor[#00000000;false]"
default.ui.default = {}
-- Colors
default.ui.default.colors = "listcolors[#00000000;#00000010;#00000000;#68B259;#FFF]"
default.ui.default.bg = "bgcolor[#00000000;false]"
-- Group default items
default.ui.group_defaults = {
planks = "default:planks",
stone = "default:stone",
soil = "default:dirt",
}
function default.ui.get_itemslot_bg(x, y, w, h)
local out = ""
@ -38,7 +51,9 @@ function default.ui.button(x, y, w, h, name, label, noclip)
nc = "true"
end
if w == 2 then
if w == 1 then
return "image_button["..x..","..y..";"..w..","..h..";ui_button_1w_inactive.png;"..name..";"..label..";"..nc..";false;ui_button_1w_active.png]"
elseif w == 2 then
return "image_button["..x..","..y..";"..w..","..h..";ui_button_2w_inactive.png;"..name..";"..label..";"..nc..";false;ui_button_2w_active.png]"
else
return "image_button["..x..","..y..";"..w..","..h..";ui_button_3w_inactive.png;"..name..";"..label..";"..nc..";false;ui_button_3w_active.png]"
@ -94,8 +109,8 @@ function default.ui.fake_itemstack(x, y, itemstack, name)
if itemname ~= "" then
-- result = result .. "image_button["..x..","..y..";1,1;"..itemimage..";"..name..";;false;false;"..itemimage.."]"
result = result .. "image_button["..x..","..y..";1,1;ui_null.png;"..name..";;false;false;ui_null.png]"
result = result .. "item_image["..x..","..y..";1,1;"..minetest.formspec_escape(itemname).."]"
result = result .. "label["..(x+0.6)..","..(y+0.5)..";"..itemamt.."]"
result = result .. "item_image["..x..","..y..";1,1;"..minetest.formspec_escape(itemname .. " " .. itemamt).."]"
result = result .. "tooltip["..name..";"..itemdesc.."]"
end
@ -121,14 +136,21 @@ function default.ui.fake_simple_itemstack(x, y, itemname, name)
return result
end
function default.ui.item_group(x, y, group, name)
function default.ui.item_group(x, y, group, count, name)
local name = name or "fake_itemgroup"
local itemname = ""
for itemn, itemdef in pairs(minetest.registered_items) do
if minetest.get_item_group(itemn, group) ~= 0 and minetest.get_item_group(itemn, "not_in_craftingguide") ~= 1 then
itemname = itemn
local group_default = default.ui.group_defaults[group]
if group_default ~= nil and minetest.registered_items[group_default] then
itemname = group_default
else
for itemn, itemdef in pairs(minetest.registered_items) do
if minetest.get_item_group(itemn, group) ~= 0
and minetest.get_item_group(itemn, "not_in_craftingguide") ~= 1 then
itemname = itemn
end
end
end
@ -139,15 +161,25 @@ function default.ui.item_group(x, y, group, name)
local result = ""
if itemname ~= "" then
-- result = result .. "image_button["..x..","..y..";1,1;"..itemimage..";"..name..";;false;false;"..itemimage.."]"
result = result .. "image_button["..x..","..y..";1,1;ui_null.png;"..name..";G;false;false;ui_null.png]"
result = result .. "item_image["..x..","..y..";1,1;"..minetest.formspec_escape(itemname).."]"
result = result .. "image_button["..x..","..y..";1,1;ui_null.png;"..name..";;false;false;ui_null.png]"
result = result .. "item_image["..x..","..y..";1,1;"..minetest.formspec_escape(itemname .. " " .. count).."]"
result = result .. "tooltip["..name..";Group: "..group.."]"
end
return result
end
function default.ui.fake_itemstack_any(x, y, itemstack, name)
local group = string.match(itemstack:get_name(), "group:(.*)")
if group == nil then
return default.ui.fake_itemstack(x, y, itemstack, name)
else
return default.ui.item_group(x, y, group, itemstack:get_count(), name)
end
end
default.ui.registered_pages = {
}
@ -166,61 +198,42 @@ function default.ui.register_page(name, form)
default.ui.registered_pages[name] = form
end
local form_core = ""
form_core = form_core .. "size[8.5,9]"
form_core = form_core .. default.ui.core.colors
form_core = form_core .. default.ui.core.bg
form_core = form_core .. default.ui.tab(-0.9, 0.5, "tab_crafting", "ui_icon_crafting.png", "Crafting")
if minetest.get_modpath("craftingguide") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 1.28, "tab_craftingguide", "ui_icon_craftingguide.png", "Crafting Guide")
end
local form_default_default = ""
form_default_default = form_default_default .. "size[8.5,9]"
form_default_default = form_default_default .. default.ui.default.colors
form_default_default = form_default_default .. default.ui.default.bg
form_default_default = form_default_default .. default.ui.tab(-0.9, 0.5, "tab_crafting", "ui_icon_crafting.png", "Crafting")
if minetest.get_modpath("armor") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 2.06, "tab_armor", "ui_icon_armor.png", "Armor")
form_default_default = form_default_default .. default.ui.tab(-0.9, 1.28, "tab_armor", "ui_icon_armor.png", "Armor")
end
if minetest.get_modpath("achievements") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 2.84, "tab_achievements", "ui_icon_achievements.png", "Achievements")
form_default_default = form_default_default .. default.ui.tab(-0.9, 2.06, "tab_achievements", "ui_icon_achievements.png", "Achievements")
end
if minetest.get_modpath("player_skins") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 3.62, "tab_player_skins", "ui_icon_player_skins.png", "Player Skins")
form_default_default = form_default_default .. default.ui.tab(-0.9, 2.84, "tab_player_skins", "ui_icon_player_skins.png", "Player Skins")
end
form_core = form_core .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
default.ui.register_page("core", form_core)
default.ui.register_page("core_2part", form_core .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
form_default_default = form_default_default .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
default.ui.register_page("default:default", form_default_default)
default.ui.register_page("default:2part", form_default_default .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
local form_core_notabs = ""
form_core_notabs = form_core_notabs .. "size[8.5,9]"
form_core_notabs = form_core_notabs .. default.ui.core.colors
form_core_notabs = form_core_notabs .. default.ui.core.bg
form_core_notabs = form_core_notabs .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
default.ui.register_page("core_notabs", form_core_notabs)
default.ui.register_page("core_notabs_2part", form_core_notabs .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
local form_default_notabs = ""
form_default_notabs = form_default_notabs .. "size[8.5,9]"
form_default_notabs = form_default_notabs .. default.ui.default.colors
form_default_notabs = form_default_notabs .. default.ui.default.bg
form_default_notabs = form_default_notabs .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
default.ui.register_page("default:notabs", form_default_notabs)
default.ui.register_page("default:notabs_2part", form_default_notabs .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
local form_core_field = ""
form_core_field = form_core_field .. "size[8.5,5]"
form_core_field = form_core_field .. default.ui.core.colors
form_core_field = form_core_field .. default.ui.core.bg
form_core_field = form_core_field .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]"
form_core_field = form_core_field .. default.ui.button_exit(2.75, 3, 3, 1, "", "Write", false)
form_core_field = form_core_field .. "field[1,1.75;7,0;text;;${text}]"
default.ui.register_page("core_field", form_core_field)
local form_default_field = ""
form_default_field = form_default_field .. "size[8.5,5]"
form_default_field = form_default_field .. default.ui.default.colors
form_default_field = form_default_field .. default.ui.default.bg
form_default_field = form_default_field .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]"
form_default_field = form_default_field .. default.ui.button_exit(2.75, 3, 3, 1, "", "Write", false)
form_default_field = form_default_field .. "field[1,1.75;7,0;text;;${text}]"
default.ui.register_page("default:field", form_default_field)
local form_crafting = default.ui.get_page("core_2part")
form_crafting = form_crafting .. "list[current_player;main;0.25,4.75;8,4;]"
form_crafting = form_crafting .. "listring[current_player;main]"
form_crafting = form_crafting .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
form_crafting = form_crafting .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
form_crafting = form_crafting .. "list[current_player;craft;2.25,0.75;3,3;]"
form_crafting = form_crafting .. "listring[current_player;craft]"
form_crafting = form_crafting .. "image[5.25,1.75;1,1;ui_arrow_bg.png^[transformR270]"
form_crafting = form_crafting .. "list[current_player;craftpreview;6.25,1.75;1,1;]"
form_crafting = form_crafting .. default.ui.get_itemslot_bg(2.25, 0.75, 3, 3)
form_crafting = form_crafting .. default.ui.get_itemslot_bg(6.25, 1.75, 1, 1)
default.ui.register_page("core_crafting", form_crafting)
local form_bookshelf = default.ui.get_page("core_2part")
local form_bookshelf = default.ui.get_page("default:2part")
form_bookshelf = form_bookshelf .. "list[current_player;main;0.25,4.75;8,4;]"
form_bookshelf = form_bookshelf .. "listring[current_player;main]"
form_bookshelf = form_bookshelf .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
@ -229,7 +242,7 @@ form_bookshelf = form_bookshelf .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
form_bookshelf = form_bookshelf .. "list[current_name;main;2.25,1.25;4,2;]"
form_bookshelf = form_bookshelf .. "listring[current_name;main]"
form_bookshelf = form_bookshelf .. default.ui.get_itemslot_bg(2.25, 1.25, 4, 2)
default.ui.register_page("core_bookshelf", form_bookshelf)
default.ui.register_page("default:bookshelf", form_bookshelf)
function default.ui.receive_fields(player, form_name, fields)
local name = player:get_player_name()
@ -237,15 +250,13 @@ function default.ui.receive_fields(player, form_name, fields)
-- print("Received formspec fields from '"..name.."': "..dump(fields))
if fields.tab_crafting then
minetest.show_formspec(name, "core_crafting", default.ui.get_page("core_crafting"))
elseif minetest.get_modpath("craftingguide") ~= nil and fields.tab_craftingguide then
minetest.show_formspec(name, "core_craftingguide", craftingguide.get_formspec(name))
minetest.show_formspec(name, "crafting:crafting", crafting.get_formspec(name))
elseif minetest.get_modpath("armor") ~= nil and fields.tab_armor then
minetest.show_formspec(name, "core_armor", default.ui.get_page("core_armor"))
minetest.show_formspec(name, "armor:armor", default.ui.get_page("armor:armor"))
elseif minetest.get_modpath("achievements") ~= nil and fields.tab_achievements then
minetest.show_formspec(name, "core_achievements", achievements.get_formspec(name))
minetest.show_formspec(name, "achievements:achievements", achievements.get_formspec(name))
elseif minetest.get_modpath("player_skins") ~= nil and fields.tab_player_skins then
minetest.show_formspec(name, "core_player_skins", player_skins.get_formspec(name))
minetest.show_formspec(name, "player_skins:player_skins", player_skins.get_formspec(name))
end
end
@ -256,5 +267,5 @@ end)
minetest.register_on_joinplayer(
function(player)
player:set_inventory_formspec(default.ui.get_page("core_crafting"))
player:set_inventory_formspec(crafting.get_formspec(player:get_player_name()))
end)

View File

@ -3,7 +3,7 @@
--
function default.furnace_active_formspec(percent, item_percent)
local form = default.ui.get_page("core_2part")
local form = default.ui.get_page("default:2part")
form = form .. "list[current_player;main;0.25,4.75;8,4;]"
form = form .. "listring[current_player;main]"
form = form .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
@ -28,7 +28,7 @@ function default.furnace_active_formspec(percent, item_percent)
return form
end
local form_furnace = default.ui.get_page("core_2part")
local form_furnace = default.ui.get_page("default:2part")
form_furnace = form_furnace .. "list[current_player;main;0.25,4.75;8,4;]"
form_furnace = form_furnace .. "listring[current_player;main]"
form_furnace = form_furnace .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
@ -142,7 +142,7 @@ minetest.register_abm(
local fuel_time = meta:get_float("fuel_time") or 0
local src_time = meta:get_float("src_time") or 0
local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
--
-- Initialize inventory
--
@ -160,24 +160,24 @@ minetest.register_abm(
local srclist = inv:get_list("src")
local fuellist = inv:get_list("fuel")
local dstlist = inv:get_list("dst")
--
-- Cooking
--
-- Check if we have cookable content
local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
local cookable = true
if cooked.time == 0 then
cookable = false
end
-- Check if we have enough fuel to burn
if fuel_time < fuel_totaltime then
-- The furnace is currently active and has enough fuel
fuel_time = fuel_time + 1
-- If there is a cookable item then check if it is ready yet
if cookable then
src_time = src_time + 1
@ -195,7 +195,7 @@ minetest.register_abm(
if cookable then
-- We need to get new fuel
local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
if fuel.time == 0 then
-- No valid fuel in fuel list
fuel_totaltime = 0
@ -204,10 +204,10 @@ minetest.register_abm(
else
-- Take fuel from fuel list
inv:set_stack("fuel", 1, afterfuel.items[1])
fuel_totaltime = fuel.time
fuel_time = 0
end
else
-- We don't need to get new fuel since there is no cookable item
@ -216,7 +216,7 @@ minetest.register_abm(
src_time = 0
end
end
--
-- Update formspec, infotext and node
--
@ -233,7 +233,7 @@ minetest.register_abm(
item_state = "Not cookable"
end
end
local fuel_state = "Empty"
local active = "inactive "
if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then
@ -248,9 +248,9 @@ minetest.register_abm(
end
swap_node(pos, "default:furnace")
end
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
--
-- Set meta values
--
@ -262,4 +262,4 @@ minetest.register_abm(
end,
})
default.log("furnace", "loaded")
default.log("furnace", "loaded")

View File

@ -44,4 +44,4 @@ dofile(minetest.get_modpath("default").."/hud.lua")
dofile(minetest.get_modpath("default").."/player.lua")
dofile(minetest.get_modpath("default").."/model.lua")
default.log("mod:default", "loaded")
default.log("mod:default", "loaded")

View File

@ -662,7 +662,7 @@ minetest.register_node(
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", default.ui.get_page("core_bookshelf"))
meta:set_string("formspec", default.ui.get_page("default:bookshelf"))
meta:set_string("infotext", "Bookshelf")
local inv = meta:get_inventory()
inv:set_size("main", 4*2)
@ -1226,7 +1226,7 @@ minetest.register_node(
on_construct = function(pos)
--local n = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", default.ui.get_page("core_field"))
meta:set_string("formspec", default.ui.get_page("default:field"))
meta:set_string("infotext", '""')
meta:set_string("text", "")
end,
@ -1483,7 +1483,7 @@ minetest.register_node(
end,
})
local form_chest = default.ui.get_page("core_2part")
local form_chest = default.ui.get_page("default:2part")
form_chest = form_chest .. "list[current_name;main;0.25,0.25;8,4;]"
form_chest = form_chest .. "listring[current_name;main]"
form_chest = form_chest .. default.ui.get_itemslot_bg(0.25, 0.25, 8, 4)
@ -1492,6 +1492,6 @@ form_chest = form_chest .. "list[current_player;main;0.25,4.75;8,4;]"
form_chest = form_chest .. "listring[current_player;main]"
form_chest = form_chest .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
form_chest = form_chest .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
default.ui.register_page("default_chest", form_chest)
default.ui.register_page("default:chest", form_chest)
default.log("nodes", "loaded")

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

View File

@ -131,7 +131,7 @@ end
local form_trading = ""
form_trading = form_trading .. default.ui.get_page("core_2part")
form_trading = form_trading .. default.ui.get_page("default:2part")
form_trading = form_trading .. "list[current_player;gold_trade_out;3.75,2.25;1,1;]"
form_trading = form_trading .. "listring[current_player;gold_trade_out]"
@ -192,7 +192,7 @@ function gold.trade(trade, trade_type, player)
form = form .. default.ui.fake_itemstack(1.25, 1.25, trade_wanted1, "trade_wanted1")
form = form .. default.ui.fake_itemstack(1.25, 2.25, trade_wanted2, "trade_wanted2")
form = form .. default.ui.fake_itemstack(3.75, 1.25, ItemStack(trade[3]), "vistrade_result")
form = form .. default.ui.fake_itemstack(3.75, 1.25, ItemStack(trade[3]), "trade_result")
minetest.show_formspec(name, "gold:trading_book", form)

View File

@ -99,7 +99,7 @@ function jewels.register_jewel(toolname, new_toolname, def)
end
end
new_tooldef.description = desc
new_tooldef.description = desc
minetest.register_tool(new_toolname, new_tooldef)
end
@ -156,7 +156,7 @@ minetest.register_node(
end,
on_punch = function(pos, node, player, pointed_thing)
local itemstack = player:get_wielded_item()
if itemstack:get_name() == "jewels:jewel" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -170,7 +170,7 @@ minetest.register_node(
achievements.trigger_achievement(player, "jeweler")
achievements.trigger_achievement(player, "master_jeweler")
end
end
end
player:set_wielded_item(itemstack)
@ -187,7 +187,7 @@ minetest.register_craft(
}
})
local form_bench = default.ui.get_page("core_2part")
local form_bench = default.ui.get_page("default:2part")
form_bench = form_bench .. "list[current_name;main;2.25,1.75;1,1;]"
form_bench = form_bench .. "listring[current_name;main]"
form_bench = form_bench .. default.ui.get_itemslot_bg(2.25, 1.75, 1, 1)

View File

@ -134,7 +134,7 @@ minetest.register_node(
end
local np = pos.x .. "," .. pos.y .. "," .. pos.z
local form = default.ui.get_page("core_2part")
local form = default.ui.get_page("default:2part")
form = form .. "list[nodemeta:" .. np .. ";main;0.25,0.25;8,4;]"
form = form .. "listring[nodemeta:" .. np .. ";main]"
form = form .. default.ui.get_itemslot_bg(0.25, 0.25, 8, 4)

View File

@ -4,7 +4,7 @@ nav.map_radius = 256
nav.waypoints = {}
local form_nav = default.ui.get_page("core")
local form_nav = default.ui.get_page("default:default")
default.ui.register_page("nav:nav", form_nav)
local open_formspecs = {}
@ -29,7 +29,7 @@ function nav.get_waypoints_in_square(pos, radius)
for name, data in pairs(nav.waypoints) do
local wp = data.pos
if wp.x > pos.x-radius and wp.x < pos.x+radius and wp.z > pos.z-radius and wp.z < pos.z+radius then
table.insert(wpts, name)
end
@ -45,7 +45,7 @@ local function get_formspec_waypoint(x, y, name, label, isinfo)
end
local form = ""
form = form .. "image_button["..(x-0.72)..","..(y-0.53)..";0.5,0.5;"..img..";"..name..";;false;false;"..img.."]"
form = form .. "tooltip["..name..";"..minetest.formspec_escape(label).."]"
@ -131,9 +131,9 @@ local function step(dtime)
for _, player in pairs(minetest.get_connected_players()) do
if player ~= nil then
local name = player:get_player_name()
players[name] = player
nav.show_map(player)
end
end
@ -188,4 +188,4 @@ achievements.register_achievement(
description = "Craft a map",
times = 1,
craftitem = "nav:map",
})
})

View File

@ -16,7 +16,7 @@ player_skins.skins = {}
local update_time = 1
local timer = 10
local skins_file = minetest.get_worldpath() .. "/player_skins"
local skins_file = minetest.get_worldpath() .. "/player_skins.dat"
local function save_skins()
local f = io.open(skins_file, "w")
@ -60,7 +60,7 @@ end
function player_skins.get_skin(name)
return "player_skins_" .. player_skins.skins[name] .. ".png"
end
function player_skins.set_skin(name, tex)
if minetest.check_player_privs(name, {player_skin = true}) then
if is_valid_skin(tex) then
@ -115,7 +115,7 @@ local function get_chatparams()
end
function player_skins.get_formspec(playername)
local form = default.ui.get_page("core")
local form = default.ui.get_page("default:default")
form = form .. "image[4,0;0.5,10.05;ui_vertical_divider.png]"
@ -129,7 +129,7 @@ function player_skins.get_formspec(playername)
end
form = form .. default.ui.button(x, y, 2, 1, "skin_select_" .. name, player_skins.skin_names[i])
form = form .. "image[" .. (x + 2.25) .. "," .. y.. ";1,1;player_skins_icon_" .. name .. ".png]"
form = form .. "image[" .. (x + 2.25) .. "," .. y.. ";1,1;player_skins_icon_" .. name .. ".png]"
if player_skins.skins[playername] == name then
form = form .. "image[" .. (x + 3.25) .. "," .. (y + 0.25).. ";0.5,0.5;ui_checkmark.png]"
end
@ -148,7 +148,7 @@ minetest.register_on_player_receive_fields(
if skinname ~= nil then
player_skins.set_skin(name, skinname)
minetest.show_formspec(name, "core_player_skins", player_skins.get_formspec(name))
minetest.show_formspec(name, "player_skins:player_skins", player_skins.get_formspec(name))
end
end
end)
@ -164,7 +164,7 @@ minetest.register_chatcommand(
if is_valid_skin(param) then
player_skins.set_skin(name, param)
elseif param == "" then
minetest.chat_send_player(name, "Current player skin: " .. player_skins.skins[name])
minetest.chat_send_player(name, "Current player skin: " .. player_skins.skins[name])
else
minetest.chat_send_player(name, "Bad param for /player_skin; type /help player_skin")
end
@ -173,4 +173,4 @@ minetest.register_chatcommand(
minetest.after(1.0, load_skins)
default.log("mod:player_skins", "loaded")
default.log("mod:player_skins", "loaded")

View File

@ -20,7 +20,7 @@ function welcome.get_formspec(name)
return ""
end
local form = default.ui.get_page("core_notabs")
local form = default.ui.get_page("default:notabs")
local rules = ""