Optimize some electric tools and fix Electric Saber not discharging after digging node
This commit is contained in:
parent
e69d16aeb0
commit
eaff4a9065
@ -19,45 +19,37 @@ industrialtest.internal.registeredElectricDrills={}
|
||||
industrialtest.internal.registeredElectricHoes={}
|
||||
industrialtest.internal.registeredElectricSabers={}
|
||||
|
||||
local function isActive(itemstack)
|
||||
return string.sub(itemstack:get_name(),-string.len("_active"),-1)=="_active"
|
||||
end
|
||||
|
||||
local function beforeUse(user,itemstack,canDig)
|
||||
local meta=itemstack:get_meta()
|
||||
local def=itemstack:get_definition()
|
||||
if meta:get_int("industrialtest.powerAmount")>=20 and canDig then
|
||||
if not isActive(itemstack) then
|
||||
itemstack:set_name(itemstack:get_name().."_active")
|
||||
end
|
||||
else
|
||||
itemstack:set_name(def._industrialtest_inactiveName)
|
||||
end
|
||||
user:set_wielded_item(itemstack)
|
||||
end
|
||||
|
||||
minetest.register_on_punchnode(function(pos,node,user,pointed)
|
||||
if user then
|
||||
if not user then
|
||||
return
|
||||
end
|
||||
local itemstack=user:get_wielded_item()
|
||||
local meta=itemstack:get_meta()
|
||||
local def=minetest.registered_nodes[node.name]
|
||||
if industrialtest.internal.registeredElectricChainsaws[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.choppy) or (industrialtest.mclAvailable and def.groups and def.groups.axey) then
|
||||
itemstack:set_name(itemstack:get_name().."_active")
|
||||
user:set_wielded_item(itemstack)
|
||||
end
|
||||
end
|
||||
beforeUse(user,itemstack,(industrialtest.mtgAvailable and def.groups and def.groups.choppy) or (industrialtest.mclAvailable and def.groups and def.groups.axey))
|
||||
elseif industrialtest.mclAvailable and industrialtest.internal.registeredElectricHoes[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 def.groups and def.groups.hoey then
|
||||
itemstack:set_name(itemstack:get_name().."_active")
|
||||
user:set_wielded_item(itemstack)
|
||||
end
|
||||
end
|
||||
beforeUse(user,itemstack,def.groups and def.groups.hoey)
|
||||
elseif industrialtest.internal.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
|
||||
beforeUse(user,itemstack,(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)))
|
||||
elseif industrialtest.internal.registeredElectricSabers[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.snappy) or (industrialtest.mclAvailable and def.groups and (def.groups.swordy or def.groups.swordy_cobweb)) then
|
||||
itemstack:set_name(itemstack:get_name().."_active")
|
||||
user:set_wielded_item(itemstack)
|
||||
end
|
||||
end
|
||||
end
|
||||
beforeUse(user,itemstack,(industrialtest.mtgAvailable and def.groups and def.groups.snappy) or (industrialtest.mclAvailable and def.groups and (def.groups.swordy or def.groups.swordy_cobweb)))
|
||||
end
|
||||
end)
|
||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
||||
local electricChainsaw={}
|
||||
|
||||
electricChainsaw.afterUse=function(itemstack,config)
|
||||
local meta=itemstack:get_meta()
|
||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||
itemstack:set_name("industrialtest:"..config.name)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
@ -30,7 +33,8 @@ local function registerElectricChainsaw(config)
|
||||
inventory_image="industrialtest_"..config.name..".png",
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=10000,
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.tool_capabilities={
|
||||
@ -93,6 +97,7 @@ local function registerElectricChainsaw(config)
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||
industrialtest.internal.registeredElectricChainsaws["industrialtest:"..config.name]=true
|
||||
industrialtest.internal.registeredElectricChainsaws["industrialtest:"..config.name.."_active"]=true
|
||||
end
|
||||
local definition={
|
||||
name="electric_chainsaw",
|
||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
||||
local electricDrill={}
|
||||
|
||||
electricDrill.afterUse=function(itemstack,config)
|
||||
local meta=itemstack:get_meta()
|
||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||
itemstack:set_name("industrialtest:"..config.name)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
@ -30,7 +33,8 @@ local function registerElectricDrill(config)
|
||||
inventory_image="industrialtest_"..config.name..".png",
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=10000,
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.tool_capabilities={
|
||||
@ -93,6 +97,7 @@ local function registerElectricDrill(config)
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||
industrialtest.internal.registeredElectricDrills["industrialtest:"..config.name]=true
|
||||
industrialtest.internal.registeredElectricDrills["industrialtest:"..config.name.."_active"]=true
|
||||
end
|
||||
local definition={
|
||||
name="electric_drill",
|
||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
||||
local electricHoe={}
|
||||
|
||||
electricHoe.afterUse=function(itemstack,config)
|
||||
local meta=itemstack:get_meta()
|
||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||
itemstack:set_name("industrialtest:"..config.name)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
@ -30,7 +33,8 @@ local function registerElectricHoe(config)
|
||||
inventory_image="industrialtest_"..config.name..".png",
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=10000,
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
-- Taken and adapted from farming mod from Minetest Game
|
||||
@ -175,6 +179,7 @@ local function registerElectricHoe(config)
|
||||
return electricHoe.afterUse(itemstack,config)
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name.."_active"]=true
|
||||
end
|
||||
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name]=true
|
||||
end
|
||||
|
@ -16,13 +16,25 @@
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
local electricSaber={}
|
||||
|
||||
electricSaber.afterUse=function(itemstack,config)
|
||||
local meta=itemstack:get_meta()
|
||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||
itemstack:set_name("industrialtest:"..config.name)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function registerElectricSaber(config)
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
inventory_image="industrialtest_"..config.name..".png",
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=10000,
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={
|
||||
@ -79,11 +91,12 @@ local function registerElectricSaber(config)
|
||||
definition._mcl_diggroups.swordy_cobweb.speed=config.activeDigSpeed
|
||||
end
|
||||
definition.groups.not_in_creative_inventory=1
|
||||
definition.after_use=function()
|
||||
return nil
|
||||
definition.after_use=function(itemstack)
|
||||
return electricSaber.afterUse(itemstack,config)
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||
industrialtest.internal.registeredElectricSabers["industrialtest:"..config.name]=true
|
||||
industrialtest.internal.registeredElectricSabers["industrialtest:"..config.name.."_active"]=true
|
||||
end
|
||||
local definition={
|
||||
name="electric_saber",
|
||||
|
Loading…
Reference in New Issue
Block a user