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
|
local updateDelta=0
|
||||||
function industrialtest.BatPackBase.update(self,player,itemstack,dtime)
|
function industrialtest.BatPackBase.update(self,player,inv,itemstack,dtime)
|
||||||
updateDelta=updateDelta+dtime
|
updateDelta=updateDelta+dtime
|
||||||
if updateDelta<industrialtest.updateDelay then
|
if updateDelta<industrialtest.updateDelay then
|
||||||
return false
|
return false
|
||||||
|
@ -63,7 +63,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
for i,itemstack in ipairs(armorList) do
|
for i,itemstack in ipairs(armorList) do
|
||||||
local def=itemstack:get_definition()
|
local def=itemstack:get_definition()
|
||||||
if def and def.groups._industrialtest_gearTool and def._industrialtest_self and def._industrialtest_self.update and
|
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)
|
inv:set_stack("armor",i,itemstack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ industrialtest.internal.unpackTableInto(industrialtest.JetpackBase,{
|
|||||||
part="torso"
|
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()
|
local control=player:get_player_control()
|
||||||
if control.jump and self:tryFly(itemstack) then
|
if control.jump and self:tryFly(itemstack) then
|
||||||
self.addYVelocityClamped(player,1,10)
|
self.addYVelocityClamped(player,1,10)
|
||||||
|
@ -15,58 +15,41 @@
|
|||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
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 updateDelta=0
|
||||||
|
function industrialtest.SolarHelmet.update(self,player,inv,itemstack,dtime)
|
||||||
local function onGlobalStep(player,inv,stack)
|
updateDelta=updateDelta+dtime
|
||||||
if stack:get_name()~="industrialtest:solar_helmet" then
|
if updateDelta<industrialtest.updateDelay then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
updateDelta=0
|
||||||
|
|
||||||
local amount=math.floor((minetest.get_node_light(player:get_pos()) or 0)/2)
|
local amount=math.floor((minetest.get_node_light(player:get_pos()) or 0)/2)
|
||||||
if amount==0 then
|
if amount==0 then
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
local armorList=inv:get_list("armor")
|
local armorList=inv:get_list("armor")
|
||||||
for i=1,#armorList do
|
for i,armorItemstack in ipairs(armorList) do
|
||||||
local meta=armorList[i]:get_meta()
|
local meta=armorItemstack:get_meta()
|
||||||
if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then
|
if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then
|
||||||
industrialtest.api.addPowerToItem(armorList[i],amount)
|
industrialtest.api.addPowerToItem(armorItemstack,amount)
|
||||||
inv:set_stack("armor",i,armorList[i])
|
inv:set_stack("armor",i,armorItemstack)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if industrialtest.mtgAvailable then
|
industrialtest.SolarHelmet:register()
|
||||||
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
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:solar_helmet",
|
output="industrialtest:solar_helmet",
|
||||||
@ -76,6 +59,7 @@ minetest.register_craft({
|
|||||||
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:solar_helmet",
|
output="industrialtest:solar_helmet",
|
||||||
@ -85,31 +69,3 @@ minetest.register_craft({
|
|||||||
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
|
{"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