Grindstone menu

This commit is contained in:
AFCMS 2022-09-10 22:34:31 +02:00
parent bf57cf3aa3
commit f6804600ba
No known key found for this signature in database
GPG Key ID: 8720389A25B652E3
3 changed files with 76 additions and 58 deletions

@ -1,3 +1,5 @@
---@diagnostic disable
unused_args = false unused_args = false
allow_defined_top = true allow_defined_top = true
max_line_length = false max_line_length = false

@ -1,31 +1,46 @@
-- Code based from mcl_anvils -- Code based from mcl_anvils
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local MAX_WEAR = 65535 local MAX_WEAR = 65535
-- formspecs local grindstone_formspec = table.concat({
local function get_grindstone_formspec() "formspec_version[6]",
return "size[9,8.75]".. "size[11.75,10.425]",
"image[3,1.5;1.5,1;gui_crafting_arrow.png]"..
"label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", S("Inventory"))).."]".. "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Repair & Disenchant"))) .. "]",
"label[1,0.1;"..minetest.formspec_escape(minetest.colorize("#313131", S("Repair & Disenchant"))).."]"..
"list[context;main;0,0;8,4;]".. mcl_formspec.get_itemslot_bg_v4(2.875, 1.25, 1, 1),
"list[current_player;main;0,4.5;9,3;9]".. "list[context;input;2.875,1.25;1,1;]",
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
"list[current_player;main;0,7.74;9,1;]".. mcl_formspec.get_itemslot_bg_v4(2.875, 2.625, 1, 1),
mcl_formspec.get_itemslot_bg(0,7.74,9,1).. "list[context;input;2.875,2.625;1,1;1]",
"list[context;input;1,1;1,1;]"..
mcl_formspec.get_itemslot_bg(1,1,1,1).. "image[2.375,1;2,2.875;grindstone_gui_9.png;2]",
"list[context;input;1,2;1,1;1]"..
mcl_formspec.get_itemslot_bg(1,2,1,1).. "image[1.875,1.5;0.5,2.875;grindstone_gui_9.png;2]",
"list[context;output;6,1.5;1,1;]".. "image[4.375,1.5;0.5,2.875;grindstone_gui_9.png;2]",
mcl_formspec.get_itemslot_bg(6,1.5,1,1)..
"listring[context;output]".. "image[5.5,1.95;1.5,1;gui_crafting_arrow.png]",
"listring[current_player;main]"..
"listring[context;input]".. mcl_formspec.get_itemslot_bg_v4(7.875, 1.9375, 1, 1),
"listring[current_player;main]" "list[context;output;7.875,1.9375;1,1;]",
end
"label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3),
"list[current_player;main;0.375,5.1;9,3;9]",
mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1),
"list[current_player;main;0.375,9.05;9,1;]",
"listring[context;output]",
"listring[current_player;main]",
"listring[context;input]",
"listring[current_player;main]",
})
-- Creates a new item with the wear of the items and custom name -- Creates a new item with the wear of the items and custom name
local function create_new_item(name_item, meta, wear) local function create_new_item(name_item, meta, wear)
@ -86,7 +101,6 @@ local function fix_stack_size(stack)
return count return count
end end
-- Update the inventory slots of an grindstone node. -- Update the inventory slots of an grindstone node.
-- meta: Metadata of grindstone node -- meta: Metadata of grindstone node
local function update_grindstone_slots(meta) local function update_grindstone_slots(meta)
@ -168,10 +182,10 @@ end
-- Drop any items inside the grindstone if destroyed -- Drop any items inside the grindstone if destroyed
local function drop_grindstone_items(pos, meta) local function drop_grindstone_items(pos, meta)
local inv = meta:get_inventory() local inv = meta:get_inventory()
for i=1, inv:get_size("input") do for i = 1, inv:get_size("input") do
local stack = inv:get_stack("input", i) local stack = inv:get_stack("input", i)
if not stack:is_empty() then if not stack:is_empty() then
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} local p = { x = pos.x + math.random(0, 10) / 10 - 0.5, y = pos.y, z = pos.z + math.random(0, 10) / 10 - 0.5 }
minetest.add_item(p, stack) minetest.add_item(p, stack)
end end
end end
@ -181,11 +195,11 @@ local node_box = {
type = "fixed", type = "fixed",
-- created with nodebox editor -- created with nodebox editor
fixed = { fixed = {
{-0.25, -0.25, -0.375, 0.25, 0.5, 0.375}, { -0.25, -0.25, -0.375, 0.25, 0.5, 0.375 },
{-0.375, -0.0625, -0.1875, -0.25, 0.3125, 0.1875}, { -0.375, -0.0625, -0.1875, -0.25, 0.3125, 0.1875 },
{0.25, -0.0625, -0.1875, 0.375, 0.3125, 0.1875}, { 0.25, -0.0625, -0.1875, 0.375, 0.3125, 0.1875 },
{0.25, -0.5, -0.125, 0.375, -0.0625, 0.125}, { 0.25, -0.5, -0.125, 0.375, -0.0625, 0.125 },
{-0.375, -0.5, -0.125, -0.25, -0.0625, 0.125}, { -0.375, -0.5, -0.125, -0.25, -0.0625, 0.125 },
} }
} }
@ -193,10 +207,13 @@ minetest.register_node("mcl_grindstone:grindstone", {
description = S("Grindstone"), description = S("Grindstone"),
_tt_help = S("Used to disenchant/fix tools"), _tt_help = S("Used to disenchant/fix tools"),
_doc_items_longdesc = S("Grindstone disenchants tools and armour except for curses, and repairs two items of the same type it is also the weapon smith's work station."), _doc_items_longdesc = S("Grindstone disenchants tools and armour except for curses, and repairs two items of the same type it is also the weapon smith's work station."),
_doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.").."\n".. _doc_items_usagehelp = S("To use the grindstone, rightclick it, Two input slots (on the left) and a single output slot.")
S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.").."\n".. .. "\n" ..
S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.").."\n".. S("To disenchant an item place enchanted item in one of the input slots and take the disenchanted item from the output.")
S("If both items have enchantments the player will get xp from both items from the disenchant.").."\n".. .. "\n" ..
S("To repair a tool you need a tool of the same type and material, put both items in the input slot and the output slot will combine two items durabilities with 5% bonus.")
.. "\n" ..
S("If both items have enchantments the player will get xp from both items from the disenchant.") .. "\n" ..
S("Curses cannot be removed and will be transfered to the new repaired item, if both items have a different curse the curses will be combined."), S("Curses cannot be removed and will be transfered to the new repaired item, if both items have a different curse the curses will be combined."),
tiles = { tiles = {
"grindstone_top.png", "grindstone_top.png",
@ -212,7 +229,7 @@ minetest.register_node("mcl_grindstone:grindstone", {
selection_box = node_box, selection_box = node_box,
collision_box = node_box, collision_box = node_box,
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = mcl_sounds.node_sound_stone_defaults(),
groups = {pickaxey = 1, deco_block = 1}, groups = { pickaxey = 1, deco_block = 1 },
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -268,7 +285,7 @@ minetest.register_node("mcl_grindstone:grindstone", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if from_list == "output" and to_list == "input" then if from_list == "output" and to_list == "input" then
local inv = meta:get_inventory() local inv = meta:get_inventory()
for i=1, inv:get_size("input") do for i = 1, inv:get_size("input") do
if i ~= to_index then if i ~= to_index then
local istack = inv:get_stack("input", i) local istack = inv:get_stack("input", i)
istack:set_count(math.max(0, istack:get_count() - count)) istack:set_count(math.max(0, istack:get_count() - count))
@ -289,8 +306,8 @@ minetest.register_node("mcl_grindstone:grindstone", {
if not input1:is_empty() and not input2:is_empty() then if not input1:is_empty() and not input2:is_empty() then
-- Get xp earnt from the enchanted items -- Get xp earnt from the enchanted items
xp_earnt = calculate_xp(input1) + calculate_xp(input1) xp_earnt = calculate_xp(input1) + calculate_xp(input1)
input1:take_item() input1:take_item(1)
input2:take_item() input2:take_item(1)
inv:set_stack("input", 1, input1) inv:set_stack("input", 1, input1)
inv:set_stack("input", 2, input2) inv:set_stack("input", 2, input2)
else else
@ -320,14 +337,13 @@ minetest.register_node("mcl_grindstone:grindstone", {
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("input", 2) inv:set_size("input", 2)
inv:set_size("output", 1) inv:set_size("output", 1)
local form = get_grindstone_formspec() meta:set_string("formspec", grindstone_formspec)
meta:set_string("formspec", form)
end, end,
on_rightclick = function(pos, node, player, itemstack) on_rightclick = function(pos, node, player, itemstack)
if not player:get_player_control().sneak then if not player:get_player_control().sneak then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
update_grindstone_slots(meta) update_grindstone_slots(meta)
meta:set_string("formspec", get_grindstone_formspec()) meta:set_string("formspec", grindstone_formspec)
end end
end, end,
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
@ -337,7 +353,7 @@ minetest.register_node("mcl_grindstone:grindstone", {
minetest.register_craft({ minetest.register_craft({
output = "mcl_grindstone:grindstone", output = "mcl_grindstone:grindstone",
recipe = { recipe = {
{ "mcl_core:stick", "mcl_stairs:slab_stone_rough", "mcl_core:stick"}, { "mcl_core:stick", "mcl_stairs:slab_stone_rough", "mcl_core:stick" },
{ "group:wood", "", "group:wood"}, { "group:wood", "", "group:wood" },
} }
}) })

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B