Search in sources :

Example 11 with PlayerData

use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.

the class ChaosUtil method getAmountPlayerCanAccept.

/**
 * Gets the amount of chaos the player could receive, include available capacity in items that store chaos.
 */
public static int getAmountPlayerCanAccept(EntityPlayer player, int maxToSend) {
    PlayerData data = PlayerDataHandler.get(player);
    int amount = data.getMaxChaos() - data.getCurrentChaos();
    for (ItemStack stack : getChaosStorageItems(player)) {
        amount += ((IChaosStorage) stack.getItem()).receiveCharge(stack, maxToSend - amount, true);
        if (amount >= maxToSend)
            return maxToSend;
    }
    return amount;
}
Also used : ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 12 with PlayerData

use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.

the class ChaosUtil method getTotalChaosAvailable.

/**
 * Gets the total amount of chaos the player has available, including chaos stored in items.
 */
public static int getTotalChaosAvailable(EntityPlayer player) {
    PlayerData data = PlayerDataHandler.get(player);
    int amount = data.getCurrentChaos();
    for (ItemStack stack : getChaosStorageItems(player)) {
        if (stack.getItem() instanceof IChaosStorage) {
            amount += ((IChaosStorage) stack.getItem()).getCharge(stack);
        }
    }
    return amount;
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 13 with PlayerData

use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData 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 14 with PlayerData

use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.

the class MessageDataSync method handleMessage.

@Override
@SideOnly(Side.CLIENT)
public IMessage handleMessage(MessageContext context) {
    ClientTickHandler.scheduledActions.add(() -> {
        PlayerData data = PlayerDataHandler.get(SilentGems.proxy.getClientPlayer());
        data.readFromNBT(tags);
        GuiChaosBar.INSTANCE.update(data.chaos, data.maxChaos);
    });
    return null;
}
Also used : PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 15 with PlayerData

use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.

the class GemsCommonEvents method onLivingDeath.

@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
    Entity entitySource = event.getSource().getTrueSource();
    EntityPlayer player = null;
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer deadPlayer = (EntityPlayer) event.getEntityLiving();
        PlayerData data = PlayerDataHandler.get(deadPlayer);
        data.haloTime = data.HALO_TIME_DEFAULT;
    }
    if (entitySource instanceof EntityPlayer) {
        player = (EntityPlayer) entitySource;
    } else if (entitySource instanceof EntityChaosProjectile) {
        EntityChaosProjectile projectile = (EntityChaosProjectile) entitySource;
        EntityLivingBase shooter = projectile.getShooter();
        if (shooter instanceof EntityPlayer)
            player = (EntityPlayer) shooter;
    }
    if (player != null) {
        ItemStack weapon = player.getHeldItem(EnumHand.MAIN_HAND);
        if (StackHelper.isValid(weapon) && weapon.getItem() instanceof ITool)
            ToolHelper.incrementStatKillCount(weapon, 1);
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityChaosProjectile(net.silentchaos512.gems.entity.EntityChaosProjectile) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData) ITool(net.silentchaos512.gems.api.ITool) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)15 ItemStack (net.minecraft.item.ItemStack)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 IChaosStorage (net.silentchaos512.gems.api.energy.IChaosStorage)3 IBlockState (net.minecraft.block.state.IBlockState)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EntityChaosProjectile (net.silentchaos512.gems.entity.EntityChaosProjectile)2 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)2 Minecraft (net.minecraft.client.Minecraft)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 Item (net.minecraft.item.Item)1 PotionEffect (net.minecraft.potion.PotionEffect)1 ActionResult (net.minecraft.util.ActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1