Search in sources :

Example 1 with ToolSkill

use of net.silentchaos512.gems.skills.ToolSkill in project SilentGems by SilentChaos512.

the class GemsCommonEvents method onGetBreakSpeed.

@SubscribeEvent
public void onGetBreakSpeed(PlayerEvent.BreakSpeed event) {
    EntityPlayer player = event.getEntityPlayer();
    ItemStack mainHand = player.getHeldItem(EnumHand.MAIN_HAND);
    if (StackHelper.isValid(mainHand)) {
        // Shears on Fluffy Blocks
        if (event.getState() == ModBlocks.fluffyBlock) {
            ModBlocks.fluffyBlock.onGetBreakSpeed(event);
        }
        // Gravity enchantment.
        int gravityLevel = EnchantmentHelper.getEnchantmentLevel(ModEnchantments.gravity, mainHand);
        if (gravityLevel > 0)
            ModEnchantments.gravity.onGetBreakSpeed(event, mainHand, gravityLevel);
        // Reduce speed for Area Miner and Lumberjack.
        ToolSkill skill = ToolHelper.getSuperSkill(mainHand);
        if (skill instanceof ToolSkillDigger && ToolHelper.isSpecialAbilityEnabled(mainHand))
            ((ToolSkillDigger) skill).onGetBreakSpeed(event);
    }
}
Also used : ToolSkill(net.silentchaos512.gems.skills.ToolSkill) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ToolSkillDigger(net.silentchaos512.gems.skills.ToolSkillDigger) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ToolSkill

use of net.silentchaos512.gems.skills.ToolSkill in project SilentGems by SilentChaos512.

the class GuiCrosshairs method renderOverlay.

public void renderOverlay(RenderGameOverlayEvent event, int type, ToolSkill skill) {
    int cost = skill.getCost(null, Minecraft.getMinecraft().player, BlockPos.ORIGIN);
    PlayerData data = PlayerDataHandler.get(Minecraft.getMinecraft().player);
    if (data != null && data.getCurrentChaos() < cost)
        GlStateManager.color(1f, 0f, 0f, 1f);
    else
        GlStateManager.color(1f, 1f, 1f, 1f);
    mc.getTextureManager().bindTexture(TEXTURE_CROSSHAIRS);
    GlStateManager.enableBlend();
    renderCrosshairs(event.getPartialTicks(), event.getResolution(), type);
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.color(1f, 1f, 1f, 1f);
}
Also used : PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 3 with ToolSkill

use of net.silentchaos512.gems.skills.ToolSkill in project SilentGems by SilentChaos512.

the class ToolHelper method onBlockStartBreak.

/**
 * Called by mining tools if block breaking isn't canceled.
 *
 * @return False in all cases, because this method is only called when Item.onBlockStartBreak returns false.
 */
public static boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) {
    boolean abilityActivated = false;
    ToolSkill skill = getSuperSkill(stack);
    if (skill != null)
        skill.activate(stack, player, pos);
    incrementStatBlocksMined(stack, 1);
    // XP for tool soul
    if (player != null && !player.world.isRemote) {
        IBlockState stateMined = player.world.getBlockState(pos);
        ToolSoul soul = SoulManager.getSoul(stack);
        if (soul != null) {
            int xpForBlockHarvest = soul.getXpForBlockHarvest(player.world, pos, stateMined);
            SoulManager.addSoulXp(xpForBlockHarvest, stack, player);
        }
    }
    return false;
}
Also used : ToolSkill(net.silentchaos512.gems.skills.ToolSkill) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) IBlockState(net.minecraft.block.state.IBlockState)

Example 4 with ToolSkill

use of net.silentchaos512.gems.skills.ToolSkill in project SilentGems by SilentChaos512.

