Search in sources :

Example 1 with MiningAssist

use of cavern.miningassist.MiningAssist 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 2 with MiningAssist

use of cavern.miningassist.MiningAssist in project Cavern2 by kegare.

the class MiningAssistEventHooks method onBlockBreak.

@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    EntityPlayer player = event.getPlayer();
    if (player == null || player instanceof FakePlayer) {
        return;
    }
    BlockPos pos = event.getPos();
    MiningAssistUnit assist = MiningAssistUnit.get(player);
    if (assist.addExperience(pos, event.getExpToDrop())) {
        event.setExpToDrop(0);
    }
    if (breaking) {
        return;
    }
    if (!(player instanceof EntityPlayerMP)) {
        return;
    }
    IBlockState state = event.getState();
    if (!isActive(player, state)) {
        return;
    }
    MiningAssist type = MiningAssist.byPlayer(player);
    MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
    if (snapshot.isEmpty()) {
        return;
    }
    PlayerInteractionManager im = ((EntityPlayerMP) player).interactionManager;
    assist.captureDrops(MiningAssistConfig.collectDrops);
    assist.captureExperiences(MiningAssistConfig.collectExps);
    breaking = true;
    for (BlockPos target : snapshot.getTargets()) {
        if (snapshot.validTarget(target) && !harvestBlock(im, target)) {
            break;
        }
    }
    breaking = false;
    Map<BlockPos, NonNullList<ItemStack>> drops = assist.captureDrops(false);
    if (drops != null && !drops.isEmpty()) {
        for (NonNullList<ItemStack> items : drops.values()) {
            for (ItemStack stack : items) {
                Block.spawnAsEntity(world, pos, stack);
            }
        }
    }
    Map<BlockPos, Integer> experiences = assist.captureExperiences(false);
    if (experiences != null && !experiences.isEmpty() && !im.isCreative() && world.getGameRules().getBoolean("doTileDrops")) {
        int exp = experiences.values().stream().mapToInt(Integer::intValue).sum();
        while (exp > 0) {
            int i = EntityXPOrb.getXPSplit(exp);
            exp -= i;
            world.spawnEntity(new EntityXPOrb(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, i));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) MiningAssist(cavern.miningassist.MiningAssist) FakePlayer(net.minecraftforge.common.util.FakePlayer) MiningSnapshot(cavern.miningassist.MiningSnapshot) NonNullList(net.minecraft.util.NonNullList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) ItemStack(net.minecraft.item.ItemStack) MiningAssistUnit(cavern.miningassist.MiningAssistUnit) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with MiningAssist

use of cavern.miningassist.MiningAssist 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 4 with MiningAssist

use of cavern.miningassist.MiningAssist in project Cavern2 by kegare.

the class MiningAssistEventHooks method onBreakSpeed.

@SubscribeEvent
public void onBreakSpeed(BreakSpeed event) {
    if (!MiningAssistConfig.modifiedHardness || !Cavern.proxy.isSinglePlayer()) {
        return;
    }
    if (checking) {
        return;
    }
    EntityPlayer player = event.getEntityPlayer();
    IBlockState state = event.getState();
    if (!isActive(player, state)) {
        return;
    }
    MiningAssistUnit assist = MiningAssistUnit.get(player);
    MiningAssist type = MiningAssist.byPlayer(player);
    BlockPos pos = event.getPos();
    checking = true;
    MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
    if (!snapshot.isEmpty()) {
        event.setNewSpeed(assist.getBreakSpeed(snapshot));
    }
    checking = false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MiningSnapshot(cavern.miningassist.MiningSnapshot) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) MiningAssist(cavern.miningassist.MiningAssist) MiningAssistUnit(cavern.miningassist.MiningAssistUnit) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with MiningAssist

use of cavern.miningassist.MiningAssist in project Cavern2 by kegare.

the class ClientEventHooks method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    EntityPlayer player = event.player;
    if (MiningAssistConfig.miningAssistNotify) {
        MiningAssist assist = MiningAssist.byPlayer(player);
        if (assist != MiningAssist.DISABLED) {
            ITextComponent message = new TextComponentTranslation(assist.getUnlocalizedName());
            message.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
            message = new TextComponentTranslation("cavern.miningassist.notify.message", message);
            player.sendMessage(message);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MiningAssist(cavern.miningassist.MiningAssist) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

MiningAssist (cavern.miningassist.MiningAssist)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 IMinerStats (cavern.api.IMinerStats)2 MiningAssistUnit (cavern.miningassist.MiningAssistUnit)2 MiningSnapshot (cavern.miningassist.MiningSnapshot)2 BlockPos (net.minecraft.util.math.BlockPos)2 IMiningData (cavern.api.IMiningData)1 ConfigDisplayPos (cavern.config.property.ConfigDisplayPos)1 MinerRank (cavern.stats.MinerRank)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 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 PlayerInteractionManager (net.minecraft.server.management.PlayerInteractionManager)1 NonNullList (net.minecraft.util.NonNullList)1