2015-12-28 00:38:12 +00:00
|
|
|
package WayofTime.bloodmagic.potion;
|
|
|
|
|
2015-12-29 19:32:35 +00:00
|
|
|
import WayofTime.bloodmagic.registry.ModItems;
|
2015-12-28 00:38:12 +00:00
|
|
|
import WayofTime.bloodmagic.registry.ModPotions;
|
2015-12-29 00:09:51 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.IProjectile;
|
2015-12-29 19:32:35 +00:00
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
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;
|
2015-12-29 19:32:35 +00:00
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
2015-12-29 00:09:51 +00:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-12-28 00:38:12 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2015-12-29 19:32:35 +00:00
|
|
|
import net.minecraftforge.event.entity.living.*;
|
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;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class PotionEventHandlers {
|
|
|
|
|
|
|
|
public PotionEventHandlers() {
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onLivingJumpEvent(LivingEvent.LivingJumpEvent event) {
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.boost)) {
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(ModPotions.boost).getAmplifier();
|
|
|
|
event.entityLiving.motionY += (0.1f) * (2 + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (event.entityLiving.isPotionActive(ModPotions.heavyHeart)) {
|
|
|
|
// event.entityLiving.motionY = 0;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
|
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.boost)) {
|
|
|
|
int i = event.entityLiving.getActivePotionEffect(ModPotions.boost).getAmplifier();
|
|
|
|
{
|
|
|
|
float percentIncrease = (i + 1) * 0.05f;
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer) {
|
|
|
|
EntityPlayer entityPlayer = (EntityPlayer) event.entityLiving;
|
|
|
|
entityPlayer.stepHeight = 1.0f;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.whirlwind)) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (Object thing : entityList) {
|
|
|
|
Entity projectile = (Entity) thing;
|
|
|
|
|
|
|
|
if (projectile == null) continue;
|
|
|
|
if (!(projectile instanceof IProjectile)) continue;
|
|
|
|
|
|
|
|
Entity throwingEntity = null;
|
|
|
|
|
|
|
|
if (projectile instanceof EntityArrow) throwingEntity = ((EntityArrow) projectile).shootingEntity;
|
|
|
|
else if (projectile instanceof EntityThrowable)
|
|
|
|
throwingEntity = ((EntityThrowable) projectile).getThrower();
|
|
|
|
|
|
|
|
if (throwingEntity != null && throwingEntity.equals(event.entityLiving)) continue;
|
|
|
|
|
|
|
|
double delX = projectile.posX - event.entityLiving.posX;
|
|
|
|
double delY = projectile.posY - event.entityLiving.posY;
|
|
|
|
double delZ = projectile.posZ - event.entityLiving.posZ;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
angle = Math.acos(angle);
|
|
|
|
|
|
|
|
if (angle < 3 * (Math.PI / 4)) continue; //angle is < 135 degrees
|
|
|
|
|
|
|
|
if (throwingEntity != null) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 19:32:35 +00:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onEntityDrop(LivingDropsEvent event) {
|
|
|
|
if (event.source.getDamageType().equals("player")) {
|
|
|
|
double rand = Math.random();
|
|
|
|
|
|
|
|
if (!(event.entityLiving instanceof EntityAnimal)) {
|
|
|
|
PotionEffect effect = event.entityLiving.getActivePotionEffect(Potion.weakness);
|
|
|
|
|
|
|
|
if (effect != null)
|
|
|
|
if (effect.getAmplifier() >= 2)
|
|
|
|
if (rand < 0.2)
|
|
|
|
event.entityLiving.dropItem(ModItems.bloodShard, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 00:09:51 +00:00
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
|
|
public void onPlayerDamageEvent(LivingAttackEvent event) {
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.whirlwind) && event.isCancelable() && event.source.isProjectile())
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onEndermanTeleportEvent(EnderTeleportEvent event) {
|
|
|
|
if (event.entityLiving.isPotionActive(ModPotions.planarBinding) && event.isCancelable()) {
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2015-12-28 00:38:12 +00:00
|
|
|
}
|
|
|
|
}
|