Search in sources :

Example 16 with ToolSoul

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

the class ToolSoul method construct.

public static ToolSoul construct(ItemSoulGem.Soul... souls) {
    // Soul weight map
    Map<EnumSoulElement, Integer> elements = new HashMap<>();
    for (ItemSoulGem.Soul soul : souls) {
        int current = elements.containsKey(soul.element1) ? elements.get(soul.element1) : 0;
        elements.put(soul.element1, current + 5);
        if (soul.element2 != EnumSoulElement.NONE) {
            current = elements.containsKey(soul.element2) ? elements.get(soul.element2) : 0;
            elements.put(soul.element2, current + 3);
        }
    }
    // Highest weight becomes element 1, second becomes element 2.
    ToolSoul toolSoul = new ToolSoul();
    // Primary
    toolSoul.element1 = selectHighestWeight(elements);
    elements.remove(toolSoul.element1);
    // Secondary (if any are left)
    if (!elements.isEmpty()) {
        toolSoul.element2 = selectHighestWeight(elements);
    }
    return toolSoul;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemSoulGem(net.silentchaos512.gems.item.ItemSoulGem)

Example 17 with ToolSoul

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

the class ToolSoul method readFromNBT.

public static ToolSoul readFromNBT(NBTTagCompound tags) {
    ToolSoul soul = new ToolSoul();
    soul.name = tags.getString("name");
    String e1 = tags.getString("element1");
    String e2 = tags.getString("element2");
    for (EnumSoulElement element : EnumSoulElement.values()) {
        if (element.name().equalsIgnoreCase(e1)) {
            soul.element1 = element;
        } else if (element.name().equalsIgnoreCase(e2)) {
            soul.element2 = element;
        }
    }
    soul.xp = tags.getInteger("xp");
    soul.level = tags.getInteger("level");
    soul.actionPoints = tags.getInteger("ap");
    // Load skills
    soul.skills.clear();
    NBTTagList tagList = tags.getTagList("skills", 10);
    for (int i = 0; i < tagList.tagCount(); ++i) {
        NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
        SoulSkill skill = SoulSkill.getById(tagCompound.getString("id"));
        if (skill != null) {
            int level = tagCompound.getShort("level");
            soul.skills.put(skill, level);
        }
    // Skills with unknown IDs are ignored!
    }
    return soul;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 18 with ToolSoul

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

the class GuiToolSouls method renderAPBarForItem.

private static void renderAPBarForItem(ItemStack stack, int xPosition, int yPosition) {
    if (!stack.isEmpty()) {
        ToolSoul soul = SoulManager.getSoul(stack);
        if (soul != null) {
            // SilentGems.logHelper.debug(soul);
            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableTexture2D();
            GlStateManager.disableAlpha();
            GlStateManager.disableBlend();
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bufferbuilder = tessellator.getBuffer();
            double ap = 1.0 - ((double) soul.getActionPoints() / soul.getMaxActionPoints());
            int rgbfordisplay = new Color(0f, 0.75f * (1f - (float) ap), 1f).getColor();
            int i = Math.round(13.0F - (float) ap * 13.0F);
            int j = rgbfordisplay;
            draw(bufferbuilder, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
            draw(bufferbuilder, xPosition + 2, yPosition + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
            GlStateManager.enableBlend();
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }
    // EntityPlayerSP entityplayersp = Minecraft.getMinecraft().player;
    // float f3 = entityplayersp == null ? 0.0F
    // : entityplayersp.getCooldownTracker().getCooldown(stack.getItem(),
    // Minecraft.getMinecraft().getRenderPartialTicks());
    // 
    // if (f3 > 0.0F) {
    // GlStateManager.disableLighting();
    // GlStateManager.disableDepth();
    // GlStateManager.disableTexture2D();
    // Tessellator tessellator1 = Tessellator.getInstance();
    // BufferBuilder bufferbuilder1 = tessellator1.getBuffer();
    // this.draw(bufferbuilder1, xPosition, yPosition + MathHelper.floor(16.0F * (1.0F - f3)), 16,
    // MathHelper.ceil(16.0F * f3), 255, 255, 255, 127);
    // //        GlStateManager.enableTexture2D();
    // //        GlStateManager.enableLighting();
    // //        GlStateManager.enableDepth();
    // }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Color(net.silentchaos512.lib.util.Color)

Example 19 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul 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 20 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul 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)

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