Implement Electric Jetpack

This commit is contained in:
mrkubax10 2024-01-10 18:59:07 +01:00
parent 536cd978ed
commit 5cef554c9e

View File

@ -17,6 +17,7 @@
local S=minetest.get_translator("industrialtest") local S=minetest.get_translator("industrialtest")
local jetpack={} local jetpack={}
local electricJetpack={}
local function registerJetpack(config) local function registerJetpack(config)
if industrialtest.mclAvailable then if industrialtest.mclAvailable then
@ -30,7 +31,7 @@ local function registerJetpack(config)
for key,value in pairs(config.groups) do for key,value in pairs(config.groups) do
groups[key]=value groups[key]=value
end end
minetest.register_tool("industrialtest:"..config.name,{ local definition={
description=config.displayName, description=config.displayName,
inventory_image="industrialtest_"..config.name.."_inv.png", inventory_image="industrialtest_"..config.name.."_inv.png",
groups=groups, groups=groups,
@ -43,22 +44,34 @@ local function registerJetpack(config)
_mcl_armor_element="torso", _mcl_armor_element="torso",
_mcl_armor_texture="industrialtest_"..config.name..".png", _mcl_armor_texture="industrialtest_"..config.name..".png",
_industrialtest_tryFly=config.tryFly _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 elseif industrialtest.mtgAvailable then
local groups={ local groups={
armor_torso=1, armor_torso=1,
armor_heal=0, armor_heal=0,
_industrialtest_jetpack=1 _industrialtest_jetpack=1
} }
for key,value in pairs(config.groups) do if config.groups then
groups[key]=value for key,value in pairs(config.groups) do
groups[key]=value
end
end end
armor:register_armor("industrialtest:"..config.name, { local definition={
description=config.displayName, description=config.displayName,
inventory_image="industrialtest_"..config.name.."_inv.png", inventory_image="industrialtest_"..config.name.."_inv.png",
groups=groups, groups=groups,
_industrialtest_tryFly=config.tryFly _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
end end
@ -73,23 +86,21 @@ end
local function onGlobalStep(player,inv,itemstack,index,def) local function onGlobalStep(player,inv,itemstack,index,def)
if def.groups and def.groups._industrialtest_jetpack then if def.groups and def.groups._industrialtest_jetpack then
local result=def._industrialtest_tryFly(player,itemstack) if def._industrialtest_tryFly(itemstack) then
if result then
addYVelocityClamped(player,1,10) addYVelocityClamped(player,1,10)
inv:set_stack("armor",index,result) inv:set_stack("armor",index,itemstack)
end end
return true return true
end end
return false return false
end end
jetpack.tryFly=function(player,itemstack) jetpack.tryFly=function(itemstack)
if itemstack:get_wear()>=65533 then if itemstack:get_wear()>=65533 then
return false return false
end end
itemstack:set_wear(itemstack:get_wear()+2) itemstack:set_wear(itemstack:get_wear()+2)
minetest.debug(itemstack:get_wear()) return true
return itemstack
end end
-- _v is hack to suppress "Registered armor doesn't have material at the end of registration name" warning from 3D Armor. -- _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) minetest.register_globalstep(function(dtime)
-- FIXME: Maybe this can be optimized? -- FIXME: Maybe this can be optimized?
local players=minetest.get_connected_players() local players=minetest.get_connected_players()