Add on_secondary_use for heads and pumpkin
This commit is contained in:
parent
d88fa0c438
commit
6426e55746
8 changed files with 120 additions and 101 deletions
|
@ -32,6 +32,69 @@ elseif minetest.get_modpath("wardrobe") then
|
|||
skin_mod = "wardrobe"
|
||||
end
|
||||
|
||||
function armor.on_armor_use(itemstack, user, pointed_thing)
|
||||
if not user or user:is_player() == false then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
if pointed_thing.type == "node" then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if user and not user:get_player_control().sneak then
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local name, player_inv, armor_inv = armor:get_valid_player(user, "[on_armor_use]")
|
||||
if not name then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local def = itemstack:get_definition()
|
||||
local slot
|
||||
if def.groups and def.groups.armor_head then
|
||||
slot = 2
|
||||
elseif def.groups and def.groups.armor_torso then
|
||||
slot = 3
|
||||
elseif def.groups and def.groups.armor_legs then
|
||||
slot = 4
|
||||
elseif def.groups and def.groups.armor_feet then
|
||||
slot = 5
|
||||
end
|
||||
|
||||
if slot then
|
||||
local itemstack_single = ItemStack(itemstack)
|
||||
itemstack_single:set_count(1)
|
||||
local itemstack_slot = armor_inv:get_stack("armor", slot)
|
||||
if itemstack_slot:is_empty() then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(user, itemstack_single)
|
||||
itemstack:take_item()
|
||||
elseif itemstack:get_count() <= 1 then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(user, itemstack_single)
|
||||
itemstack = ItemStack(itemstack_slot)
|
||||
elseif itemstack:get_count() <= 1 then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(user, itemstack_single)
|
||||
itemstack = ItemStack(itemstack_slot)
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
armor.def = {
|
||||
count = 0,
|
||||
}
|
||||
|
|
|
@ -8,62 +8,6 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/alias.lua")
|
|||
local longdesc = S("This is a piece of equippable armor which reduces the amount of damage you receive.")
|
||||
local usage = S("To equip it, put it on the corresponding armor slot in your inventory menu.")
|
||||
|
||||
local function on_armor_use(itemstack, user, pointed_thing)
|
||||
if not user or user:is_player() == false then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
if pointed_thing.type == "node" then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if user and not user:get_player_control().sneak then
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local name, player_inv, armor_inv = armor:get_valid_player(user, "[on_armor_use]")
|
||||
if not name then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local def = itemstack:get_definition()
|
||||
local slot
|
||||
if def.groups and def.groups.armor_head then
|
||||
slot = 2
|
||||
elseif def.groups and def.groups.armor_torso then
|
||||
slot = 3
|
||||
elseif def.groups and def.groups.armor_legs then
|
||||
slot = 4
|
||||
elseif def.groups and def.groups.armor_feet then
|
||||
slot = 5
|
||||
end
|
||||
|
||||
if slot then
|
||||
local itemstack_single = ItemStack(itemstack)
|
||||
itemstack_single:set_count(1)
|
||||
local itemstack_slot = armor_inv:get_stack("armor", slot)
|
||||
if itemstack_slot:is_empty() then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(user, itemstack_single)
|
||||
itemstack:take_item()
|
||||
elseif itemstack:get_count() <= 1 then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(user, itemstack_single)
|
||||
itemstack = ItemStack(itemstack_slot)
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
minetest.register_tool("mcl_armor:helmet_leather", {
|
||||
description = S("Leather Cap"),
|
||||
_doc_items_longdesc = longdesc,
|
||||
|
@ -75,8 +19,8 @@ minetest.register_tool("mcl_armor:helmet_leather", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:helmet_iron", {
|
||||
|
@ -91,8 +35,8 @@ minetest.register_tool("mcl_armor:helmet_iron", {
|
|||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:helmet_gold", {
|
||||
|
@ -106,8 +50,8 @@ minetest.register_tool("mcl_armor:helmet_gold", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:helmet_diamond",{
|
||||
|
@ -121,8 +65,8 @@ minetest.register_tool("mcl_armor:helmet_diamond",{
|
|||
_mcl_armor_equip = "mcl_armor_equip_diamond",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_diamond",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:helmet_chain", {
|
||||
|
@ -136,8 +80,8 @@ minetest.register_tool("mcl_armor:helmet_chain", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_chainmail",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_chainmail",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
-- Regisiter Torso Armor
|
||||
|
@ -153,8 +97,8 @@ minetest.register_tool("mcl_armor:chestplate_leather", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:chestplate_iron", {
|
||||
|
@ -168,8 +112,8 @@ minetest.register_tool("mcl_armor:chestplate_iron", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:chestplate_gold", {
|
||||
|
@ -183,8 +127,8 @@ minetest.register_tool("mcl_armor:chestplate_gold", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:chestplate_diamond",{
|
||||
|
@ -198,8 +142,8 @@ minetest.register_tool("mcl_armor:chestplate_diamond",{
|
|||
_mcl_armor_equip = "mcl_armor_equip_diamond",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_diamond",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:chestplate_chain", {
|
||||
|
@ -213,8 +157,8 @@ minetest.register_tool("mcl_armor:chestplate_chain", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_chainmail",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_chainmail",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
-- Regisiter Leg Armor
|
||||
|
@ -230,8 +174,8 @@ minetest.register_tool("mcl_armor:leggings_leather", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:leggings_iron", {
|
||||
|
@ -245,8 +189,8 @@ minetest.register_tool("mcl_armor:leggings_iron", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:leggings_gold", {
|
||||
|
@ -260,8 +204,8 @@ minetest.register_tool("mcl_armor:leggings_gold", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:leggings_diamond",{
|
||||
|
@ -275,8 +219,8 @@ minetest.register_tool("mcl_armor:leggings_diamond",{
|
|||
_mcl_armor_equip = "mcl_armor_equip_diamond",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_diamond",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:leggings_chain", {
|
||||
|
@ -290,8 +234,8 @@ minetest.register_tool("mcl_armor:leggings_chain", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_chainmail",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_chainmail",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
-- Regisiter Boots
|
||||
|
||||
|
@ -306,8 +250,8 @@ minetest.register_tool("mcl_armor:boots_leather", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:boots_iron", {
|
||||
|
@ -321,8 +265,8 @@ minetest.register_tool("mcl_armor:boots_iron", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:boots_gold", {
|
||||
|
@ -336,8 +280,8 @@ minetest.register_tool("mcl_armor:boots_gold", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_iron",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:boots_diamond",{
|
||||
|
@ -351,8 +295,8 @@ minetest.register_tool("mcl_armor:boots_diamond",{
|
|||
_mcl_armor_equip = "mcl_armor_equip_diamond",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_diamond",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_armor:boots_chain", {
|
||||
|
@ -366,8 +310,8 @@ minetest.register_tool("mcl_armor:boots_chain", {
|
|||
_mcl_armor_equip = "mcl_armor_equip_chainmail",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_chainmail",
|
||||
},
|
||||
on_place = on_armor_use,
|
||||
on_secondary_use = on_armor_use,
|
||||
on_place = armor.on_armor_use,
|
||||
on_secondary_use = armor.on_armor_use,
|
||||
})
|
||||
|
||||
-- Register Craft Recipies
|
||||
|
|
|
@ -3,5 +3,6 @@ mcl_sounds
|
|||
mcl_wool
|
||||
mcl_torches
|
||||
mcl_weather
|
||||
mcl_armor?
|
||||
mobs_mc
|
||||
doc?
|
||||
|
|
|
@ -66,7 +66,7 @@ A mature pumpkin stem attempts to grow a pumpkin at one of its four adjacent blo
|
|||
Faceless Pumpkin=Gesichtsloser Kürbis
|
||||
A faceless pumpkin is a decorative block. It can be carved with shears to obtain pumpkin seeds.=Ein gesichtsloser Kürbis ist ein dekorativer Block. Mit einer Schere kann man in ihm ein Muster schnitzen, um Kürbissamen zu erhalten.
|
||||
Pumpkin=Kürbis
|
||||
A pumpkin can be worn as a helmet for fun, but it doesn't offer any protection. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.=Einen Kürbis kann zum Spaß als Helm getragen werden, aber er bietet keinen Schutz. Kürbisse wachsen aus Kürbisstängeln, welche wiederum aus Kürbissamen wachsen.
|
||||
A pumpkin can be worn as a helmet. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.=Einen Kürbis kann zum Spaß als Helm getragen werden, aber er bietet keinen Schutz. Kürbisse wachsen aus Kürbisstängeln, welche wiederum aus Kürbissamen wachsen.
|
||||
Jack o'Lantern=Kürbislaterne
|
||||
A jack o'lantern is a traditional Halloween decoration made from a pumpkin. It glows brightly.=Eine Kürbislaterne ist eine traditionelle Dekoration für Halloween. Sie leuchtet hell.
|
||||
Pumpkin Pie=Kürbiskuchen
|
||||
|
|
|
@ -66,7 +66,7 @@ A mature pumpkin stem attempts to grow a pumpkin at one of its four adjacent blo
|
|||
Faceless Pumpkin=
|
||||
A faceless pumpkin is a decorative block. It can be carved with shears to obtain pumpkin seeds.=
|
||||
Pumpkin=
|
||||
A pumpkin can be worn as a helmet for fun, but it doesn't offer any protection. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.=
|
||||
A pumpkin can be worn as a helmet. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.=
|
||||
Jack o'Lantern=
|
||||
A jack o'lantern is a traditional Halloween decoration made from a pumpkin. It glows brightly.=
|
||||
Pumpkin Pie=
|
||||
|
|
|
@ -107,11 +107,16 @@ minetest.register_node("mcl_farming:pumpkin", pumpkin_base_def)
|
|||
|
||||
local pumpkin_face_base_def = table.copy(pumpkin_base_def)
|
||||
pumpkin_face_base_def.description = S("Pumpkin")
|
||||
pumpkin_face_base_def._doc_items_longdesc = S("A pumpkin can be worn as a helmet for fun, but it doesn't offer any protection. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.")
|
||||
pumpkin_face_base_def._doc_items_longdesc = S("A pumpkin can be worn as a helmet. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.")
|
||||
pumpkin_face_base_def._doc_items_usagehelp = nil
|
||||
pumpkin_face_base_def.tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"}
|
||||
pumpkin_face_base_def.groups.armor_head=1
|
||||
pumpkin_face_base_def._mcl_armor_mob_range_factor = 0
|
||||
pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:enderman"
|
||||
pumpkin_face_base_def.groups.non_combat_armor=1
|
||||
if minetest.get_modpath("mcl_armor") then
|
||||
pumpkin_face_base_def.on_secondary_use = armor.on_armor_use
|
||||
end
|
||||
|
||||
-- Register stem growth
|
||||
mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 30, 5)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
mcl_sounds
|
||||
mcl_armor?
|
||||
screwdriver?
|
||||
doc?
|
||||
|
|
|
@ -3,6 +3,11 @@ local S = minetest.get_translator("mcl_heads")
|
|||
local mod_doc = minetest.get_modpath("doc")
|
||||
local mod_screwdriver = minetest.get_modpath("screwdriver")
|
||||
|
||||
local equip_armor
|
||||
if minetest.get_modpath("mcl_armor") then
|
||||
equip_armor = armor.on_armor_use
|
||||
end
|
||||
|
||||
-- Heads system
|
||||
|
||||
local function addhead(name, texture, desc, longdesc, rangemob, rangefactor)
|
||||
|
@ -101,12 +106,12 @@ local function addhead(name, texture, desc, longdesc, rangemob, rangefactor)
|
|||
itemstack:set_name(itemstring)
|
||||
return itemstack
|
||||
end,
|
||||
on_secondary_use = equip_armor,
|
||||
|
||||
on_rotate = on_rotate_floor,
|
||||
|
||||
_mcl_blast_resistance = 5,
|
||||
_mcl_hardness = 1,
|
||||
_mcl_armor_mob_range_factor = rangefactor,
|
||||
_mcl_armor_mob_range_mob = rangemob,
|
||||
})
|
||||
|
||||
minetest.register_node("mcl_heads:"..name.."_wall", {
|
||||
|
|
Reference in a new issue