Fix some bugs,and add diyos BattleSigns

This commit is contained in:
Alexander committed 2014-04-02 20:38:48 -04:00
1 parent 1124d54a7b
commit 42a5af5566
27 files changed
+500 -92

No files matched your search

@@ -23,17 +23,23 @@ import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSourceIndirect;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.util.Vec3;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
@@ -162,6 +168,13 @@ public class TEventHandler
event.overrideResult(arrow);
}
}
if (event.tool == TRepo.battlesign)
{
int modifiers = toolTag.getInteger("Modifiers");
modifiers += 1;
toolTag.setInteger("Modifiers", modifiers);
}
}
private boolean allowCrafting (int head, int handle, int accessory)
@@ -240,14 +253,95 @@ public class TEventHandler
@SubscribeEvent
public void onHurt (LivingHurtEvent event)
{
if (event.entityLiving instanceof EntityPlayer)
EntityLivingBase reciever = event.entityLiving;
if (reciever instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entityLiving;
// Cutlass
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.getItem() == TRepo.cutlass && player.isUsingItem())
if (stack != null && player.isUsingItem())
{
player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 3 * 20, 1));
Item item = stack.getItem();
if (item == TRepo.cutlass)
{
player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 3 * 20, 1));
}
else if (item == TRepo.battlesign)
{
event.ammount *= 1.5; //Puts battlesign blocking at 3/4 instead of 1/2
}
}
}
else if (reciever instanceof EntityCreeper)
{
Entity attacker = event.source.getEntity();
if (attacker instanceof EntityLivingBase)
{
Entity target = ((EntityCreeper) reciever).getAttackTarget();
if (target != null)
{
float d1 = reciever.getDistanceToEntity(((EntityCreeper) reciever).getAttackTarget());
float d2 = reciever.getDistanceToEntity(attacker);
if (d2 < d1)
{
((EntityCreeper) event.entityLiving).setAttackTarget((EntityLivingBase) event.source.getEntity());
}
}
}
}
}
@SubscribeEvent
public void onAttack (LivingAttackEvent event)
{
//System.out.println("Damage: "+event.ammount);
if (event.entityLiving instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entityLiving;
//Cutlass
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.getItem() == TRepo.battlesign && player.isUsingItem())
{
DamageSource source = event.source;
if (!source.isUnblockable() && !source.isMagicDamage() && !source.isExplosion())
{
if (source instanceof EntityDamageSourceIndirect)
{
if (random.nextInt(3) == 0)
{
Entity attacker = source.getEntity();
Entity projectile = ((EntityDamageSourceIndirect) source).getSourceOfDamage();
projectile.motionX *= -1;
projectile.motionZ *= -1;
projectile.setDead();
event.setCanceled(true);
if (projectile.getClass() == EntityArrow.class && !player.worldObj.isRemote)
{
EntityArrow reflection = null;
if (attacker instanceof EntityLivingBase)
reflection = new EntityArrow(player.worldObj, (EntityLivingBase) attacker, 0);
else
reflection = new EntityArrow(player.worldObj, player, 0);
Vec3 look = player.getLookVec();
reflection.posX = projectile.posX;
reflection.posY = projectile.posY;
reflection.posZ = projectile.posZ;
reflection.motionX = (projectile.motionX + (look.xCoord * 8)) / 6;
reflection.motionY = (projectile.motionY + (look.yCoord * 8)) / 6;
reflection.motionZ = (projectile.motionZ + (look.zCoord * 8)) / 6;
reflection.damage = ((EntityArrow) projectile).damage;
player.worldObj.spawnEntityInWorld(reflection);
}
}
}
else
{
Entity attacker = source.getEntity();
attacker.attackEntityFrom(DamageSource.causeThornsDamage(player), event.ammount);
}
}
}
}
}