Implement Electric Drill

This commit is contained in:
mrkubax10 2023-04-10 12:53:26 +02:00
parent af09857dbc
commit c26191320a

134
tools.lua
View File

@ -514,6 +514,131 @@ if industrialtest.mclAvailable then
})
end
local registeredElectricDrills={}
local function registerElectricDrill(config)
local definition={
description=S(config.displayName),
inventory_image="industrialtest_"..config.name..".png",
_industrialtest_powerStorage=true,
_industrialtest_powerCapacity=10000,
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
}
if industrialtest.mtgAvailable then
definition.tool_capabilities={
full_punch_interval=0.5,
max_drop_level=config.maxDropLevel,
groupcaps={
cracky={
times=config.inactiveTimes,
maxlevel=config.maxLevel
},
crumbly={
times=config.inactiveTimes,
maxlevel=config.maxLevel
}
}
}
definition.groups={
pickaxe=1,
shovel=1
}
elseif industrialtest.mclAvailable then
definition.tool_capabilities={
full_punch_interval=0.5,
max_drop_level=config.maxDropLevel
}
definition.groups={
tool=1,
dig_speed_class=config.digSpeedClass
}
definition.after_use=function()
-- Hack to make sure that drill won't be destroyed when has 0 EU in MCL
return nil
end
definition._mcl_diggroups={
pickaxey={
speed=config.inactiveDigSpeed,
level=config.digLevel,
uses=-1
},
shovely={
speed=config.inactiveDigSpeed,
level=config.digLevel,
uses=-1
}
}
definition._mcl_toollike_wield=true
end
minetest.register_tool("industrialtest:"..config.name,definition)
definition=table.copy(definition)
if industrialtest.mtgAvailable then
definition.tool_capabilities.groupcaps.cracky.times=config.activeTimes
definition.tool_capabilities.groupcaps.crumbly.times=config.activeTimes
elseif industrialtest.mclAvailable then
definition._mcl_diggroups.pickaxey.speed=config.activeDigSpeed
definition._mcl_diggroups.shovely.speed=config.activeDigSpeed
end
definition.groups.not_in_creative_inventory=1
definition.after_use=function(itemstack)
industrialtest.api.addPowerToItem(itemstack,-20)
itemstack:set_name("industrialtest:"..config.name)
return itemstack
end
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
registeredElectricDrills["industrialtest:"..config.name]=true
end
definition={
name="electric_drill",
displayName="Electric Drill"
}
if industrialtest.mtgAvailable then
definition.maxDropLevel=1
definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4}
definition.maxLevel=2
definition.activeTimes={[1]=2.0,[2]=0.8,[3]=0.4}
elseif industrialtest.mclAvailable then
definition.digSpeedClass=4
definition.maxDropLevel=4
definition.inactiveDigSpeed=1
definition.digLevel=4
definition.activeDigSpeed=7
end
registerElectricDrill(definition)
minetest.register_craft({
type="shaped",
output="industrialtest:electric_drill",
recipe={
{"","industrialtest:refined_iron_ingot",""},
{"industrialtest:refined_iron_ingot","industrialtest:electronic_circuit","industrialtest:refined_iron_ingot"},
{"industrialtest:refined_iron_ingot","industrialtest:re_battery","industrialtest:refined_iron_ingot"}
}
})
definition={
name="diamond_electric_drill",
displayName="Diamond Electric Drill"
}
if industrialtest.mtgAvailable then
definition.maxDropLevel=1
definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4}
definition.maxLevel=3
definition.activeTimes={[1]=2.0,[2]=0.8,[3]=0.4}
elseif industrialtest.mclAvailable then
definition.digSpeedClass=5
definition.maxDropLevel=5
definition.inactiveDigSpeed=1
definition.digLevel=5
definition.activeDigSpeed=9
end
registerElectricDrill(definition)
minetest.register_craft({
type="shaped",
output="industrialtest:diamond_electric_drill",
recipe={
{"",industrialtest.elementKeys.diamond,""},
{industrialtest.elementKeys.diamond,"industrialtest:electric_drill",industrialtest.elementKeys.diamond}
}
})
-- Tool callbacks
minetest.register_on_punchnode(function(pos,node,user,pointed)
if user then
@ -536,6 +661,15 @@ minetest.register_on_punchnode(function(pos,node,user,pointed)
user:set_wielded_item(itemstack)
end
end
elseif registeredElectricDrills[itemstack:get_name()] then
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=20 then
local def=minetest.registered_nodes[node.name]
if (industrialtest.mtgAvailable and def.groups and (def.groups.cracky or def.groups.crumbly)) or (industrialtest.mclAvailable and def.groups and (def.groups.pickaxey or def.groups.shovely)) then
itemstack:set_name(itemstack:get_name().."_active")
user:set_wielded_item(itemstack)
end
end
end
end
end)