Fixes #1728 Mark the entity as dead before spawning overflow

This commit is contained in:
yueh 2015-07-21 17:37:49 +02:00 committed by thatsIch
parent 33e2eb5a74
commit 432724623e

View file

@ -273,8 +273,12 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
if( capture ) if( capture )
{ {
ServerHelper.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, this.tile.getWorld(), new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, this.side, false ) ); final boolean changed = this.storeEntityItem( (EntityItem) entity );
this.storeEntityItem( (EntityItem) entity );
if( changed )
{
ServerHelper.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, this.tile.getWorld(), new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, this.side, false ) );
}
} }
} }
} }
@ -290,21 +294,25 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
* *
* @param entityItem {@link EntityItem} to store * @param entityItem {@link EntityItem} to store
*/ */
private void storeEntityItem( EntityItem entityItem ) private boolean storeEntityItem( EntityItem entityItem )
{ {
if( !entityItem.isDead ) if( !entityItem.isDead )
{ {
this.storeItemStack( entityItem.getEntityItem() ); final IAEItemStack overflow = this.storeItemStack( entityItem.getEntityItem() );
entityItem.setDead();
return this.handleOverflow( entityItem, overflow );
} }
return false;
} }
/** /**
* Stores an {@link ItemStack} inside the network. * Stores an {@link ItemStack} inside the network.
* *
* @param item {@link ItemStack} to store * @param item {@link ItemStack} to store
* @return the leftover items, which could not be stored inside the network
*/ */
private void storeItemStack( ItemStack item ) private IAEItemStack storeItemStack( ItemStack item )
{ {
final IAEItemStack itemToStore = AEItemStack.create( item ); final IAEItemStack itemToStore = AEItemStack.create( item );
try try
@ -313,28 +321,43 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
final IEnergyGrid energy = this.proxy.getEnergy(); final IEnergyGrid energy = this.proxy.getEnergy();
final IAEItemStack overflow = Platform.poweredInsert( energy, storage.getItemInventory(), itemToStore, this.mySrc ); final IAEItemStack overflow = Platform.poweredInsert( energy, storage.getItemInventory(), itemToStore, this.mySrc );
this.spawnOverflowItemStack( overflow );
this.isAccepting = overflow == null; this.isAccepting = overflow == null;
return overflow;
} }
catch( final GridAccessException e1 ) catch( final GridAccessException e1 )
{ {
// :P // :P
} }
return null;
} }
private void spawnOverflowItemStack( IAEItemStack overflow ) /**
* Handles a possible overflow or none at all.
* It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
* amount.
*
* @param entityItem the entity to update or destroy
* @param overflow the leftover {@link IAEItemStack}
* @return true, if the entity was changed otherwise false.
*/
private boolean handleOverflow( EntityItem entityItem, IAEItemStack overflow )
{ {
if( overflow == null ) if( overflow == null || overflow.getStackSize() == 0 )
{ {
return; entityItem.setDead();
return true;
} }
final TileEntity tileEntity = this.getTile(); final int oldStackSize = entityItem.getEntityItem().stackSize;
final WorldServer world = (WorldServer) tileEntity.getWorld(); final int newStackSize = (int) overflow.getStackSize();
final boolean changed = oldStackSize != newStackSize;
entityItem.getEntityItem().stackSize = newStackSize;
return changed;
BlockPos pos = tileEntity.getPos().offset( side.getFacing() );
Platform.spawnDrops( world, pos, Lists.newArrayList( overflow.getItemStack() ) );
} }
protected boolean isAnnihilationPlane( TileEntity blockTileEntity, AEPartLocation side ) protected boolean isAnnihilationPlane( TileEntity blockTileEntity, AEPartLocation side )