2014-01-17 19:12:49 +00:00
|
|
|
package WayofTime.alchemicalWizardry.common;
|
|
|
|
|
2014-01-17 21:54:16 +00:00
|
|
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
2014-01-17 19:12:49 +00:00
|
|
|
import WayofTime.alchemicalWizardry.common.entity.projectile.EnergyBlastProjectile;
|
2014-01-19 21:42:31 +00:00
|
|
|
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
2014-01-17 21:05:38 +00:00
|
|
|
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
2014-01-17 19:12:49 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.IProjectile;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.PlayerCapabilities;
|
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
2014-01-19 21:42:31 +00:00
|
|
|
import net.minecraft.potion.Potion;
|
2014-01-17 19:12:49 +00:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
|
|
|
|
2014-01-17 21:05:38 +00:00
|
|
|
import java.util.*;
|
|
|
|
|
2014-01-17 21:43:13 +00:00
|
|
|
public class AlchemicalWizardryEventHooks
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
public static Map<String,Boolean> playerFlightBuff = new HashMap();
|
|
|
|
public static Map<String,Boolean> playerBoostStepHeight = new HashMap();
|
2014-01-17 19:12:49 +00:00
|
|
|
public static List<String> playersWith1Step = new ArrayList();
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onLivingJumpEvent(LivingJumpEvent event)
|
|
|
|
{
|
|
|
|
if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionBoost))
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionBoost).getAmplifier();
|
|
|
|
event.entityLiving.motionY += (0.1f) * (2 + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onEntityDamaged(LivingAttackEvent event)
|
|
|
|
{
|
|
|
|
EntityLivingBase entityAttacked = event.entityLiving;
|
|
|
|
|
|
|
|
if (entityAttacked.isPotionActive(AlchemicalWizardry.customPotionReciprocation))
|
|
|
|
{
|
|
|
|
Entity entityAttacking = event.source.getSourceOfDamage();
|
|
|
|
|
|
|
|
if (entityAttacking != null && entityAttacking instanceof EntityLivingBase)
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionReciprocation).getAmplifier();
|
|
|
|
float damageRecieve = event.ammount / 2 * (i + 1);
|
2014-01-17 21:05:38 +00:00
|
|
|
((EntityLivingBase) entityAttacking).attackEntityFrom(DamageSource.generic, damageRecieve);
|
2014-01-17 19:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-19 21:42:31 +00:00
|
|
|
|
|
|
|
if(entityAttacked.isPotionActive(AlchemicalWizardry.customPotionFlameCloak))
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionFlameCloak).getAmplifier();
|
|
|
|
|
|
|
|
Entity entityAttacking = event.source.getSourceOfDamage();
|
|
|
|
|
|
|
|
if(entityAttacking != null && entityAttacking instanceof EntityLivingBase && !entityAttacking.isImmuneToFire() && !((EntityLivingBase)entityAttacking).isPotionActive(Potion.fireResistance))
|
|
|
|
{
|
|
|
|
entityAttacking.attackEntityFrom(DamageSource.inFire, 2*i+2);
|
|
|
|
entityAttacking.setFire(3);
|
|
|
|
}
|
|
|
|
}
|
2014-01-17 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @ForgeSubscribe
|
|
|
|
// public void onFOVUpdate(FOVUpdateEvent event)
|
|
|
|
// {
|
|
|
|
// event.setResult(Result.DEFAULT);
|
|
|
|
// }
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onEntityUpdate(LivingUpdateEvent event)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
EntityLivingBase entityLiving = event.entityLiving;
|
2014-01-19 21:42:31 +00:00
|
|
|
double x = entityLiving.posX;
|
|
|
|
double y = entityLiving.posY;
|
|
|
|
double z = entityLiving.posZ;
|
2014-01-17 19:12:49 +00:00
|
|
|
|
|
|
|
if (entityLiving instanceof EntityPlayer && entityLiving.worldObj.isRemote)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) entityLiving;
|
2014-01-17 19:12:49 +00:00
|
|
|
boolean highStepListed = playersWith1Step.contains(entityPlayer.username);
|
|
|
|
boolean hasHighStep = entityPlayer.isPotionActive(AlchemicalWizardry.customPotionBoost);
|
|
|
|
|
|
|
|
if (hasHighStep && !highStepListed)
|
|
|
|
{
|
|
|
|
playersWith1Step.add(entityPlayer.username);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasHighStep && highStepListed)
|
|
|
|
{
|
|
|
|
playersWith1Step.remove(entityPlayer.username);
|
|
|
|
entityPlayer.stepHeight = 0.5F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionDrowning))
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionDrowning).getAmplifier();
|
|
|
|
|
2014-01-17 21:05:38 +00:00
|
|
|
if (event.entityLiving.worldObj.getWorldTime() % ((int) (20 / (i + 1))) == 0)
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
|
|
|
event.entityLiving.attackEntityFrom(DamageSource.drown, 2);
|
|
|
|
event.entityLiving.hurtResistantTime = Math.min(event.entityLiving.hurtResistantTime, 20 / (i + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionBoost))
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionBoost).getAmplifier();
|
|
|
|
EntityLivingBase entity = event.entityLiving;
|
|
|
|
//if(!entity.isSneaking())
|
|
|
|
{
|
|
|
|
double percentIncrease = (i + 1) * 0.03d;
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) event.entityLiving;
|
2014-01-17 19:12:49 +00:00
|
|
|
entityPlayer.stepHeight = 1.0f;
|
|
|
|
|
|
|
|
if (!entityPlayer.worldObj.isRemote)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
float speed = ((Float) ReflectionHelper.getPrivateValue(PlayerCapabilities.class, entityPlayer.capabilities, new String[]{"walkSpeed", "g", "field_75097_g"})).floatValue();
|
|
|
|
ObfuscationReflectionHelper.setPrivateValue(PlayerCapabilities.class, entityPlayer.capabilities, Float.valueOf(speed + (float) percentIncrease), new String[]{"walkSpeed", "g", "field_75097_g"}); //CAUTION
|
2014-01-17 19:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionProjProt))
|
|
|
|
{
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionProjProt).getAmplifier();
|
|
|
|
EntityLivingBase entity = event.entityLiving;
|
2014-01-17 21:05:38 +00:00
|
|
|
int posX = (int) Math.round(entity.posX - 0.5f);
|
|
|
|
int posY = (int) Math.round(entity.posY);
|
|
|
|
int posZ = (int) Math.round(entity.posZ - 0.5f);
|
2014-01-17 19:12:49 +00:00
|
|
|
int d0 = i;
|
|
|
|
AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB(posX - 0.5, posY - 0.5, posZ - 0.5, posX + 0.5, posY + 0.5, posZ + 0.5).expand(d0, d0, d0);
|
|
|
|
List list = event.entityLiving.worldObj.getEntitiesWithinAABB(Entity.class, axisalignedbb);
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
EntityLivingBase livingEntity;
|
|
|
|
|
|
|
|
while (iterator.hasNext())
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
Entity projectile = (Entity) iterator.next();
|
2014-01-17 19:12:49 +00:00
|
|
|
|
|
|
|
if (projectile == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(projectile instanceof IProjectile))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (projectile instanceof EntityArrow)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
if (((EntityArrow) projectile).shootingEntity == null)
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
} else if (!(((EntityArrow) projectile).shootingEntity == null) && ((EntityArrow) projectile).shootingEntity.equals(entity))
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-01-17 21:05:38 +00:00
|
|
|
} else if (projectile instanceof EnergyBlastProjectile)
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
if (!(((EnergyBlastProjectile) projectile).shootingEntity == null) && ((EnergyBlastProjectile) projectile).shootingEntity.equals(entity))
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double delX = projectile.posX - entity.posX;
|
|
|
|
double delY = projectile.posY - entity.posY;
|
|
|
|
double delZ = projectile.posZ - entity.posZ;
|
|
|
|
double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
|
|
|
|
//NOTE: It appears that it constantly reverses the direction.
|
|
|
|
//Any way to do it only once? Or find the shooting entity?
|
|
|
|
delX /= curVel;
|
|
|
|
delY /= curVel;
|
|
|
|
delZ /= curVel;
|
|
|
|
double newVel = Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ);
|
|
|
|
projectile.motionX = newVel * delX;
|
|
|
|
projectile.motionY = newVel * delY;
|
|
|
|
projectile.motionZ = newVel * delZ;
|
|
|
|
//TODO make this not affect player's projectiles
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionFlight))
|
|
|
|
{
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) event.entityLiving;
|
2014-01-17 19:12:49 +00:00
|
|
|
String ownerName = entityPlayer.username;
|
|
|
|
playerFlightBuff.put(ownerName, true);
|
|
|
|
entityPlayer.capabilities.allowFlying = true;
|
|
|
|
//entityPlayer.sendPlayerAbilities();
|
|
|
|
}
|
2014-01-17 21:05:38 +00:00
|
|
|
} else
|
2014-01-17 19:12:49 +00:00
|
|
|
{
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
{
|
2014-01-17 21:05:38 +00:00
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) event.entityLiving;
|
2014-01-17 19:12:49 +00:00
|
|
|
String ownerName = entityPlayer.username;
|
|
|
|
|
|
|
|
if (!playerFlightBuff.containsKey(ownerName))
|
|
|
|
{
|
|
|
|
playerFlightBuff.put(ownerName, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playerFlightBuff.get(ownerName))
|
|
|
|
{
|
|
|
|
playerFlightBuff.put(ownerName, false);
|
|
|
|
|
|
|
|
if (!entityPlayer.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
entityPlayer.capabilities.allowFlying = false;
|
|
|
|
entityPlayer.capabilities.isFlying = false;
|
|
|
|
entityPlayer.sendPlayerAbilities();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 21:42:31 +00:00
|
|
|
|
|
|
|
if(entityLiving.isPotionActive(AlchemicalWizardry.customPotionFlameCloak))
|
|
|
|
{
|
|
|
|
entityLiving.worldObj.spawnParticle("flame", x+SpellHelper.gaussian(1),y-1.3+SpellHelper.gaussian(0.3),z+SpellHelper.gaussian(1), 0, 0.06d, 0);
|
|
|
|
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionFlameCloak).getAmplifier();
|
|
|
|
double range = i*0.5;
|
|
|
|
|
|
|
|
List<Entity> entities = SpellHelper.getEntitiesInRange(entityLiving.worldObj, x, y, z, range, range);
|
|
|
|
if(entities!=null)
|
|
|
|
{
|
|
|
|
for(Entity entity : entities)
|
|
|
|
{
|
|
|
|
if(!entity.equals(entityLiving)&&!entity.isImmuneToFire()&&!(entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.fireResistance)))
|
|
|
|
{
|
|
|
|
entity.setFire(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 19:12:49 +00:00
|
|
|
}
|
|
|
|
}
|