Search in sources :

Example 1 with MinerRank

use of cavern.stats.MinerRank 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 MinerRank

use of cavern.stats.MinerRank in project Cavern2 by kegare.

the class CaveEventHooks method onHarvestDrops.

@SubscribeEvent
public void onHarvestDrops(HarvestDropsEvent event) {
    if (!GeneralConfig.criticalMining || event.isSilkTouching()) {
        return;
    }
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    EntityPlayer player = event.getHarvester();
    if (player == null || player instanceof FakePlayer || !CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    IBlockState state = event.getState();
    if (MinerStats.getPointAmount(state) <= 0) {
        return;
    }
    if (state.getMaterial() != Material.ROCK) {
        return;
    }
    MinerRank rank = MinerRank.get(MinerStats.get(player).getRank());
    float f = rank.getBoost();
    if (f <= 1.0F) {
        return;
    }
    f = (f - 1.0F) * 0.3F;
    ItemStack held = player.getHeldItemMainhand();
    String tool = state.getBlock().getHarvestTool(state);
    if (held.isEmpty() || tool == null) {
        return;
    }
    int toolLevel = held.getItem().getHarvestLevel(held, tool, player, state);
    if (toolLevel <= 0) {
        return;
    }
    f *= 1.0F + toolLevel * 0.1F;
    List<ItemStack> originalDrops = event.getDrops();
    List<ItemStack> drops = Lists.newArrayList();
    for (ItemStack stack : originalDrops) {
        if (!stack.isEmpty() && !(stack.getItem() instanceof ItemBlock) && RANDOM.nextFloat() <= f) {
            drops.add(stack.copy());
        }
    }
    if (!drops.isEmpty()) {
        CriticalMiningEvent criticalEvent = new CriticalMiningEvent(world, event.getPos(), state, player, event.getFortuneLevel(), originalDrops, drops);
        if (MinecraftForge.EVENT_BUS.post(criticalEvent)) {
            return;
        }
        player.sendStatusMessage(new TextComponentTranslation("cavern.message.mining.critical"), true);
        originalDrops.addAll(criticalEvent.getBonusDrops());
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) CriticalMiningEvent(cavern.api.event.CriticalMiningEvent) World(net.minecraft.world.World) ItemBlock(net.minecraft.item.ItemBlock) FakePlayer(net.minecraftforge.common.util.FakePlayer) MinerRank(cavern.stats.MinerRank) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

MinerRank (cavern.stats.MinerRank)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IMinerStats (cavern.api.IMinerStats)1 IMiningData (cavern.api.IMiningData)1 CriticalMiningEvent (cavern.api.event.CriticalMiningEvent)1 ConfigDisplayPos (cavern.config.property.ConfigDisplayPos)1 MiningAssist (cavern.miningassist.MiningAssist)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 ItemBlock (net.minecraft.item.ItemBlock)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 World (net.minecraft.world.World)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1