use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.
the class ToolHelper method onBlockStartBreak.
/**
* Called by mining tools if block breaking isn't canceled.
*
* @return False in all cases, because this method is only called when Item.onBlockStartBreak returns false.
*/
public static boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) {
boolean abilityActivated = false;
ToolSkill skill = getSuperSkill(stack);
if (skill != null)
skill.activate(stack, player, pos);
incrementStatBlocksMined(stack, 1);
// XP for tool soul
if (player != null && !player.world.isRemote) {
IBlockState stateMined = player.world.getBlockState(pos);
ToolSoul soul = SoulManager.getSoul(stack);
if (soul != null) {
int xpForBlockHarvest = soul.getXpForBlockHarvest(player.world, pos, stateMined);
SoulManager.addSoulXp(xpForBlockHarvest, stack, player);
}
}
return false;
}
use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.
the class ItemToolSoul method onUpdate.
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (StackHelper.isValid(stack) && !stack.hasTagCompound()) {
// Randomize souls with no data!
ToolSoul soul = ToolSoul.randomSoul();
setSoul(stack, soul);
}
}
use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.
the class ToolRenderHelper method clAddInformation.
@Override
public void clAddInformation(ItemStack tool, World world, List list, boolean advanced) {
LocalizationHelper loc = SilentGems.instance.localizationHelper;
boolean controlDown = KeyTracker.isControlDown();
boolean altDown = KeyTracker.isAltDown();
boolean shiftDown = KeyTracker.isShiftDown();
String line;
// Tipped upgrade
ToolPartTip partTip = (ToolPartTip) ToolHelper.getConstructionTip(tool);
if (partTip != null) {
String tipName = partTip.getUnlocalizedName().replaceFirst("[^:]+:", "");
tipName = loc.getMiscText("Tooltip." + tipName);
line = loc.getMiscText("Tooltip.Tipped", tipName);
list.add(line);
}
// UUID
if (GemsConfig.DEBUG_MODE && controlDown && shiftDown) {
UUID uuid = ToolHelper.hasUUID(tool) ? ToolHelper.getUUID(tool) : null;
list.add(uuid == null ? "No UUID" : uuid.toString());
uuid = ToolHelper.getSoulUUID(tool);
list.add(uuid == null ? "No Soul UUID" : uuid.toString());
}
// Tool Soul
ToolSoul soul = SoulManager.getSoul(tool);
if (soul != null) {
soul.addInformation(tool, world, list, advanced);
}
// Show original owner?
if (controlDown) {
String owner = ToolHelper.getOriginalOwner(tool);
if (owner.equals(SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Creative")))
owner = TextFormatting.LIGHT_PURPLE + owner;
if (!owner.isEmpty())
list.add(loc.getMiscText("Tooltip.OriginalOwner", owner));
else
list.add(loc.getMiscText("Tooltip.OriginalOwner.Unknown"));
}
if (controlDown && tool.getTagCompound().getBoolean(ToolHelper.NBT_LOCK_STATS)) {
list.add(loc.getMiscText("Tooltip.LockedStats"));
}
// Example tool?
if (tool.hasTagCompound() && tool.getTagCompound().hasKey(ToolHelper.NBT_EXAMPLE_TOOL_TIER)) {
EnumMaterialTier tier = EnumMaterialTier.values()[tool.getTagCompound().getInteger(ToolHelper.NBT_EXAMPLE_TOOL_TIER)];
list.add(loc.getMiscText("Tooltip.ExampleTool", tier));
} else // Missing data?
if (ToolHelper.hasNoConstruction(tool)) {
list.add(loc.getMiscText("Tooltip.NoData1"));
list.add(loc.getMiscText("Tooltip.NoData2"));
} else // Broken?
if (ToolHelper.isBroken(tool)) {
line = loc.getMiscText("Tooltip.Broken");
list.add(line);
}
final Item item = tool.getItem();
final boolean isSword = item instanceof ItemGemSword;
final boolean isAxe = item instanceof ItemGemAxe;
final boolean isWeapon = isSword || isAxe;
final boolean isCaster = isSword && ToolHelper.getToolTier(tool).ordinal() >= EnumMaterialTier.SUPER.ordinal();
final boolean isBow = item instanceof ItemGemBow;
final boolean isDigger = item instanceof ItemTool;
final boolean isShield = item instanceof ItemGemShield;
final String sep = loc.getMiscText("Tooltip.Separator");
if (controlDown) {
// Properties Header
line = loc.getMiscText("Tooltip.Properties");
list.add(line);
TextFormatting color = TextFormatting.YELLOW;
// Tier
EnumMaterialTier tier = ToolHelper.getToolTier(tool);
line = TextFormatting.RESET + loc.getMiscText("ToolTier." + tier);
list.add(" " + color + loc.getMiscText("ToolTier", line));
int durabilityMax = tool.getMaxDamage();
int durability = durabilityMax - tool.getItemDamage();
String s1 = String.format(durability > 9999 ? "%,d" : "%d", durability);
String s2 = String.format(durabilityMax > 9999 ? "%,d" : "%d", durabilityMax);
float durabilityBoost = ToolSoul.getDurabilityModifierForDisplay(soul);
String durBoostLine = durabilityBoost == 0f ? "" : " (" + TooltipHelper.numberToPercent(durabilityBoost, 0, true) + TextFormatting.RESET + ")";
line = loc.getMiscText("Tooltip.Durability", s1 + " / " + s2 + durBoostLine);
list.add(color + " " + line);
if (isShield) {
float magicProtection = (int) (ToolHelper.getMagicProtection(tool) * 100);
list.add(color + getTooltipLine("MagicProtection", magicProtection, 0f));
}
if (isDigger) {
// @formatter:off
int harvestLevel = ToolHelper.getHarvestLevel(tool);
String str = color + getTooltipLine("HarvestLevel", harvestLevel, 0f);
String key = "Tooltip.level" + harvestLevel;
String val = SilentGems.localizationHelper.getMiscText(key);
if (!val.equals("misc.silentgems:" + key))
str += " (" + val + ")";
list.add(str);
float harvestSpeedModifier = ToolSoul.getHarvestSpeedModifierForDisplay(soul);
list.add(color + getTooltipLine("HarvestSpeed", ToolHelper.getDigSpeedOnProperMaterial(tool), harvestSpeedModifier));
}
if (isWeapon) {
float meleeSpeed = 4 + ToolHelper.getMeleeSpeedModifier(tool);
list.add(color + getTooltipLine("MeleeSpeed", meleeSpeed, 0f).replaceFirst("%", ""));
float meleeDamage = 1 + ToolHelper.getMeleeDamageModifier(tool);
float meleeModifier = ToolSoul.getMeleeDamageModifierForDisplay(soul);
list.add(color + getTooltipLine("MeleeDamage", meleeDamage, meleeModifier));
if (isCaster) {
EnumMagicType magicType = EnumMagicType.getMagicType(tool);
float damagePerShot = magicType.getDamagePerShot(tool);
String damageString = damagePerShot == (int) damagePerShot ? Integer.toString((int) damagePerShot) : String.format(TooltipHelper.FORMAT_FLOAT, damagePerShot);
String str = damageString + "" + TextFormatting.DARK_GRAY + "x" + magicType.getShotCount(tool);
float magicModifier = ToolSoul.getMagicDamageModifierForDisplay(soul);
list.add(color + getTooltipLine("MagicDamage", str, magicModifier));
}
}
if (isBow) {
ToolStats statsNoSoul = ToolHelper.getStats(tool, false);
float drawSpeed = ModItems.bow.getDrawSpeedForDisplay(tool);
float drawSpeedPreSoul = ItemGemBow.getDrawSpeedForDisplay(statsNoSoul.meleeSpeed, statsNoSoul.harvestSpeed);
float drawSpeedBoost = (drawSpeed - drawSpeedPreSoul) / drawSpeedPreSoul;
list.add(color + getTooltipLine("DrawSpeed", drawSpeed, drawSpeedBoost));
float arrowDamage = ModItems.bow.getArrowDamageForDisplay(tool);
float arrowDamagePreSoul = ItemGemBow.getArrowDamageForDisplay(statsNoSoul.meleeDamage);
float arrowDamageBoost = (arrowDamage - arrowDamagePreSoul) / arrowDamagePreSoul;
list.add(color + getTooltipLine("ArrowDamage", arrowDamage, arrowDamageBoost));
}
list.add(color + getTooltipLine("ChargeSpeed", ToolHelper.getChargeSpeed(tool), 0f));
} else {
list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.CtrlForProp"));
}
if (altDown) {
// Statistics Header
list.add(sep);
line = loc.getMiscText("Tooltip.Statistics");
list.add(line);
list.add(getTooltipLine("BlocksMined", ToolHelper.getStatBlocksMined(tool), 0f));
if (isDigger) {
list.add(getTooltipLine("BlocksPlaced", ToolHelper.getStatBlocksPlaced(tool), 0f));
}
if (item instanceof ItemGemShovel) {
list.add(getTooltipLine("PathsMade", ToolHelper.getStatPathsMade(tool), 0f));
}
if (item instanceof ItemGemHoe) {
list.add(getTooltipLine("BlocksTilled", ToolHelper.getStatBlocksTilled(tool), 0f));
}
list.add(getTooltipLine("HitsLanded", ToolHelper.getStatHitsLanded(tool), 0f));
if (isCaster || isBow)
list.add(getTooltipLine("ShotsFired", ToolHelper.getStatShotsFired(tool), 0f));
if (item instanceof ItemGemTomahawk)
list.add(getTooltipLine("ThrownCount", ToolHelper.getStatThrownCount(tool), 0f));
if (isWeapon)
list.add(getTooltipLine("KillCount", ToolHelper.getStatKillCount(tool), 0f));
list.add(getTooltipLine("Redecorated", ToolHelper.getStatRedecorated(tool), 0f));
list.add(sep);
line = loc.getMiscText("Tooltip.Construction");
list.add(line);
ToolPart[] parts = ToolHelper.getConstructionParts(tool);
EnumMaterialGrade[] grades = ToolHelper.getConstructionGrades(tool);
for (int i = 0; i < parts.length; ++i) {
ToolPart part = parts[i];
EnumMaterialGrade grade = grades[i];
line = " " + TextFormatting.YELLOW + part.getKey() + TextFormatting.GOLD + " (" + grade + ")";
list.add(line);
}
ToolPart partRod = ToolHelper.getConstructionRod(tool);
if (partRod != null) {
list.add(" " + TextFormatting.YELLOW + partRod.getKey());
}
list.add(sep);
} else {
list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.AltForStat"));
}
// Debug render layers
if (controlDown && shiftDown && tool.hasTagCompound()) {
if (!altDown)
list.add(sep);
list.add("Render Layers");
IModelData modelData = getModelCache(tool);
if (modelData != null) {
for (ToolPartPosition pos : ToolPartPosition.values()) {
String key = "Layer" + pos.ordinal();
String str = " %s: %s, %X";
ToolPart renderPart = ToolHelper.getRenderPart(tool, pos);
ModelResourceLocation model = renderPart == null ? null : renderPart.getModel(tool, pos, 0);
str = String.format(str, pos.name(), model == null ? "null" : model.toString(), modelData.getColor(pos, 0));
list.add(str);
}
}
}
}
use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.
the class ItemGemHoe method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (ToolHelper.isBroken(stack)) {
return EnumActionResult.PASS;
}
int tilledCount = 0;
EnumActionResult result;
// Till the target block first.
result = super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
if (result == EnumActionResult.SUCCESS) {
++tilledCount;
} else {
return EnumActionResult.FAIL;
}
// Do we have super till and can it be used?
ToolSkill skill = ToolHelper.getSuperSkill(stack);
boolean skillEnabled = skill instanceof SkillAreaTill && ToolHelper.isSpecialAbilityEnabled(stack);
int skillCost = skill != null ? skill.getCost(stack, player, pos) : 0;
PlayerData data = PlayerDataHandler.get(player);
// Must have tilled first block, has skill and is enabled, player has enough chaos.
if (tilledCount > 0 && skillEnabled && data.getCurrentChaos() >= skillCost) {
EnumFacing playerFacing = player.getHorizontalFacing();
// Tilling up to 8 extra blocks in the direction the player is facing.
for (int i = 0, yOffset = 0; i < 8; ++i) {
BlockPos blockpos = pos.offset(playerFacing, i + 1).up(yOffset);
if (super.onItemUse(player, world, blockpos, hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Same height.
++tilledCount;
} else if (super.onItemUse(player, world, blockpos.up(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Go up one block.
++tilledCount;
++yOffset;
} else if (super.onItemUse(player, world, blockpos.down(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Go down one block.
++tilledCount;
--yOffset;
} else {
// Hit a cliff or wall.
break;
}
}
if (tilledCount > 1) {
if (data != null) {
data.drainChaos(skillCost);
}
}
}
// Sound, XP, damage, stats
if (tilledCount > 0) {
world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1f, 1f);
if (!world.isRemote) {
ToolSoul soul = SoulManager.getSoul(stack);
if (soul != null) {
soul.addXp((int) (ToolSoul.XP_FACTOR_TILLING * tilledCount), stack, player);
}
ToolHelper.incrementStatBlocksTilled(stack, tilledCount);
ToolHelper.attemptDamageTool(stack, tilledCount, player);
}
}
return EnumActionResult.SUCCESS;
}
use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onLivingDrops.
@SubscribeEvent
public void onLivingDrops(LivingDropsEvent event) {
Entity entity = event.getSource().getTrueSource();
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
ItemStack weapon = player.getHeldItemMainhand();
// Soul Gems
EntityLivingBase killed = event.getEntityLiving();
Soul soul = ModItems.soulGem.getSoul(killed.getClass());
if (soul != null && SilentGems.random.nextFloat() < soul.getDropRate()) {
ItemStack soulGem = ModItems.soulGem.getStack(soul);
if (StackHelper.isValid(soulGem)) {
EntityItem entityItem = new EntityItem(killed.world, killed.posX, killed.posY + killed.height / 2f, killed.posZ, soulGem);
event.getDrops().add(entityItem);
}
}
ToolSoul toolSoul = SoulManager.getSoul(weapon);
if (toolSoul != null) {
// Head bonus?
if (toolSoul.hasSkill(SoulSkill.HEAD_BONUS)) {
int level = toolSoul.getSkillLevel(SoulSkill.HEAD_BONUS);
float rate = Skulls.getDropRate(killed);
if (SilentGems.random.nextFloat() < 1.5f * level * rate) {
ItemStack skull = Skulls.getSkull(killed);
if (StackHelper.isValid(skull)) {
EntityItem entityItem = new EntityItem(killed.world, killed.posX, killed.posY + killed.height / 2f, killed.posZ, skull);
event.getDrops().add(entityItem);
}
}
}
}
}
}
Aggregations