Search in sources :

Example 1 with IMinerStats

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

the class MinerStats method adjustData.

public static void adjustData(EntityPlayerMP player) {
    IMinerStats stats = MinerStats.get(player, true);
    if (stats != null) {
        stats.adjustData();
        CaveNetworkRegistry.sendTo(new MiningRecordsMessage(stats), player);
    }
}
Also used : MiningRecordsMessage(cavern.network.client.MiningRecordsMessage) IMinerStats(cavern.api.IMinerStats)

Example 2 with IMinerStats

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

the class MinerDataMessage method process.

@SideOnly(Side.CLIENT)
@Override
public IMessage process(EntityPlayerSP player) {
    IMinerStats stats = MinerStats.get(player, true);
    if (stats != null) {
        stats.setPoint(point, false);
        stats.setRank(rank, false);
        stats.setMiningAssist(miningAssist, false);
    }
    return null;
}
Also used : IMinerStats(cavern.api.IMinerStats) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IMinerStats

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

the class MiningAssistEventHooks method isActive.

private boolean isActive(EntityPlayer player, IBlockState state) {
    ItemStack held = player.getHeldItemMainhand();
    if (!MiningAssistConfig.isEffectiveItem(held)) {
        return false;
    }
    IMinerStats stats = MinerStats.get(player);
    if (stats.getRank() < MiningAssistConfig.minerRank.getValue()) {
        return false;
    }
    MiningAssist type = MiningAssist.get(stats.getMiningAssist());
    if (type == MiningAssist.DISABLED) {
        return false;
    }
    return type.isEffectiveTarget(held, state);
}
Also used : ItemStack(net.minecraft.item.ItemStack) MiningAssist(cavern.miningassist.MiningAssist) IMinerStats(cavern.api.IMinerStats)

Example 4 with IMinerStats

use of cavern.api.IMinerStats 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 5 with IMinerStats

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

the class CaveCapabilities method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
    EntityPlayer player = event.getEntityPlayer();
    if (player.world.isRemote) {
        return;
    }
    EntityPlayer original = event.getOriginal();
    IPortalCache originalPortalCache = getCapability(original, PORTAL_CACHE);
    IPortalCache portalCache = getCapability(player, PORTAL_CACHE);
    if (originalPortalCache != null && portalCache != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalPortalCache.writeToNBT(nbt);
        portalCache.readFromNBT(nbt);
    }
    IPlayerData originalPlayerData = getCapability(original, PLAYER_DATA);
    IPlayerData playerData = getCapability(player, PLAYER_DATA);
    if (originalPlayerData != null && playerData != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalPlayerData.writeToNBT(nbt);
        playerData.readFromNBT(nbt);
    }
    IMinerStats originalMinerStats = getCapability(original, MINER_STATS);
    IMinerStats minerStats = getCapability(player, MINER_STATS);
    if (originalMinerStats != null && minerStats != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalMinerStats.writeToNBT(nbt);
        minerStats.readFromNBT(nbt);
    }
}
Also used : IPortalCache(cavern.api.IPortalCache) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerData(cavern.api.IPlayerData) IMinerStats(cavern.api.IMinerStats) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IMinerStats (cavern.api.IMinerStats)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 IMiningData (cavern.api.IMiningData)2 MiningAssist (cavern.miningassist.MiningAssist)2 IBlockState (net.minecraft.block.state.IBlockState)2 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 IIceEquipment (cavern.api.IIceEquipment)1 IPlayerData (cavern.api.IPlayerData)1 IPortalCache (cavern.api.IPortalCache)1 ConfigDisplayPos (cavern.config.property.ConfigDisplayPos)1 MiningMessage (cavern.network.client.MiningMessage)1 MiningRecordsMessage (cavern.network.client.MiningRecordsMessage)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