mirror of
https://github.com/Sokomine/cottages.git
synced 2025-07-03 16:40:24 +02:00
fix public anvil support
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
local S = cottages.S
|
||||
local F = minetest.formspec_escape
|
||||
local FS = function(...) return F(S(...)) end
|
||||
local FS = function(...)
|
||||
return F(S(...))
|
||||
end
|
||||
local anvil = cottages.anvil
|
||||
|
||||
local add_entity = minetest.add_entity
|
||||
@ -44,10 +46,8 @@ function anvil.get_anvil_info(pos)
|
||||
|
||||
if input:is_empty() then
|
||||
return S("anvil")
|
||||
|
||||
elseif input:get_wear() > 0 then
|
||||
return S("anvil; repairing @1 (@2%)", get_safe_short_description(input), wear)
|
||||
|
||||
else
|
||||
return S("anvil; @1 is repaired", get_safe_short_description(input))
|
||||
end
|
||||
@ -55,8 +55,8 @@ end
|
||||
|
||||
function anvil.get_anvil_fs_parts()
|
||||
return {
|
||||
("size[8,8]"),
|
||||
("image[4,3;1,1;cottages_tool_steelhammer.png]"),
|
||||
"size[8,8]",
|
||||
"image[4,3;1,1;cottages_tool_steelhammer.png]",
|
||||
("label[2.5,1.0;%s]"):format(FS("Workpiece:")),
|
||||
("label[6.0,2.7;%s]"):format(FS("Optional")),
|
||||
("label[6.0,3.0;%s]"):format(FS("storage for")),
|
||||
@ -64,13 +64,13 @@ function anvil.get_anvil_fs_parts()
|
||||
("label[0,0.0;%s]"):format(FS("Anvil")),
|
||||
("label[0,3.0;%s]"):format(FS("Punch anvil with hammer to")),
|
||||
("label[0,3.3;%s]"):format(FS("repair tool in workpiece-slot.")),
|
||||
("list[context;input;2.5,1.5;1,1;]"),
|
||||
("list[context;hammer;5,3;1,1;]"),
|
||||
("list[current_player;main;0,4;8,4;]"),
|
||||
("listring[context;hammer]"),
|
||||
("listring[current_player;main]"),
|
||||
("listring[context;input]"),
|
||||
("listring[current_player;main]"),
|
||||
"list[context;input;2.5,1.5;1,1;]",
|
||||
"list[context;hammer;5,3;1,1;]",
|
||||
"list[current_player;main;0,4;8,4;]",
|
||||
"listring[context;hammer]",
|
||||
"listring[current_player;main]",
|
||||
"listring[context;input]",
|
||||
"listring[current_player;main]",
|
||||
}
|
||||
end
|
||||
|
||||
@ -81,10 +81,10 @@ local function sparks(pos)
|
||||
time = 0.1,
|
||||
minpos = pos,
|
||||
maxpos = pos,
|
||||
minvel = {x = 2, y = 3, z = 2},
|
||||
maxvel = {x = -2, y = 1, z = -2},
|
||||
minacc = {x = 0, y = -10, z = 0},
|
||||
maxacc = {x = 0, y = -10, z = 0},
|
||||
minvel = { x = 2, y = 3, z = 2 },
|
||||
maxvel = { x = -2, y = 1, z = -2 },
|
||||
minacc = { x = 0, y = -10, z = 0 },
|
||||
maxacc = { x = 0, y = -10, z = 0 },
|
||||
minexptime = 0.5,
|
||||
maxexptime = 1,
|
||||
minsize = 1,
|
||||
@ -106,7 +106,6 @@ local function update_hud(puncher, tool)
|
||||
if tool_hud_enabled then
|
||||
hud1, hud2, hud3 = unpack(hud_info_by_puncher_name[puncher_name])
|
||||
hud1_def = puncher:hud_get(hud1)
|
||||
|
||||
else
|
||||
hud2, hud3 = unpack(hud_info_by_puncher_name[puncher_name])
|
||||
end
|
||||
@ -118,16 +117,15 @@ local function update_hud(puncher, tool)
|
||||
puncher:hud_change(hud1, "text", hud_image)
|
||||
end
|
||||
puncher:hud_change(hud3, "number", damage_state)
|
||||
|
||||
else
|
||||
if tool_hud_enabled and hud_image then
|
||||
hud1 = puncher:hud_add({
|
||||
hud_elem_type = "image",
|
||||
name = "anvil_image",
|
||||
text = hud_image,
|
||||
scale = {x = 15, y = 15},
|
||||
position = {x = 0.5, y = 0.5},
|
||||
alignment = {x = 0, y = 0}
|
||||
scale = { x = 15, y = 15 },
|
||||
position = { x = 0.5, y = 0.5 },
|
||||
alignment = { x = 0, y = 0 },
|
||||
})
|
||||
end
|
||||
hud2 = puncher:hud_add({
|
||||
@ -136,10 +134,10 @@ local function update_hud(puncher, tool)
|
||||
text = "default_cloud.png^[colorize:#ff0000:256",
|
||||
number = 40,
|
||||
direction = 0, -- left to right
|
||||
position = {x = 0.5, y = 0.65},
|
||||
alignment = {x = 0, y = 0},
|
||||
offset = {x = -320, y = 0},
|
||||
size = {x = 32, y = 32},
|
||||
position = { x = 0.5, y = 0.65 },
|
||||
alignment = { x = 0, y = 0 },
|
||||
offset = { x = -320, y = 0 },
|
||||
size = { x = 32, y = 32 },
|
||||
})
|
||||
hud3 = puncher:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
@ -147,18 +145,17 @@ local function update_hud(puncher, tool)
|
||||
text = "default_cloud.png^[colorize:#00ff00:256",
|
||||
number = damage_state,
|
||||
direction = 0, -- left to right
|
||||
position = {x = 0.5, y = 0.65},
|
||||
alignment = {x = 0, y = 0},
|
||||
offset = {x = -320, y = 0},
|
||||
size = {x = 32, y = 32},
|
||||
position = { x = 0.5, y = 0.65 },
|
||||
alignment = { x = 0, y = 0 },
|
||||
offset = { x = -320, y = 0 },
|
||||
size = { x = 32, y = 32 },
|
||||
})
|
||||
end
|
||||
|
||||
if tool_hud_enabled then
|
||||
hud_info_by_puncher_name[puncher_name] = {hud1, hud2, hud3, os.time() + hud_timeout}
|
||||
|
||||
hud_info_by_puncher_name[puncher_name] = { hud1, hud2, hud3, os.time() + hud_timeout }
|
||||
else
|
||||
hud_info_by_puncher_name[puncher_name] = {hud2, hud3, os.time() + hud_timeout}
|
||||
hud_info_by_puncher_name[puncher_name] = { hud2, hud3, os.time() + hud_timeout }
|
||||
end
|
||||
end
|
||||
|
||||
@ -178,14 +175,12 @@ function anvil.use_anvil(pos, puncher)
|
||||
|
||||
if tool:is_empty() then
|
||||
return
|
||||
|
||||
elseif not anvil.can_repair(tool) then
|
||||
-- just to make sure that tool really can't be repaired if it should not
|
||||
-- (if the check of placing the item in the input slot failed somehow)
|
||||
minetest.chat_send_player(puncher_name, S("@1 is not repairable by the anvil", tool_name))
|
||||
|
||||
elseif tool:get_wear() > 0 then
|
||||
minetest.sound_play({name = "anvil_clang"}, {pos = pos})
|
||||
minetest.sound_play({ name = "anvil_clang" }, { pos = pos })
|
||||
sparks(pos)
|
||||
|
||||
-- do the actual repair
|
||||
@ -201,7 +196,6 @@ function anvil.use_anvil(pos, puncher)
|
||||
if has_stamina then
|
||||
stamina.exhaust_player(puncher, stamina_use, "cottages:anvil")
|
||||
end
|
||||
|
||||
else
|
||||
-- tell the player when the job is done, but only once
|
||||
if meta:get_int("informed") > 0 then
|
||||
@ -229,7 +223,6 @@ function anvil.rightclick_anvil(pos, clicker, itemstack)
|
||||
local taken
|
||||
if anvil.allow_metadata_inventory_take(pos, "input", 1, input_stack, clicker) > 0 then
|
||||
taken = inv:remove_item("input", input_stack)
|
||||
|
||||
elseif anvil.allow_metadata_inventory_take(pos, "hammer", 1, hammer_stack, clicker) > 0 then
|
||||
taken = inv:remove_item("hammer", hammer_stack)
|
||||
end
|
||||
@ -240,7 +233,6 @@ function anvil.rightclick_anvil(pos, clicker, itemstack)
|
||||
inv:add_item("input", itemstack)
|
||||
itemstack:clear()
|
||||
meta:set_int("informed", 0)
|
||||
|
||||
elseif taken and not itemstack:is_empty() then
|
||||
-- put it back
|
||||
inv:add_item("input", input_stack)
|
||||
@ -261,11 +253,9 @@ function anvil.get_entity(pos)
|
||||
local ent_pos = ent.pos
|
||||
if not ent_pos then
|
||||
obj:remove()
|
||||
|
||||
elseif v_eq(ent_pos, pos) then
|
||||
if to_return then
|
||||
obj:remove()
|
||||
|
||||
else
|
||||
to_return = obj
|
||||
end
|
||||
@ -297,11 +287,11 @@ function anvil.add_entity(pos)
|
||||
|
||||
local entity_pos = v_add(pos, v_new(0, tool_entity_displacement, 0))
|
||||
|
||||
local obj = add_entity(entity_pos, "cottages:anvil_item", serialize({pos, tool_name}))
|
||||
local obj = add_entity(entity_pos, "cottages:anvil_item", serialize({ pos, tool_name }))
|
||||
|
||||
if obj then
|
||||
local yaw = math.pi * 2 - node.param2 * math.pi / 2
|
||||
obj:set_rotation({ x = -math.pi / 2, y = yaw, z = 0}) -- x is pitch
|
||||
obj:set_rotation({ x = -math.pi / 2, y = yaw, z = 0 }) -- x is pitch
|
||||
end
|
||||
end
|
||||
|
||||
@ -314,14 +304,12 @@ function anvil.update_entity(pos)
|
||||
|
||||
if tool:is_empty() and obj then
|
||||
anvil.clear_entity(pos)
|
||||
|
||||
elseif obj then
|
||||
local e = obj:get_luaentity()
|
||||
if e.item ~= tool_name then
|
||||
e.item = tool_name
|
||||
obj:set_properties({wield_item = tool_name})
|
||||
obj:set_properties({ wield_item = tool_name })
|
||||
end
|
||||
|
||||
elseif tool_entity_enabled and not tool:is_empty() then
|
||||
anvil.add_entity(pos)
|
||||
end
|
||||
@ -375,8 +363,10 @@ function anvil.allow_metadata_inventory_move(pos, from_list, from_index, to_list
|
||||
local inv = meta:get_inventory()
|
||||
local from_stack = inv:get_stack(from_list, from_index)
|
||||
|
||||
if anvil.allow_metadata_inventory_take(pos, from_list, from_index, from_stack, player) > 0
|
||||
and anvil.allow_metadata_inventory_put(pos, to_list, to_index, from_stack, player) > 0 then
|
||||
if
|
||||
anvil.allow_metadata_inventory_take(pos, from_list, from_index, from_stack, player) > 0
|
||||
and anvil.allow_metadata_inventory_put(pos, to_list, to_index, from_stack, player) > 0
|
||||
then
|
||||
return count
|
||||
end
|
||||
|
||||
@ -424,7 +414,6 @@ function anvil.preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||
if owner == "" then
|
||||
drop_meta:set_int("shared", 1)
|
||||
drop_meta:set_string("description", S("Anvil (public)"))
|
||||
|
||||
elseif owner == " " then
|
||||
drop_meta:set_int("shared", 2)
|
||||
drop_meta:set_string("description", S("Anvil (protected)"))
|
||||
@ -438,6 +427,19 @@ function anvil.on_destruct(pos)
|
||||
anvil.clear_entity(pos)
|
||||
end
|
||||
|
||||
function anvil.preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||
if tonumber(oldmeta.public) == 2 then
|
||||
for _, drop in ipairs(drops) do
|
||||
if drop:get_name() == "cottages:anvil" then
|
||||
local dropmeta = drop:get_meta()
|
||||
dropmeta:set_int("shared", 1)
|
||||
dropmeta:set_string("description", S("Anvil (public)"))
|
||||
end
|
||||
end
|
||||
end
|
||||
return drops
|
||||
end
|
||||
|
||||
cottages.api.register_machine("cottages:anvil", {
|
||||
description = S("anvil"),
|
||||
drawtype = "nodebox",
|
||||
@ -445,14 +447,14 @@ cottages.api.register_machine("cottages:anvil", {
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.3, 0.5, -0.4, 0.3},
|
||||
{-0.35, -0.4, -0.25, 0.35, -0.3, 0.25},
|
||||
{-0.3, -0.3, -0.15, 0.3, -0.1, 0.15},
|
||||
{-0.35, -0.1, -0.2, 0.35, 0.1, 0.2},
|
||||
{ -0.5, -0.5, -0.3, 0.5, -0.4, 0.3 },
|
||||
{ -0.35, -0.4, -0.25, 0.35, -0.3, 0.25 },
|
||||
{ -0.3, -0.3, -0.15, 0.3, -0.1, 0.15 },
|
||||
{ -0.35, -0.1, -0.2, 0.35, 0.1, 0.2 },
|
||||
},
|
||||
},
|
||||
tiles = {"cottages_stone.png^[colorize:#000:192"},
|
||||
groups = {cracky = 2},
|
||||
tiles = { "cottages_stone.png^[colorize:#000:192" },
|
||||
groups = { cracky = 2 },
|
||||
sounds = cottages.sounds.metal,
|
||||
|
||||
inv_info = {
|
||||
@ -474,6 +476,7 @@ cottages.api.register_machine("cottages:anvil", {
|
||||
allow_metadata_inventory_take = anvil.allow_metadata_inventory_take,
|
||||
|
||||
on_destruct = anvil.on_destruct,
|
||||
preserve_metadata = anvil.preserve_metadata,
|
||||
})
|
||||
|
||||
-- clear hud info
|
||||
@ -485,7 +488,6 @@ minetest.register_globalstep(function()
|
||||
local hud1, hud2, hud3, hud_expire_time
|
||||
if tool_hud_enabled then
|
||||
hud1, hud2, hud3, hud_expire_time = unpack(hud_info)
|
||||
|
||||
else
|
||||
hud2, hud3, hud_expire_time = unpack(hud_info)
|
||||
end
|
||||
@ -511,7 +513,6 @@ minetest.register_globalstep(function()
|
||||
|
||||
hud_info_by_puncher_name[puncher_name] = nil
|
||||
end
|
||||
|
||||
else
|
||||
hud_info_by_puncher_name[puncher_name] = nil
|
||||
end
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
if cottages.has.technic then
|
||||
-- make rechargeable technic tools unrepairable`
|
||||
cottages.anvil.make_unrepairable("technic:water_can")
|
||||
@ -27,12 +26,10 @@ if cottages.has.technic then
|
||||
end
|
||||
|
||||
if cottages.has.anvil then
|
||||
minetest.clear_craft({output = "anvil:anvil"})
|
||||
minetest.clear_craft({ output = "anvil:anvil" })
|
||||
minetest.register_alias_force("anvil:anvil", "cottages:anvil")
|
||||
|
||||
minetest.clear_craft({output = "anvil:hammer"})
|
||||
minetest.clear_craft({ output = "anvil:hammer" })
|
||||
minetest.register_alias_force("anvil:hammer", "cottages:hammer")
|
||||
|
||||
else
|
||||
minetest.register_alias("anvil:anvil", "cottages:anvil")
|
||||
minetest.register_alias("anvil:hammer", "cottages:hammer")
|
||||
|
@ -5,17 +5,19 @@ if ci.steel then
|
||||
minetest.register_craft({
|
||||
output = "cottages:anvil",
|
||||
recipe = {
|
||||
{ci.steel, ci.steel, ci.steel},
|
||||
{"", ci.steel, ""},
|
||||
{ci.steel, ci.steel, ci.steel}},
|
||||
{ ci.steel, ci.steel, ci.steel },
|
||||
{ "", ci.steel, "" },
|
||||
{ ci.steel, ci.steel, ci.steel },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "cottages:hammer",
|
||||
recipe = {
|
||||
{ci.steel},
|
||||
{"cottages:anvil"},
|
||||
{ci.stick}}
|
||||
{ ci.steel },
|
||||
{ "cottages:anvil" },
|
||||
{ ci.stick },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
@ -28,29 +30,16 @@ if ci.paper then
|
||||
return stack:to_string()
|
||||
end
|
||||
|
||||
local function build_protected_string()
|
||||
local stack = ItemStack("cottages:anvil")
|
||||
local meta = stack:get_meta()
|
||||
meta:set_int("shared", 2)
|
||||
meta:set_string("description", S("Anvil (protected)"))
|
||||
return stack:to_string()
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = build_protected_string(),
|
||||
type = "shapeless",
|
||||
recipe = {"cottages:anvil", ci.paper}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = build_public_string(),
|
||||
type = "shapeless",
|
||||
recipe = {build_protected_string(), ci.paper}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "cottages:anvil",
|
||||
type = "shapeless",
|
||||
recipe = {build_public_string(), ci.paper}
|
||||
recipe = { "cottages:anvil", ci.paper },
|
||||
})
|
||||
end
|
||||
|
||||
-- allows reverting public anvil
|
||||
minetest.register_craft({
|
||||
output = "cottages:anvil",
|
||||
type = "shapeless",
|
||||
recipe = { "cottages:anvil" },
|
||||
})
|
||||
|
@ -2,9 +2,11 @@ local S = cottages.S
|
||||
|
||||
minetest.register_node("cottages:rope", {
|
||||
description = S("Rope"),
|
||||
tiles = {"cottages_rope.png"},
|
||||
tiles = { "cottages_rope.png" },
|
||||
groups = {
|
||||
snappy = 3, choppy = 3, oddly_breakable_by_hand = 3,
|
||||
snappy = 3,
|
||||
choppy = 3,
|
||||
oddly_breakable_by_hand = 3,
|
||||
},
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
@ -13,7 +15,7 @@ minetest.register_node("cottages:rope", {
|
||||
drawtype = "plantlike",
|
||||
is_ground_content = false,
|
||||
can_dig = function(pos, player)
|
||||
local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
local below = minetest.get_node({ x = pos.x, y = pos.y - 1, z = pos.z })
|
||||
|
||||
if below.name == "cottages:rope" then
|
||||
if minetest.is_player(player) then
|
||||
@ -25,16 +27,16 @@ minetest.register_node("cottages:rope", {
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
if cottages.has.carts then
|
||||
local groups = table.copy(carts:get_rail_groups())
|
||||
groups.attached_node = 1
|
||||
groups.attached_node = 0
|
||||
carts:register_rail("cottages:ladder_with_rope_and_rail", {
|
||||
description = S("Ladder with \"rail support\""),
|
||||
description = S('Ladder with "rail support"'),
|
||||
tiles = {
|
||||
"default_ladder_wood.png^carts_rail_straight.png^cottages_rope.png"
|
||||
"default_ladder_wood.png^carts_rail_straight.png^cottages_rope.png",
|
||||
},
|
||||
inventory_image = "default_ladder_wood.png",
|
||||
wield_image = "default_ladder_wood.png",
|
||||
@ -43,15 +45,14 @@ if cottages.has.carts then
|
||||
paramtype2 = "wallmounted",
|
||||
legacy_wallmounted = true,
|
||||
}, {})
|
||||
|
||||
else
|
||||
minetest.register_node("cottages:ladder_with_rope_and_rail", {
|
||||
description = S("Ladder with \"rail support\""),
|
||||
description = S('Ladder with "rail support"'),
|
||||
inventory_image = "default_ladder_wood.png",
|
||||
wield_image = "default_ladder_wood.png",
|
||||
drawtype = "raillike",
|
||||
tiles = {
|
||||
"default_ladder_wood.png^carts_rail_straight.png^cottages_rope.png"
|
||||
"default_ladder_wood.png^carts_rail_straight.png^cottages_rope.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
@ -63,9 +64,10 @@ else
|
||||
type = "wallmounted",
|
||||
},
|
||||
groups = {
|
||||
choppy = 2, oddly_breakable_by_hand = 3, rail = 1,
|
||||
choppy = 2,
|
||||
oddly_breakable_by_hand = 3,
|
||||
rail = 1,
|
||||
connect_to_raillike = minetest.raillike_group("rail"),
|
||||
attached_node = 1,
|
||||
},
|
||||
legacy_wallmounted = true,
|
||||
sounds = cottages.sounds.wood,
|
||||
|
Reference in New Issue
Block a user