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;
}
Aggregations