Search in sources :

Example 1 with WorldAndCoord

use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.

the class HackableHandler method getHackableForCoord.

public static IHackableBlock getHackableForCoord(IBlockAccess world, BlockPos pos, 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 = PneumaticHelmetRegistry.getInstance().hackableBlocks.get(entry.getKey().getBlock());
        if (hackableBlockClazz != entry.getValue().getClass() || !entry.getValue().canHack(entry.getKey().world, entry.getKey().pos, player) && !isInDisplayCooldown(entry.getValue(), entry.getKey().world, entry.getKey().pos, player))
            iterator.remove();
    }
    Block block = world.getBlockState(pos).getBlock();
    if (block instanceof IHackableBlock && ((IHackableBlock) block).canHack(world, pos, player))
        return (IHackableBlock) block;
    IHackableBlock hackable = getInstance().trackedHackableBlocks.get(new WorldAndCoord(world, pos));
    if (hackable == null) {
        if (!PneumaticHelmetRegistry.getInstance().hackableBlocks.containsKey(block))
            return null;
        try {
            hackable = PneumaticHelmetRegistry.getInstance().hackableBlocks.get(block).newInstance();
            if (hackable.canHack(world, pos, player)) {
                getInstance().trackedHackableBlocks.put(new WorldAndCoord(world, pos), hackable);
            } else {
                hackable = null;
            }
        } catch (Exception e) {
            // shouldn't happen, checked earlier.
            e.printStackTrace();
        }
    }
    return hackable;
}
Also used : IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) Block(net.minecraft.block.Block) HashMap(java.util.HashMap) Map(java.util.Map) WorldAndCoord(me.desht.pneumaticcraft.common.util.WorldAndCoord)

Example 2 with WorldAndCoord

use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.

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 : PneumaticHelmetRegistry.getInstance().hackableBlocks.entrySet()) {
                if (hackableBlock.getClass() == registeredEntry.getValue()) {
                    if (hackedBlock.getBlock() == registeredEntry.getKey()) {
                        if (!hackableBlock.afterHackTick((World) hackedBlock.world, hackedBlock.pos)) {
                            blockIterator.remove();
                        }
                        found = true;
                        break;
                    }
                }
            }
            if (!found)
                blockIterator.remove();
        }
    }
}
Also used : IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) Block(net.minecraft.block.Block) World(net.minecraft.world.World) HashMap(java.util.HashMap) Map(java.util.Map) WorldAndCoord(me.desht.pneumaticcraft.common.util.WorldAndCoord) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with WorldAndCoord

use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.

the class PacketHackingBlockStart method handleClientSide.

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

Example 4 with WorldAndCoord

use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.

the class PacketHackingBlockFinish method handleClientSide.

@Override
public void handleClientSide(PacketHackingBlockFinish message, EntityPlayer player) {
    IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(player.world, message.pos, player);
    if (hackableBlock != null) {
        hackableBlock.onHackFinished(player.world, message.pos, player);
        PneumaticCraftRepressurized.proxy.getHackTickHandler().trackBlock(new WorldAndCoord(player.world, message.pos), hackableBlock);
        CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(null);
        player.playSound(Sounds.HELMET_HACK_FINISH, 1.0F, 1.0F);
    }
}
Also used : IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) WorldAndCoord(me.desht.pneumaticcraft.common.util.WorldAndCoord)

Example 5 with WorldAndCoord

use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.

the class PacketHackingBlockStart method handleServerSide.

@Override
public void handleServerSide(PacketHackingBlockStart message, EntityPlayer player) {
    CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.world, message.pos));
    NetworkHandler.sendToAllAround(message, player.world);
}
Also used : WorldAndCoord(me.desht.pneumaticcraft.common.util.WorldAndCoord)

Aggregations

WorldAndCoord (me.desht.pneumaticcraft.common.util.WorldAndCoord)5 IHackableBlock (me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Block (net.minecraft.block.Block)2 BlockTrackUpgradeHandler (me.desht.pneumaticcraft.client.render.pneumaticArmor.BlockTrackUpgradeHandler)1 RenderBlockTarget (me.desht.pneumaticcraft.client.render.pneumaticArmor.RenderBlockTarget)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1