Optimize some electric tools and fix Electric Saber not discharging after digging node
This commit is contained in:
@@ -19,45 +19,37 @@ industrialtest.internal.registeredElectricDrills={}
|
||||
industrialtest.internal.registeredElectricHoes={}
|
||||
industrialtest.internal.registeredElectricSabers={}
|
||||
|
||||
minetest.register_on_punchnode(function(pos,node,user,pointed)
|
||||
if user then
|
||||
local itemstack=user:get_wielded_item()
|
||||
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
|
||||
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
|
||||
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 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)
|
||||
|
||||
Reference in New Issue
Block a user