Make it possible to make stripped trunks with chainsaw

This commit is contained in:
mrkubax10 2023-04-08 19:28:33 +02:00
parent 90c9779bf0
commit 248bcd1af5
3 changed files with 45 additions and 29 deletions

View File

@ -29,7 +29,6 @@ industrialtest.api.hvPowerFlow=10200
industrialtest.api.evPowerFlow=40800
industrialtest.api.ivPowerFlow=163800
industrialtest.internal={}
industrialtest.internal.clamp=function(num,min,max)
return math.max(math.min(num,max),min)
end

View File

@ -39,6 +39,39 @@ end
industrialtest.elementKeys={}
industrialtest.internal={}
if industrialtest.mclAvailable then
industrialtest.internal.mclMakeStrippedTrunk=function(itemstack,placer,pointedThing,electricTool)
-- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_tools/init.lua#L360
if pointedThing.type ~= "node" then return end
local node = minetest.get_node(pointedThing.under)
local noddef = minetest.registered_nodes[minetest.get_node(pointedThing.under).name]
if not placer:get_player_control().sneak and noddef.on_rightclick then
return minetest.item_place(itemstack, placer, pointedThing)
end
if minetest.is_protected(pointedThing.under, placer:get_player_name()) then
minetest.record_protection_violation(pointedThing.under, placer:get_player_name())
return itemstack
end
if noddef._mcl_stripped_variant == nil then
return itemstack
else
minetest.swap_node(pointedThing.under, {name=noddef._mcl_stripped_variant, param2=node.param2})
if not minetest.is_creative_enabled(placer:get_player_name()) or electricTool then
-- Add wear (as if digging a axey node)
local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "axey")
itemstack:add_wear(wear)
end
end
return itemstack
end
end
-- compatibilty that adds not existing elements
if industrialtest.mclAvailable then
industrialtest.registerMetal=function(name,displayName,oreBlastResistance,oreHardness,rawBlockBlastResistance,rawBlockHardness,blockBlastResistance,blockHardness)
@ -217,34 +250,7 @@ if industrialtest.mclAvailable then
max_level_drop=config.levelDrop,
damage_groups={fleshy=config.damage+3},
},
on_place=function(itemstack,placer,pointedThing)
-- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_tools/init.lua#L360
if pointedThing.type ~= "node" then return end
local node = minetest.get_node(pointedThing.under)
local noddef = minetest.registered_nodes[minetest.get_node(pointedThing.under).name]
if not placer:get_player_control().sneak and noddef.on_rightclick then
return minetest.item_place(itemstack, placer, pointedThing)
end
if minetest.is_protected(pointedThing.under, placer:get_player_name()) then
minetest.record_protection_violation(pointedThing.under, placer:get_player_name())
return itemstack
end
if noddef._mcl_stripped_variant == nil then
return itemstack
else
minetest.swap_node(pointedThing.under, {name=noddef._mcl_stripped_variant, param2=node.param2})
if not minetest.is_creative_enabled(placer:get_player_name()) then
-- Add wear (as if digging a axey node)
local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "axey")
itemstack:add_wear(wear)
end
end
return itemstack
end,
on_place=industrialtest.internal.mclMakeStrippedTrunk,
sound={breaks="default_tool_breaks"},
_repair_material="industrialtest:"..material,
_mcl_toollike_wield=true,

View File

@ -216,6 +216,17 @@ local function registerElectricChainsaw(config)
definition.groups={
dig_speed_class=config.digSpeedClass,
}
definition.on_place=function(itemstack,user,pointed)
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=20 then
local itemstackCopy=itemstack
if itemstack:get_wear()~=industrialtest.internal.mclMakeStrippedTrunk(itemstackCopy,user,pointed,true):get_wear() then
industrialtest.api.addPowerToItem(itemstack,-20)
return itemstack
end
end
return nil
end
definition.after_use=function(itemstack)
-- Hack to make sure that chainsaw won't be destroyed when has 0 EU in MCL
return nil