Search in sources :

Example 1 with EntityTrackEvent

use of pneumaticCraft.api.client.pneumaticHelmet.EntityTrackEvent in project PneumaticCraft by MineMaarten.

the class EntityTrackUpgradeHandler method update.

@Override
@SideOnly(Side.CLIENT)
public void update(EntityPlayer player, int rangeUpgrades) {
    ItemStack helmetStack = player.getCurrentArmor(3);
    String entityFilter = "";
    if (helmetStack != null)
        entityFilter = NBTUtil.getString(helmetStack, "entityFilter");
    double entityTrackRange = ENTITY_TRACKING_RANGE + rangeUpgrades * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
    AxisAlignedBB bbBox = getAABBFromRange(player, rangeUpgrades);
    List<Entity> mobs = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bbBox);
    if (mobs.contains(player))
        mobs.remove(player);
    for (int i = 0; i < mobs.size(); i++) {
        if (player.getDistanceToEntity(mobs.get(i)) > entityTrackRange || !PneumaticCraftUtils.isEntityValidForFilter(entityFilter, mobs.get(i)) || MinecraftForge.EVENT_BUS.post(new EntityTrackEvent(mobs.get(i))))
            continue;
        boolean inList = false;
        for (int j = 0; j < targets.size(); j++) {
            if (targets.get(j).entity == mobs.get(i)) {
                inList = true;
                // cancel
                targets.get(j).ticksExisted = Math.abs(targets.get(j).ticksExisted);
                // targets
                break;
            }
        }
        if (!inList) {
            //player.worldObj.playSoundAtEntity(player, Sounds.CANNON_SOUND, 1.0F, 1.0F);
            targets.add(new RenderTarget(mobs.get(i)));
            if (mobs.get(i) instanceof EntityMob && !isEntityWithinPlayerFOV(player, mobs.get(i))) {
            //       HUDHandler.instance().addMessage(new ArmorMessage("A mob is sneaking up on you!", new ArrayList<String>(), 60, 0x70FF0000));
            }
        }
    }
    for (int j = 0; j < targets.size(); j++) {
        RenderTarget target = targets.get(j);
        if (target.entity.isDead || player.getDistanceToEntity(target.entity) > entityTrackRange + 5 || !PneumaticCraftUtils.isEntityValidForFilter(entityFilter, target.entity)) {
            if (target.ticksExisted > 0) {
                target.ticksExisted = -60;
            } else if (target.ticksExisted == -1) {
                targets.remove(target);
                j--;
            }
        }
    }
    if (targets.size() > ENTITY_TRACK_THRESHOLD) {
        if (!shouldStopSpamOnEntityTracking) {
            shouldStopSpamOnEntityTracking = true;
            HUDHandler.instance().addMessage(new ArmorMessage("Stopped spam on Entity Tracker", new ArrayList<String>(), 60, 0x7700AA00));
        }
    } else {
        shouldStopSpamOnEntityTracking = false;
    }
    List<String> text = new ArrayList<String>();
    for (RenderTarget target : targets) {
        boolean wasNegative = target.ticksExisted < 0;
        target.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
        if (target.ticksExisted >= 0 && wasNegative)
            target.ticksExisted = -1;
        target.update();
        if (target.isLookingAtTarget) {
            if (target.isInitialized()) {
                text.add(EnumChatFormatting.GRAY + target.entity.getCommandSenderName());
                text.addAll(target.getEntityText());
            } else {
                text.add(EnumChatFormatting.GRAY + "Acquiring target...");
            }
        }
    }
    if (text.size() == 0) {
        text.add("Filter mode: " + (entityFilter.equals("") ? "None" : entityFilter));
    }
    entityTrackInfo.setText(text);
    //Remove entities that don't need to be tracked anymore.
    Iterator<Entry<Entity, Integer>> iterator = targetingEntities.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<Entity, Integer> entry = iterator.next();
        Entity entity = entry.getKey();
        if (entry.getValue() >= 0)
            entry.setValue(entry.getValue() + 1);
        if (entity.isDead || !player.worldObj.getLoadedEntityList().contains(entity) || entry.getValue() > 50)
            iterator.remove();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityTrackEvent(pneumaticCraft.api.client.pneumaticHelmet.EntityTrackEvent) ArrayList(java.util.ArrayList) EntityMob(net.minecraft.entity.monster.EntityMob) Entry(java.util.Map.Entry) ItemStack(net.minecraft.item.ItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

SideOnly (cpw.mods.fml.relauncher.SideOnly)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Entity (net.minecraft.entity.Entity)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 EntityTrackEvent (pneumaticCraft.api.client.pneumaticHelmet.EntityTrackEvent)1