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();
}
}
Aggregations