Reworked hammer crushing

- crushing is now done by digging with a hammer
- cobble is now crushable
This commit is contained in:
the-real-herowl 2024-09-29 21:01:45 +02:00 committed by teknomunk
parent bfa2d4d11f
commit d79c6b5694
4 changed files with 21 additions and 59 deletions

@ -318,6 +318,12 @@ function minetest.handle_node_drops(pos, drops, digger)
end end
end end
-- 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
end
if tool and nodedef._mcl_fortune_drop and enchantments.fortune then if tool and nodedef._mcl_fortune_drop and enchantments.fortune then
local fortune_level = enchantments.fortune local fortune_level = enchantments.fortune
local fortune_drop = nodedef._mcl_fortune_drop local fortune_drop = nodedef._mcl_fortune_drop

@ -772,6 +772,7 @@ minetest.register_node("mcl_core:cobble", {
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
_mcl_hardness = 2, _mcl_hardness = 2,
_vl_crushing_drop = { "mcl_core:gravel" }
}) })
minetest.register_node("mcl_core:mossycobble", { minetest.register_node("mcl_core:mossycobble", {

@ -12,7 +12,7 @@ minetest.register_node("mcl_core:glass", {
paramtype2 = "glasslikeliquidlevel", paramtype2 = "glasslikeliquidlevel",
sunlight_propagates = true, sunlight_propagates = true,
stack_max = 64, stack_max = 64,
groups = {handy=1, glass=1, building_block=1, material_glass=1, crushable=1}, groups = {handy=1, glass=1, building_block=1, material_glass=1},
sounds = mcl_sounds.node_sound_glass_defaults(), sounds = mcl_sounds.node_sound_glass_defaults(),
drop = "", drop = "",
_mcl_blast_resistance = 0.3, _mcl_blast_resistance = 0.3,

@ -5,7 +5,7 @@ local S = minetest.get_translator(modname)
local hammer_tt = S("Can crush blocks") .. "\n" .. S("Increased knockback") 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_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, hold the hammer in your hand, then use (rightclick) the block. This only works with some blocks.") 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_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_longdesc = S("Spears are great in melee combat, as they have an increased reach. They can also be thrown.")
@ -13,51 +13,6 @@ local spear_use = S("To throw a spear, hold it in your hand, then hold use (righ
local wield_scale = mcl_vars.tool_wield_scale local wield_scale = mcl_vars.tool_wield_scale
local function crush(pos)
if pos == nil then
return false
end
local node = minetest.get_node(pos)
local name = node.name
if minetest.get_item_group(name, "crushable") == 2 then
node.name = minetest.registered_nodes[name]._mcl_crushed_into
if node.name then
minetest.set_node(pos, node)
minetest.sound_play("default_dig_cracky", { pos = pos, gain = 0.5 }, true)
return true
end
elseif minetest.get_item_group(name, "crushable") == 1 then
minetest.set_node(pos, {name="air"})
minetest.sound_play(mcl_sounds.node_sound_glass_defaults().dug, { pos = pos, gain = 0.5 }, true)
return true
end
return false
end
local hammer_on_place = function(wear_divisor)
return function(itemstack, user, pointed_thing)
-- Call on_rightclick if the pointed node defines it
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
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
minetest.record_protection_violation(pointed_thing.under, user:get_player_name())
return itemstack
end
if crush(pointed_thing.under) then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:add_wear(65535/wear_divisor)
end
return itemstack
end
end
end
local GRAVITY = 9.81 local GRAVITY = 9.81
local YAW_OFFSET = -math.pi/2 local YAW_OFFSET = -math.pi/2
local function dir_to_pitch(dir) local function dir_to_pitch(dir)
@ -554,7 +509,6 @@ minetest.register_tool("vl_weaponry:hammer_wood", {
_doc_items_hidden = false, _doc_items_hidden = false,
inventory_image = "vl_tool_woodhammer.png", inventory_image = "vl_tool_woodhammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.wood),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=15 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.2, full_punch_interval = 1.2,
@ -566,7 +520,8 @@ minetest.register_tool("vl_weaponry:hammer_wood", {
_repair_material = "group:wood", _repair_material = "group:wood",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 60 } pickaxey = { speed = 1, level = 1, uses = 60 },
shovely = { speed = 1, level = 2, uses = 60 }
}, },
}) })
minetest.register_tool("vl_weaponry:hammer_stone", { minetest.register_tool("vl_weaponry:hammer_stone", {
@ -576,7 +531,6 @@ minetest.register_tool("vl_weaponry:hammer_stone", {
_doc_items_usagehelp = hammer_use, _doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_stonehammer.png", inventory_image = "vl_tool_stonehammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.stone),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=5 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=5 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.3, full_punch_interval = 1.3,
@ -588,7 +542,8 @@ minetest.register_tool("vl_weaponry:hammer_stone", {
_repair_material = "group:cobble", _repair_material = "group:cobble",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 132 } pickaxey = { speed = 2, level = 3, uses = 132 },
shovely = { speed = 2, level = 3, uses = 132 }
}, },
}) })
minetest.register_tool("vl_weaponry:hammer_iron", { minetest.register_tool("vl_weaponry:hammer_iron", {
@ -598,7 +553,6 @@ minetest.register_tool("vl_weaponry:hammer_iron", {
_doc_items_usagehelp = hammer_use, _doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_steelhammer.png", inventory_image = "vl_tool_steelhammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.iron),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=14 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=14 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.2, full_punch_interval = 1.2,
@ -610,7 +564,8 @@ minetest.register_tool("vl_weaponry:hammer_iron", {
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 251 } pickaxey = { speed = 3, level = 4, uses = 251 },
shovely = { speed = 3, level = 4, uses = 251 }
}, },
}) })
minetest.register_tool("vl_weaponry:hammer_gold", { minetest.register_tool("vl_weaponry:hammer_gold", {
@ -620,7 +575,6 @@ minetest.register_tool("vl_weaponry:hammer_gold", {
_doc_items_usagehelp = hammer_use, _doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_goldhammer.png", inventory_image = "vl_tool_goldhammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.gold),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=22 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=22 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.0, full_punch_interval = 1.0,
@ -632,7 +586,8 @@ minetest.register_tool("vl_weaponry:hammer_gold", {
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 33 } pickaxey = { speed = 8, level = 4, uses = 33 },
shovely = { speed = 8, level = 4, uses = 33 }
}, },
}) })
minetest.register_tool("vl_weaponry:hammer_diamond", { minetest.register_tool("vl_weaponry:hammer_diamond", {
@ -642,7 +597,6 @@ minetest.register_tool("vl_weaponry:hammer_diamond", {
_doc_items_usagehelp = hammer_use, _doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_diamondhammer.png", inventory_image = "vl_tool_diamondhammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.diamond),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.0, full_punch_interval = 1.0,
@ -654,7 +608,8 @@ minetest.register_tool("vl_weaponry:hammer_diamond", {
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 1562 } pickaxey = { speed = 4, level = 5, uses = 1562 },
pickaxey = { speed = 4, level = 5, uses = 1562 }
}, },
_mcl_upgradable = true, _mcl_upgradable = true,
_mcl_upgrade_item = "vl_weaponry:hammer_netherite" _mcl_upgrade_item = "vl_weaponry:hammer_netherite"
@ -666,7 +621,6 @@ minetest.register_tool("vl_weaponry:hammer_netherite", {
_doc_items_usagehelp = hammer_use, _doc_items_usagehelp = hammer_use,
inventory_image = "vl_tool_netheritehammer.png", inventory_image = "vl_tool_netheritehammer.png",
wield_scale = wield_scale, wield_scale = wield_scale,
on_place = hammer_on_place(uses.netherite),
groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10, fire_immune=1 }, groups = { weapon=1, hammer=1, dig_speed_class=2, enchantability=10, fire_immune=1 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.0, full_punch_interval = 1.0,
@ -678,7 +632,8 @@ minetest.register_tool("vl_weaponry:hammer_netherite", {
_repair_material = "mcl_nether:netherite_ingot", _repair_material = "mcl_nether:netherite_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_diggroups = { _mcl_diggroups = {
pickaxey = { speed = 2, level = 1, uses = 2031 } pickaxey = { speed = 6, level = 6, uses = 2031 },
shovely = { speed = 6, level = 6, uses = 2031 }
}, },
}) })