Search in sources :

Example 1 with IHackableBlock

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

the class BlockTrackEntryHackable method addInformation.

@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList) {
    IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(world, x, y, z, PneumaticCraft.proxy.getPlayer());
    int hackTime = HUDHandler.instance().getSpecificRenderer(BlockTrackUpgradeHandler.class).getTargetForCoord(x, y, z).getHackTime();
    if (hackTime == 0) {
        hackableBlock.addInfo(world, x, y, z, infoList, PneumaticCraft.proxy.getPlayer());
    } else {
        int requiredHackTime = hackableBlock.getHackTime(world, x, y, z, PneumaticCraft.proxy.getPlayer());
        int percentageComplete = hackTime * 100 / requiredHackTime;
        if (percentageComplete < 100) {
            infoList.add(I18n.format("pneumaticHelmet.hacking.hacking") + " (" + percentageComplete + "%%)");
        } else if (hackTime < requiredHackTime + 20) {
            hackableBlock.addPostHackInfo(world, x, y, z, infoList, PneumaticCraft.proxy.getPlayer());
        } else {
            hackableBlock.addInfo(world, x, y, z, infoList, PneumaticCraft.proxy.getPlayer());
        }
    }
}
Also used : IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock)

Example 2 with IHackableBlock

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

the class HackableHandler method getHackableForCoord.

public static IHackableBlock getHackableForCoord(IBlockAccess world, int x, int y, int z, EntityPlayer player) {
    //clean up the map
    Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> iterator = getInstance().trackedHackableBlocks.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<WorldAndCoord, IHackableBlock> entry = iterator.next();
        Class<? extends IHackableBlock> hackableBlockClazz = PneumaticCraftAPIHandler.getInstance().hackableBlocks.get(entry.getKey().getBlock());
        if (hackableBlockClazz != entry.getValue().getClass() || !entry.getValue().canHack(entry.getKey().world, entry.getKey().x, entry.getKey().y, entry.getKey().z, player) && !isInDisplayCooldown(entry.getValue(), entry.getKey().world, entry.getKey().x, entry.getKey().y, entry.getKey().z, player))
            iterator.remove();
    }
    Block block = world.getBlock(x, y, z);
    if (block instanceof IHackableBlock && ((IHackableBlock) block).canHack(world, x, y, z, player))
        return (IHackableBlock) block;
    IHackableBlock hackable = getInstance().trackedHackableBlocks.get(new WorldAndCoord(world, x, y, z));
    if (hackable == null) {
        if (!PneumaticCraftAPIHandler.getInstance().hackableBlocks.containsKey(block))
            return null;
        try {
            hackable = PneumaticCraftAPIHandler.getInstance().hackableBlocks.get(block).newInstance();
            if (hackable.canHack(world, x, y, z, player)) {
                getInstance().trackedHackableBlocks.put(new WorldAndCoord(world, x, y, z), hackable);
            } else {
                hackable = null;
            }
        } catch (Exception e) {
            //shouldn't happen, checked earlier.
            e.printStackTrace();
        }
    }
    return hackable;
}
Also used : IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) Block(net.minecraft.block.Block) Map(java.util.Map) HashMap(java.util.HashMap) WorldAndCoord(pneumaticCraft.common.util.WorldAndCoord)

Example 3 with IHackableBlock

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

the class RenderBlockTarget method update.

public void update() {
    if (te != null && te.isInvalid())
        te = null;
    stat.update();
    List<IBlockTrackEntry> applicableTrackEntries = getApplicableEntries();
    if (CommonHUDHandler.getHandlerForPlayer().ticksExisted % 100 == 0) {
        boolean sentUpdate = false;
        for (IBlockTrackEntry entry : applicableTrackEntries) {
            if (entry.shouldBeUpdatedFromServer(te)) {
                if (!sentUpdate) {
                    NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(blockX, blockY, blockZ));
                    sentUpdate = true;
                }
            }
        }
    }
    playerIsLooking = isPlayerLookingAtTarget();
    arrowRenderer.ticksExisted++;
    if (!getBlock().isAir(world, blockX, blockY, blockZ)) {
        textList = new ArrayList<String>();
        if (ticksExisted > 120) {
            stat.closeWindow();
            for (IBlockTrackEntry entry : applicableTrackEntries) {
                if (blockTracker.countBlockTrackersOfType(entry) <= entry.spamThreshold()) {
                    stat.openWindow();
                    break;
                }
            }
            if (playerIsLooking) {
                stat.openWindow();
                addBlockTrackInfo(textList);
            }
            stat.setText(textList);
        } else if (ticksExisted < -30) {
            stat.closeWindow();
            stat.setText(textList);
        }
    }
    if (hackTime > 0) {
        IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(world, blockX, blockY, blockZ, player);
        if (hackableBlock != null) {
            // = Math.min(hackTime + 1, hackableBlock.getHackTime(world, blockX, blockY, blockZ, player));
            hackTime++;
        } else {
            hackTime = 0;
        }
    }
}
Also used : IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) IBlockTrackEntry(pneumaticCraft.api.client.pneumaticHelmet.IBlockTrackEntry) PacketDescriptionPacketRequest(pneumaticCraft.common.network.PacketDescriptionPacketRequest)

Example 4 with IHackableBlock

use of pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock 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 5 with IHackableBlock

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

the class HackTickHandler method onServerTick.

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> blockIterator = hackedBlocks.entrySet().iterator();
        while (blockIterator.hasNext()) {
            Map.Entry<WorldAndCoord, IHackableBlock> entry = blockIterator.next();
            IHackableBlock hackableBlock = entry.getValue();
            WorldAndCoord hackedBlock = entry.getKey();
            boolean found = false;
            for (Map.Entry<Block, Class<? extends IHackableBlock>> registeredEntry : PneumaticCraftAPIHandler.getInstance().hackableBlocks.entrySet()) {
                if (hackableBlock.getClass() == registeredEntry.getValue()) {
                    if (hackedBlock.getBlock() == registeredEntry.getKey()) {
                        if (!hackableBlock.afterHackTick((World) hackedBlock.world, hackedBlock.x, hackedBlock.y, hackedBlock.z)) {
                            blockIterator.remove();
                        }
                        found = true;
                        break;
                    }
                }
            }
            if (!found)
                blockIterator.remove();
        }
    }
}
Also used : IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) Block(net.minecraft.block.Block) World(net.minecraft.world.World) HashMap(java.util.HashMap) Map(java.util.Map) WorldAndCoord(pneumaticCraft.common.util.WorldAndCoord) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

IHackableBlock (pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock)7 WorldAndCoord (pneumaticCraft.common.util.WorldAndCoord)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Block (net.minecraft.block.Block)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 World (net.minecraft.world.World)1 IBlockTrackEntry (pneumaticCraft.api.client.pneumaticHelmet.IBlockTrackEntry)1 IHackableEntity (pneumaticCraft.api.client.pneumaticHelmet.IHackableEntity)1 PacketDescriptionPacketRequest (pneumaticCraft.common.network.PacketDescriptionPacketRequest)1 PacketHackingBlockFinish (pneumaticCraft.common.network.PacketHackingBlockFinish)1 PacketHackingEntityFinish (pneumaticCraft.common.network.PacketHackingEntityFinish)1