1
0
Fork 0

Added enchanted book to disenchant and drop items when destroyed

This commit is contained in:
Chris Page 2022-08-18 19:45:30 +01:00
parent 58d36d4596
commit 9580fdb81b
2 changed files with 23 additions and 1 deletions

View File

@ -1,7 +1,10 @@
-- Code based from mcl_anvils
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local MAX_WEAR = 65535 local MAX_WEAR = 65535
-- formspecs
local function get_grindstone_formspec() local function get_grindstone_formspec()
return "size[9,8.75]".. return "size[9,8.75]"..
"image[3,1.5;1.5,1;gui_crafting_arrow.png]".. "image[3,1.5;1.5,1;gui_crafting_arrow.png]"..
@ -117,6 +120,7 @@ local function update_grindstone_slots(meta)
new_output = "" new_output = ""
end end
-- Check if at least one input has an item -- Check if at least one input has an item
-- Check if the item is's an enchanted book or tool
elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then
if input2:is_empty() then if input2:is_empty() then
local def1 = input1:get_definition() local def1 = input1:get_definition()
@ -126,6 +130,9 @@ local function update_grindstone_slots(meta)
local wear = input1:get_wear() local wear = input1:get_wear()
local new_item = create_new_item(name, meta, wear) local new_item = create_new_item(name, meta, wear)
new_output = transfer_curse(input1, new_item) new_output = transfer_curse(input1, new_item)
elseif input1:get_name() == "mcl_enchanting:book_enchanted" then
local new_item = ItemStack("mcl_books:book")
new_output = transfer_curse(input1, new_item)
else else
new_output = "" new_output = ""
end end
@ -137,6 +144,9 @@ local function update_grindstone_slots(meta)
local wear = input2:get_wear() local wear = input2:get_wear()
local new_item = create_new_item(name, meta, wear) local new_item = create_new_item(name, meta, wear)
new_output = transfer_curse(input2, new_item) new_output = transfer_curse(input2, new_item)
elseif input2:get_name() == "mcl_enchanting:book_enchanted" then
local new_item = ItemStack("mcl_books:book")
new_output = transfer_curse(input2, new_item)
else else
new_output = "" new_output = ""
end end
@ -152,6 +162,18 @@ local function update_grindstone_slots(meta)
end end
end end
-- Drop any items inside the grindstone if destroyed
local function drop_grindstone_items(pos, meta)
local inv = meta:get_inventory()
for i=1, inv:get_size("input") do
local stack = inv:get_stack("input", i)
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}
minetest.add_item(p, stack)
end
end
end
minetest.register_node("mcl_grindstone:grindstone", { 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"),

View File

@ -1,4 +1,4 @@
name = mcl_grindstone name = mcl_grindstone
author = TheRandomLegoBrick, ChrisPHP author = TheRandomLegoBrick, ChrisPHP
depends = mcl_experience, mcl_sounds depends = mcl_experience, mcl_sounds
description = Adds a cool looking block for the weaponsmiths jobsite description = Adds a cool looking block for the weaponsmiths jobsite and to disenchant or repair tools.