EntityPotion .java

net.minecraft.entity.projectile.EntityPotion (class): members: getPotionDamage, setPotionDamage, potionDamage, getGravityVelocity, getInaccuracy, onImpact.

net.minecraft.entity.projectileclass185 linescommonextends EntityThrowable5.5 KB

API Surface (8)

float getGravityVelocity()
float getVelocity()
float getInaccuracy()
void setPotionDamage(int potionId)
int getPotionDamage()
void onImpact(MovingObjectPosition p_70184_1_)
void readEntityFromNBT(NBTTagCompound tagCompund)
void writeEntityToNBT(NBTTagCompound tagCompound)

Fields & Constants (1)

potionDamage

String literals (2)

"Potion"
"potionValue"

Full Source

EntityPotion.java185 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.projectile;
2
3
import java.util.List;
4
import net.minecraft.entity.EntityLivingBase;
5
import net.minecraft.init.Items;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.nbt.NBTTagCompound;
8
import net.minecraft.potion.Potion;
9
import net.minecraft.potion.PotionEffect;
10
import net.minecraft.util.AxisAlignedBB;
11
import net.minecraft.util.BlockPos;
12
import net.minecraft.util.MovingObjectPosition;
13
import net.minecraft.world.World;
14
15
public class EntityPotion extends EntityThrowable
16
{
17
    /**
18
     * The damage value of the thrown potion that this EntityPotion represents.
19
     */
20
    private ItemStack potionDamage;
21
22
    public EntityPotion(World worldIn)
23
    {
24
        super(worldIn);
25
    }
26
27
    public EntityPotion(World worldIn, EntityLivingBase throwerIn, int meta)
28
    {
29
        this(worldIn, throwerIn, new ItemStack(Items.potionitem, 1, meta));
30
    }
31
32
    public EntityPotion(World worldIn, EntityLivingBase throwerIn, ItemStack potionDamageIn)
33
    {
34
        super(worldIn, throwerIn);
35
        this.potionDamage = potionDamageIn;
36
    }
37
38
    public EntityPotion(World worldIn, double x, double y, double z, int p_i1791_8_)
39
    {
40
        this(worldIn, x, y, z, new ItemStack(Items.potionitem, 1, p_i1791_8_));
41
    }
42
43
    public EntityPotion(World worldIn, double x, double y, double z, ItemStack potionDamageIn)
44
    {
45
        super(worldIn, x, y, z);
46
        this.potionDamage = potionDamageIn;
47
    }
48
49
    /**
50
     * Gets the amount of gravity to apply to the thrown entity with each tick.
51
     */
52
    protected float getGravityVelocity()
53
    {
54
        return 0.05F;
55
    }
56
57
    protected float getVelocity()
58
    {
59
        return 0.5F;
60
    }
61
62
    protected float getInaccuracy()
63
    {
64
        return -20.0F;
65
    }
66
67
    /**
68
     * Sets the PotionEffect by the given id of the potion effect.
69
     */
70
    public void setPotionDamage(int potionId)
71
    {
72
        if (this.potionDamage == null)
73
        {
74
            this.potionDamage = new ItemStack(Items.potionitem, 1, 0);
75
        }
76
77
        this.potionDamage.setItemDamage(potionId);
78
    }
79
80
    /**
81
     * Returns the damage value of the thrown potion that this EntityPotion represents.
82
     */
83
    public int getPotionDamage()
84
    {
85
        if (this.potionDamage == null)
86
        {
87
            this.potionDamage = new ItemStack(Items.potionitem, 1, 0);
88
        }
89
90
        return this.potionDamage.getMetadata();
91
    }
92
93
    /**
94
     * Called when this EntityThrowable hits a block or entity.
95
     */
96
    protected void onImpact(MovingObjectPosition p_70184_1_)
97
    {
98
        if (!this.worldObj.isRemote)
99
        {
100
            List<PotionEffect> list = Items.potionitem.getEffects(this.potionDamage);
101
102
            if (list != null && !list.isEmpty())
103
            {
104
                AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D);
105
                List<EntityLivingBase> list1 = this.worldObj.<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
106
107
                if (!list1.isEmpty())
108
                {
109
                    for (EntityLivingBase entitylivingbase : list1)
110
                    {
111
                        double d0 = this.getDistanceSqToEntity(entitylivingbase);
112
113
                        if (d0 < 16.0D)
114
                        {
115
                            double d1 = 1.0D - Math.sqrt(d0) / 4.0D;
116
117
                            if (entitylivingbase == p_70184_1_.entityHit)
118
                            {
119
                                d1 = 1.0D;
120
                            }
121
122
                            for (PotionEffect potioneffect : list)
123
                            {
124
                                int i = potioneffect.getPotionID();
125
126
                                if (Potion.potionTypes[i].isInstant())
127
                                {
128
                                    Potion.potionTypes[i].affectEntity(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1);
129
                                }
130
                                else
131
                                {
132
                                    int j = (int)(d1 * (double)potioneffect.getDuration() + 0.5D);
133
134
                                    if (j > 20)
135
                                    {
136
                                        entitylivingbase.addPotionEffect(new PotionEffect(i, j, potioneffect.getAmplifier()));
137
                                    }
138
                                }
139
                            }
140
                        }
141
                    }
142
                }
143
            }
144
145
            this.worldObj.playAuxSFX(2002, new BlockPos(this), this.getPotionDamage());
146
            this.setDead();
147
        }
148
    }
149
150
    /**
151
     * (abstract) Protected helper method to read subclass entity data from NBT.
152
     */
153
    public void readEntityFromNBT(NBTTagCompound tagCompund)
154
    {
155
        super.readEntityFromNBT(tagCompund);
156
157
        if (tagCompund.hasKey("Potion", 10))
158
        {
159
            this.potionDamage = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("Potion"));
160
        }
161
        else
162
        {
163
            this.setPotionDamage(tagCompund.getInteger("potionValue"));
164
        }
165
166
        if (this.potionDamage == null)
167
        {
168
            this.setDead();
169
        }
170
    }
171
172
    /**
173
     * (abstract) Protected helper method to write subclass entity data to NBT.
174
     */
175
    public void writeEntityToNBT(NBTTagCompound tagCompound)
176
    {
177
        super.writeEntityToNBT(tagCompound);
178
179
        if (this.potionDamage != null)
180
        {
181
            tagCompound.setTag("Potion", this.potionDamage.writeToNBT(new NBTTagCompound()));
182
        }
183
    }
184
}
185

Deobfuscated MCP 1.8.9 source of EntityPotion from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/projectile/EntityPotion.java), stored verbatim.