Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Fix XP gained by weapons. The new stuff is recognized properly now, a…
Browse files Browse the repository at this point in the history
…nd Arrows also get XP!
  • Loading branch information
bonii-xx committed Dec 22, 2014
1 parent 0650604 commit 7eaa9ae
Showing 1 changed file with 49 additions and 40 deletions.
Expand Up @@ -23,8 +23,11 @@
import tconstruct.library.event.ToolCraftEvent;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.Weapon;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.tools.TinkerTools;

import java.util.Arrays;

public class LevelingEventHandler {
@SubscribeEvent
public void onHurt (LivingHurtEvent event)
Expand All @@ -50,7 +53,7 @@ public void onHurt (LivingHurtEvent event)

int xp = 0;
// is a weapon?
if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Battleaxe || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow"))
if (Arrays.asList(((ToolCore) stack.getItem()).getTraits()).contains("weapon"))
xp = Math.round(event.ammount);
else
xp = Math.round((event.ammount-0.1f)/2);
Expand All @@ -59,43 +62,54 @@ public void onHurt (LivingHurtEvent event)
if (event.entityLiving instanceof EntityAnimal)
xp = Math.max(1, xp/2);

ItemStack ammo = null;
// projectile weapons also get xp on their ammo!
if(stack.getItem() instanceof ProjectileWeapon)
ammo = ((ProjectileWeapon) stack.getItem()).searchForAmmo(player, stack);

if (xp > 0)
{
LevelingLogic.addXP(stack, player, xp);

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");

// bonus chance for luck if hitting passive mob
if(event.entityLiving instanceof EntityAnimal)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LAPIS, xp+5, tags);
// otherwise damage chance
else
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.ATTACK, xp, tags);

// spiders also increase bane chance
if(event.entityLiving instanceof EntitySpider)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BANE, Math.max(1,xp/2), tags);
// blazes give fiery chance (yes, blizz gives fiery :P)
else if(event.entityLiving instanceof EntityBlaze)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BLAZE, Math.max(1,xp/2), tags);
// zombie pigman gives lifesteal
else if(event.entityLiving instanceof EntityPigZombie)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, Math.max(1,xp/2), tags);
// zombie gives smite
else if(event.entityLiving instanceof EntityZombie)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.SMITE, Math.max(1,xp/2), tags);
// wither skeleton gives lifesteal
else if(event.entityLiving instanceof EntitySkeleton) {
if (((EntitySkeleton) event.entityLiving).getSkeletonType() != 0)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, Math.max(1,xp/2)+2, tags);
}
// enderman gives beheading
else if(event.entityLiving instanceof EntityEnderman)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BEHEADING, Math.max(1,xp/2)+3, tags);
for(ItemStack itemstack : new ItemStack[] {stack, ammo})
{
if(itemstack == null)
continue;

LevelingLogic.addXP(itemstack, player, xp);

NBTTagCompound tags = itemstack.getTagCompound().getCompoundTag("InfiTool");

// bonus chance for luck if hitting passive mob
if (event.entityLiving instanceof EntityAnimal)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LAPIS, xp + 5, tags);
// otherwise damage chance
else
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.ATTACK, xp, tags);

// spiders also increase bane chance
if (event.entityLiving instanceof EntitySpider)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BANE, Math.max(1, xp / 2), tags);
// blazes give fiery chance (yes, blizz gives fiery :P)
else if (event.entityLiving instanceof EntityBlaze)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BLAZE, Math.max(1, xp / 2), tags);
// zombie pigman gives lifesteal
else if (event.entityLiving instanceof EntityPigZombie)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, Math.max(1, xp / 2), tags);
// zombie gives smite
else if (event.entityLiving instanceof EntityZombie)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.SMITE, Math.max(1, xp / 2), tags);
// wither skeleton gives lifesteal
else if (event.entityLiving instanceof EntitySkeleton) {
if (((EntitySkeleton) event.entityLiving).getSkeletonType() != 0)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, Math.max(1, xp / 2) + 2, tags);
}
// enderman gives beheading
else if (event.entityLiving instanceof EntityEnderman)
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BEHEADING, Math.max(1, xp / 2) + 3, tags);

// knocking back enemies with spriting gives knockback chance
if(player.isSprinting())
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.KNOCKBACK, xp+2, tags);
// knocking back enemies with spriting gives knockback chance
if (player.isSprinting())
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.KNOCKBACK, xp + 2, tags);
}
}

}
Expand Down Expand Up @@ -134,15 +148,10 @@ public void onCrafting(PlayerEvent.ItemCraftedEvent event)

@SubscribeEvent
public void onCraftTool (ToolCraftEvent.NormalTool event) {
// arrows don't get levels
if(event.tool instanceof Arrow)
return;

// add tags for tool leveling
NBTTagCompound toolTag = event.toolTag.getCompoundTag("InfiTool");
LevelingLogic.addLevelingTags(toolTag, event.tool);


// remove modifiers
toolTag.setInteger("Modifiers", Math.max(toolTag.getInteger("Modifiers") - (3-Config.toolLevelingExtraModifiers), 0));
}
Expand Down

0 comments on commit 7eaa9ae

Please sign in to comment.