2015-12-28 00:38:12 +00:00
|
|
|
package WayofTime.bloodmagic.potion;
|
|
|
|
|
2016-01-31 03:22:46 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-29 00:09:51 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.IProjectile;
|
2015-12-28 00:38:12 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-12-29 00:09:51 +00:00
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
|
|
|
import net.minecraft.entity.projectile.EntityThrowable;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-12-28 00:38:12 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2016-01-31 03:22:46 +00:00
|
|
|
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
2015-12-29 00:09:51 +00:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
2015-12-28 00:38:12 +00:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2016-01-31 03:22:46 +00:00
|
|
|
import WayofTime.bloodmagic.registry.ModPotions;
|
2015-12-28 00:38:12 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class PotionEventHandlers
|
|
|
|
{
|
|
|
|
public PotionEventHandlers()
|
|
|
|
{
|
2015-12-28 00:38:12 +00:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onLivingJumpEvent(LivingEvent.LivingJumpEvent event)
|
|
|
|
{
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.boost))
|
|
|
|
{
|
2015-12-28 00:38:12 +00:00
|
|
|
int i = event.entityLiving.getActivePotionEffect(ModPotions.boost).getAmplifier();
|
|
|
|
event.entityLiving.motionY += (0.1f) * (2 + i);
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
// if (event.entityLiving.isPotionActive(ModPotions.heavyHeart)) {
|
|
|
|
// event.entityLiving.motionY = 0;
|
|
|
|
// }
|
2015-12-28 00:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onEntityUpdate(LivingEvent.LivingUpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.boost))
|
|
|
|
{
|
2015-12-28 00:38:12 +00:00
|
|
|
int i = event.entityLiving.getActivePotionEffect(ModPotions.boost).getAmplifier();
|
|
|
|
{
|
|
|
|
float percentIncrease = (i + 1) * 0.05f;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
{
|
2015-12-28 00:38:12 +00:00
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) event.entityLiving;
|
|
|
|
|
|
|
|
if ((entityPlayer.onGround || entityPlayer.capabilities.isFlying) && entityPlayer.moveForward > 0F)
|
|
|
|
entityPlayer.moveFlying(0F, 1F, entityPlayer.capabilities.isFlying ? (percentIncrease / 2.0f) : percentIncrease);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 00:09:51 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.whirlwind))
|
|
|
|
{
|
2015-12-29 00:09:51 +00:00
|
|
|
int d0 = 3;
|
|
|
|
AxisAlignedBB axisAlignedBB = AxisAlignedBB.fromBounds(event.entityLiving.posX - 0.5, event.entityLiving.posY - 0.5, event.entityLiving.posZ - 0.5, event.entityLiving.posX + 0.5, event.entityLiving.posY + 0.5, event.entityLiving.posZ + 0.5).expand(d0, d0, d0);
|
|
|
|
List entityList = event.entityLiving.worldObj.getEntitiesWithinAABB(Entity.class, axisAlignedBB);
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
for (Object thing : entityList)
|
|
|
|
{
|
2015-12-29 00:09:51 +00:00
|
|
|
Entity projectile = (Entity) thing;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (projectile == null)
|
|
|
|
continue;
|
|
|
|
if (!(projectile instanceof IProjectile))
|
|
|
|
continue;
|
2015-12-29 00:09:51 +00:00
|
|
|
|
|
|
|
Entity throwingEntity = null;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (projectile instanceof EntityArrow)
|
|
|
|
throwingEntity = ((EntityArrow) projectile).shootingEntity;
|
2015-12-29 00:09:51 +00:00
|
|
|
else if (projectile instanceof EntityThrowable)
|
|
|
|
throwingEntity = ((EntityThrowable) projectile).getThrower();
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (throwingEntity != null && throwingEntity.equals(event.entityLiving))
|
|
|
|
continue;
|
2015-12-29 00:09:51 +00:00
|
|
|
|
|
|
|
double delX = projectile.posX - event.entityLiving.posX;
|
|
|
|
double delY = projectile.posY - event.entityLiving.posY;
|
|
|
|
double delZ = projectile.posZ - event.entityLiving.posZ;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
double angle = (delX * projectile.motionX + delY * projectile.motionY + delZ * projectile.motionZ) / (Math.sqrt(delX * delX + delY * delY + delZ * delZ) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
|
2015-12-29 00:09:51 +00:00
|
|
|
|
|
|
|
angle = Math.acos(angle);
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (angle < 3 * (Math.PI / 4))
|
|
|
|
continue; // angle is < 135 degrees
|
2015-12-29 00:09:51 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (throwingEntity != null)
|
|
|
|
{
|
2015-12-29 00:09:51 +00:00
|
|
|
delX = -projectile.posX + throwingEntity.posX;
|
|
|
|
delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
|
|
|
|
delZ = -projectile.posZ + throwingEntity.posZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onPlayerDamageEvent(LivingAttackEvent event)
|
|
|
|
{
|
2015-12-29 00:09:51 +00:00
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.whirlwind) && event.isCancelable() && event.source.isProjectile())
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onEndermanTeleportEvent(EnderTeleportEvent event)
|
|
|
|
{
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.planarBinding) && event.isCancelable())
|
|
|
|
{
|
2015-12-29 00:09:51 +00:00
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2015-12-28 00:38:12 +00:00
|
|
|
}
|
|
|
|
}
|