forked from mrkubax10/industrialtest
Refactor Solar Helmet
This commit is contained in:
parent
e34c1eba66
commit
30c67390b2
@ -21,7 +21,7 @@ industrialtest.internal.unpackTableInto(industrialtest.BatPackBase,{
|
||||
})
|
||||
|
||||
local updateDelta=0
|
||||
function industrialtest.BatPackBase.update(self,player,itemstack,dtime)
|
||||
function industrialtest.BatPackBase.update(self,player,inv,itemstack,dtime)
|
||||
updateDelta=updateDelta+dtime
|
||||
if updateDelta<industrialtest.updateDelay then
|
||||
return false
|
||||
|
@ -63,7 +63,7 @@ minetest.register_globalstep(function(dtime)
|
||||
for i,itemstack in ipairs(armorList) do
|
||||
local def=itemstack:get_definition()
|
||||
if def and def.groups._industrialtest_gearTool and def._industrialtest_self and def._industrialtest_self.update and
|
||||
def._industrialtest_self:update(player,itemstack,dtime) then
|
||||
def._industrialtest_self:update(player,inv,itemstack,dtime) then
|
||||
inv:set_stack("armor",i,itemstack)
|
||||
end
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ industrialtest.internal.unpackTableInto(industrialtest.JetpackBase,{
|
||||
part="torso"
|
||||
})
|
||||
|
||||
function industrialtest.JetpackBase.update(self,player,itemstack,dtime)
|
||||
function industrialtest.JetpackBase.update(self,player,inv,itemstack,dtime)
|
||||
local control=player:get_player_control()
|
||||
if control.jump and self:tryFly(itemstack) then
|
||||
self.addYVelocityClamped(player,1,10)
|
||||
|
@ -15,58 +15,41 @@
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
industrialtest.SolarHelmet=table.copy(industrialtest.GearTool)
|
||||
industrialtest.internal.unpackTableInto(industrialtest.SolarHelmet,{
|
||||
name="industrialtest:solar_helmet",
|
||||
description=S("Solar Helmet"),
|
||||
inventoryImage="industrialtest_solar_helmet_inv.png",
|
||||
part="head",
|
||||
modelImage="industrialtest_solar_helmet.png"
|
||||
})
|
||||
|
||||
local updateDelta=0
|
||||
|
||||
local function onGlobalStep(player,inv,stack)
|
||||
if stack:get_name()~="industrialtest:solar_helmet" then
|
||||
function industrialtest.SolarHelmet.update(self,player,inv,itemstack,dtime)
|
||||
updateDelta=updateDelta+dtime
|
||||
if updateDelta<industrialtest.updateDelay then
|
||||
return false
|
||||
end
|
||||
updateDelta=0
|
||||
|
||||
local amount=math.floor((minetest.get_node_light(player:get_pos()) or 0)/2)
|
||||
if amount==0 then
|
||||
return true
|
||||
return false
|
||||
end
|
||||
local armorList=inv:get_list("armor")
|
||||
for i=1,#armorList do
|
||||
local meta=armorList[i]:get_meta()
|
||||
for i,armorItemstack in ipairs(armorList) do
|
||||
local meta=armorItemstack:get_meta()
|
||||
if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then
|
||||
industrialtest.api.addPowerToItem(armorList[i],amount)
|
||||
inv:set_stack("armor",i,armorList[i])
|
||||
industrialtest.api.addPowerToItem(armorItemstack,amount)
|
||||
inv:set_stack("armor",i,armorItemstack)
|
||||
break
|
||||
end
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end
|
||||
|
||||
if industrialtest.mtgAvailable then
|
||||
armor:register_armor("industrialtest:solar_helmet",{
|
||||
description=S("Solar Helmet"),
|
||||
inventory_image="industrialtest_solar_helmet_inv.png",
|
||||
groups={
|
||||
armor_head=1,
|
||||
armor_heal=0
|
||||
}
|
||||
})
|
||||
elseif industrialtest.mclAvailable then
|
||||
minetest.register_tool("industrialtest:solar_helmet",{
|
||||
description=S("Solar Helmet"),
|
||||
inventory_image="industrialtest_solar_helmet_inv.png",
|
||||
groups={
|
||||
armor=1,
|
||||
non_combat_armor=1,
|
||||
armor_head=1,
|
||||
non_combat_feet=1
|
||||
},
|
||||
sounds={
|
||||
_mcl_armor_equip="mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip="mcl_armor_unequip_iron"
|
||||
},
|
||||
on_place=mcl_armor.equip_on_use,
|
||||
on_secondary_use=mcl_armor.equip_on_use,
|
||||
_mcl_armor_element="head",
|
||||
_mcl_armor_texture="industrialtest_solar_helmet.png"
|
||||
})
|
||||
end
|
||||
industrialtest.SolarHelmet:register()
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:solar_helmet",
|
||||
@ -76,6 +59,7 @@ minetest.register_craft({
|
||||
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:solar_helmet",
|
||||
@ -85,31 +69,3 @@ minetest.register_craft({
|
||||
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
updateDelta=updateDelta+dtime
|
||||
if updateDelta<industrialtest.updateDelay then
|
||||
return
|
||||
end
|
||||
updateDelta=0
|
||||
local players=minetest.get_connected_players()
|
||||
for _,player in ipairs(players) do
|
||||
if industrialtest.mtgAvailable then
|
||||
local _,inv=armor:get_valid_player(player,"")
|
||||
if inv then
|
||||
local armorList=inv:get_list("armor")
|
||||
assert(armorList)
|
||||
for i=1,#armorList do
|
||||
local stack=armorList[i]
|
||||
if onGlobalStep(player,inv,stack) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
local inv=player:get_inventory()
|
||||
local stack=inv:get_stack("armor",1)
|
||||
onGlobalStep(player,inv,stack)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user