the class ItemGemHoe method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (ToolHelper.isBroken(stack)) {
        return EnumActionResult.PASS;
    }
    int tilledCount = 0;
    EnumActionResult result;
    // Till the target block first.
    result = super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
    if (result == EnumActionResult.SUCCESS) {
        ++tilledCount;
    } else {
        return EnumActionResult.FAIL;
    }
    // Do we have super till and can it be used?
    ToolSkill skill = ToolHelper.getSuperSkill(stack);
    boolean skillEnabled = skill instanceof SkillAreaTill && ToolHelper.isSpecialAbilityEnabled(stack);
    int skillCost = skill != null ? skill.getCost(stack, player, pos) : 0;
    PlayerData data = PlayerDataHandler.get(player);
    // Must have tilled first block, has skill and is enabled, player has enough chaos.
    if (tilledCount > 0 && skillEnabled && data.getCurrentChaos() >= skillCost) {
        EnumFacing playerFacing = player.getHorizontalFacing();
        // Tilling up to 8 extra blocks in the direction the player is facing.
        for (int i = 0, yOffset = 0; i < 8; ++i) {
            BlockPos blockpos = pos.offset(playerFacing, i + 1).up(yOffset);
            if (super.onItemUse(player, world, blockpos, hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
                // Same height.
                ++tilledCount;
            } else if (super.onItemUse(player, world, blockpos.up(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
                // Go up one block.
                ++tilledCount;
                ++yOffset;
            } else if (super.onItemUse(player, world, blockpos.down(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
                // Go down one block.
                ++tilledCount;
                --yOffset;
            } else {
                // Hit a cliff or wall.
                break;
            }
        }
        if (tilledCount > 1) {
            if (data != null) {
                data.drainChaos(skillCost);
            }
        }
    }
    // Sound, XP, damage, stats
    if (tilledCount > 0) {
        world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1f, 1f);
        if (!world.isRemote) {
            ToolSoul soul = SoulManager.getSoul(stack);
            if (soul != null) {
                soul.addXp((int) (ToolSoul.XP_FACTOR_TILLING * tilledCount), stack, player);
            }
            ToolHelper.incrementStatBlocksTilled(stack, tilledCount);
            ToolHelper.attemptDamageTool(stack, tilledCount, player);
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : ToolSkill(net.silentchaos512.gems.skills.ToolSkill) EnumActionResult(net.minecraft.util.EnumActionResult) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) SkillAreaTill(net.silentchaos512.gems.skills.SkillAreaTill) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 5 with ToolSkill

use of net.silentchaos512.gems.skills.ToolSkill in project SilentGems by SilentChaos512.

the class GemsClientEvents method renderCrosshairs.

private void renderCrosshairs(RenderGameOverlayEvent event) {
    EntityPlayer player = Minecraft.getMinecraft().player;
    ItemStack mainHand = player.getHeldItem(EnumHand.MAIN_HAND);
    if (mainHand == null) {
        return;
    }
    Item item = mainHand.getItem();
    if (event.isCancelable() && event.getType() == ElementType.CROSSHAIRS) {
        if (ToolHelper.isSpecialAbilityEnabled(mainHand)) {
            ToolSkill skill = ToolHelper.getSuperSkill(mainHand);
            if (skill != null) {
                event.setCanceled(true);
                int type = skill == SkillAreaMiner.INSTANCE || skill == SkillAreaTill.INSTANCE ? 0 : skill == SkillLumberjack.INSTANCE ? 1 : 2;
                GuiCrosshairs.INSTANCE.renderOverlay(event, type, skill);
            }
        }
    }
}
Also used : ToolSkill(net.silentchaos512.gems.skills.ToolSkill) Item(net.minecraft.item.Item) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ToolSkill (net.silentchaos512.gems.skills.ToolSkill)4 ItemStack (net.minecraft.item.ItemStack)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)2 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)2 IBlockState (net.minecraft.block.state.IBlockState)1 Item (net.minecraft.item.Item)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SkillAreaTill (net.silentchaos512.gems.skills.SkillAreaTill)1 ToolSkillDigger (net.silentchaos512.gems.skills.ToolSkillDigger)1