Search in sources :

Example 1 with PlayerData

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

the class SkillAreaMiner method activate.

@Override
public boolean activate(ItemStack tool, EntityPlayer player, BlockPos pos) {
    World world = player.world;
    IBlockState state = world.getBlockState(pos);
    Item item = tool.getItem();
    if (state == null || state.getBlock() == null) {
        return false;
    }
    // Must be super tool with special enabled.
    if (ToolHelper.getToolTier(tool).ordinal() < EnumMaterialTier.SUPER.ordinal() || !ToolHelper.isSpecialAbilityEnabled(tool)) {
        return false;
    }
    // Tool must be effective on block!
    if (!isToolEffective(tool, world, pos, state)) {
        return false;
    }
    // Does player have enough chaos?
    PlayerData data = PlayerDataHandler.get(player);
    int cost = getCost(tool, player, pos);
    if (data.chaos >= cost) {
        data.drainChaos(cost);
    } else {
        String msg = SilentGems.localizationHelper.getLocalizedString("skill", "all.insufficientChaos");
        ChatHelper.sendStatusMessage(player, msg, true);
        return false;
    }
    RayTraceResult mop = raytraceFromEntity(world, player, false, 4.5);
    if (mop == null) {
        return false;
    }
    int sideHit = mop.sideHit.getIndex();
    int xRange = 1;
    int yRange = 1;
    int zRange = 0;
    switch(sideHit) {
        case 0:
        case 1:
            yRange = 0;
            zRange = 1;
            break;
        case 2:
        case 3:
            xRange = 1;
            zRange = 0;
            break;
        case 4:
        case 5:
            xRange = 0;
            zRange = 1;
            break;
    }
    int blocksBroken = 0;
    final int x = pos.getX();
    final int y = pos.getY();
    final int z = pos.getZ();
    for (int xPos = x - xRange; xPos <= x + xRange; xPos++) {
        for (int yPos = y - yRange; yPos <= y + yRange; yPos++) {
            for (int zPos = z - zRange; zPos <= z + zRange; zPos++) {
                if (xPos == x && yPos == y && zPos == z) {
                    continue;
                }
                if (breakExtraBlock(tool, player.world, new BlockPos(xPos, yPos, zPos), player, pos)) {
                    ++blocksBroken;
                }
            }
        }
    }
    ToolHelper.incrementStatBlocksMined(tool, blocksBroken);
    return true;
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 2 with PlayerData

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

the class SkillLumberjack method onGetBreakSpeed.

@Override
public void onGetBreakSpeed(PlayerEvent.BreakSpeed event) {
    if (!event.getState().getBlock().isWood(event.getEntityPlayer().world, event.getPos())) {
        return;
    }
    PlayerData data = PlayerDataHandler.get(event.getEntityPlayer());
    int cost = event.getEntityPlayer().capabilities.isCreativeMode ? 0 : CHAOS_COST;
    if (data.chaos >= cost) {
        event.setNewSpeed(event.getNewSpeed() * DIG_SPEED_MULTIPLIER);
    }
}
Also used : PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 3 with PlayerData

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

the class ChaosUtil method canPlayerAcceptFullAmount.

// Use getAmountPlayerCanAccept instead
@Deprecated
public static boolean canPlayerAcceptFullAmount(EntityPlayer player, int amount) {
    PlayerData data = PlayerDataHandler.get(player);
    amount -= data.getMaxChaos() - data.getCurrentChaos();
    for (ItemStack stack : getChaosStorageItems(player)) {
        if (stack.getItem() instanceof IChaosStorage) {
            amount -= ((IChaosStorage) stack.getItem()).receiveCharge(stack, amount, true);
        }
    }
    return amount <= 0;
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 4 with PlayerData

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

the class ItemGemSword method onItemLeftClickSL.

// ==============
// Item overrides
// ==============
@Override
public ActionResult<ItemStack> onItemLeftClickSL(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!player.isSneaking() || ToolHelper.getToolTier(stack).ordinal() < EnumMaterialTier.SUPER.ordinal()) {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
    }
    if (world.isRemote) {
        GuiChaosBar.INSTANCE.show();
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }
    int costToCast = getShotCost(player, stack);
    int cooldown = getShotCooldown(player, stack);
    PlayerData data = PlayerDataHandler.get(player);
    if (data.chaos >= costToCast && data.magicCooldown <= 0) {
        if (!player.capabilities.isCreativeMode) {
            data.drainChaos(costToCast);
            data.magicCooldown = cooldown;
            stack.damageItem(1, player);
        }
        ToolHelper.incrementStatShotsFired(stack, 1);
        if (!world.isRemote) {
            for (EntityChaosProjectile shot : getShots(player, stack)) {
                EntityHelper.safeSpawn(shot);
            }
        }
    }
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityChaosProjectile(net.silentchaos512.gems.entity.EntityChaosProjectile) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 5 with PlayerData

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

the class ChaosBuff method applyToPlayer.

public void applyToPlayer(EntityPlayer player, int level, ItemStack stack) {
    if (potion != null) {
        int duration = getApplyDuration(player, level);
        if (duration > 0) {
            player.addPotionEffect(new PotionEffect(potion, duration, level - 1, false, false));
            // (Tough As Nails) Remove hyper/hypothermia when using heat/cold resistance.
            if (this == HEAT_RESISTANCE)
                player.removeActivePotionEffect(hyperthermia);
            else if (this == COLD_RESISTANCE)
                player.removeActivePotionEffect(hypothermia);
        }
    }
    if (this == FLIGHT) {
        player.capabilities.allowFlying = true;
        PlayerData data = PlayerDataHandler.get(player);
        if (data != null)
            data.flightTime = 100;
        if (!player.world.isRemote && player.world.getTotalWorldTime() % 20 == 0) {
            NetworkHandler.INSTANCE.sendTo(new MessageSetFlight(true), (EntityPlayerMP) player);
        }
    }
}
Also used : MessageSetFlight(net.silentchaos512.gems.network.message.MessageSetFlight) PotionEffect(net.minecraft.potion.PotionEffect) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

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