Search in sources :

Example 6 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulManager method addSoulXp.

public static void addSoulXp(int amount, ItemStack tool, EntityPlayer player) {
    ToolSoul soul = getSoul(tool);
    if (soul != null && amount > 0) {
        int current = soul.getXp();
        soul.addXp(amount, tool, player);
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul)

Example 7 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulManager method onPlayerDamage.

@SubscribeEvent
public void onPlayerDamage(LivingHurtEvent event) {
    // Player took fall damage?
    if (event.getSource() == DamageSource.FALL && event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        ItemStack mainHand = player.getHeldItemMainhand();
        ItemStack offHand = player.getHeldItemOffhand();
        ToolSoul soulMain = getSoul(mainHand);
        ToolSoul soulOff = getSoul(offHand);
        // Get highest level of Aerial on either main or off hand.
        int levelMain = soulMain == null ? 0 : soulMain.getSkillLevel(SoulSkill.AERIAL);
        int levelOff = soulOff == null ? 0 : soulOff.getSkillLevel(SoulSkill.AERIAL);
        ToolSoul soulToDrain = levelMain > levelOff ? soulMain : soulOff;
        int aerialLevel = Math.max(levelMain, levelOff);
        if (aerialLevel > 0) {
            float amountToReduce = Math.max(2 + 2 * aerialLevel, 0.15f * aerialLevel * event.getAmount());
            event.setAmount(event.getAmount() - amountToReduce);
            soulToDrain.addActionPoints(-SoulSkill.AERIAL.apCost);
        }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ToolHelper method attemptDamageTool.

public static void attemptDamageTool(ItemStack tool, int amount, EntityLivingBase entityLiving) {
    if (entityLiving instanceof EntityPlayer && ((EntityPlayer) entityLiving).capabilities.isCreativeMode) {
        return;
    }
    if (!GemsConfigHC.TOOLS_BREAK) {
        amount = Math.min(tool.getMaxDamage() - tool.getItemDamage(), amount);
    }
    boolean wouldBreak = ItemHelper.attemptDamageItem(tool, amount, SilentGems.random);
    if (isBroken(tool)) {
        // Player broke the tool. Update the head model.
        recalculateStats(tool);
        ModItems.toolRenderHelper.updateModelCache(tool);
    } else if (GemsConfigHC.TOOLS_BREAK && wouldBreak) {
        // Return the tool soul, even though the tool is destroyed.
        ToolSoul soul = SoulManager.getSoul(tool);
        if (soul != null) {
            ItemStack toGive = new ItemStack(ModItems.toolSoul);
            ModItems.toolSoul.setSoul(toGive, soul);
            if (soul.hasName()) {
                // Soul already has a name.
                toGive.setStackDisplayName(soul.getName(StackHelper.empty()));
            }
            PlayerHelper.giveItem((EntityPlayer) entityLiving, toGive);
        }
        entityLiving.renderBrokenItemStack(tool);
        StackHelper.shrink(tool, 1);
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ToolHelper method onUpdate.

public static void onUpdate(ItemStack toolOrArmor, World world, Entity entity, int itemSlot, boolean isSelected) {
    // Tick tool souls
    if (entity instanceof EntityPlayer) {
        ToolSoul soul = SoulManager.getSoul(toolOrArmor);
        if (soul != null) {
            soul.updateTick(toolOrArmor, (EntityPlayer) entity);
        }
    }
    if (!world.isRemote) {
        // Randomize tools with no data.
        if (hasNoConstruction(toolOrArmor)) {
            ItemStack newTool = ToolRandomizer.INSTANCE.randomize(toolOrArmor);
        }
        // If the player gave him/herself a tool via JEI or creative, remove the example tag.
        if (isExampleItem(toolOrArmor)) {
            // tool.getTagCompound().setBoolean(NBT_EXAMPLE_TOOL, false);
            toolOrArmor.getTagCompound().removeTag(NBT_EXAMPLE_TOOL);
        }
        initRootTag(toolOrArmor);
        // Generate UUID if tool does not have one.
        if (!hasUUID(toolOrArmor)) {
            toolOrArmor.getTagCompound().setUniqueId(NBT_UUID, UUID.randomUUID());
        }
        return;
    }
    // Client-side name generation
    if (world.getTotalWorldTime() % CHECK_NAME_FREQUENCY == 0 && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (toolOrArmor.hasTagCompound() && toolOrArmor.getTagCompound().hasKey(NBT_TEMP_PARTLIST)) {
            NBTTagCompound compound = toolOrArmor.getTagCompound().getCompoundTag(NBT_TEMP_PARTLIST);
            int i = 0;
            String key = "part" + i;
            List<ItemStack> parts = Lists.newArrayList();
            // Load part stacks.
            do {
                NBTTagCompound tag = compound.getCompoundTag(key);
                parts.add(StackHelper.loadFromNBT(tag));
                key = "part" + ++i;
            } while (compound.hasKey(key));
            // Create name on the client.
            String displayName = createToolName(toolOrArmor.getItem(), parts);
            // tool.setStackDisplayName(displayName);
            // Send to the server.
            MessageItemRename message = new MessageItemRename(player.getName(), itemSlot, displayName, toolOrArmor);
            String line = String.format("%s crafted \"%s\"", player.getName(), displayName);
            SilentGems.logHelper.info(line);
            NetworkHandler.INSTANCE.sendToServer(message);
        }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MessageItemRename(net.silentchaos512.gems.network.message.MessageItemRename) ItemStack(net.minecraft.item.ItemStack)

Example 10 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ToolHelper method getStats.

public static ToolStats getStats(ItemStack toolOrArmor, boolean applySoulModifiers) {
    ToolPart[] parts = getConstructionParts(toolOrArmor);
    EnumMaterialGrade[] grades = getConstructionGrades(toolOrArmor);
    if (parts.length == 0)
        return new ToolStats(toolOrArmor);
    ToolStats stats = new ToolStats(toolOrArmor, parts, grades);
    if (toolOrArmor.getTagCompound().getBoolean(NBT_LOCK_STATS)) {
        // TODO: Is this right?
        stats.chargeSpeed = getChargeSpeed(toolOrArmor);
        stats.durability = getMaxDamage(toolOrArmor);
        stats.enchantability = getItemEnchantability(toolOrArmor);
        stats.harvestLevel = getHarvestLevel(toolOrArmor);
        stats.harvestSpeed = getDigSpeedOnProperMaterial(toolOrArmor);
        stats.magicDamage = getMagicDamage(toolOrArmor);
        stats.meleeDamage = getMeleeDamage(toolOrArmor);
        stats.meleeSpeed = getMeleeSpeed(toolOrArmor);
        stats.protection = getProtection(toolOrArmor);
        return stats;
    }
    stats.calculate();
    if (applySoulModifiers) {
        ToolSoul soul = SoulManager.getSoul(toolOrArmor);
        if (soul != null) {
            soul.applyToStats(stats);
        }
    }
    return stats;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ToolStats(net.silentchaos512.gems.api.tool.ToolStats)

Aggregations

ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)25 ItemStack (net.minecraft.item.ItemStack)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 IArmor (net.silentchaos512.gems.api.IArmor)5 ITool (net.silentchaos512.gems.api.ITool)5 UUID (java.util.UUID)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)4 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)3 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)3 SoulSkill (net.silentchaos512.gems.lib.soul.SoulSkill)3 LinkedHashMap (java.util.LinkedHashMap)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 ToolStats (net.silentchaos512.gems.api.tool.ToolStats)2 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)2