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