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={}
|
||||||
|
|
||||||
minetest.register_on_punchnode(function(pos,node,user,pointed)
|
local function isActive(itemstack)
|
||||||
if user then
|
return string.sub(itemstack:get_name(),-string.len("_active"),-1)=="_active"
|
||||||
local itemstack=user:get_wielded_item()
|
end
|
||||||
if industrialtest.internal.registeredElectricChainsaws[itemstack:get_name()] then
|
|
||||||
local meta=itemstack:get_meta()
|
local function beforeUse(user,itemstack,canDig)
|
||||||
if meta:get_int("industrialtest.powerAmount")>=20 then
|
local meta=itemstack:get_meta()
|
||||||
local def=minetest.registered_nodes[node.name]
|
local def=itemstack:get_definition()
|
||||||
if (industrialtest.mtgAvailable and def.groups and def.groups.choppy) or (industrialtest.mclAvailable and def.groups and def.groups.axey) then
|
if meta:get_int("industrialtest.powerAmount")>=20 and canDig then
|
||||||
itemstack:set_name(itemstack:get_name().."_active")
|
if not isActive(itemstack) then
|
||||||
user:set_wielded_item(itemstack)
|
itemstack:set_name(itemstack:get_name().."_active")
|
||||||
end
|
|
||||||
end
|
|
||||||
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
|
|
||||||
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
|
|
||||||
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
|
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 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
|
||||||
|
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
|
||||||
|
beforeUse(user,itemstack,def.groups and def.groups.hoey)
|
||||||
|
elseif industrialtest.internal.registeredElectricDrills[itemstack:get_name()] then
|
||||||
|
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
|
||||||
|
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
|
||||||
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)
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
|
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)
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
|
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)
|
||||||
itemstack:set_name("industrialtest:"..config.name)
|
if meta:get_int("industrialtest.powerAmount")<20 then
|
||||||
|
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