Search in sources :

Example 1 with IMiningData

use of cavern.api.IMiningData in project Cavern2 by kegare.

the class MinerStatsHUDEventHooks method onRenderGamePostOverlay.

@SubscribeEvent
public void onRenderGamePostOverlay(RenderGameOverlayEvent.Post event) {
    if (event.getType() != ElementType.HOTBAR) {
        return;
    }
    Minecraft mc = FMLClientHandler.instance().getClient();
    ConfigDisplayPos.Type displayType = getDisplayType();
    if (!canRenderHUD(mc)) {
        miningPointPer = -1.0D;
        return;
    }
    ScaledResolution resolution = event.getResolution();
    IMinerStats stats = MinerStats.get(mc.player, true);
    if (stats == null || stats.getPoint() < 0) {
        return;
    }
    MinerRank minerRank = MinerRank.get(stats.getRank());
    MiningAssist miningAssist = MiningAssist.get(stats.getMiningAssist());
    String point = Integer.toString(stats.getPoint());
    String rank = I18n.format(minerRank.getUnlocalizedName());
    if (miningAssist != MiningAssist.DISABLED && stats.getRank() >= MiningAssistConfig.minerRank.getValue()) {
        rank += " / " + I18n.format(miningAssist.getUnlocalizedName());
    }
    setDisplayPos(displayType, mc, resolution.getScaledWidth(), resolution.getScaledHeight());
    int x = posX;
    int y = posY;
    RenderItem renderItem = mc.getRenderItem();
    FontRenderer renderer = mc.fontRenderer;
    boolean flag = false;
    IMiningData data = MiningData.get(mc.player);
    long processTime = mc.world.getTotalWorldTime() - data.getLastMiningTime();
    if (data.getLastMiningTime() > 0L && processTime < 50 && data.getLastMiningBlock() != null && data.getLastMiningPoint() != 0) {
        IBlockState state = data.getLastMiningBlock();
        ItemStack stack = new ItemStack(CaveRenderingRegistry.getRenderBlock(state.getBlock()), 1, state.getBlock().getMetaFromState(state));
        RenderHelper.enableGUIStandardItemLighting();
        renderItem.renderItemIntoGUI(stack, x, y);
        renderItem.renderItemOverlayIntoGUI(renderer, stack, x, y, Integer.toString(data.getLastMiningPoint()));
        RenderHelper.disableStandardItemLighting();
        flag = true;
    }
    if (flag) {
        x += displayType.isLeft() ? 20 : -20;
    }
    renderItem.renderItemIntoGUI(minerRank.getItemStack(), x, y);
    GlStateManager.pushMatrix();
    GlStateManager.disableDepth();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    if (point.length() <= 1) {
        point = " " + point;
    }
    MinerRank nextRank = MinerRank.get(stats.getRank() + 1);
    if (minerRank.getRank() < nextRank.getRank()) {
        String per = String.format("%.2f", calcMiningPointPer(stats.getPoint(), nextRank.getPhase(), false)) + "%";
        point = displayType.isLeft() ? point + " < " + per : per + " > " + point;
    }
    String combo = null;
    if (data.getMiningCombo() > 0) {
        TextFormatting format = TextFormatting.WHITE;
        if (processTime < 3 * 20) {
            format = TextFormatting.BOLD;
        } else if (processTime > 12 * 20) {
            format = TextFormatting.GRAY;
        }
        combo = format + String.format("%d COMBO!", data.getMiningCombo()) + TextFormatting.RESET;
    }
    boolean showRank = DisplayConfig.showMinerRank;
    boolean hasCombo = combo != null;
    int pointX = displayType.isLeft() ? x + 5 : x + 17 - renderer.getStringWidth(point);
    int pointY = y + 9;
    int rankX = showRank ? displayType.isLeft() ? posX + 5 : posX + 17 - renderer.getStringWidth(rank) : -1;
    int rankY = showRank ? displayType.isTop() ? y + 21 : y - 12 : -1;
    int comboX = hasCombo ? displayType.isLeft() ? posX + 5 : posX + 17 - renderer.getStringWidth(combo) : -1;
    int comboY = hasCombo ? displayType.isTop() ? y + 33 : y - 24 : -1;
    renderer.drawStringWithShadow(point, pointX, pointY, 0xCECECE);
    if (showRank) {
        renderer.drawStringWithShadow(rank, rankX, rankY, 0xCECECE);
        if (hasCombo) {
            renderer.drawStringWithShadow(combo, comboX, comboY, 0xFFFFFF);
        }
    }
    GlStateManager.enableDepth();
    GlStateManager.disableBlend();
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Minecraft(net.minecraft.client.Minecraft) MiningAssist(cavern.miningassist.MiningAssist) IMinerStats(cavern.api.IMinerStats) MinerRank(cavern.stats.MinerRank) RenderItem(net.minecraft.client.renderer.RenderItem) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IMiningData(cavern.api.IMiningData) ConfigDisplayPos(cavern.config.property.ConfigDisplayPos) TextFormatting(net.minecraft.util.text.TextFormatting) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IMiningData

use of cavern.api.IMiningData in project Cavern2 by kegare.

the class CaveEventHooks method onBlockBreak.

@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
    EntityPlayer entityPlayer = event.getPlayer();
    if (entityPlayer == null || entityPlayer instanceof FakePlayer || !(entityPlayer instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
    if (!CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    World world = event.getWorld();
    IBlockState state = event.getState();
    ItemStack stack = player.getHeldItemMainhand();
    if (GeneralConfig.isMiningPointItem(stack)) {
        int point = MinerStats.getPointAmount(state);
        if (point != 0) {
            IMinerStats stats = MinerStats.get(player);
            IMiningData data = MiningData.get(player);
            if (player.inventory.hasItemStack(ItemCave.EnumType.MINER_ORB.getItemStack())) {
                if (RANDOM.nextDouble() < 0.15D) {
                    point += Math.max(point / 2, 1);
                }
            }
            stats.addPoint(point);
            stats.addMiningRecord(new BlockMeta(state));
            data.notifyMining(state, point);
            int combo = data.getMiningCombo();
            if (combo > 0 && combo % 10 == 0) {
                world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((RANDOM.nextFloat() - RANDOM.nextFloat()) * 0.7F + 1.8F));
                player.addExperience(combo / 10);
            }
            if (combo >= 50) {
                PlayerHelper.grantAdvancement(player, "good_mine");
            }
            CaveNetworkRegistry.sendTo(new MiningMessage(state, point), player);
        }
    }
    if (CavernAPI.dimension.isInFrostMountains(player)) {
        if (player.capabilities.isCreativeMode) {
            return;
        }
        if (state.getBlock() != Blocks.PACKED_ICE || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) {
            return;
        }
        BlockPos pos = event.getPos();
        Biome biome = world.getBiome(pos);
        if (!biome.isSnowyBiome()) {
            return;
        }
        if (RANDOM.nextDouble() < 0.05D) {
            Block.spawnAsEntity(world, pos, new ItemStack(Blocks.ICE));
        } else if (RANDOM.nextDouble() < 0.005D) {
            Block.spawnAsEntity(world, pos, RandomiteHelper.getDropItem());
        } else if (stack.getItem() instanceof IIceEquipment && RANDOM.nextDouble() < 0.03D || RANDOM.nextDouble() < 0.01D) {
            Block.spawnAsEntity(world, pos, new ItemStack(Blocks.PACKED_ICE));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IIceEquipment(cavern.api.IIceEquipment) World(net.minecraft.world.World) FakePlayer(net.minecraftforge.common.util.FakePlayer) IMinerStats(cavern.api.IMinerStats) IMiningData(cavern.api.IMiningData) Biome(net.minecraft.world.biome.Biome) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MiningMessage(cavern.network.client.MiningMessage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockMeta(cavern.util.BlockMeta) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IMinerStats (cavern.api.IMinerStats)2 IMiningData (cavern.api.IMiningData)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IIceEquipment (cavern.api.IIceEquipment)1 ConfigDisplayPos (cavern.config.property.ConfigDisplayPos)1 MiningAssist (cavern.miningassist.MiningAssist)1 MiningMessage (cavern.network.client.MiningMessage)1 MinerRank (cavern.stats.MinerRank)1 BlockMeta (cavern.util.BlockMeta)1 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 RenderItem (net.minecraft.client.renderer.RenderItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 World (net.minecraft.world.World)1