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.registeredElectricHoes={}
|
||||||
industrialtest.internal.registeredElectricSabers={}
|
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)
|
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 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
|
if industrialtest.internal.registeredElectricChainsaws[itemstack:get_name()] then
|
||||||
local meta=itemstack:get_meta()
|
beforeUse(user,itemstack,(industrialtest.mtgAvailable and def.groups and def.groups.choppy) or (industrialtest.mclAvailable and def.groups and def.groups.axey))
|
||||||
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
|
|
||||||
elseif industrialtest.mclAvailable and industrialtest.internal.registeredElectricHoes[itemstack:get_name()] then
|
elseif industrialtest.mclAvailable and industrialtest.internal.registeredElectricHoes[itemstack:get_name()] then
|
||||||
local meta=itemstack:get_meta()
|
beforeUse(user,itemstack,def.groups and def.groups.hoey)
|
||||||
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
|
|
||||||
elseif industrialtest.internal.registeredElectricDrills[itemstack:get_name()] then
|
elseif industrialtest.internal.registeredElectricDrills[itemstack:get_name()] then
|
||||||
local meta=itemstack:get_meta()
|
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)))
|
||||||
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
|
|
||||||
elseif industrialtest.internal.registeredElectricSabers[itemstack:get_name()] then
|
elseif industrialtest.internal.registeredElectricSabers[itemstack:get_name()] then
|
||||||
local meta=itemstack:get_meta()
|
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)))
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
|||||||
local electricChainsaw={}
|
local electricChainsaw={}
|
||||||
|
|
||||||
electricChainsaw.afterUse=function(itemstack,config)
|
electricChainsaw.afterUse=function(itemstack,config)
|
||||||
|
local meta=itemstack:get_meta()
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||||
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
itemstack:set_name("industrialtest:"..config.name)
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,7 +33,8 @@ local function registerElectricChainsaw(config)
|
|||||||
inventory_image="industrialtest_"..config.name..".png",
|
inventory_image="industrialtest_"..config.name..".png",
|
||||||
_industrialtest_powerStorage=true,
|
_industrialtest_powerStorage=true,
|
||||||
_industrialtest_powerCapacity=10000,
|
_industrialtest_powerCapacity=10000,
|
||||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||||
|
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||||
}
|
}
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
definition.tool_capabilities={
|
definition.tool_capabilities={
|
||||||
@ -93,6 +97,7 @@ local function registerElectricChainsaw(config)
|
|||||||
end
|
end
|
||||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||||
industrialtest.internal.registeredElectricChainsaws["industrialtest:"..config.name]=true
|
industrialtest.internal.registeredElectricChainsaws["industrialtest:"..config.name]=true
|
||||||
|
industrialtest.internal.registeredElectricChainsaws["industrialtest:"..config.name.."_active"]=true
|
||||||
end
|
end
|
||||||
local definition={
|
local definition={
|
||||||
name="electric_chainsaw",
|
name="electric_chainsaw",
|
||||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
|||||||
local electricDrill={}
|
local electricDrill={}
|
||||||
|
|
||||||
electricDrill.afterUse=function(itemstack,config)
|
electricDrill.afterUse=function(itemstack,config)
|
||||||
|
local meta=itemstack:get_meta()
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||||
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
itemstack:set_name("industrialtest:"..config.name)
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,7 +33,8 @@ local function registerElectricDrill(config)
|
|||||||
inventory_image="industrialtest_"..config.name..".png",
|
inventory_image="industrialtest_"..config.name..".png",
|
||||||
_industrialtest_powerStorage=true,
|
_industrialtest_powerStorage=true,
|
||||||
_industrialtest_powerCapacity=10000,
|
_industrialtest_powerCapacity=10000,
|
||||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||||
|
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||||
}
|
}
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
definition.tool_capabilities={
|
definition.tool_capabilities={
|
||||||
@ -93,6 +97,7 @@ local function registerElectricDrill(config)
|
|||||||
end
|
end
|
||||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||||
industrialtest.internal.registeredElectricDrills["industrialtest:"..config.name]=true
|
industrialtest.internal.registeredElectricDrills["industrialtest:"..config.name]=true
|
||||||
|
industrialtest.internal.registeredElectricDrills["industrialtest:"..config.name.."_active"]=true
|
||||||
end
|
end
|
||||||
local definition={
|
local definition={
|
||||||
name="electric_drill",
|
name="electric_drill",
|
||||||
|
@ -19,8 +19,11 @@ local S=minetest.get_translator("industrialtest")
|
|||||||
local electricHoe={}
|
local electricHoe={}
|
||||||
|
|
||||||
electricHoe.afterUse=function(itemstack,config)
|
electricHoe.afterUse=function(itemstack,config)
|
||||||
|
local meta=itemstack:get_meta()
|
||||||
industrialtest.api.addPowerToItem(itemstack,-20)
|
industrialtest.api.addPowerToItem(itemstack,-20)
|
||||||
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
itemstack:set_name("industrialtest:"..config.name)
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,7 +33,8 @@ local function registerElectricHoe(config)
|
|||||||
inventory_image="industrialtest_"..config.name..".png",
|
inventory_image="industrialtest_"..config.name..".png",
|
||||||
_industrialtest_powerStorage=true,
|
_industrialtest_powerStorage=true,
|
||||||
_industrialtest_powerCapacity=10000,
|
_industrialtest_powerCapacity=10000,
|
||||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||||
|
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||||
}
|
}
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
-- Taken and adapted from farming mod from Minetest Game
|
-- Taken and adapted from farming mod from Minetest Game
|
||||||
@ -175,6 +179,7 @@ local function registerElectricHoe(config)
|
|||||||
return electricHoe.afterUse(itemstack,config)
|
return electricHoe.afterUse(itemstack,config)
|
||||||
end
|
end
|
||||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||||
|
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name.."_active"]=true
|
||||||
end
|
end
|
||||||
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name]=true
|
industrialtest.internal.registeredElectricHoes["industrialtest:"..config.name]=true
|
||||||
end
|
end
|
||||||
|
@ -16,13 +16,25 @@
|
|||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
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 function registerElectricSaber(config)
|
||||||
local definition={
|
local definition={
|
||||||
description=config.displayName,
|
description=config.displayName,
|
||||||
inventory_image="industrialtest_"..config.name..".png",
|
inventory_image="industrialtest_"..config.name..".png",
|
||||||
_industrialtest_powerStorage=true,
|
_industrialtest_powerStorage=true,
|
||||||
_industrialtest_powerCapacity=10000,
|
_industrialtest_powerCapacity=10000,
|
||||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow,
|
||||||
|
_industrialtest_inactiveName="industrialtest:"..config.name
|
||||||
}
|
}
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
definition.groups={
|
definition.groups={
|
||||||
@ -79,11 +91,12 @@ local function registerElectricSaber(config)
|
|||||||
definition._mcl_diggroups.swordy_cobweb.speed=config.activeDigSpeed
|
definition._mcl_diggroups.swordy_cobweb.speed=config.activeDigSpeed
|
||||||
end
|
end
|
||||||
definition.groups.not_in_creative_inventory=1
|
definition.groups.not_in_creative_inventory=1
|
||||||
definition.after_use=function()
|
definition.after_use=function(itemstack)
|
||||||
return nil
|
return electricSaber.afterUse(itemstack,config)
|
||||||
end
|
end
|
||||||
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
minetest.register_tool("industrialtest:"..config.name.."_active",definition)
|
||||||
industrialtest.internal.registeredElectricSabers["industrialtest:"..config.name]=true
|
industrialtest.internal.registeredElectricSabers["industrialtest:"..config.name]=true
|
||||||
|
industrialtest.internal.registeredElectricSabers["industrialtest:"..config.name.."_active"]=true
|
||||||
end
|
end
|
||||||
local definition={
|
local definition={
|
||||||
name="electric_saber",
|
name="electric_saber",
|
||||||
|
Loading…
Reference in New Issue
Block a user