diff --git a/api.lua b/api.lua index 3d61b57..f7fb016 100644 --- a/api.lua +++ b/api.lua @@ -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 diff --git a/compatibility.lua b/compatibility.lua index ad23fd9..8fe4ff5 100644 --- a/compatibility.lua +++ b/compatibility.lua @@ -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, diff --git a/tools.lua b/tools.lua index a2d84e8..aa44c21 100644 --- a/tools.lua +++ b/tools.lua @@ -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