2011-02-06 00:37:33 +01:00
package net.minecraft.server ;
2013-07-01 13:03:00 +02:00
import java.util.Collection ;
2011-02-06 00:37:33 +01:00
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Set ;
2013-11-04 14:07:38 +01:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2012-07-22 08:18:00 +02:00
// CraftBukkit start
import org.bukkit.entity.Player ;
import org.bukkit.event.player.PlayerVelocityEvent ;
// CraftBukkit end
2011-02-06 00:37:33 +01:00
public class EntityTrackerEntry {
2013-11-04 14:07:38 +01:00
private static final Logger p = LogManager . getLogger ( ) ;
2011-04-20 19:05:14 +02:00
public Entity tracker ;
2011-02-06 00:37:33 +01:00
public int b ;
public int c ;
2012-02-29 22:31:04 +01:00
public int xLoc ;
public int yLoc ;
public int zLoc ;
public int yRot ;
public int xRot ;
2012-03-01 11:49:23 +01:00
public int i ;
2011-02-06 00:37:33 +01:00
public double j ;
public double k ;
2012-03-01 11:49:23 +01:00
public double l ;
2013-07-01 13:03:00 +02:00
public int m ;
2011-02-06 00:37:33 +01:00
private double q ;
2012-03-01 11:49:23 +01:00
private double r ;
2013-11-04 14:07:38 +01:00
private double s ;
2011-04-20 19:05:14 +02:00
private boolean isMoving ;
2013-11-04 14:07:38 +01:00
private boolean u ;
private int v ;
private Entity w ;
private boolean x ;
2013-07-01 13:03:00 +02:00
public boolean n ;
2011-04-20 19:05:14 +02:00
public Set trackedPlayers = new HashSet ( ) ;
2011-02-06 00:37:33 +01:00
public EntityTrackerEntry ( Entity entity , int i , int j , boolean flag ) {
2011-04-20 19:05:14 +02:00
this . tracker = entity ;
2011-02-06 00:37:33 +01:00
this . b = i ;
this . c = j ;
2013-11-04 14:07:38 +01:00
this . u = flag ;
2012-02-29 22:31:04 +01:00
this . xLoc = MathHelper . floor ( entity . locX * 32 . 0D ) ;
this . yLoc = MathHelper . floor ( entity . locY * 32 . 0D ) ;
this . zLoc = MathHelper . floor ( entity . locZ * 32 . 0D ) ;
this . yRot = MathHelper . d ( entity . yaw * 256 . 0F / 360 . 0F ) ;
this . xRot = MathHelper . d ( entity . pitch * 256 . 0F / 360 . 0F ) ;
2013-04-27 11:40:05 +02:00
this . i = MathHelper . d ( entity . getHeadRotation ( ) * 256 . 0F / 360 . 0F ) ;
2011-02-06 00:37:33 +01:00
}
public boolean equals ( Object object ) {
2013-11-04 14:07:38 +01:00
return object instanceof EntityTrackerEntry ? ( ( EntityTrackerEntry ) object ) . tracker . getId ( ) = = this . tracker . getId ( ) : false ;
2011-02-06 00:37:33 +01:00
}
public int hashCode ( ) {
2013-11-04 14:07:38 +01:00
return this . tracker . getId ( ) ;
2011-02-06 00:37:33 +01:00
}
2011-04-20 19:05:14 +02:00
public void track ( List list ) {
2012-03-01 11:49:23 +01:00
this . n = false ;
2013-11-04 14:07:38 +01:00
if ( ! this . isMoving | | this . tracker . e ( this . q , this . r , this . s ) > 16 . 0D ) {
this . q = this . tracker . locX ;
this . r = this . tracker . locY ;
this . s = this . tracker . locZ ;
this . isMoving = true ;
2012-03-01 11:49:23 +01:00
this . n = true ;
2011-04-20 19:05:14 +02:00
this . scanPlayers ( list ) ;
2011-02-06 00:37:33 +01:00
}
2013-11-04 14:07:38 +01:00
if ( this . w ! = this . tracker . vehicle | | this . tracker . vehicle ! = null & & this . m % 60 = = 0 ) {
this . w = this . tracker . vehicle ;
this . broadcast ( new PacketPlayOutAttachEntity ( 0 , this . tracker , this . tracker . vehicle ) ) ;
2012-07-29 09:33:13 +02:00
}
2012-01-30 21:28:04 +01:00
2013-03-25 05:22:32 +01:00
if ( this . tracker instanceof EntityItemFrame /*&& this.m % 10 == 0*/ ) { // CraftBukkit - Moved below, should always enter this block
2013-07-01 13:03:00 +02:00
EntityItemFrame i3 = ( EntityItemFrame ) this . tracker ;
2013-09-19 20:25:08 +02:00
ItemStack i4 = i3 . getItem ( ) ;
2012-10-25 05:53:23 +02:00
2013-07-01 13:03:00 +02:00
if ( this . m % 10 = = 0 & & i4 ! = null & & i4 . getItem ( ) instanceof ItemWorldMap ) { // CraftBukkit - Moved this.m % 10 logic here so item frames do not enter the other blocks
2013-11-04 14:07:38 +01:00
WorldMap i6 = Items . MAP . getSavedMap ( i4 , this . tracker . world ) ;
2013-07-01 13:03:00 +02:00
Iterator i7 = this . trackedPlayers . iterator ( ) ; // CraftBukkit
2012-10-25 05:53:23 +02:00
2013-07-01 13:03:00 +02:00
while ( i7 . hasNext ( ) ) {
EntityHuman i8 = ( EntityHuman ) i7 . next ( ) ;
EntityPlayer i9 = ( EntityPlayer ) i8 ;
2012-10-25 05:53:23 +02:00
2013-07-01 13:03:00 +02:00
i6 . a ( i9 , i4 ) ;
2013-11-04 14:07:38 +01:00
Packet j0 = Items . MAP . c ( i4 , this . tracker . world , i9 ) ;
2012-10-25 05:53:23 +02:00
2013-11-04 14:07:38 +01:00
if ( j0 ! = null ) {
i9 . playerConnection . sendPacket ( j0 ) ;
2012-10-25 05:53:23 +02:00
}
}
}
2013-07-01 13:03:00 +02:00
this . b ( ) ;
2013-11-04 14:07:38 +01:00
} else if ( this . m % this . c = = 0 | | this . tracker . am | | this . tracker . getDataWatcher ( ) . a ( ) ) {
2012-10-25 05:53:23 +02:00
int i ;
int j ;
if ( this . tracker . vehicle = = null ) {
2013-11-04 14:07:38 +01:00
+ + this . v ;
2013-03-13 23:33:27 +01:00
i = this . tracker . at . a ( this . tracker . locX ) ;
2012-10-25 05:53:23 +02:00
j = MathHelper . floor ( this . tracker . locY * 32 . 0D ) ;
2013-03-13 23:33:27 +01:00
int k = this . tracker . at . a ( this . tracker . locZ ) ;
2012-07-29 09:33:13 +02:00
int l = MathHelper . d ( this . tracker . yaw * 256 . 0F / 360 . 0F ) ;
int i1 = MathHelper . d ( this . tracker . pitch * 256 . 0F / 360 . 0F ) ;
int j1 = i - this . xLoc ;
int k1 = j - this . yLoc ;
int l1 = k - this . zLoc ;
Object object = null ;
2012-10-25 05:53:23 +02:00
boolean flag = Math . abs ( j1 ) > = 4 | | Math . abs ( k1 ) > = 4 | | Math . abs ( l1 ) > = 4 | | this . m % 60 = = 0 ;
2012-07-29 09:33:13 +02:00
boolean flag1 = Math . abs ( l - this . yRot ) > = 4 | | Math . abs ( i1 - this . xRot ) > = 4 ;
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Code moved from below
2012-07-29 09:33:13 +02:00
if ( flag ) {
this . xLoc = i ;
this . yLoc = j ;
this . zLoc = k ;
2011-02-06 00:37:33 +01:00
}
2012-07-29 09:33:13 +02:00
if ( flag1 ) {
this . yRot = l ;
this . xRot = i1 ;
2012-01-30 21:28:04 +01:00
}
// CraftBukkit end
2011-02-06 00:37:33 +01:00
2013-04-27 11:40:05 +02:00
if ( this . m > 0 | | this . tracker instanceof EntityArrow ) {
2013-11-04 14:07:38 +01:00
if ( j1 > = - 128 & & j1 < 128 & & k1 > = - 128 & & k1 < 128 & & l1 > = - 128 & & l1 < 128 & & this . v < = 400 & & ! this . x ) {
2013-03-20 21:09:23 +01:00
if ( flag & & flag1 ) {
2013-11-04 14:07:38 +01:00
object = new PacketPlayOutRelEntityMoveLook ( this . tracker . getId ( ) , ( byte ) j1 , ( byte ) k1 , ( byte ) l1 , ( byte ) l , ( byte ) i1 ) ;
2013-03-20 21:09:23 +01:00
} else if ( flag ) {
2013-11-04 14:07:38 +01:00
object = new PacketPlayOutRelEntityMove ( this . tracker . getId ( ) , ( byte ) j1 , ( byte ) k1 , ( byte ) l1 ) ;
2013-03-20 21:09:23 +01:00
} else if ( flag1 ) {
2013-11-04 14:07:38 +01:00
object = new PacketPlayOutEntityLook ( this . tracker . getId ( ) , ( byte ) l , ( byte ) i1 ) ;
2013-03-20 21:09:23 +01:00
}
} else {
2013-11-04 14:07:38 +01:00
this . v = 0 ;
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Refresh list of who can see a player before sending teleport packet
2013-03-20 21:09:23 +01:00
if ( this . tracker instanceof EntityPlayer ) {
this . scanPlayers ( new java . util . ArrayList ( this . trackedPlayers ) ) ;
}
// CraftBukkit end
2013-11-04 14:07:38 +01:00
object = new PacketPlayOutEntityTeleport ( this . tracker . getId ( ) , i , j , k , ( byte ) l , ( byte ) i1 ) ;
2012-07-29 09:33:13 +02:00
}
}
2011-02-06 00:37:33 +01:00
2013-11-04 14:07:38 +01:00
if ( this . u ) {
2012-07-29 09:33:13 +02:00
double d0 = this . tracker . motX - this . j ;
double d1 = this . tracker . motY - this . k ;
double d2 = this . tracker . motZ - this . l ;
double d3 = 0 . 02D ;
double d4 = d0 * d0 + d1 * d1 + d2 * d2 ;
if ( d4 > d3 * d3 | | d4 > 0 . 0D & & this . tracker . motX = = 0 . 0D & & this . tracker . motY = = 0 . 0D & & this . tracker . motZ = = 0 . 0D ) {
this . j = this . tracker . motX ;
this . k = this . tracker . motY ;
this . l = this . tracker . motZ ;
2013-11-04 14:07:38 +01:00
this . broadcast ( new PacketPlayOutEntityVelocity ( this . tracker . getId ( ) , this . j , this . k , this . l ) ) ;
2012-07-29 09:33:13 +02:00
}
2011-02-06 00:37:33 +01:00
}
2012-07-29 09:33:13 +02:00
if ( object ! = null ) {
this . broadcast ( ( Packet ) object ) ;
}
2011-02-06 00:37:33 +01:00
2013-07-01 13:03:00 +02:00
this . b ( ) ;
2013-03-25 05:22:32 +01:00
/ * CraftBukkit start - Code moved up
2012-07-29 09:33:13 +02:00
if ( flag ) {
this . xLoc = i ;
this . yLoc = j ;
this . zLoc = k ;
}
2011-02-23 03:37:56 +01:00
2012-07-29 09:33:13 +02:00
if ( flag1 ) {
this . yRot = l ;
this . xRot = i1 ;
}
// CraftBukkit end */
2012-11-06 13:05:28 +01:00
2013-11-04 14:07:38 +01:00
this . x = false ;
2012-10-25 05:53:23 +02:00
} else {
i = MathHelper . d ( this . tracker . yaw * 256 . 0F / 360 . 0F ) ;
j = MathHelper . d ( this . tracker . pitch * 256 . 0F / 360 . 0F ) ;
boolean flag2 = Math . abs ( i - this . yRot ) > = 4 | | Math . abs ( j - this . xRot ) > = 4 ;
if ( flag2 ) {
2013-11-04 14:07:38 +01:00
this . broadcast ( new PacketPlayOutEntityLook ( this . tracker . getId ( ) , ( byte ) i , ( byte ) j ) ) ;
2012-10-25 05:53:23 +02:00
this . yRot = i ;
this . xRot = j ;
}
2013-03-13 23:33:27 +01:00
this . xLoc = this . tracker . at . a ( this . tracker . locX ) ;
2012-10-25 05:53:23 +02:00
this . yLoc = MathHelper . floor ( this . tracker . locY * 32 . 0D ) ;
2013-03-13 23:33:27 +01:00
this . zLoc = this . tracker . at . a ( this . tracker . locZ ) ;
2013-07-01 13:03:00 +02:00
this . b ( ) ;
2013-11-04 14:07:38 +01:00
this . x = true ;
2012-02-29 22:31:04 +01:00
}
2012-07-29 09:33:13 +02:00
2013-04-27 11:40:05 +02:00
i = MathHelper . d ( this . tracker . getHeadRotation ( ) * 256 . 0F / 360 . 0F ) ;
2012-10-25 05:53:23 +02:00
if ( Math . abs ( i - this . i ) > = 4 ) {
2013-11-04 14:07:38 +01:00
this . broadcast ( new PacketPlayOutEntityHeadRotation ( this . tracker , ( byte ) i ) ) ;
2012-10-25 05:53:23 +02:00
this . i = i ;
}
2013-11-04 14:07:38 +01:00
this . tracker . am = false ;
2011-02-06 00:37:33 +01:00
}
2013-03-13 23:33:27 +01:00
+ + this . m ;
2011-04-20 19:05:14 +02:00
if ( this . tracker . velocityChanged ) {
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Create PlayerVelocity event
2011-07-28 07:17:31 +02:00
boolean cancelled = false ;
2011-11-20 09:01:14 +01:00
if ( this . tracker instanceof EntityPlayer ) {
2012-07-22 08:18:00 +02:00
Player player = ( Player ) this . tracker . getBukkitEntity ( ) ;
2011-07-28 07:17:31 +02:00
org . bukkit . util . Vector velocity = player . getVelocity ( ) ;
2012-07-22 08:18:00 +02:00
PlayerVelocityEvent event = new PlayerVelocityEvent ( player , velocity ) ;
2011-07-28 07:17:31 +02:00
this . tracker . world . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
2011-11-20 09:01:14 +01:00
if ( event . isCancelled ( ) ) {
2011-07-28 07:17:31 +02:00
cancelled = true ;
2011-11-20 09:01:14 +01:00
} else if ( ! velocity . equals ( event . getVelocity ( ) ) ) {
2011-07-28 07:17:31 +02:00
player . setVelocity ( velocity ) ;
}
}
2011-11-20 09:01:14 +01:00
if ( ! cancelled ) {
2013-11-04 14:07:38 +01:00
this . broadcastIncludingSelf ( ( Packet ) ( new PacketPlayOutEntityVelocity ( this . tracker ) ) ) ;
2011-07-28 07:17:31 +02:00
}
// CraftBukkit end
2012-10-25 05:53:23 +02:00
2011-04-20 19:05:14 +02:00
this . tracker . velocityChanged = false ;
2011-02-06 00:37:33 +01:00
}
}
2013-07-01 13:03:00 +02:00
private void b ( ) {
DataWatcher datawatcher = this . tracker . getDataWatcher ( ) ;
if ( datawatcher . a ( ) ) {
2013-11-04 14:07:38 +01:00
this . broadcastIncludingSelf ( new PacketPlayOutEntityMetadata ( this . tracker . getId ( ) , datawatcher , false ) ) ;
2013-07-01 13:03:00 +02:00
}
if ( this . tracker instanceof EntityLiving ) {
2013-11-04 14:07:38 +01:00
AttributeMapServer attributemapserver = ( AttributeMapServer ) ( ( EntityLiving ) this . tracker ) . bc ( ) ;
2013-07-01 13:03:00 +02:00
Set set = attributemapserver . b ( ) ;
if ( ! set . isEmpty ( ) ) {
2013-07-24 04:30:38 +02:00
// CraftBukkit start - Send scaled max health
if ( this . tracker instanceof EntityPlayer ) {
( ( EntityPlayer ) this . tracker ) . getBukkitEntity ( ) . injectScaledMaxHealth ( set , false ) ;
}
// CraftBukkit end
2013-11-04 14:07:38 +01:00
this . broadcastIncludingSelf ( new PacketPlayOutUpdateAttributes ( this . tracker . getId ( ) , set ) ) ;
2013-07-01 13:03:00 +02:00
}
set . clear ( ) ;
}
}
2012-01-14 21:03:48 +01:00
public void broadcast ( Packet packet ) {
2011-04-20 19:05:14 +02:00
Iterator iterator = this . trackedPlayers . iterator ( ) ;
2011-02-06 00:37:33 +01:00
while ( iterator . hasNext ( ) ) {
EntityPlayer entityplayer = ( EntityPlayer ) iterator . next ( ) ;
2012-12-20 05:03:52 +01:00
entityplayer . playerConnection . sendPacket ( packet ) ;
2011-02-06 00:37:33 +01:00
}
}
2012-01-14 21:03:48 +01:00
public void broadcastIncludingSelf ( Packet packet ) {
this . broadcast ( packet ) ;
2011-04-20 19:05:14 +02:00
if ( this . tracker instanceof EntityPlayer ) {
2012-12-20 05:03:52 +01:00
( ( EntityPlayer ) this . tracker ) . playerConnection . sendPacket ( packet ) ;
2011-02-06 00:37:33 +01:00
}
}
public void a ( ) {
2012-07-29 09:33:13 +02:00
Iterator iterator = this . trackedPlayers . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
EntityPlayer entityplayer = ( EntityPlayer ) iterator . next ( ) ;
2013-11-04 14:07:38 +01:00
entityplayer . removeQueue . add ( Integer . valueOf ( this . tracker . getId ( ) ) ) ;
2012-07-29 09:33:13 +02:00
}
2011-02-06 00:37:33 +01:00
}
public void a ( EntityPlayer entityplayer ) {
2011-04-20 19:05:14 +02:00
if ( this . trackedPlayers . contains ( entityplayer ) ) {
2013-11-04 14:07:38 +01:00
entityplayer . removeQueue . add ( Integer . valueOf ( this . tracker . getId ( ) ) ) ;
2011-04-20 19:05:14 +02:00
this . trackedPlayers . remove ( entityplayer ) ;
2011-02-06 00:37:33 +01:00
}
}
2012-02-29 22:31:04 +01:00
public void updatePlayer ( EntityPlayer entityplayer ) {
2011-04-20 19:05:14 +02:00
if ( entityplayer ! = this . tracker ) {
2012-02-29 22:31:04 +01:00
double d0 = entityplayer . locX - ( double ) ( this . xLoc / 32 ) ;
double d1 = entityplayer . locZ - ( double ) ( this . zLoc / 32 ) ;
2011-02-06 00:37:33 +01:00
if ( d0 > = ( double ) ( - this . b ) & & d0 < = ( double ) this . b & & d1 > = ( double ) ( - this . b ) & & d1 < = ( double ) this . b ) {
2013-11-04 14:07:38 +01:00
if ( ! this . trackedPlayers . contains ( entityplayer ) & & ( this . d ( entityplayer ) | | this . tracker . o ) ) {
2012-01-31 20:54:15 +01:00
// CraftBukkit start
2012-10-13 22:27:45 +02:00
if ( this . tracker instanceof EntityPlayer ) {
Player player = ( ( EntityPlayer ) this . tracker ) . getBukkitEntity ( ) ;
2012-01-31 20:54:15 +01:00
if ( ! entityplayer . getBukkitEntity ( ) . canSee ( player ) ) {
return ;
}
}
2012-10-13 22:27:45 +02:00
2013-11-04 14:07:38 +01:00
entityplayer . removeQueue . remove ( Integer . valueOf ( this . tracker . getId ( ) ) ) ;
2012-01-31 20:54:15 +01:00
// CraftBukkit end
2012-10-25 05:53:23 +02:00
2011-04-20 19:05:14 +02:00
this . trackedPlayers . add ( entityplayer ) ;
2013-07-01 13:03:00 +02:00
Packet packet = this . c ( ) ;
2012-07-29 09:33:13 +02:00
2012-12-20 05:03:52 +01:00
entityplayer . playerConnection . sendPacket ( packet ) ;
if ( ! this . tracker . getDataWatcher ( ) . d ( ) ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutEntityMetadata ( this . tracker . getId ( ) , this . tracker . getDataWatcher ( ) , true ) ) ;
2012-10-25 05:53:23 +02:00
}
2013-07-01 13:03:00 +02:00
if ( this . tracker instanceof EntityLiving ) {
2013-11-04 14:07:38 +01:00
AttributeMapServer attributemapserver = ( AttributeMapServer ) ( ( EntityLiving ) this . tracker ) . bc ( ) ;
2013-07-01 13:03:00 +02:00
Collection collection = attributemapserver . c ( ) ;
2013-07-24 04:30:38 +02:00
// CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
2013-11-04 14:07:38 +01:00
if ( this . tracker . getId ( ) = = entityplayer . getId ( ) ) {
2013-07-24 04:30:38 +02:00
( ( EntityPlayer ) this . tracker ) . getBukkitEntity ( ) . injectScaledMaxHealth ( collection , false ) ;
}
// CraftBukkit end
2013-07-01 13:03:00 +02:00
if ( ! collection . isEmpty ( ) ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutUpdateAttributes ( this . tracker . getId ( ) , collection ) ) ;
2013-07-01 13:03:00 +02:00
}
}
2012-07-29 09:33:13 +02:00
this . j = this . tracker . motX ;
this . k = this . tracker . motY ;
this . l = this . tracker . motZ ;
2013-11-04 14:07:38 +01:00
if ( this . u & & ! ( packet instanceof PacketPlayOutSpawnEntityLiving ) ) {
entityplayer . playerConnection . sendPacket ( new PacketPlayOutEntityVelocity ( this . tracker . getId ( ) , this . tracker . motX , this . tracker . motY , this . tracker . motZ ) ) ;
2011-02-06 00:37:33 +01:00
}
2013-08-01 19:12:40 +02:00
if ( this . tracker . vehicle ! = null ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutAttachEntity ( 0 , this . tracker , this . tracker . vehicle ) ) ;
2013-08-01 19:12:40 +02:00
}
2013-08-04 00:03:49 +02:00
// CraftBukkit start
if ( this . tracker . passenger ! = null ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutAttachEntity ( 0 , this . tracker . passenger , this . tracker ) ) ;
2013-08-04 00:03:49 +02:00
}
// CraftBukkit end
2013-09-19 20:25:08 +02:00
if ( this . tracker instanceof EntityInsentient & & ( ( EntityInsentient ) this . tracker ) . getLeashHolder ( ) ! = null ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutAttachEntity ( 1 , this . tracker , ( ( EntityInsentient ) this . tracker ) . getLeashHolder ( ) ) ) ;
2012-07-29 09:33:13 +02:00
}
2012-10-25 05:53:23 +02:00
if ( this . tracker instanceof EntityLiving ) {
for ( int i = 0 ; i < 5 ; + + i ) {
ItemStack itemstack = ( ( EntityLiving ) this . tracker ) . getEquipment ( i ) ;
2011-02-06 00:37:33 +01:00
2012-10-25 05:53:23 +02:00
if ( itemstack ! = null ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutEntityEquipment ( this . tracker . getId ( ) , i , itemstack ) ) ;
2012-10-25 05:53:23 +02:00
}
2011-02-06 00:37:33 +01:00
}
}
2011-05-31 15:55:45 +02:00
if ( this . tracker instanceof EntityHuman ) {
EntityHuman entityhuman = ( EntityHuman ) this . tracker ;
if ( entityhuman . isSleeping ( ) ) {
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutBed ( entityhuman , MathHelper . floor ( this . tracker . locX ) , MathHelper . floor ( this . tracker . locY ) , MathHelper . floor ( this . tracker . locZ ) ) ) ;
2011-05-31 15:55:45 +02:00
}
}
2011-09-15 02:23:52 +02:00
2012-05-13 04:31:17 +02:00
// CraftBukkit start - Fix for nonsensical head yaw
2013-04-27 11:40:05 +02:00
this . i = MathHelper . d ( this . tracker . getHeadRotation ( ) * 256 . 0F / 360 . 0F ) ; // tracker.ao() should be getHeadRotation
2013-11-04 14:07:38 +01:00
this . broadcast ( new PacketPlayOutEntityHeadRotation ( this . tracker , ( byte ) i ) ) ;
2012-05-13 04:31:17 +02:00
// CraftBukkit end
2011-09-15 02:23:52 +02:00
if ( this . tracker instanceof EntityLiving ) {
EntityLiving entityliving = ( EntityLiving ) this . tracker ;
2011-09-24 23:03:31 +02:00
Iterator iterator = entityliving . getEffects ( ) . iterator ( ) ;
2011-09-15 02:23:52 +02:00
while ( iterator . hasNext ( ) ) {
MobEffect mobeffect = ( MobEffect ) iterator . next ( ) ;
2013-11-04 14:07:38 +01:00
entityplayer . playerConnection . sendPacket ( new PacketPlayOutEntityEffect ( this . tracker . getId ( ) , mobeffect ) ) ;
2011-09-15 02:23:52 +02:00
}
}
2011-02-06 00:37:33 +01:00
}
2011-04-20 19:05:14 +02:00
} else if ( this . trackedPlayers . contains ( entityplayer ) ) {
this . trackedPlayers . remove ( entityplayer ) ;
2013-11-04 14:07:38 +01:00
entityplayer . removeQueue . add ( Integer . valueOf ( this . tracker . getId ( ) ) ) ;
2011-02-06 00:37:33 +01:00
}
}
}
2012-07-29 09:33:13 +02:00
private boolean d ( EntityPlayer entityplayer ) {
2013-11-04 14:07:38 +01:00
return entityplayer . r ( ) . getPlayerChunkMap ( ) . a ( entityplayer , this . tracker . ai , this . tracker . ak ) ;
2012-07-29 09:33:13 +02:00
}
2011-04-20 19:05:14 +02:00
public void scanPlayers ( List list ) {
2012-11-06 13:05:28 +01:00
for ( int i = 0 ; i < list . size ( ) ; + + i ) {
this . updatePlayer ( ( EntityPlayer ) list . get ( i ) ) ;
2011-02-06 00:37:33 +01:00
}
}
2013-07-01 13:03:00 +02:00
private Packet c ( ) {
2011-11-20 09:01:14 +01:00
if ( this . tracker . dead ) {
2013-03-25 05:22:32 +01:00
// CraftBukkit start - Remove useless error spam, just return
2013-11-04 14:07:38 +01:00
// p.warn("Fetching addPacket for removed entity");
2012-04-24 19:42:53 +02:00
return null ;
// CraftBukkit end
2011-11-20 09:01:14 +01:00
}
2011-04-20 19:05:14 +02:00
if ( this . tracker instanceof EntityItem ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 2 , 1 ) ;
2011-04-20 19:05:14 +02:00
} else if ( this . tracker instanceof EntityPlayer ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutNamedEntitySpawn ( ( EntityHuman ) this . tracker ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityMinecartAbstract ) {
EntityMinecartAbstract entityminecartabstract = ( EntityMinecartAbstract ) this . tracker ;
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 10 , entityminecartabstract . m ( ) ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityBoat ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 1 ) ;
2013-03-13 23:33:27 +01:00
} else if ( ! ( this . tracker instanceof IAnimal ) & & ! ( this . tracker instanceof EntityEnderDragon ) ) {
if ( this . tracker instanceof EntityFishingHook ) {
EntityHuman entityhuman = ( ( EntityFishingHook ) this . tracker ) . owner ;
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 90 , entityhuman ! = null ? entityhuman . getId ( ) : this . tracker . getId ( ) ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityArrow ) {
Entity entity = ( ( EntityArrow ) this . tracker ) . shooter ;
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 60 , entity ! = null ? entity . getId ( ) : this . tracker . getId ( ) ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntitySnowball ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 61 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityPotion ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 73 , ( ( EntityPotion ) this . tracker ) . getPotionValue ( ) ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityThrownExpBottle ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 75 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityEnderPearl ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 65 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityEnderSignal ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 72 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityFireworks ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 76 ) ;
2013-03-13 23:33:27 +01:00
} else {
2013-11-04 14:07:38 +01:00
PacketPlayOutSpawnEntity packetplayoutspawnentity ;
2011-11-20 09:01:14 +01:00
2013-03-13 23:33:27 +01:00
if ( this . tracker instanceof EntityFireball ) {
EntityFireball entityfireball = ( EntityFireball ) this . tracker ;
2011-11-20 09:01:14 +01:00
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity = null ;
2013-03-13 23:33:27 +01:00
byte b0 = 63 ;
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
if ( this . tracker instanceof EntitySmallFireball ) {
b0 = 64 ;
} else if ( this . tracker instanceof EntityWitherSkull ) {
b0 = 66 ;
}
2011-11-20 09:01:14 +01:00
2013-03-13 23:33:27 +01:00
if ( entityfireball . shooter ! = null ) {
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity = new PacketPlayOutSpawnEntity ( this . tracker , b0 , ( ( EntityFireball ) this . tracker ) . shooter . getId ( ) ) ;
2011-11-20 09:01:14 +01:00
} else {
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity = new PacketPlayOutSpawnEntity ( this . tracker , b0 , 0 ) ;
2011-11-20 09:01:14 +01:00
}
2013-03-13 23:33:27 +01:00
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity . d ( ( int ) ( entityfireball . dirX * 8000 . 0D ) ) ;
packetplayoutspawnentity . e ( ( int ) ( entityfireball . dirY * 8000 . 0D ) ) ;
packetplayoutspawnentity . f ( ( int ) ( entityfireball . dirZ * 8000 . 0D ) ) ;
return packetplayoutspawnentity ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityEgg ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 62 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityTNTPrimed ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 50 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityEnderCrystal ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 51 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityFallingBlock ) {
EntityFallingBlock entityfallingblock = ( EntityFallingBlock ) this . tracker ;
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntity ( this . tracker , 70 , Block . b ( entityfallingblock . f ( ) ) | entityfallingblock . data < < 16 ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityPainting ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntityPainting ( ( EntityPainting ) this . tracker ) ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityItemFrame ) {
EntityItemFrame entityitemframe = ( EntityItemFrame ) this . tracker ;
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity = new PacketPlayOutSpawnEntity ( this . tracker , 71 , entityitemframe . direction ) ;
packetplayoutspawnentity . a ( MathHelper . d ( ( float ) ( entityitemframe . x * 32 ) ) ) ;
packetplayoutspawnentity . b ( MathHelper . d ( ( float ) ( entityitemframe . y * 32 ) ) ) ;
packetplayoutspawnentity . c ( MathHelper . d ( ( float ) ( entityitemframe . z * 32 ) ) ) ;
return packetplayoutspawnentity ;
2013-07-01 13:03:00 +02:00
} else if ( this . tracker instanceof EntityLeash ) {
EntityLeash entityleash = ( EntityLeash ) this . tracker ;
2013-11-04 14:07:38 +01:00
packetplayoutspawnentity = new PacketPlayOutSpawnEntity ( this . tracker , 77 ) ;
packetplayoutspawnentity . a ( MathHelper . d ( ( float ) ( entityleash . x * 32 ) ) ) ;
packetplayoutspawnentity . b ( MathHelper . d ( ( float ) ( entityleash . y * 32 ) ) ) ;
packetplayoutspawnentity . c ( MathHelper . d ( ( float ) ( entityleash . z * 32 ) ) ) ;
return packetplayoutspawnentity ;
2013-03-13 23:33:27 +01:00
} else if ( this . tracker instanceof EntityExperienceOrb ) {
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntityExperienceOrb ( ( EntityExperienceOrb ) this . tracker ) ;
2013-03-13 23:33:27 +01:00
} else {
throw new IllegalArgumentException ( " Don \ 't know how to add " + this . tracker . getClass ( ) + " ! " ) ;
2011-02-06 00:37:33 +01:00
}
}
2013-03-13 23:33:27 +01:00
} else {
2013-04-27 11:40:05 +02:00
this . i = MathHelper . d ( this . tracker . getHeadRotation ( ) * 256 . 0F / 360 . 0F ) ;
2013-11-04 14:07:38 +01:00
return new PacketPlayOutSpawnEntityLiving ( ( EntityLiving ) this . tracker ) ;
2011-02-06 00:37:33 +01:00
}
}
2012-02-29 22:31:04 +01:00
public void clear ( EntityPlayer entityplayer ) {
2011-04-20 19:05:14 +02:00
if ( this . trackedPlayers . contains ( entityplayer ) ) {
this . trackedPlayers . remove ( entityplayer ) ;
2013-11-04 14:07:38 +01:00
entityplayer . removeQueue . add ( Integer . valueOf ( this . tracker . getId ( ) ) ) ;
2011-02-06 00:37:33 +01:00
}
}
}