2012-11-13 23:23:04 -06:00
package net.minecraft.server ;
import java.util.ArrayList ;
import java.util.Iterator ;
2014-06-19 14:38:45 -04:00
import org.bukkit.craftbukkit.event.CraftEventFactory ; // CraftBukkit
2012-11-18 18:48:21 -06:00
2012-11-13 23:23:04 -06:00
public class EntityFallingBlock extends Entity {
2013-11-04 07:07:38 -06:00
public Block id ; // CraftBukkit - private -> public
2012-11-13 23:23:04 -06:00
public int data ;
2013-11-04 07:07:38 -06:00
public int b ;
2012-11-13 23:23:04 -06:00
public boolean dropItem ;
2013-03-13 17:33:27 -05:00
private boolean f ;
2012-11-13 23:23:04 -06:00
private boolean hurtEntities ;
private int fallHurtMax ;
private float fallHurtAmount ;
2013-03-13 17:33:27 -05:00
public NBTTagCompound tileEntityData ;
2012-11-13 23:23:04 -06:00
public EntityFallingBlock ( World world ) {
super ( world ) ;
this . dropItem = true ;
2012-12-19 22:03:52 -06:00
this . fallHurtMax = 40 ;
2012-11-13 23:23:04 -06:00
this . fallHurtAmount = 2 . 0F ;
}
2013-11-04 07:07:38 -06:00
public EntityFallingBlock ( World world , double d0 , double d1 , double d2 , Block block ) {
this ( world , d0 , d1 , d2 , block , 0 ) ;
2012-11-13 23:23:04 -06:00
}
2013-11-04 07:07:38 -06:00
public EntityFallingBlock ( World world , double d0 , double d1 , double d2 , Block block , int i ) {
2012-11-13 23:23:04 -06:00
super ( world ) ;
this . dropItem = true ;
2012-12-19 22:03:52 -06:00
this . fallHurtMax = 40 ;
2012-11-13 23:23:04 -06:00
this . fallHurtAmount = 2 . 0F ;
2013-11-04 07:07:38 -06:00
this . id = block ;
this . data = i ;
2014-03-20 22:26:30 -06:00
this . k = true ;
2012-11-13 23:23:04 -06:00
this . a ( 0 . 98F , 0 . 98F ) ;
this . height = this . length / 2 . 0F ;
this . setPosition ( d0 , d1 , d2 ) ;
this . motX = 0 . 0D ;
this . motY = 0 . 0D ;
this . motZ = 0 . 0D ;
this . lastX = d0 ;
this . lastY = d1 ;
this . lastZ = d2 ;
}
2013-11-04 07:07:38 -06:00
protected boolean g_ ( ) {
2012-11-13 23:23:04 -06:00
return false ;
}
2013-11-04 07:07:38 -06:00
protected void c ( ) { }
2012-11-13 23:23:04 -06:00
2014-03-20 22:26:30 -06:00
public boolean Q ( ) {
2012-11-13 23:23:04 -06:00
return ! this . dead ;
}
2013-11-04 07:07:38 -06:00
public void h ( ) {
if ( this . id . getMaterial ( ) = = Material . AIR ) {
2012-11-13 23:23:04 -06:00
this . die ( ) ;
} else {
this . lastX = this . locX ;
this . lastY = this . locY ;
this . lastZ = this . locZ ;
2013-11-04 07:07:38 -06:00
+ + this . b ;
2012-11-13 23:23:04 -06:00
this . motY - = 0 . 03999999910593033D ;
this . move ( this . motX , this . motY , this . motZ ) ;
this . motX * = 0 . 9800000190734863D ;
this . motY * = 0 . 9800000190734863D ;
this . motZ * = 0 . 9800000190734863D ;
if ( ! this . world . isStatic ) {
int i = MathHelper . floor ( this . locX ) ;
int j = MathHelper . floor ( this . locY ) ;
int k = MathHelper . floor ( this . locZ ) ;
2013-11-04 07:07:38 -06:00
if ( this . b = = 1 ) {
2012-12-19 22:03:52 -06:00
// CraftBukkit - compare data and call event
2013-11-04 07:07:38 -06:00
if ( this . b ! = 1 | | this . world . getType ( i , j , k ) ! = this . id | | this . world . getData ( i , j , k ) ! = this . data | | CraftEventFactory . callEntityChangeBlockEvent ( this , i , j , k , Blocks . AIR , 0 ) . isCancelled ( ) ) {
2012-11-13 23:23:04 -06:00
this . die ( ) ;
2012-12-19 22:03:52 -06:00
return ;
2012-11-13 23:23:04 -06:00
}
2012-12-19 22:03:52 -06:00
2013-03-13 17:33:27 -05:00
this . world . setAir ( i , j , k ) ;
2012-11-13 23:23:04 -06:00
}
if ( this . onGround ) {
this . motX * = 0 . 699999988079071D ;
this . motZ * = 0 . 699999988079071D ;
this . motY * = - 0 . 5D ;
2013-11-04 07:07:38 -06:00
if ( this . world . getType ( i , j , k ) ! = Blocks . PISTON_MOVING ) {
2012-11-13 23:23:04 -06:00
this . die ( ) ;
2014-03-20 22:26:30 -06:00
// CraftBukkit start - fire EntityChangeBlockEvent
2013-11-04 07:07:38 -06:00
if ( ! this . f & & this . world . mayPlace ( this . id , i , j , k , true , 1 , ( Entity ) null , ( ItemStack ) null ) & & ! BlockFalling . canFall ( this . world , i , j - 1 , k ) /* mimic the false conditions of setTypeIdAndData */ & & i > = - 30000000 & & k > = - 30000000 & & i < 30000000 & & k < 30000000 & & j > 0 & & j < 256 & & ! ( this . world . getType ( i , j , k ) = = this . id & & this . world . getData ( i , j , k ) = = this . data ) ) {
2012-12-04 18:30:10 -06:00
if ( CraftEventFactory . callEntityChangeBlockEvent ( this , i , j , k , this . id , this . data ) . isCancelled ( ) ) {
return ;
}
2013-11-04 07:07:38 -06:00
this . world . setTypeAndData ( i , j , k , this . id , this . data , 3 ) ;
2012-12-04 18:30:10 -06:00
// CraftBukkit end
2013-03-13 17:33:27 -05:00
2013-11-04 07:07:38 -06:00
if ( this . id instanceof BlockFalling ) {
( ( BlockFalling ) this . id ) . a ( this . world , i , j , k , this . data ) ;
2012-11-13 23:23:04 -06:00
}
2013-03-13 17:33:27 -05:00
2013-11-04 07:07:38 -06:00
if ( this . tileEntityData ! = null & & this . id instanceof IContainer ) {
2013-03-13 17:33:27 -05:00
TileEntity tileentity = this . world . getTileEntity ( i , j , k ) ;
if ( tileentity ! = null ) {
NBTTagCompound nbttagcompound = new NBTTagCompound ( ) ;
tileentity . b ( nbttagcompound ) ;
Iterator iterator = this . tileEntityData . c ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
2013-11-04 07:07:38 -06:00
String s = ( String ) iterator . next ( ) ;
NBTBase nbtbase = this . tileEntityData . get ( s ) ;
2013-03-13 17:33:27 -05:00
2013-11-04 07:07:38 -06:00
if ( ! s . equals ( " x " ) & & ! s . equals ( " y " ) & & ! s . equals ( " z " ) ) {
nbttagcompound . set ( s , nbtbase . clone ( ) ) ;
2013-03-13 17:33:27 -05:00
}
}
tileentity . a ( nbttagcompound ) ;
tileentity . update ( ) ;
}
}
} else if ( this . dropItem & & ! this . f ) {
2013-11-04 07:07:38 -06:00
this . a ( new ItemStack ( this . id , 1 , this . id . getDropData ( this . data ) ) , 0 . 0F ) ;
2012-11-13 23:23:04 -06:00
}
}
2013-11-04 07:07:38 -06:00
} else if ( this . b > 100 & & ! this . world . isStatic & & ( j < 1 | | j > 256 ) | | this . b > 600 ) {
2012-11-13 23:23:04 -06:00
if ( this . dropItem ) {
2013-11-04 07:07:38 -06:00
this . a ( new ItemStack ( this . id , 1 , this . id . getDropData ( this . data ) ) , 0 . 0F ) ;
2012-11-13 23:23:04 -06:00
}
this . die ( ) ;
}
}
}
}
2013-07-01 06:03:00 -05:00
protected void b ( float f ) {
2012-11-13 23:23:04 -06:00
if ( this . hurtEntities ) {
int i = MathHelper . f ( f - 1 . 0F ) ;
if ( i > 0 ) {
ArrayList arraylist = new ArrayList ( this . world . getEntities ( this , this . boundingBox ) ) ;
2013-11-04 07:07:38 -06:00
boolean flag = this . id = = Blocks . ANVIL ;
DamageSource damagesource = flag ? DamageSource . ANVIL : DamageSource . FALLING_BLOCK ;
2012-11-13 23:23:04 -06:00
Iterator iterator = arraylist . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Entity entity = ( Entity ) iterator . next ( ) ;
2014-06-19 14:38:45 -04:00
CraftEventFactory . entityDamage = this ; // CraftBukkit
entity . damageEntity ( damagesource , ( float ) Math . min ( MathHelper . d ( ( float ) i * this . fallHurtAmount ) , this . fallHurtMax ) ) ;
CraftEventFactory . entityDamage = null ; // CraftBukkit
2012-11-13 23:23:04 -06:00
}
2013-11-04 07:07:38 -06:00
if ( flag & & ( double ) this . random . nextFloat ( ) < 0 . 05000000074505806D + ( double ) i * 0 . 05D ) {
2012-11-13 23:23:04 -06:00
int j = this . data > > 2 ;
int k = this . data & 3 ;
+ + j ;
if ( j > 2 ) {
2013-03-13 17:33:27 -05:00
this . f = true ;
2012-11-13 23:23:04 -06:00
} else {
this . data = k | j < < 2 ;
}
}
}
}
}
protected void b ( NBTTagCompound nbttagcompound ) {
2013-11-04 07:07:38 -06:00
nbttagcompound . setByte ( " Tile " , ( byte ) Block . b ( this . id ) ) ;
nbttagcompound . setInt ( " TileID " , Block . b ( this . id ) ) ;
2012-11-13 23:23:04 -06:00
nbttagcompound . setByte ( " Data " , ( byte ) this . data ) ;
2013-11-04 07:07:38 -06:00
nbttagcompound . setByte ( " Time " , ( byte ) this . b ) ;
2012-11-13 23:23:04 -06:00
nbttagcompound . setBoolean ( " DropItem " , this . dropItem ) ;
nbttagcompound . setBoolean ( " HurtEntities " , this . hurtEntities ) ;
nbttagcompound . setFloat ( " FallHurtAmount " , this . fallHurtAmount ) ;
nbttagcompound . setInt ( " FallHurtMax " , this . fallHurtMax ) ;
2013-01-01 23:17:38 -06:00
if ( this . tileEntityData ! = null ) {
2013-11-04 07:07:38 -06:00
nbttagcompound . set ( " TileEntityData " , this . tileEntityData ) ;
2013-01-01 23:17:38 -06:00
}
2012-11-13 23:23:04 -06:00
}
protected void a ( NBTTagCompound nbttagcompound ) {
2013-11-04 07:07:38 -06:00
if ( nbttagcompound . hasKeyOfType ( " TileID " , 99 ) ) {
this . id = Block . e ( nbttagcompound . getInt ( " TileID " ) ) ;
2013-03-13 17:33:27 -05:00
} else {
2013-11-04 07:07:38 -06:00
this . id = Block . e ( nbttagcompound . getByte ( " Tile " ) & 255 ) ;
2013-03-13 17:33:27 -05:00
}
2012-11-13 23:23:04 -06:00
this . data = nbttagcompound . getByte ( " Data " ) & 255 ;
2013-11-04 07:07:38 -06:00
this . b = nbttagcompound . getByte ( " Time " ) & 255 ;
if ( nbttagcompound . hasKeyOfType ( " HurtEntities " , 99 ) ) {
2012-11-13 23:23:04 -06:00
this . hurtEntities = nbttagcompound . getBoolean ( " HurtEntities " ) ;
this . fallHurtAmount = nbttagcompound . getFloat ( " FallHurtAmount " ) ;
this . fallHurtMax = nbttagcompound . getInt ( " FallHurtMax " ) ;
2013-11-04 07:07:38 -06:00
} else if ( this . id = = Blocks . ANVIL ) {
2012-11-13 23:23:04 -06:00
this . hurtEntities = true ;
}
2013-11-04 07:07:38 -06:00
if ( nbttagcompound . hasKeyOfType ( " DropItem " , 99 ) ) {
2013-03-13 17:33:27 -05:00
this . dropItem = nbttagcompound . getBoolean ( " DropItem " ) ;
}
2013-11-04 07:07:38 -06:00
if ( nbttagcompound . hasKeyOfType ( " TileEntityData " , 10 ) ) {
2013-03-13 17:33:27 -05:00
this . tileEntityData = nbttagcompound . getCompound ( " TileEntityData " ) ;
}
2013-11-04 07:07:38 -06:00
if ( this . id . getMaterial ( ) = = Material . AIR ) {
this . id = Blocks . SAND ;
2012-11-13 23:23:04 -06:00
}
}
2013-03-13 17:33:27 -05:00
public void a ( boolean flag ) {
2012-11-13 23:23:04 -06:00
this . hurtEntities = flag ;
}
2012-12-19 22:03:52 -06:00
public void a ( CrashReportSystemDetails crashreportsystemdetails ) {
super . a ( crashreportsystemdetails ) ;
2013-11-04 07:07:38 -06:00
crashreportsystemdetails . a ( " Immitating block ID " , Integer . valueOf ( Block . b ( this . id ) ) ) ;
2012-12-19 22:03:52 -06:00
crashreportsystemdetails . a ( " Immitating block data " , Integer . valueOf ( this . data ) ) ;
}
2013-11-04 07:07:38 -06:00
public Block f ( ) {
return this . id ;
}
2012-11-13 23:23:04 -06:00
}