2011-11-29 11:22:35 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-01-20 09:56:02 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.event.entity.PotionSplashEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-11-29 11:22:35 +01:00
|
|
|
public class EntityPotion extends EntityProjectile {
|
|
|
|
|
|
|
|
private int d;
|
|
|
|
|
|
|
|
public EntityPotion(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityPotion(World world, EntityLiving entityliving, int i) {
|
|
|
|
super(world, entityliving);
|
|
|
|
this.d = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityPotion(World world, double d0, double d1, double d2, int i) {
|
|
|
|
super(world, d0, d1, d2);
|
|
|
|
this.d = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float e() {
|
|
|
|
return 0.05F;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float c() {
|
|
|
|
return 0.5F;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float d() {
|
|
|
|
return -20.0F;
|
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
public int getPotionValue() {
|
2011-11-29 11:22:35 +01:00
|
|
|
return this.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(MovingObjectPosition movingobjectposition) {
|
|
|
|
if (!this.world.isStatic) {
|
|
|
|
List list = Item.POTION.b(this.d);
|
|
|
|
|
|
|
|
if (list != null && !list.isEmpty()) {
|
2012-01-12 16:27:39 +01:00
|
|
|
AxisAlignedBB axisalignedbb = this.boundingBox.grow(4.0D, 2.0D, 4.0D);
|
2011-11-29 11:22:35 +01:00
|
|
|
List list1 = this.world.a(EntityLiving.class, axisalignedbb);
|
|
|
|
|
|
|
|
if (list1 != null && !list1.isEmpty()) {
|
|
|
|
Iterator iterator = list1.iterator();
|
|
|
|
|
2012-01-20 09:56:02 +01:00
|
|
|
// CraftBukkit
|
|
|
|
HashMap<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>();
|
|
|
|
|
2011-11-29 11:22:35 +01:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
2012-03-01 11:49:23 +01:00
|
|
|
double d0 = this.j(entity);
|
2011-11-29 11:22:35 +01:00
|
|
|
|
|
|
|
if (d0 < 16.0D) {
|
|
|
|
double d1 = 1.0D - Math.sqrt(d0) / 4.0D;
|
|
|
|
|
|
|
|
if (entity == movingobjectposition.entity) {
|
|
|
|
d1 = 1.0D;
|
|
|
|
}
|
|
|
|
|
2012-01-20 09:56:02 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
affected.put((LivingEntity) entity.getBukkitEntity(), d1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent(this, affected);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
for (LivingEntity victim : event.getAffectedEntities()) {
|
|
|
|
if (!(victim instanceof CraftLivingEntity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
EntityLiving entity = ((CraftLivingEntity) victim).getHandle();
|
|
|
|
double d1 = event.getIntensity(victim);
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-11-29 11:22:35 +01:00
|
|
|
Iterator iterator1 = list.iterator();
|
|
|
|
|
|
|
|
while (iterator1.hasNext()) {
|
|
|
|
MobEffect mobeffect = (MobEffect) iterator1.next();
|
|
|
|
int i = mobeffect.getEffectId();
|
|
|
|
|
2012-02-09 03:02:18 +01:00
|
|
|
// CraftBukkit start - abide by PVP settings
|
|
|
|
if (!this.world.pvpMode && entity instanceof EntityPlayer && entity != this.shooter) {
|
|
|
|
// Block SLOWER_MOVEMENT, SLOWER_DIG, HARM, BLINDNESS, HUNGER, WEAKNESS and POISON potions
|
|
|
|
if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18 || i == 19) continue;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
if (MobEffectList.byId[i].isInstant()) {
|
|
|
|
// CraftBukkit - added 'this'
|
|
|
|
MobEffectList.byId[i].applyInstantEffect(this.shooter, (EntityLiving) entity, mobeffect.getAmplifier(), d1, this);
|
2011-11-29 11:22:35 +01:00
|
|
|
} else {
|
|
|
|
int j = (int) (d1 * (double) mobeffect.getDuration() + 0.5D);
|
|
|
|
|
|
|
|
if (j > 20) {
|
|
|
|
((EntityLiving) entity).addEffect(new MobEffect(i, j, mobeffect.getAmplifier()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
this.world.triggerEffect(2002, (int) Math.round(this.locX), (int) Math.round(this.locY), (int) Math.round(this.locZ), this.d);
|
2011-11-29 11:22:35 +01:00
|
|
|
this.die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|