Skip to content

Commit

Permalink
Preserve anvil's shared state on blast (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames authored Nov 22, 2023
1 parent cafef4e commit 16700e5
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ end

local S = minetest.get_translator(minetest.get_current_modname())

local shared_anvil_item = ItemStack({
name = "anvil:anvil",
meta = {
shared = 1,
description = S("Shared anvil")
}
})

-- the hammer for the anvil

local hammer_def = {
Expand Down Expand Up @@ -236,10 +244,8 @@ minetest.register_node("anvil:anvil", {
end,

preserve_metadata = function(pos, oldnode, oldmeta, drops)
if next(drops) and tonumber(oldmeta.shared) == 1 then
local meta = drops[next(drops)]:get_meta()
meta:set_int("shared", 1)
meta:set_string("description", S("Shared anvil"))
if drops[1] and tonumber(oldmeta.shared) == 1 then
drops[1] = ItemStack(shared_anvil_item)
end
return drops
end,
Expand Down Expand Up @@ -478,8 +484,13 @@ minetest.register_node("anvil:anvil", {
is_ground_content = false,

on_blast = function(pos, intensity)
local drops = {"anvil:anvil"}
local drops = {}
local meta = minetest.get_meta(pos)
if meta:get_int("shared") == 1 then
drops[1] = ItemStack(shared_anvil_item)
else
drops[1] = ItemStack("anvil:anvil")
end
local inv = meta:get_inventory()
local input = inv:get_stack("input", 1)
if not input:is_empty() then
Expand Down Expand Up @@ -536,11 +547,8 @@ minetest.register_craft({
recipe = {"anvil:anvil"}
})

local shared_anvil_craft_stack = ItemStack("anvil:anvil")
shared_anvil_craft_stack:get_meta():set_int("shared", 1)
shared_anvil_craft_stack:get_meta():set_string("description", S("Shared anvil"))
minetest.register_craft({
output = shared_anvil_craft_stack:to_string(),
output = shared_anvil_item:to_string(),
type = "shapeless",
recipe = {"anvil:anvil", "default:paper"}
})
Expand Down

0 comments on commit 16700e5

Please sign in to comment.