Start adding crafting recipes to everything with the new crafting system and fix some things with armor

This commit is contained in:
KaadmY 2017-05-15 20:57:30 -07:00
parent d7b63ec912
commit dc8674b93f
7 changed files with 263 additions and 232 deletions

View File

@ -1,2 +1,3 @@
default
crafting
achievements

View File

@ -6,24 +6,44 @@
armor = {}
armor.player_skin = "character.png"
armor.update_time = 1
armor.materials = {
-- material craftitem % description
-- material craftitem % description
{"wood", "group:planks", 15, "Wooden"},
{"steel", "default:ingot_steel", 30, "Steel"},
{"chainmail", "armor:chainmail_sheet", 45, "Chainmail"},
{"carbonsteel", "default:ingot_carbonsteel", 60, "Carbonsteel"},
}
armor.slots = {"helmet", "chestplate", "boots"}
-- Usable slots
local form_armor = default.ui.get_page("default:2part")
default.ui.register_page("armor:armor", form_armor)
armor.slots = {"helmet", "chestplate", "boots"}
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
local armor_timer = 10
-- Timer
local timer_interval = 1
local timer = 10
-- Formspec
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)
form_armor = form_armor .. "listring[current_player;main]"
form_armor = form_armor .. "label[3.25,1;Helmet]"
form_armor = form_armor .. "label[3.25,2;Chestplate]"
form_armor = form_armor .. "label[3.25,3;Boots]"
form_armor = form_armor .. "list[current_player;armor;2.25,0.75;1,3;]"
form_armor = form_armor .. "listring[current_player;armor]"
form_armor = form_armor .. default.ui.get_itemslot_bg(2.25, 0.75, 1, 3)
default.ui.register_page("armor:armor", form_armor)
function armor.is_armor(itemname)
local item = minetest.registered_items[itemname]
@ -57,9 +77,10 @@ function armor.get_texture(player, base)
local image = base
for _, slot in ipairs(armor.slots) do
local itemstack = inv:get_stack("armor_"..slot, 1)
for slot_index, slot in ipairs(armor.slots) do
local itemstack = inv:get_stack("armor", slot_index)
local itemname = itemstack:get_name()
if armor.is_armor(itemname) and armor.is_slot(itemname, slot) then
local item = minetest.registered_items[itemname]
local mat = armor.materials[item.groups.armor_material][1]
@ -68,7 +89,7 @@ function armor.get_texture(player, base)
end
end
-- print("[armor] Got armor texture: " .. image)
-- print("[armor] Got armor texture: " .. image)
return image
end
@ -81,8 +102,8 @@ function armor.get_groups(player)
local inv = player:get_inventory()
for _, slot in ipairs(armor.slots) do
local itemstack = inv:get_stack("armor_"..slot, 1)
for slot_index, slot in ipairs(armor.slots) do
local itemstack = inv:get_stack("armor", slot_index)
local itemname = itemstack:get_name()
if armor.is_armor(itemname) then
@ -96,9 +117,11 @@ function armor.get_groups(player)
if match_mat == nil then
match_mat = mat
end
if mat == match_mat then
match_amt = match_amt + 1
end
break
end
end
@ -106,7 +129,9 @@ function armor.get_groups(player)
end
end
if match_amt == #armor.slots then -- if full set of same armor material, then boost armor by 10%
-- If full set of same armor material, then boost armor by 10%
if match_amt == #armor.slots then
groups.fleshy = groups.fleshy - 10
end
@ -118,10 +143,8 @@ end
function armor.init(player)
local inv = player:get_inventory()
for _, slot in ipairs(armor.slots) do
if inv:get_size("armor_"..slot) ~= 1 then
inv:set_size("armor_"..slot, 1)
end
if inv:get_size("armor") ~= 3 then
inv:set_size("armor", 3)
end
end
@ -143,13 +166,13 @@ local function on_joinplayer(player)
armor.init(player)
end
local function on_die(player)
local function on_dieplayer(player)
local pos = player:getpos()
local inv = player:get_inventory()
for _, slot in ipairs(armor.slots) do
local item = inv:get_stack("armor_"..slot, 1)
for slot_index, slot in ipairs(armor.slots) do
local item = inv:get_stack("armor", slot_index)
local rpos = {
x = pos.x + math.random(-0.2, 0.2),
@ -173,53 +196,73 @@ local function on_die(player)
end
end
local function step(dtime)
armor_timer = armor_timer + dtime
local function on_globalstep(dtime)
timer = timer + dtime
if timer < timer_interval then
return
end
timer = 0
if armor_timer > armor.update_time then
for _, player in pairs(minetest.get_connected_players()) do
armor.update(player)
end
armor_timer = 0
end
end
if enable_drop then
minetest.register_on_dieplayer(on_dieplayer)
end
minetest.register_on_newplayer(on_newplayer)
minetest.register_on_joinplayer(on_joinplayer)
minetest.register_globalstep(on_globalstep)
-- Chainmail
minetest.register_craftitem(
"armor:chainmail_sheet",
{
description = "Chainmail sheet",
description = "Chainmail Sheet",
inventory_image = "armor_chainmail.png",
wield_image = "armor_chainmail.png",
stack_max = 20,
})
})
minetest.register_craft(
crafting.register_craft(
{
output = "armor:chainmail_sheet 3",
recipe = {
{"default:ingot_steel", "", "default:ingot_steel"},
{"", "default:ingot_steel", ""},
{"default:ingot_steel", "", "default:ingot_steel"},
items = {
"default:ingot_steel 5",
}
})
})
-- Armor pieces
for mat_index, _ in ipairs(armor.materials) do
local def = armor.materials[mat_index]
local mat = def[1]
local armor_def = math.floor(def[3] / #armor.slots)
-- print("Material " .. mat .. ": " .. armor_def)
-- print("Material " .. mat .. ": " .. armor_def)
for _, slot in ipairs(armor.slots) do
minetest.register_craftitem(
"armor:"..slot.."_"..mat,
{
description = def[4].." "..slot,
local slot_pretty = slot:gsub(
"(%a)([%w_']*)",
function(first, rest)
return first:upper() .. rest:lower()
end)
inventory_image = "armor_"..slot.."_"..mat.."_inventory.png",
wield_image = "armor_"..slot.."_"..mat.."_inventory.png",
minetest.register_craftitem(
"armor:" .. slot .. "_" .. mat,
{
description = def[4] .. " " .. slot_pretty,
inventory_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
wield_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
groups = {
is_armor = 1,
@ -231,69 +274,31 @@ for mat_index, _ in ipairs(armor.materials) do
})
end
local n = def[2]
crafting.register_craft(
{
output = "armor:helmet_" .. mat,
items = {
def[2] .. " 5",
}
})
minetest.register_craft(
crafting.register_craft(
{
output = "armor:helmet_"..mat,
recipe = {
{n, n, n},
{n, "", n},
{"", "", ""},
output = "armor:chestplate_" .. mat,
items = {
def[2] .. " 8",
}
})
minetest.register_craft(
crafting.register_craft(
{
output = "armor:chestplate_"..mat,
recipe = {
{n, "", n},
{n, n, n},
{n, n, n},
}
})
minetest.register_craft(
{
output = "armor:boots_"..mat,
recipe = {
{"", "", ""},
{n, "", n},
{n, "", n},
output = "armor:boots_" .. mat,
items = {
def[2] .. " 6",
}
})
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("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)
form_armor = form_armor .. "listring[current_player;main]"
form_armor = form_armor .. "label[3.25,3;Boots]"
form_armor = form_armor .. "list[current_player;armor_boots;2.25,2.75;1,1;]"
form_armor = form_armor .. "listring[current_player;armor_boots]"
form_armor = form_armor .. default.ui.get_itemslot_bg(2.25, 2.75, 1, 1)
form_armor = form_armor .. "label[3.25,2;Chestplate]"
form_armor = form_armor .. "list[current_player;armor_chestplate;2.25,1.75;1,1;]"
form_armor = form_armor .. "listring[current_player;armor_chestplate]"
form_armor = form_armor .. default.ui.get_itemslot_bg(2.25, 1.75, 1, 1)
form_armor = form_armor .. "label[3.25,1;Helmet]"
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("armor:armor", form_armor)
-- Achievements
achievements.register_achievement(
@ -303,15 +308,15 @@ achievements.register_achievement(
description = "Craft a piece of armor",
times = 1,
craftitem = "group:is_armor",
})
})
achievements.register_achievement(
"warrior",
{
title = "Warrior",
description = "Craft 10 piece of armor",
description = "Craft 10 pieces of armor",
times = 10,
craftitem = "group:is_armor",
})
})
default.log("mod:armor", "loaded")

View File

@ -189,8 +189,8 @@ crafting.register_craft(
{
output = "default:dust_carbonsteel",
items = {
"default:lump_coal",
"default:lump_iron 2",
"default:lump_coal 2",
"default:lump_iron 3",
}
})

View File

@ -1,2 +1,3 @@
default
crafting
achievements

View File

@ -6,6 +6,7 @@
door = {}
-- Registers a door
function door.register_door(name, def)
def.groups.not_in_creative_inventory = 1
@ -47,7 +48,8 @@ function door.register_door(name, def)
local ptu = pointed_thing.under
local nu = minetest.get_node(ptu)
if minetest.registered_nodes[nu.name].on_rightclick then
return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack)
return minetest.registered_nodes[nu.name].on_rightclick(
ptu, nu, placer, itemstack)
end
local pt = pointed_thing.above
@ -120,9 +122,21 @@ function door.register_door(name, def)
end
if minetest.get_meta(pos):get_int("right") ~= 0 then
minetest.sound_play(snd_1, {pos = pos, gain = 0.8, max_hear_distance = 10})
minetest.sound_play(
snd_1,
{
pos = pos,
gain = 0.8,
max_hear_distance = 10
})
else
minetest.sound_play(snd_2, {pos = pos, gain = 0.8, max_hear_distance = 10})
minetest.sound_play(
snd_2,
{
pos = pos,
gain = 0.8,
max_hear_distance = 10
})
end
end
@ -282,17 +296,17 @@ door.register_door(
tiles_bottom = {"door_wood_b.png", "door_brown.png"},
sounds = default.node_sound_wood_defaults(),
sunlight = false,
})
})
minetest.register_craft(
crafting.register_craft(
{
output = "door:door_wood",
recipe = {
{"default:fiber", "default:glass", "default:fiber"},
{"default:stick", "default:stick", "default:stick"},
{"default:fiber", "group:planks", "default:fiber"},
items = {
"default:fiber 6",
"default:stick 7",
"group:planks 2",
}
})
})
door.register_door(
"door:door_stone",
@ -304,17 +318,17 @@ door.register_door(
tiles_bottom = {"door_stone_b.png", "door_brown.png"},
sounds = default.node_sound_stone_defaults(),
sunlight = false,
})
})
minetest.register_craft(
crafting.register_craft(
{
output = "door:door_stone",
recipe = {
{"default:fiber", "default:glass", "default:fiber"},
{"default:stick", "default:stick", "default:stick"},
{"default:fiber", "group:stone", "default:fiber"},
items = {
"default:fiber 6",
"default:stick 7",
"group:stone 2",
}
})
})
-- Achievements
@ -325,6 +339,6 @@ achievements.register_achievement(
description = "Craft a door",
times = 1,
craftitem = "group:door",
})
})
default.log("mod:door", "loaded")

