Search in sources :

Example 1 with SkillAreaTill

use of net.silentchaos512.gems.skills.SkillAreaTill 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)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)1 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)1 SkillAreaTill (net.silentchaos512.gems.skills.SkillAreaTill)1 ToolSkill (net.silentchaos512.gems.skills.ToolSkill)1