001    
002    /**
003     * BaseEntity.java - Class for accessing things that all entities share - X, Y,
004     * Z, health.
005     * @author James
006     */
007    public class BaseEntity {
008        fe entity;
009        
010        /**
011         * Creates an interface for an entity
012         * @param entity
013         */
014        public BaseEntity(fe entity) {
015            this.entity = entity;
016        }
017    
018        /**
019         * Interface for entities.
020         */
021        public BaseEntity() {
022        }
023    
024        /**
025         * Returns the ID for this mob
026         * @return id
027         */
028        public int getId() {
029            return entity.g;
030        }
031    
032        /**
033         * Teleports to the provided location
034         * @param x
035         * @param rotation
036         * @param y
037         * @param z
038         * @param pitch
039         */
040        public void teleportTo(double x, double y, double z, float rotation, float pitch) {
041            entity.b(x, y, z, rotation, pitch);
042        }
043    
044        /**
045         * Teleports to the other entity
046         * @param ent entity to teleport to
047         */
048        public void teleportTo(BaseEntity ent) {
049            teleportTo(ent.getX(), ent.getY(), ent.getZ(), ent.getRotation(), ent.getPitch());
050        }
051    
052        /**
053         * Teleports to the provided location
054         * @param location location to teleport to
055         */
056        public void teleportTo(Location location) {
057            teleportTo(location.x, location.y, location.z, location.rotX, location.rotY);
058        }
059    
060        /**
061         * Returns the entity's X
062         * @return x
063         */
064        public double getX() {
065            return entity.p;
066        }
067    
068        /**
069         * Sets the entity's X
070         * @param x x to set
071         */
072        public void setX(double x) {
073            teleportTo(x, getY(), getZ(), getRotation(), getPitch());
074        }
075    
076        /**
077         * Returns the entity's Y
078         * @return y
079         */
080        public double getY() {
081            return entity.q;
082        }
083    
084        /**
085         * Sets the entity's Y
086         * @param y y to set
087         */
088        public void setY(double y) {
089            teleportTo(getX(), y, getZ(), getRotation(), getPitch());
090        }
091    
092        /**
093         * Returns the entity's Z
094         * @return z
095         */
096        public double getZ() {
097            return entity.r;
098        }
099    
100        /**
101         * Sets the entity's Z
102         * @param z z to set
103         */
104        public void setZ(double z) {
105            teleportTo(getX(), getY(), z, getRotation(), getPitch());
106        }
107    
108        /**
109         * Returns the entity's pitch
110         * @return pitch
111         */
112        public float getPitch() {
113            return entity.w;
114        }
115    
116        /**
117         * Sets the entity's pitch
118         * @param pitch pitch to set
119         */
120        public void setPitch(float pitch) {
121            teleportTo(getX(), getY(), getZ(), getRotation(), pitch);
122        }
123    
124        /**
125         * Returns the entity's rotation
126         * @return rotation
127         */
128        public float getRotation() {
129            return entity.v;
130        }
131    
132        /**
133         * Sets the entity's rotation
134         * @param rotation rotation to set
135         */
136        public void setRotation(float rotation) {
137            teleportTo(getX(), getY(), getZ(), rotation, getPitch());
138        }
139        
140        /**
141         * Returns the entity we're wrapping.
142         * @return
143         */
144        public fe getEntity() {
145            return entity;
146        }
147    
148        /**
149         * Returns whether or not this entity is a mob
150         * @return true if mob
151         */
152        public boolean isMob() {
153            return entity instanceof hq || entity instanceof hl;
154        }
155    
156        /**
157         * Returns whether or not this entity is an animal
158         * @return true if animal
159         */
160        public boolean isAnimal() {
161            return entity instanceof bl;
162        }
163    
164        /**
165         * Returns true if this entity is a player
166         * @return true if player
167         */
168        public boolean isPlayer() {
169            return entity instanceof fy;
170        }
171            
172        /**
173         * Returns whether or not this entity is alive
174         * @return true if living entity
175         */
176        public boolean isLiving() {
177            return entity instanceof mj;
178        }
179    
180        /**
181         * Returns the player for this entity
182         * @return player
183         */
184        public Player getPlayer() {
185            if (!isPlayer())
186                return null;
187    
188            fy p = (fy) entity;
189    
190            return p.getPlayer();
191        }
192    
193        /**
194         * Get the default amount of AirTicks for this entity
195         * 20 ticks per second.
196         * 
197         * @return
198         */
199        public int getBaseAirTicks() {
200            return getEntity().aa;
201        }
202    
203        /**
204         * Set the default amount of AirTicks for this entity
205         * 20 ticks per second.
206         * 
207         * @param ticks
208         */
209        public void setBaseAirTicks(int ticks) {
210            getEntity().aa = ticks;
211        }
212    
213        /**
214         * Get the current NoDamageTicks for this entity
215         * 
216         * This gets lowered every game tick, until its smaller than half the BaseNoDamageTicks
217         * it only registers any damage more than {@link LivingEntity#getLastDamage()}.
218         * 20 ticks per second.
219         * 
220         * @return
221         */
222        public int getNoDamageTicks() {
223            return getEntity().ac;
224        }
225    
226        /**
227         * Set the current NoDamageTicks for this entity
228         * 
229         * This gets lowered every game tick, until its smaller than half the BaseNoDamageTicks
230         * it only registers any damage more than {@link LivingEntity#getLastDamage()}.
231         * 20 ticks per second.
232         * 
233         * @param ticks
234         */
235        public void setNoDamageTicks(int ticks) {
236            getEntity().ac = ticks;
237        }
238    
239        /**
240         * Get the amount of AirTicks left.
241         * 
242         * This gets lowered every game tick when you are under water. 
243         * 20 ticks per second.
244         * 
245         * @return
246         */
247        public int getAirTicks() {
248            return getEntity().ad;
249        }
250    
251        /**
252         * Set the amount of AirTicks left.
253         * 
254         * This gets lowered every game tick when you are under water. 
255         * 20 ticks per second.
256         * 
257         * @return
258         */
259        public void setAirTicks(int ticks) {
260            getEntity().ad = ticks;
261        }
262    
263        /**
264         * Get the amount of FireTicks left.
265         * 
266         * This gets lowered every game tick when you are on fire. 
267         * 20 ticks per second.
268         * 
269         * @return
270         */
271        public int getFireTicks() {
272            return getEntity().Z;
273        }
274    
275        /**
276         * Set the amount of FireTicks left.
277         * 
278         * This gets lowered every game tick when you are on fire. 
279         * 20 ticks per second.
280         * 
281         * @return
282         */
283        public void setFireTicks(int ticks) {
284            getEntity().Z = ticks;
285        }
286    }