Merge pull request 'New weapons' (#4261) from hammers_spears into master

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4261
This commit is contained in:
the-real-herowl 2024-12-29 08:09:33 +01:00
commit b41960d5ed
24 changed files with 639 additions and 57 deletions

@ -318,7 +318,12 @@ function minetest.handle_node_drops(pos, drops, digger)
end
end
if tool and nodedef._mcl_fortune_drop and enchantments.fortune then
-- Special node drops (crushing) when digging with a hammer
local hammer = tooldef.groups.hammer
if hammer and hammer > 0 and nodedef._vl_crushing_drop then
drops = nodedef._vl_crushing_drop
-- Fortune drops
elseif tool and nodedef._mcl_fortune_drop and enchantments.fortune then
local fortune_level = enchantments.fortune
local fortune_drop = nodedef._mcl_fortune_drop
local simple_drop = nodedef._mcl_fortune_drop.drop_without_fortune

@ -450,10 +450,13 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
local is_player = hitter:is_player()
local mob_pos = self.object:get_pos()
local player_pos = hitter:get_pos()
local weapon = hitter:get_wielded_item()
if is_player then
-- is mob out of reach?
if vector_distance(mob_pos, player_pos) > 3 then return end
if vector.distance(mob_pos, player_pos) > (weapon:get_definition().range or 3) then
return
end
-- is mob protected?
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then return end
@ -489,7 +492,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
end
-- punch interval
local weapon = hitter:get_wielded_item()
local punch_interval = 1.4
-- exhaust attacker
@ -627,6 +629,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
if hitter and is_player then
local wielditem = hitter:get_wielded_item()
kb = kb + 9 * mcl_enchanting.get_enchantment(wielditem, "knockback")
kb = kb + 9 * minetest.get_item_group(wielditem:get_name(), "hammer")
-- add player velocity to mob knockback
local hv = hitter:get_velocity()
local dir_dot = (hv.x * dir.x) + (hv.z * dir.z)

@ -875,7 +875,7 @@ minetest.register_globalstep(function(dtime)
if minetest.is_creative_enabled(name) then
local touch_enabled = is_touch_enabled(name)
if touch_enabled ~= players[name].last_touch_enabled then
if not players[name] or touch_enabled ~= players[name].last_touch_enabled then
mcl_inventory.set_creative_formspec(player)
end
end

@ -26,6 +26,9 @@ local bow_load = {}
-- Another player table, this one stores the wield index of the bow being charged
local bow_index = {}
-- And yet another player table, this one stores the load level of the bow
local bow_load_level = {}
-- define FOV modifier(s)
mcl_fovapi.register_modifier({
name = "bowcomplete",
@ -177,6 +180,7 @@ local function reset_bows(player)
for place, stack in pairs(list) do
if stack:get_name() == "mcl_bows:bow" or stack:get_name() == "mcl_bows:bow_enchanted" then
stack:get_meta():set_string("active", "")
stack:get_meta():set_string("inventory_image", "")
elseif stack:get_name()=="mcl_bows:bow_0" or stack:get_name()=="mcl_bows:bow_1" or stack:get_name()=="mcl_bows:bow_2" then
stack:set_name("mcl_bows:bow")
stack:get_meta():set_string("active", "")
@ -197,6 +201,7 @@ local function reset_bow_state(player, also_reset_bows)
bow_load[player:get_player_name()] = nil
bow_index[player:get_player_name()] = nil
bow_load_level[player:get_player_name()] = nil
if minetest.get_modpath("playerphysics") then
playerphysics.remove_physics_factor(player, "speed", "mcl_bows:use_bow")
end
@ -205,18 +210,18 @@ local function reset_bow_state(player, also_reset_bows)
end
end
-- Bow in charging state
-- Old Bows in charging state, purely for conversion if some accidentally stayed behind
for level=0, 2 do
minetest.register_tool("mcl_bows:bow_"..level, {
description = S("Bow"),
_doc_items_create_entry = false,
inventory_image = "mcl_bows_bow_"..level..".png",
inventory_image = "mcl_bows_bow.png^vl_unknown.png",
wield_scale = mcl_vars.tool_wield_scale,
stack_max = 1,
range = 0, -- Pointing range to 0 to prevent punching with bow :D
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, cannot_block=1, enchantability=1},
-- Trick to disable digging as well
on_use = function() return end,
on_use = function(_, user) reset_bow_state(user, true) return end,
on_drop = function(itemstack, dropper, pos)
reset_bow_state(dropper)
itemstack:get_meta():set_string("active", "")
@ -230,7 +235,8 @@ for level=0, 2 do
return itemstack
end,
-- Prevent accidental interaction with itemframes and other nodes
on_place = function(itemstack)
on_place = function(itemstack, placer)
reset_bow_state(placer, true)
return itemstack
end,
touch_interaction = "short_dig_long_place",
@ -241,12 +247,11 @@ end
controls.register_on_release(function(player, key, time)
if key~="RMB" and key~="zoom" then return end
--local inv = minetest.get_inventory({type="player", name=player:get_player_name()})
local wielditem = player:get_wielded_item()
if (wielditem:get_name()=="mcl_bows:bow_0" or wielditem:get_name()=="mcl_bows:bow_1" or wielditem:get_name()=="mcl_bows:bow_2" or
wielditem:get_name()=="mcl_bows:bow_0_enchanted" or wielditem:get_name()=="mcl_bows:bow_1_enchanted" or wielditem:get_name()=="mcl_bows:bow_2_enchanted") then
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
local name = wielditem:get_name()
if name == "mcl_bows:bow" or name == "mcl_bows:bow_enchanted" then
local meta = wielditem:get_meta()
local enchanted = mcl_enchanting.is_enchanted(name)
local speed, damage
local p_load = bow_load[player:get_player_name()]
local charge
@ -286,12 +291,6 @@ controls.register_on_release(function(player, key, time)
local has_shot = player_shoot_arrow(wielditem, player, speed, damage, is_critical)
if enchanted then
wielditem:set_name("mcl_bows:bow_enchanted")
else
wielditem:set_name("mcl_bows:bow")
end
if has_shot and not minetest.is_creative_enabled(player:get_player_name()) then
local durability = BOW_DURABILITY
local unbreaking = mcl_enchanting.get_enchantment(wielditem, "unbreaking")
@ -312,23 +311,22 @@ controls.register_on_hold(function(player, key, time)
if (key ~= "RMB" and key ~= "zoom") or not (creative or get_arrow(player)) then
return
end
--local inv = minetest.get_inventory({type="player", name=name})
local wielditem = player:get_wielded_item()
local meta = wielditem:get_meta()
if bow_load[name] == nil
and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted")
and (wielditem:get_meta():get("active") or key == "zoom") and (creative or get_arrow(player)) then
and (meta:get("active") or key == "zoom") and (creative or get_arrow(player)) then
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
if enchanted then
wielditem:set_name("mcl_bows:bow_0_enchanted")
else
wielditem:set_name("mcl_bows:bow_0")
end
local im_string = "mcl_bows_bow_0.png"
if enchanted then im_string = im_string .. mcl_enchanting.overlay end
meta:set_string("inventory_image", im_string)
player:set_wielded_item(wielditem)
if minetest.get_modpath("playerphysics") then
-- Slow player down when using bow
playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED)
end
bow_load[name] = minetest.get_us_time()
bow_load_level[name] = 0
bow_index[name] = player:get_wield_index()
-- begin Bow Zoom.
@ -336,24 +334,27 @@ controls.register_on_hold(function(player, key, time)
else
if player:get_wield_index() == bow_index[name] then
if type(bow_load[name]) == "number" then
if wielditem:get_name() == "mcl_bows:bow_0" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
wielditem:set_name("mcl_bows:bow_1")
elseif wielditem:get_name() == "mcl_bows:bow_0_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
wielditem:set_name("mcl_bows:bow_1_enchanted")
elseif wielditem:get_name() == "mcl_bows:bow_1" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
wielditem:set_name("mcl_bows:bow_2")
elseif wielditem:get_name() == "mcl_bows:bow_1_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
wielditem:set_name("mcl_bows:bow_2_enchanted")
local level = 0
if minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
if bow_load_level[name] == 2 then return end
level = 2
bow_load_level[name] = 2
elseif minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
if bow_load_level[name] == 1 then return end
level = 1
bow_load_level[name] = 1
else return end
local im_string = "mcl_bows_bow_"..level..".png"
if wielditem:get_name() == "mcl_bows:bow_enchanted" then
im_string = im_string .. mcl_enchanting.overlay
end
meta:set_string("inventory_image", im_string)
else
if wielditem:get_name() == "mcl_bows:bow_0" or wielditem:get_name() == "mcl_bows:bow_1" or wielditem:get_name() == "mcl_bows:bow_2" then
wielditem:set_name("mcl_bows:bow")
elseif wielditem:get_name() == "mcl_bows:bow_0_enchanted" or wielditem:get_name() == "mcl_bows:bow_1_enchanted" or wielditem:get_name() == "mcl_bows:bow_2_enchanted" then
wielditem:set_name("mcl_bows:bow_enchanted")
end
meta:set_string("inventory_image", "")
bow_load_level[name] = nil
end
player:set_wielded_item(wielditem)
else
elseif bow_load[name] then
reset_bow_state(player, true)
end
end
@ -364,8 +365,9 @@ minetest.register_globalstep(function(dtime)
local name = player:get_player_name()
local wielditem = player:get_wielded_item()
local wieldindex = player:get_wield_index()
--local controls = player:get_player_control()
if type(bow_load[name]) == "number" and ((wielditem:get_name()~="mcl_bows:bow_0" and wielditem:get_name()~="mcl_bows:bow_1" and wielditem:get_name()~="mcl_bows:bow_2" and wielditem:get_name()~="mcl_bows:bow_0_enchanted" and wielditem:get_name()~="mcl_bows:bow_1_enchanted" and wielditem:get_name()~="mcl_bows:bow_2_enchanted") or wieldindex ~= bow_index[name]) then
if type(bow_load[name]) == "number"
and ((wielditem:get_name()~="mcl_bows:bow" and wielditem:get_name()~="mcl_bows:bow_enchanted")
or wieldindex ~= bow_index[name]) then
reset_bow_state(player, true)
end
end
@ -403,10 +405,3 @@ minetest.register_craft({
recipe = "group:bow",
burntime = 15,
})
-- Add entry aliases for the Help
if minetest.get_modpath("doc") then
doc.add_entry_alias("tools", "mcl_bows:bow", "tools", "mcl_bows:bow_0")
doc.add_entry_alias("tools", "mcl_bows:bow", "tools", "mcl_bows:bow_1")
doc.add_entry_alias("tools", "mcl_bows:bow", "tools", "mcl_bows:bow_2")
end

@ -563,6 +563,20 @@ minetest.register_node("mcl_core:gravel", {
},
[3] = "mcl_core:flint",
},
_vl_crushing_drops = { "mcl_core:greysand" },
})
minetest.register_node("mcl_core:greysand", {
description = S("Grey Sand"),
_doc_items_longdesc = S("Grey sand is found where stone erosion takes place."),
_doc_items_hidden = false,
tiles = {"mcl_core_grey_sand.png"},
is_ground_content = true,
stack_max = 64,
groups = {handy=1,shovely=1, falling_node=1, sand=1, soil_sugarcane=1, enderman_takable=1, building_block=1, material_sand=1},
sounds = mcl_sounds.node_sound_sand_defaults(),
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
})
-- sandstone --
@ -590,6 +604,7 @@ minetest.register_node("mcl_core:sandstone", {
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 0.8,
_mcl_hardness = 0.8,
_vl_crushing_drops = { "mcl_core:sand" },
})
minetest.register_node("mcl_core:sandstonesmooth", {
@ -653,6 +668,7 @@ minetest.register_node("mcl_core:redsandstone", {
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 0.8,
_mcl_hardness = 0.8,
_vl_crushing_drops = { "mcl_core:redsand" },
})
minetest.register_node("mcl_core:redsandstonesmooth", {
@ -772,6 +788,7 @@ minetest.register_node("mcl_core:cobble", {
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 6,
_mcl_hardness = 2,
_vl_crushing_drop = { "mcl_core:gravel" }
})
minetest.register_node("mcl_core:mossycobble", {

@ -285,7 +285,8 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
local wielditem = hitter:get_wielded_item()
--knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback")
local enchant = mcl_enchanting.get_enchantment(wielditem, "knockback")
knockback = knockback + 3.22 * enchant
local hammer = minetest.get_item_group(wielditem:get_name(), "hammer")
knockback = knockback + 3.22 * enchant + 3.22 * hammer
-- add vertical lift to knockback
local v = player:get_velocity()
local added_v = 0

@ -65,7 +65,7 @@ local hoe_usagehelp = S("Use the hoe on a cultivatable block (by rightclicking i
minetest.register_tool("mcl_farming:hoe_wood", {
description = S("Wood Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.wood),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
_doc_items_hidden = false,
@ -109,7 +109,7 @@ minetest.register_craft({
minetest.register_tool("mcl_farming:hoe_stone", {
description = S("Stone Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.stone),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
inventory_image = "farming_tool_stonehoe.png",
@ -147,7 +147,7 @@ minetest.register_craft({
minetest.register_tool("mcl_farming:hoe_iron", {
description = S("Iron Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.iron),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
inventory_image = "farming_tool_steelhoe.png",
@ -193,7 +193,7 @@ minetest.register_craft({
minetest.register_tool("mcl_farming:hoe_gold", {
description = S("Golden Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.gold),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
inventory_image = "farming_tool_goldhoe.png",
@ -240,7 +240,7 @@ minetest.register_craft({
minetest.register_tool("mcl_farming:hoe_diamond", {
description = S("Diamond Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.diamond),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
inventory_image = "farming_tool_diamondhoe.png",
@ -280,7 +280,7 @@ minetest.register_craft({
minetest.register_tool("mcl_farming:hoe_netherite", {
description = S("Netherite Hoe"),
_tt_help = hoe_tt.."\n"..S("Uses: @1", uses.netherite),
_tt_help = hoe_tt,
_doc_items_longdesc = hoe_longdesc,
_doc_items_usagehelp = hoe_usagehelp,
inventory_image = "farming_tool_netheritehoe.png",

@ -22,9 +22,14 @@ dig_speed_class group:
-- Help texts
local pickaxe_longdesc = S("Pickaxes are mining tools to mine hard blocks, such as stone. A pickaxe can also be used as weapon, but it is rather inefficient.")
local axe_longdesc = S("An axe is your tool of choice to cut down trees, wood-based blocks and other blocks. Axes deal a lot of damage as well, but they are rather slow.")
local sword_longdesc = S("Swords are great in melee combat, as they are fast, deal high damage and can endure countless battles. Swords can also be used to cut down a few particular blocks, such as cobwebs.")
-- local sword_use = S("To slash multiple enemies, hold the sword in your hand, then use (rightclick) an enemy.")
-- TODO slash attack not implemented yet
local shovel_longdesc = S("Shovels are tools for digging coarse blocks, such as dirt, sand and gravel. They can also be used to turn grass blocks to grass paths. Shovels can be used as weapons, but they are very weak.")
local shovel_use = S("To turn a grass block into a grass path, hold the shovel in your hand, then use (rightclick) the top or side of a grass block. This only works when there's air above the grass block.")
local shears_longdesc = S("Shears are tools to shear sheep and to mine a few block types. Shears are a special mining tool and can be used to obtain the original item from grass, leaves and similar blocks that require cutting.")
local shears_use = S("To shear sheep or carve faceless pumpkins, use the “place” key on them. Faces can only be carved at the side of faceless pumpkins. Mining works as usual, but the drops are different for a few blocks.")

@ -0,0 +1,552 @@
local modname = core.get_current_modname()
local modpath = core.get_modpath(modname)
local S = core.get_translator(modname)
local hammer_tt = S("Can crush blocks") .. "\n" .. S("Increased knockback")
local hammer_longdesc = S("Hammers are great in melee combat, as they deal high damage with increased knockback and can endure countless battles. Hammers can also be used to crush things.")
local hammer_use = S("To crush a block, dig the block with the hammer. This only works with some blocks.")
local spear_tt = S("Reaches farther") .. "\n" .. S("Can be thrown")
local spear_longdesc = S("Spears are great in melee combat, as they have an increased reach. They can also be thrown.")
local spear_use = S("To throw a spear, hold it in your hand, then hold use (rightclick) in the air.")
local wield_scale = mcl_vars.tool_wield_scale
local spear_entity = table.copy(mcl_bows.arrow_entity)
table.update(spear_entity,{
visual = "item",
visual_size = {x=-0.5, y=-0.5},
textures = {"vl_weaponry:spear_wood"},
_on_remove = function(self)
-- Prevent item duplication
if self._picked_up then return end
self._picked_up = true
vl_projectile.replace_with_item_drop(self, self.object:get_pos())
end,
})
table.update(spear_entity._vl_projectile,{
behaviors = {
vl_projectile.sticks,
vl_projectile.burns,
vl_projectile.has_tracer,
vl_projectile.has_owner_grace_distance,
vl_projectile.collides_with_solids,
vl_projectile.raycast_collides_with_entities,
-- Drop spears that are sliding
function(self, dtime)
if not self._last_pos then return end
local pos = self.object:get_pos()
local y_diff = math.abs(self._last_pos.y - pos.y)
if y_diff > 0.0001 then
self._flat_time = 0
return
end
local flat_time = (self._flat_time or 0) + dtime
self._flat_time = flat_time
if flat_time < 0.25 then return end
mcl_util.remove_entity(self)
return true
end,
},
pitch_offset = math.pi / 4,
})
vl_projectile.register("vl_weaponry:spear_entity", spear_entity)
local SPEAR_THROW_POWER = 30
local function spear_on_place(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
-- Call on_rightclick if the pointed node defines it
local node = core.get_node(pointed_thing.under)
if user and not user:get_player_control().sneak then
if core.registered_nodes[node.name] and core.registered_nodes[node.name].on_rightclick then
return core.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
end
end
end
itemstack:get_meta():set_int("active", 1)
return itemstack
end
local function throw_spear(itemstack, user, power_factor)
if not core.is_creative_enabled(user:get_player_name()) then
mcl_util.use_item_durability(itemstack, 1)
end
local meta = itemstack:get_meta()
meta:set_string("inventory_image", "")
meta:set_int("active", 0)
local pos = user:get_pos()
pos.y = pos.y + 1.5
local dir = user:get_look_dir()
local yaw = user:get_look_horizontal()
local obj = vl_projectile.create("vl_weaponry:spear_entity",{
pos = pos,
dir = dir,
owner = user,
velocity = SPEAR_THROW_POWER * power_factor,
})
obj:set_properties({textures = {itemstack:get_name()}})
local le = obj:get_luaentity()
le._shooter = user
le._source_object = user
le._damage = itemstack:get_definition()._mcl_spear_thrown_damage * power_factor
le._is_critical = false -- TODO get from luck?
le._startpos = pos
le._collectable = true
le._arrow_item = itemstack:to_string()
core.sound_play("mcl_bows_bow_shoot", {pos=pos, max_hear_distance=16}, true)
if user and user:is_player() then
if obj:get_luaentity().player == "" then
obj:get_luaentity().player = user
end
end
user:set_wielded_item(ItemStack())
end
-- Factor to multiply with player speed while player uses bow
-- This emulates the sneak speed.
local AIMING_MOVEMENT_SPEED =
tonumber(core.settings:get("movement_speed_crouch"))
/ tonumber(core.settings:get("movement_speed_walk"))
local SPEAR_FULL_CHARGE_TIME = 1000000 -- time until full charge in microseconds
local spear_raise_time = {}
local spear_index = {}
local function reset_spear_state(player, skip_inv_cleanup)
-- clear the FOV change from the player.
mcl_fovapi.remove_modifier(player, "bowcomplete")
spear_raise_time[player:get_player_name()] = nil
spear_index[player:get_player_name()] = nil
if core.get_modpath("playerphysics") then
playerphysics.remove_physics_factor(player, "speed", "mcl_bows:use_bow")
end
if skip_inv_cleanup then return end
local inv = player:get_inventory()
local list = inv:get_list("main")
for place, stack in pairs(list) do
if core.get_item_group(stack:get_name(), "spear") > 0 then
local meta = stack:get_meta()
meta:set_int("active", 0)
meta:set_string("inventory_image", "")
end
end
inv:set_list("main", list)
end
controls.register_on_release(function(player, key, time)
if key~="RMB" and key~="zoom" then return end
local wielditem = player:get_wielded_item()
if core.get_item_group(wielditem:get_name(), "spear") < 1 then return end
local pname = player:get_player_name()
local raise_moment = spear_raise_time[pname] or 0
local power = math.max(math.min((core.get_us_time() - raise_moment)
/ SPEAR_FULL_CHARGE_TIME, 1), 0)
throw_spear(wielditem, player, power)
reset_spear_state(player, true)
end)
controls.register_on_hold(function(player, key, time)
local name = player:get_player_name()
local creative = core.is_creative_enabled(name)
local wielditem = player:get_wielded_item()
if (key ~= "RMB" and key ~= "zoom")
or core.get_item_group(wielditem:get_name(), "spear") < 1 then
return
end
local meta = wielditem:get_meta()
if spear_raise_time[name] == nil and (meta:get("active") or key == "zoom") then
meta:set_string("inventory_image", wielditem:get_definition().inventory_image .. "^[transformR90")
player:set_wielded_item(wielditem)
if core.get_modpath("playerphysics") then
-- Slow player down when using bow
playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", AIMING_MOVEMENT_SPEED)
end
spear_raise_time[name] = core.get_us_time()
spear_index[name] = player:get_wield_index()
-- begin aiming Zoom.
mcl_fovapi.apply_modifier(player, "bowcomplete")
else
if player:get_wield_index() ~= spear_index[name] then
reset_spear_state(player)
end
end
end)
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local wielditem = player:get_wielded_item()
local wieldindex = player:get_wield_index()
if type(spear_raise_time[name]) == "number"
and (core.get_item_group(wielditem:get_name(), "spear") < 1
or wieldindex ~= spear_index[name]) then
reset_spear_state(player)
end
end
end)
local uses = {
wood = 60,
stone = 132,
iron = 251,
gold = 33,
diamond = 1562,
netherite = 2031,
}
local materials = {
wood = "group:wood",
stone = "group:cobble",
iron = "mcl_core:iron_ingot",
gold = "mcl_core:gold_ingot",
diamond = "mcl_core:diamond",
}
local SPEAR_RANGE = 4.5
--Hammers
core.register_tool("vl_weaponry:hammer_wood", {
description = S("Wooden Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
_doc_items_hidden = false,
inventory_image = "vl_tool_woodhammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = {
full_punch_interval = 1.2,
max_drop_level=1,
damage_groups = {fleshy=4},
punch_attack_uses = uses.wood,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 1, level = 1, uses = uses.wood },
shovely = { speed = 1, level = 2, uses = uses.wood }
},
})
core.register_tool("vl_weaponry:hammer_stone", {
description = S("Stone Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_stonehammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=5 },
tool_capabilities = {
full_punch_interval = 1.3,
max_drop_level=3,
damage_groups = {fleshy=5},
punch_attack_uses = uses.stone,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "group:cobble",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 2, level = 3, uses = uses.stone },
shovely = { speed = 2, level = 3, uses = uses.stone }
},
})
core.register_tool("vl_weaponry:hammer_iron", {
description = S("Iron Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_steelhammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=14 },
tool_capabilities = {
full_punch_interval = 1.2,
max_drop_level=4,
damage_groups = {fleshy=6},
punch_attack_uses = uses.iron,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 3, level = 4, uses = uses.iron },
shovely = { speed = 3, level = 4, uses = uses.iron }
},
})
core.register_tool("vl_weaponry:hammer_gold", {
description = S("Golden Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_goldhammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=22 },
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=2,
damage_groups = {fleshy=5},
punch_attack_uses = uses.gold,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 8, level = 4, uses = uses.gold },
shovely = { speed = 8, level = 4, uses = uses.gold }
},
})
core.register_tool("vl_weaponry:hammer_diamond", {
description = S("Diamond Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_diamondhammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10 },
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=5,
damage_groups = {fleshy=7},
punch_attack_uses = uses.diamond,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 4, level = 5, uses = uses.diamond },
pickaxey = { speed = 4, level = 5, uses = uses.diamond }
},
_mcl_upgradable = true,
_mcl_upgrade_item = "vl_weaponry:hammer_netherite"
})
core.register_tool("vl_weaponry:hammer_netherite", {
description = S("Netherite Hammer"),
_tt_help = hammer_tt,
_doc_items_longdesc = hammer_longdesc,
_doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_netheritehammer.png",
wield_scale = wield_scale,
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10, fire_immune=1 },
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=5,
damage_groups = {fleshy=9},
punch_attack_uses = uses.netherite,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_nether:netherite_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 6, level = 6, uses = uses.netherite },
shovely = { speed = 6, level = 6, uses = uses.netherite }
},
})
--Spears
core.register_tool("vl_weaponry:spear_wood", {
description = S("Wooden Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
_doc_items_hidden = false,
inventory_image = "vl_tool_woodspear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=15 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=1,
damage_groups = {fleshy=3},
punch_attack_uses = uses.wood,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.wood },
swordy_cobweb = { speed = 2, level = 1, uses = uses.wood }
},
_mcl_spear_thrown_damage = 5,
})
core.register_tool("vl_weaponry:spear_stone", {
description = S("Stone Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
inventory_image = "vl_tool_stonespear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=5 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=3,
damage_groups = {fleshy=4},
punch_attack_uses = uses.stone,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "group:cobble",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.stone },
swordy_cobweb = { speed = 2, level = 1, uses = uses.stone }
},
_mcl_spear_thrown_damage = 6,
})
core.register_tool("vl_weaponry:spear_iron", {
description = S("Iron Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
inventory_image = "vl_tool_steelspear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=14 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=4,
damage_groups = {fleshy=5},
punch_attack_uses = uses.iron,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.iron },
swordy_cobweb = { speed = 2, level = 1, uses = uses.iron }
},
_mcl_spear_thrown_damage = 7,
})
core.register_tool("vl_weaponry:spear_gold", {
description = S("Golden Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
inventory_image = "vl_tool_goldspear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=22 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=2,
damage_groups = {fleshy=3},
punch_attack_uses = uses.gold,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.gold },
swordy_cobweb = { speed = 2, level = 1, uses = uses.gold }
},
_mcl_spear_thrown_damage = 5,
})
core.register_tool("vl_weaponry:spear_diamond", {
description = S("Diamond Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
inventory_image = "vl_tool_diamondspear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=10 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=5,
damage_groups = {fleshy=6},
punch_attack_uses = uses.diamond,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.diamond },
swordy_cobweb = { speed = 2, level = 1, uses = uses.diamond }
},
_mcl_spear_thrown_damage = 8,
_mcl_upgradable = true,
_mcl_upgrade_item = "vl_weaponry:spear_netherite"
})
core.register_tool("vl_weaponry:spear_netherite", {
description = S("Netherite Spear"),
_tt_help = spear_tt,
_doc_items_longdesc = spear_longdesc,
_doc_items_usagehelp = spear_use,
inventory_image = "vl_tool_netheritespear.png",
wield_scale = wield_scale,
on_place = spear_on_place,
on_secondary_use = spear_on_place,
groups = { weapon=1, spear=1, dig_speed_class=2, enchantability=10, fire_immune=1 },
range = SPEAR_RANGE,
tool_capabilities = {
full_punch_interval = 0.75,
max_drop_level=5,
damage_groups = {fleshy=8},
punch_attack_uses = uses.netherite,
},
sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_nether:netherite_ingot",
_mcl_toollike_wield = true,
_mcl_diggroups = {
swordy = { speed = 2, level = 1, uses = uses.netherite },
swordy_cobweb = { speed = 2, level = 1, uses = uses.netherite }
},
_mcl_spear_thrown_damage = 12,
})
-- Crafting recipes
local s = "mcl_core:stick"
local b = ""
for t,m in pairs(materials) do
core.register_craft({
output = "vl_weaponry:hammer_"..t,
recipe = {
{ m, b, m },
{ m, s, m },
{ b, s, b },
}
})
core.register_craft({
output = "vl_weaponry:spear_"..t,
recipe = {
{ m, b, b },
{ b, s, b },
{ b, b, s },
}
})
core.register_craft({
output = "vl_weaponry:spear_"..t,
recipe = {
{ b, b, m },
{ b, s, b },
{ s, b, b },
}
})
end

@ -0,0 +1,3 @@
name = vl_weaponry
author = Herowl
depends = mcl_sounds, mcl_init, mcl_bows, vl_projectile, controls

@ -726,9 +726,10 @@ end, -200)
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
-- attack reach limit
if hitter and hitter:is_player() then
local weapon = hitter:get_wielded_item()
local player_pos = player:get_pos()
local hitter_pos = hitter:get_pos()
if vector.distance(player_pos, hitter_pos) > 3 then
if vector.distance(player_pos, hitter_pos) > (weapon:get_definition().range or 3) then
damage = 0
return damage
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B