1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-27 11:10:37 +01:00
server-nalc/minetestforfun_game/mods/default/craftitems.lua

187 lines
5.3 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- mods/default/craftitems.lua
minetest.register_craftitem("default:stick", {
description = "Stick",
stack_max = 1000,
2014-10-28 18:01:32 +01:00
inventory_image = "default_stick.png",
wield_image = "default_stick.png^[transformR90",
groups = {stick=1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:paper", {
description = "Paper",
wield_scale = {x = 1, y = 1, z = 0.25},
2014-10-28 18:01:32 +01:00
inventory_image = "default_paper.png",
})
local function book_on_use(itemstack, user, pointed_thing)
local player_name = user:get_player_name()
local data = minetest.deserialize(itemstack:get_metadata())
local title, text, owner = "", "", player_name
if data then
title, text, owner = data.title, data.text, data.owner
end
local formspec
if owner == player_name then
formspec = "size[8,8]"..default.gui_bg..
"field[0.5,1;7.5,0;title;Title:;"..
minetest.formspec_escape(title).."]"..
"textarea[0.5,1.5;7.5,7;text;Contents:;"..
minetest.formspec_escape(text).."]"..
"button_exit[2.5,7.5;3,1;save;Save]"
else
formspec = "size[8,8]"..default.gui_bg..
"label[0.5,0.5;by "..owner.."]"..
"label[0.5,0;"..minetest.formspec_escape(title).."]"..
2015-10-21 14:06:13 +02:00
"tableoptions[background=#00000000;highlight=#00000000;border=false]"..
"table[0.5,1.5;7.5,7;;"..minetest.formspec_escape(text):gsub("\n", ",")..";1]"
end
minetest.show_formspec(user:get_player_name(), "default:book", formspec)
end
minetest.register_on_player_receive_fields(function(player, form_name, fields)
if form_name ~= "default:book" or not fields.save or
fields.title == "" or fields.text == "" then
return
end
local inv = player:get_inventory()
local stack = player:get_wielded_item()
local new_stack, data
if stack:get_name() ~= "default:book_written" then
local count = stack:get_count()
if count == 1 then
stack:set_name("default:book_written")
else
stack:set_count(count - 1)
new_stack = ItemStack("default:book_written")
end
else
data = minetest.deserialize(stack:get_metadata())
end
if not data then data = {} end
data.title = fields.title
data.text = fields.text
data.owner = player:get_player_name()
local data_str = minetest.serialize(data)
if new_stack then
new_stack:set_metadata(data_str)
if inv:room_for_item("main", new_stack) then
inv:add_item("main", new_stack)
else
minetest.add_item(player:getpos(), new_stack)
end
else
stack:set_metadata(data_str)
end
player:set_wielded_item(stack)
end)
2014-10-28 18:01:32 +01:00
minetest.register_craftitem("default:book", {
description = "Book",
inventory_image = "default_book.png",
2014-12-15 00:04:45 +01:00
groups = {book=1},
on_use = book_on_use,
})
minetest.register_craftitem("default:book_written", {
description = "Book With Text",
inventory_image = "default_book.png",
groups = {book=1, not_in_creative_inventory=1},
stack_max = 1,
on_use = book_on_use,
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:coal_lump", {
description = "Coal Lump",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_coal_lump.png",
groups = {coal = 1}
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:iron_lump", {
description = "Iron Lump",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_iron_lump.png",
groups = {ingot_lump = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:copper_lump", {
description = "Copper Lump",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_copper_lump.png",
groups = {ingot_lump = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:mese_crystal", {
description = "Mese Crystal",
inventory_image = "default_mese_crystal.png",
})
minetest.register_craftitem("default:gold_lump", {
description = "Gold Lump",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_gold_lump.png",
groups = {ingot_lump = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:diamond", {
description = "Diamond",
inventory_image = "default_diamond.png",
})
minetest.register_craftitem("default:clay_lump", {
description = "Clay Lump",
stack_max = 200,
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_clay_lump.png",
})
minetest.register_craftitem("default:steel_ingot", {
description = "Steel Ingot",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_steel_ingot.png",
groups = {ingot = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:copper_ingot", {
description = "Copper Ingot",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_copper_ingot.png",
groups = {ingot = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:bronze_ingot", {
description = "Bronze Ingot",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_bronze_ingot.png",
groups = {ingot = 1},
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:gold_ingot", {
description = "Gold Ingot",
wield_scale = {x = 1, y = 1, z = 2},
groups = {ingot = 1},
inventory_image = "default_gold_ingot.png"
2014-10-28 18:01:32 +01:00
})
minetest.register_craftitem("default:mese_crystal_fragment", {
description = "Mese Crystal Fragment",
inventory_image = "default_mese_crystal_fragment.png",
})
minetest.register_craftitem("default:clay_brick", {
description = "Clay Brick",
wield_scale = {x = 1, y = 1, z = 2},
2014-10-28 18:01:32 +01:00
inventory_image = "default_clay_brick.png",
})
minetest.register_craftitem("default:scorched_stuff", {
description = "Scorched Stuff",
inventory_image = "default_scorched_stuff.png",
})
2014-10-28 18:01:32 +01:00
minetest.register_craftitem("default:obsidian_shard", {
description = "Obsidian Shard",
inventory_image = "default_obsidian_shard.png",
})