View File

@ -1,23 +1,30 @@
--
-- Crafts and items
--
-- Items
minetest.register_craftitem(
"farming:cotton",
{
description = "Cotton",
inventory_image = "farming_cotton.png"
})
})
minetest.register_craftitem(
"farming:wheat",
{
description = "Wheat",
inventory_image = "farming_wheat.png"
})
})
minetest.register_craftitem(
"farming:flour",
{
description = "Flour",
inventory_image = "farming_flour.png"
})
})
minetest.register_craftitem(
"farming:bread",
@ -25,25 +32,27 @@ minetest.register_craftitem(
description = "Bread",
inventory_image = "farming_bread.png",
on_use = minetest.item_eat({hp = 4, sat = 40})
})
})
minetest.register_craft(
-- Craft recipes
crafting.register_craft(
{
output = "farming:flour",
recipe = {
{"farming:wheat", "farming:wheat"},
{"farming:wheat", "farming:wheat"},
items = {
"farming:wheat 4",
}
})
})
minetest.register_craft(
crafting.register_craft(
{
output = "farming:cotton_bale 2",
recipe = {
{"farming:cotton", "farming:cotton"},
{"farming:cotton", "farming:cotton"},
items = {
"farming:cotton 2",
}
})
})
-- Cooking
minetest.register_craft(
{
@ -51,6 +60,6 @@ minetest.register_craft(
output = "farming:bread",
recipe = "farming:flour",
cooktime = 15,
})
})
default.log("craft", "loaded")

View File

@ -1,3 +1,4 @@
default
weather
crafting
achievements