use of pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity in project PneumaticCraft by MineMaarten.
the class CommonHUDHandler method handleHacking.
private void handleHacking(EntityPlayer player) {
if (hackedBlock != null) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(hackedBlock, player);
if (hackableBlock != null) {
if (++hackTime >= hackableBlock.getHackTime(hackedBlock.world, hackedBlock.x, hackedBlock.y, hackedBlock.z, player)) {
hackableBlock.onHackFinished(player.worldObj, hackedBlock.x, hackedBlock.y, hackedBlock.z, player);
PneumaticCraft.proxy.getHackTickHandler().trackBlock(hackedBlock, hackableBlock);
NetworkHandler.sendToAllAround(new PacketHackingBlockFinish(hackedBlock), player.worldObj);
setHackedBlock(null);
}
} else {
setHackedBlock(null);
}
} else if (hackedEntity != null) {
IHackableEntity hackableEntity = HackableHandler.getHackableForEntity(hackedEntity, player);
if (hackableEntity != null) {
if (++hackTime >= hackableEntity.getHackTime(hackedEntity, player)) {
hackableEntity.onHackFinished(hackedEntity, player);
PneumaticCraft.proxy.getHackTickHandler().trackEntity(hackedEntity, hackableEntity);
NetworkHandler.sendToAllAround(new PacketHackingEntityFinish(hackedEntity), new NetworkRegistry.TargetPoint(hackedEntity.worldObj.provider.dimensionId, hackedEntity.posX, hackedEntity.posY, hackedEntity.posZ, 64));
setHackedEntity(null);
}
} else {
setHackedEntity(null);
}
}
}
use of pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity in project PneumaticCraft by MineMaarten.
the class PneumaticCraftAPIHandler method addHackable.
@Override
public void addHackable(Class<? extends Entity> entityClazz, Class<? extends IHackableEntity> iHackable) {
if (entityClazz == null)
throw new NullPointerException("Entity class is null!");
if (iHackable == null)
throw new NullPointerException("IHackableEntity is null!");
if (Entity.class.isAssignableFrom(iHackable)) {
Log.warning("Entities that implement IHackableEntity shouldn't be registered as hackable! Registering entity: " + entityClazz.getCanonicalName());
} else {
try {
IHackableEntity hackableEntity = iHackable.newInstance();
if (hackableEntity.getId() != null)
stringToEntityHackables.put(hackableEntity.getId(), iHackable);
hackableEntities.put(entityClazz, iHackable);
} catch (InstantiationException e) {
Log.error("Not able to register hackable entity: " + iHackable.getName() + ". Does the class have a parameterless constructor?");
e.printStackTrace();
} catch (IllegalAccessException e) {
Log.error("Not able to register hackable entity: " + iHackable.getName() + ". Is the class a public class?");
e.printStackTrace();
}
}
}
use of pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity in project PneumaticCraft by MineMaarten.
the class RenderTarget method update.
public void update() {
stat.update();
stat.setTitle(entity.getCommandSenderName());
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
if (ticksExisted >= 30 && !didMakeLockSound) {
didMakeLockSound = true;
player.worldObj.playSound(player.posX, player.posY, player.posZ, Sounds.HUD_ENTITY_LOCK, 0.1F, 1.0F, true);
}
boolean tagged = NBTUtil.getInteger(player.getCurrentArmor(3), NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE) == entity.getEntityId();
circle1.setRenderingAsTagged(tagged);
circle2.setRenderingAsTagged(tagged);
circle1.update();
circle2.update();
for (IEntityTrackEntry tracker : trackEntries) {
tracker.update(entity);
}
isLookingAtTarget = isPlayerLookingAtTarget();
if (hackTime > 0) {
IHackableEntity hackableEntity = HackableHandler.getHackableForEntity(entity, PneumaticCraft.proxy.getPlayer());
if (hackableEntity != null) {
// = Math.min(hackTime + 1, hackableEntity.getHackTime(entity, PneumaticCraft.proxy.getPlayer()));
hackTime++;
} else {
hackTime = 0;
}
}
}
use of pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity in project PneumaticCraft by MineMaarten.
the class HackableHandler method getHackableForEntity.
public static IHackableEntity getHackableForEntity(Entity entity, EntityPlayer player) {
//clean up the map
Iterator<Map.Entry<Entity, IHackableEntity>> iterator = getInstance().trackedHackableEntities.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Entity, IHackableEntity> entry = iterator.next();
if (entry.getKey().isDead || !entry.getValue().canHack(entry.getKey(), player) && !isInDisplayCooldown(entry.getValue(), entry.getKey()))
iterator.remove();
}
if (entity instanceof IHackableEntity && ((IHackableEntity) entity).canHack(entity, player))
return (IHackableEntity) entity;
IHackableEntity hackable = getInstance().trackedHackableEntities.get(entity);
if (hackable == null) {
for (Map.Entry<Class<? extends Entity>, Class<? extends IHackableEntity>> entry : PneumaticCraftAPIHandler.getInstance().hackableEntities.entrySet()) {
if (entry.getKey().isAssignableFrom(entity.getClass())) {
try {
hackable = entry.getValue().newInstance();
if (hackable.canHack(entity, player)) {
getInstance().trackedHackableEntities.put(entity, hackable);
break;
} else {
hackable = null;
}
} catch (Exception e) {
//shouldn't happen, checked earlier.
e.printStackTrace();
}
}
}
}
return hackable;
}
use of pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity in project PneumaticCraft by MineMaarten.
the class PacketHackingEntityFinish method handleClientSide.
@Override
public void handleClientSide(PacketHackingEntityFinish message, EntityPlayer player) {
Entity entity = player.worldObj.getEntityByID(message.entityId);
if (entity != null) {
IHackableEntity hackableEntity = HackableHandler.getHackableForEntity(entity, player);
if (hackableEntity != null) {
hackableEntity.onHackFinished(entity, player);
PneumaticCraft.proxy.getHackTickHandler().trackEntity(entity, hackableEntity);
CommonHUDHandler.getHandlerForPlayer(player).setHackedEntity(null);
player.worldObj.playSound(entity.posX, entity.posY, entity.posZ, "PneumaticCraft:helmetHackFinish", 1.0F, 1.0F, false);
}
}
}
Aggregations