Search in sources :

Example 1 with WorldAndCoord

use of pneumaticCraft.common.util.WorldAndCoord 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 2 with WorldAndCoord

use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.

the class PacketHackingBlockStart method handleServerSide.

@Override
public void handleServerSide(PacketHackingBlockStart message, EntityPlayer player) {
    CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z));
    NetworkHandler.sendToAllAround(message, player.worldObj);
}
Also used : WorldAndCoord(pneumaticCraft.common.util.WorldAndCoord)

Example 3 with WorldAndCoord

use of pneumaticCraft.common.util.WorldAndCoord 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)

Example 4 with WorldAndCoord

use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.

the class PacketHackingBlockFinish method handleClientSide.

@Override
public void handleClientSide(PacketHackingBlockFinish message, EntityPlayer player) {
    IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(player.worldObj, message.x, message.y, message.z, player);
    if (hackableBlock != null) {
        hackableBlock.onHackFinished(player.worldObj, message.x, message.y, message.z, player);
        PneumaticCraft.proxy.getHackTickHandler().trackBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z), hackableBlock);
        CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(null);
        player.worldObj.playSound(message.x, message.y, message.z, "PneumaticCraft:helmetHackFinish", 1.0F, 1.0F, false);
    }
}
Also used : IHackableBlock(pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock) WorldAndCoord(pneumaticCraft.common.util.WorldAndCoord)

Example 5 with WorldAndCoord

use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.

the class PacketHackingBlockStart method handleClientSide.

@Override
public void handleClientSide(PacketHackingBlockStart message, EntityPlayer player) {
    CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z));
    RenderBlockTarget target = HUDHandler.instance().getSpecificRenderer(BlockTrackUpgradeHandler.class).getTargetForCoord(message.x, message.y, message.z);
    if (target != null)
        target.onHackConfirmServer();
}
Also used : RenderBlockTarget(pneumaticCraft.client.render.pneumaticArmor.RenderBlockTarget) BlockTrackUpgradeHandler(pneumaticCraft.client.render.pneumaticArmor.BlockTrackUpgradeHandler) WorldAndCoord(pneumaticCraft.common.util.WorldAndCoord)

Aggregations

WorldAndCoord (pneumaticCraft.common.util.WorldAndCoord)5 IHackableBlock (pneumaticCraft.api.client.pneumaticHelmet.IHackableBlock)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 BlockTrackUpgradeHandler (pneumaticCraft.client.render.pneumaticArmor.BlockTrackUpgradeHandler)1 RenderBlockTarget (pneumaticCraft.client.render.pneumaticArmor.RenderBlockTarget)1