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