Search in sources :

Example 6 with ItemJetpack

use of tonius.simplyjetpacks.item.ItemPack.ItemJetpack in project SimplyJetpacks by Tonius.

the class LivingTickHandler method onLivingTick.

@SubscribeEvent
public void onLivingTick(LivingUpdateEvent evt) {
    if (!evt.entityLiving.worldObj.isRemote) {
        ParticleType jetpackState = null;
        ItemStack armor = evt.entityLiving.getEquipmentInSlot(3);
        Jetpack jetpack = null;
        if (armor != null && armor.getItem() instanceof ItemJetpack) {
            jetpack = ((ItemJetpack) armor.getItem()).getPack(armor);
            if (jetpack != null) {
                jetpackState = jetpack.getDisplayParticleType(armor, (ItemJetpack) armor.getItem(), evt.entityLiving);
            }
        }
        if (jetpackState != lastJetpackState.get(evt.entityLiving.getEntityId())) {
            if (jetpackState == null) {
                lastJetpackState.remove(evt.entityLiving.getEntityId());
            } else {
                lastJetpackState.put(evt.entityLiving.getEntityId(), jetpackState);
            }
            PacketHandler.instance.sendToAllAround(new MessageJetpackSync(evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1), new TargetPoint(evt.entityLiving.dimension, evt.entityLiving.posX, evt.entityLiving.posY, evt.entityLiving.posZ, 256));
        } else if (jetpack != null && evt.entityLiving.worldObj.getTotalWorldTime() % 160L == 0) {
            PacketHandler.instance.sendToAllAround(new MessageJetpackSync(evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1), new TargetPoint(evt.entityLiving.dimension, evt.entityLiving.posX, evt.entityLiving.posY, evt.entityLiving.posZ, 256));
        }
        if (evt.entityLiving.worldObj.getTotalWorldTime() % 200L == 0) {
            Iterator<Integer> itr = lastJetpackState.keySet().iterator();
            while (itr.hasNext()) {
                int entityId = itr.next();
                if (evt.entityLiving.worldObj.getEntityByID(entityId) == null) {
                    itr.remove();
                }
            }
        }
    }
}
Also used : MessageJetpackSync(tonius.simplyjetpacks.network.message.MessageJetpackSync) ItemJetpack(tonius.simplyjetpacks.item.ItemPack.ItemJetpack) ParticleType(tonius.simplyjetpacks.setup.ParticleType) ItemStack(net.minecraft.item.ItemStack) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) Jetpack(tonius.simplyjetpacks.item.meta.Jetpack) ItemJetpack(tonius.simplyjetpacks.item.ItemPack.ItemJetpack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemJetpack (tonius.simplyjetpacks.item.ItemPack.ItemJetpack)6 ItemStack (net.minecraft.item.ItemStack)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 Jetpack (tonius.simplyjetpacks.item.meta.Jetpack)3 ParticleType (tonius.simplyjetpacks.setup.ParticleType)3 IEnergyContainerItem (cofh.api.energy.IEnergyContainerItem)1 TargetPoint (cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntitySkeleton (net.minecraft.entity.monster.EntitySkeleton)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SoundJetpack (tonius.simplyjetpacks.client.audio.SoundJetpack)1 ItemJetpackFueller (tonius.simplyjetpacks.item.ItemJetpackFueller)1 ItemMeta (tonius.simplyjetpacks.item.ItemMeta)1 MetaItem (tonius.simplyjetpacks.item.ItemMeta.MetaItem)1 ItemMysteriousPotato (tonius.simplyjetpacks.item.ItemMysteriousPotato)1 ItemPack (tonius.simplyjetpacks.item.ItemPack)1 ItemFluxPack (tonius.simplyjetpacks.item.ItemPack.ItemFluxPack)1 JetPlate (tonius.simplyjetpacks.item.meta.JetPlate)1