2013-05-25 08:57:21 +00:00
|
|
|
package biomesoplenty.potions;
|
|
|
|
|
2013-08-30 11:38:54 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
2013-05-25 16:02:56 +00:00
|
|
|
import net.minecraft.entity.monster.EntityCreeper;
|
2013-05-25 08:57:21 +00:00
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
2013-05-25 16:02:56 +00:00
|
|
|
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
|
2013-05-25 08:57:21 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
2013-05-25 09:33:37 +00:00
|
|
|
import biomesoplenty.api.Potions;
|
2013-05-25 08:57:21 +00:00
|
|
|
|
2013-05-31 10:34:02 +00:00
|
|
|
public class PotionEventHandler
|
2013-05-25 08:57:21 +00:00
|
|
|
{
|
|
|
|
@ForgeSubscribe
|
2013-05-31 10:34:02 +00:00
|
|
|
public void onEntityUpdate(LivingUpdateEvent event)
|
2013-05-25 08:57:21 +00:00
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
if (event.entityLiving.isPotionActive(Potions.paralysis.get()))
|
|
|
|
{
|
|
|
|
event.entityLiving.motionX = 0.0;
|
|
|
|
if (!event.entityLiving.isAirBorne) {
|
|
|
|
event.entityLiving.motionY = 0.0;
|
|
|
|
}
|
|
|
|
event.entityLiving.motionZ = 0.0;
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityCreeper) {
|
|
|
|
((EntityCreeper)event.entityLiving).setCreeperState(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.getActivePotionEffect(Potions.paralysis.get()).getDuration() == 0)
|
|
|
|
{
|
|
|
|
event.entityLiving.removePotionEffect(Potions.paralysis.get().id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-08-30 11:38:54 +00:00
|
|
|
|
|
|
|
if (event.entityLiving.isPotionActive(Potions.possession.get()))
|
|
|
|
{
|
|
|
|
Random rand = event.entityLiving.worldObj.rand;
|
|
|
|
|
|
|
|
double posX = event.entityLiving.posX;
|
|
|
|
double posY = event.entityLiving.posY;
|
|
|
|
double posZ = event.entityLiving.posZ;
|
|
|
|
|
2013-10-11 15:52:13 +00:00
|
|
|
double randX = 1.0 - (rand.nextDouble() * 2.0);
|
|
|
|
double randY = (double) rand.nextInt(3);
|
|
|
|
double randZ = 1.0 - (rand.nextDouble() * 2.0);
|
2013-08-30 11:38:54 +00:00
|
|
|
|
|
|
|
event.entityLiving.motionX = 0.0;
|
|
|
|
event.entityLiving.motionY = 0.0;
|
|
|
|
event.entityLiving.motionZ = 0.0;
|
|
|
|
|
|
|
|
if (rand.nextInt(5) == 0)
|
|
|
|
{
|
2013-10-11 15:52:13 +00:00
|
|
|
if (!event.entityLiving.worldObj.checkBlockCollision(event.entityLiving.boundingBox.offset(randX, randY, randZ)))
|
|
|
|
event.entityLiving.setPosition(posX + randX, posY + randY, posZ + randZ);
|
2013-08-30 11:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event.entityLiving.getActivePotionEffect(Potions.possession.get()).getDuration() == 0)
|
|
|
|
{
|
|
|
|
event.entityLiving.removePotionEffect(Potions.possession.get().id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 16:02:56 +00:00
|
|
|
}
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-05-25 16:02:56 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void onEndermanTP(EnderTeleportEvent event)
|
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
if (event.entityLiving.isPotionActive(Potions.paralysis.get())) {
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2013-05-25 08:57:21 +00:00
|
|
|
}
|
|
|
|
}
|