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