Search in sources :

Example 1 with IHackableEntity

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);
        }
    }
}
Also used : PacketHackingBlockFinish(pneumaticCraft.common.network.PacketHackingBlockFinish) IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity) PacketHackingEntityFinish(pneumaticCraft.common.network.PacketHackingEntityFinish)

Example 2 with IHackableEntity

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();
        }
    }
}
Also used : IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity)

Example 3 with IHackableEntity

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;
        }
    }
}
Also used : IEntityTrackEntry(pneumaticCraft.api.client.pneumaticHelmet.IEntityTrackEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity)

Example 4 with IHackableEntity

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;
}
Also used : Entity(net.minecraft.entity.Entity) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with IHackableEntity

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);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity) IHackableEntity(pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity)

Aggregations

IHackableEntity (pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity)5 Entity (net.minecraft.entity.Entity)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IEntityTrackEntry (pneumaticCraft.api.client.pneumaticHelmet.IEntityTrackEntry)1 IHackableBlock (pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock)1 PacketHackingBlockFinish (pneumaticCraft.common.network.PacketHackingBlockFinish)1 PacketHackingEntityFinish (pneumaticCraft.common.network.PacketHackingEntityFinish)1