Search in sources :

Example 6 with SoulSkill

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

the class ItemSkillOrb method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack offhand = player.getHeldItemOffhand();
    // Orb in main hand, tool/armor in offhand.
    if (hand != EnumHand.MAIN_HAND || StackHelper.isEmpty(offhand) || !(offhand.getItem() instanceof ITool || offhand.getItem() instanceof IArmor)) {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand));
    }
    ItemStack orb = player.getHeldItemMainhand();
    // Check for tool soul.
    ToolSoul soul = SoulManager.getSoul(offhand);
    if (soul == null) {
        if (!world.isRemote) {
            ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "no_soul"));
        }
        return new ActionResult<ItemStack>(EnumActionResult.PASS, orb);
    }
    // Check skill on orb.
    SoulSkill skill = getSkill(orb);
    if (skill == null) {
        if (!world.isRemote) {
            ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "no_skill"));
        }
        return new ActionResult<ItemStack>(EnumActionResult.PASS, orb);
    }
    if (world.isRemote) {
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
    }
    // Try to add or level up the skill.
    if (soul.addOrLevelSkill(skill, offhand, player)) {
        ToolHelper.recalculateStats(offhand);
        StackHelper.shrink(orb, 1);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, orb);
    } else {
        ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "max_level"));
        return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand));
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) SoulSkill(net.silentchaos512.gems.lib.soul.SoulSkill) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 7 with SoulSkill

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

the class MessageSoulSync method handleMessage.

@Override
@SideOnly(Side.CLIENT)
public IMessage handleMessage(MessageContext context) {
    ClientTickHandler.scheduledActions.add(() -> {
        UUID uuid = new UUID(uuidMost, uuidLeast);
        ToolSoul soul = SoulManager.getSoulByUuid(uuid);
        if (soul != null) {
            soul.setXp(xp);
            soul.setLevel(level);
            soul.setActionPoints(ap);
            if (skillLearned != null && !skillLearned.isEmpty()) {
                SoulSkill skill = SoulSkill.getById(skillLearned);
                soul.setSkillLevel(skill, skillLevel, StackHelper.empty(), Minecraft.getMinecraft().player);
            }
        }
    });
    return null;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) SoulSkill(net.silentchaos512.gems.lib.soul.SoulSkill) UUID(java.util.UUID) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with SoulSkill

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

the class ToolSoul method addOrLevelSkill.

// ==========
// = Skills =
// ==========
public boolean addOrLevelSkill(SoulSkill skill, ItemStack tool, EntityPlayer player) {
    if (skill == null) {
        return false;
    }
    LocalizationHelper loc = SilentGems.localizationHelper;
    if (skills.containsKey(skill)) {
        // Has skill already.
        int level = skills.get(skill);
        if (level < skill.maxLevel) {
            // Can be leveled up.
            ++level;
            skills.put(skill, level);
            if (player != null) {
                ChatHelper.sendMessage(player, loc.getMiscText("ToolSoul.skillLearned", skill.getLocalizedName(tool, level)));
            }
            return true;
        } else {
            // Already max level.
            return false;
        }
    } else {
        skills.put(skill, 1);
        if (player != null) {
            ChatHelper.sendMessage(player, loc.getMiscText("ToolSoul.skillLearned", skill.getLocalizedName(tool, 1)));
        }
        return true;
    }
}
Also used : LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper)

Example 9 with SoulSkill

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

the class ToolSoul method sendUpdatePacket.

protected void sendUpdatePacket(ItemStack tool, EntityPlayer player, SoulSkill skillLearned, int skillLevel) {
    // Server side: send update packet to player.
    if (!player.world.isRemote) {
        UUID uuid = ToolHelper.getSoulUUID(tool);
        MessageSoulSync message = new MessageSoulSync(uuid, xp, level, actionPoints, skillLearned, skillLevel);
        NetworkHandler.INSTANCE.sendTo(message, (EntityPlayerMP) player);
    }
}
Also used : MessageSoulSync(net.silentchaos512.gems.network.message.MessageSoulSync) UUID(java.util.UUID)

Aggregations

SoulSkill (net.silentchaos512.gems.lib.soul.SoulSkill)4 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)3 UUID (java.util.UUID)2 ItemStack (net.minecraft.item.ItemStack)2 IArmor (net.silentchaos512.gems.api.IArmor)2 ITool (net.silentchaos512.gems.api.ITool)2 ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)2 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)2 LinkedHashMap (java.util.LinkedHashMap)1 Random (java.util.Random)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 PageDebugTool (net.silentchaos512.gems.guide.page.PageDebugTool)1 PageOreSpawn (net.silentchaos512.gems.guide.page.PageOreSpawn)1 PageSoulSkill (net.silentchaos512.gems.guide.page.PageSoulSkill)1