Implement Electric Jetpack
This commit is contained in:
parent
536cd978ed
commit
5cef554c9e
|
@ -17,6 +17,7 @@
|
|||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
local jetpack={}
|
||||
local electricJetpack={}
|
||||
|
||||
local function registerJetpack(config)
|
||||
if industrialtest.mclAvailable then
|
||||
|
@ -30,7 +31,7 @@ local function registerJetpack(config)
|
|||
for key,value in pairs(config.groups) do
|
||||
groups[key]=value
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name,{
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
inventory_image="industrialtest_"..config.name.."_inv.png",
|
||||
groups=groups,
|
||||
|
@ -43,22 +44,34 @@ local function registerJetpack(config)
|
|||
_mcl_armor_element="torso",
|
||||
_mcl_armor_texture="industrialtest_"..config.name..".png",
|
||||
_industrialtest_tryFly=config.tryFly
|
||||
})
|
||||
}
|
||||
for key,value in pairs(config.customKeys) do
|
||||
definition[key]=value
|
||||
end
|
||||
minetest.register_tool("industrialtest:"..config.name,definition)
|
||||
elseif industrialtest.mtgAvailable then
|
||||
local groups={
|
||||
armor_torso=1,
|
||||
armor_heal=0,
|
||||
_industrialtest_jetpack=1
|
||||
}
|
||||
for key,value in pairs(config.groups) do
|
||||
groups[key]=value
|
||||
if config.groups then
|
||||
for key,value in pairs(config.groups) do
|
||||
groups[key]=value
|
||||
end
|
||||
end
|
||||
armor:register_armor("industrialtest:"..config.name, {
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
inventory_image="industrialtest_"..config.name.."_inv.png",
|
||||
groups=groups,
|
||||
_industrialtest_tryFly=config.tryFly
|
||||
})
|
||||
}
|
||||
if config.customKeys then
|
||||
for key,value in pairs(config.customKeys) do
|
||||
definition[key]=value
|
||||
end
|
||||
end
|
||||
armor:register_armor("industrialtest:"..config.name,definition)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,23 +86,21 @@ end
|
|||
|
||||
local function onGlobalStep(player,inv,itemstack,index,def)
|
||||
if def.groups and def.groups._industrialtest_jetpack then
|
||||
local result=def._industrialtest_tryFly(player,itemstack)
|
||||
if result then
|
||||
if def._industrialtest_tryFly(itemstack) then
|
||||
addYVelocityClamped(player,1,10)
|
||||
inv:set_stack("armor",index,result)
|
||||
inv:set_stack("armor",index,itemstack)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
jetpack.tryFly=function(player,itemstack)
|
||||
jetpack.tryFly=function(itemstack)
|
||||
if itemstack:get_wear()>=65533 then
|
||||
return false
|
||||
end
|
||||
itemstack:set_wear(itemstack:get_wear()+2)
|
||||
minetest.debug(itemstack:get_wear())
|
||||
return itemstack
|
||||
return true
|
||||
end
|
||||
|
||||
-- _v is hack to suppress "Registered armor doesn't have material at the end of registration name" warning from 3D Armor.
|
||||
|
@ -112,6 +123,35 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
electricJetpack.tryFly=function(itemstack)
|
||||
local meta=itemstack:get_meta()
|
||||
if meta:get_int("industrialtest.powerAmount")<10 then
|
||||
return false
|
||||
end
|
||||
industrialtest.api.addPowerToItem(itemstack,-10)
|
||||
return true
|
||||
end
|
||||
|
||||
registerJetpack({
|
||||
name="electric_jetpack",
|
||||
displayName=S("Electric Jetpack"),
|
||||
tryFly=electricJetpack.tryFly,
|
||||
customKeys={
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=30000,
|
||||
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:electric_jetpack",
|
||||
recipe={
|
||||
{"industrialtest:refined_iron_ingot","industrialtest:advanced_electronic_circuit","industrialtest:refined_iron_ingot"},
|
||||
{"industrialtest:refined_iron_ingot","industrialtest:batbox","industrialtest:refined_iron_ingot"},
|
||||
{industrialtest.elementKeys.yellowDust,"",industrialtest.elementKeys.yellowDust}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
-- FIXME: Maybe this can be optimized?
|
||||
local players=minetest.get_connected_players()
|
||||
|
|
Loading…
Reference in New Issue