New crafting method along with a plethora of bugfixes in general; crafts in the default mod all should be functional

This commit is contained in:
KaadmY 2017-05-14 14:50:37 -07:00
parent 7e825c4a6a
commit fdb2e11951
8 changed files with 939 additions and 899 deletions

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")

View File

@ -0,0 +1 @@
default

View File

@ -1,343 +1,10 @@
--
-- Crafting mod
-- By Kaadmy, for Pixture
--
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(output, def)
-- `output` can be any ItemStack value, but count is NOT used
local itemstack = ItemStack(output)
local itemn = itemstack:get_name()
if crafting.registered_crafts[itemn] ~= nil then
minetest.log("warning",
"Tried to register an existing craft " .. itemn .. ", 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 " .. itemn .." with more than "
.. crafting.max_inputs .. " inputs, keeping")
end
for i = 1, crafting.max_inputs do
craftdef.items[i] = ItemStack(craftdef.items[i])
end
crafting.registered_crafts[itemn] = craftdef
minetest.log("info", "Registered recipe for " .. itemn)
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 ipairs(filter) do
if craftdef[filtername] ~= nil and craftdef[filtername] == filtervalue 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
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
minetest.log("warning",
"Not enough items to craft " .. wanted:to_string())
return nil
end
end
end
-- Put stuff in output stack
print("Free space: " .. output:get_free_space())
if craft_count - output:get_free_space() > 0 then
craft_count = craft_count - (craft_count - output:get_free_space())
end
if craft_count < 1 then
minetest.log("warning",
"Output stack too full to hold " .. wanted:to_string())
return nil
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,0.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, 0.25, 1, 1)
form = form .. "image[7.25,1.25;1,1;ui_arrow_bg.png]"
form = form .. default.ui.button(7.25, 2.25, 1, 1, "do_craft_1", "1")
form = form .. default.ui.button(7.25, 3.25, 1, 1, "do_craft_10", "10")
form = form .. "tableoptions[background=#DDDDDD30]"
form = form .. "tablecolumns[text,align=left,width=1]"
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)
for _, itemn in ipairs(craftitems) do
if craft_list ~= "" then
craft_list = craft_list .. ","
end
local itemdef = minetest.registered_items[itemn]
if itemdef ~= nil then
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 .. "]"
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
minetest.log("warning",
"Trying to craft " .. wanted_itemstack:to_string() ..
" but output has too many/different items")
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 and 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
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)
crafting.register_craft(
"default:stone",
{
items = {
{name = "default:stick", count = 1},
{name = "default:fiber", count = 1},
},
})
crafting.register_craft(
"default:apple",
{
items = {
{name = "default:fiber", count = 5},
},
})
crafting.register_craft(
"default:stick",
{
items = {
{name = "default:stone", count = 2},
{name = "default:tree", count = 2},
},
})
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,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,10 +1,23 @@
default.ui = {}
-- UI defaults
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 = ""
for i = 0, w - 1, 1 do
@ -96,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
@ -123,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
@ -141,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 = {
}

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

@ -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)