Skip to content

Commit

Permalink
Changed all remaining dealings with null ItemStacks in the API to ins…
Browse files Browse the repository at this point in the history
…tead deal with empty ones, and updated the method descriptions accordingly.
  • Loading branch information
Phylogeny committed Dec 24, 2016
1 parent 8f6a7db commit 9a5d94b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java
Expand Up @@ -65,7 +65,7 @@ IBitAccess getBitAccess(
BlockPos pos ) throws CannotBeChiseled;

/**
* Create a bit access from an item, passing null creates an empty item,
* Create a bit access from an item, passing an empty ItemStack creates an empty bit access,
* passing an invalid item returns null.
*
* @return a {@link IBitAccess} for an item.
Expand All @@ -77,7 +77,7 @@ IBitAccess createBitItem(
* Create a brush from an item, once created you can use it many times.
*
* @param bitItem
* @return A brush for the specified item, if null is passed for the item an
* @return A brush for the specified item, if passed an empty ItemStack an
* air brush is created.
* @throws InvalidBitItem
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mod/chiselsandbits/core/api/BitAccess.java
Expand Up @@ -184,7 +184,7 @@ public ItemStack getBitsAsItem(
itemstack = new ItemStack( ChiselsAndBits.getItems().itemPositiveprint );
break;
default:
return null;
return ModUtil.getEmptyStack();
}

itemstack.setTagCompound( nbttagcompound );
Expand Down
60 changes: 31 additions & 29 deletions src/main/java/mod/chiselsandbits/core/api/ChiselAndBitsAPI.java
Expand Up @@ -118,7 +118,7 @@ public IBitAccess getBitAccess(
public IBitBrush createBrush(
final ItemStack bitItem ) throws InvalidBitItem
{
if ( bitItem == null )
if ( ModUtil.isEmpty(bitItem) )
{
return new BitBrush( 0 );
}
Expand Down Expand Up @@ -159,42 +159,42 @@ public IBitLocation getBitPos(
public ItemType getItemType(
final ItemStack item )
{
if ( item != null && item.getItem() instanceof ItemChiseledBit )
if ( item.getItem() instanceof ItemChiseledBit )
{
return ItemType.CHISLED_BIT;
}

if ( item != null && item.getItem() instanceof ItemBitBag )
if ( item.getItem() instanceof ItemBitBag )
{
return ItemType.BIT_BAG;
}

if ( item != null && item.getItem() instanceof ItemChisel )
if ( item.getItem() instanceof ItemChisel )
{
return ItemType.CHISEL;
}

if ( item != null && item.getItem() instanceof ItemBlockChiseled )
if ( item.getItem() instanceof ItemBlockChiseled )
{
return ItemType.CHISLED_BLOCK;
}

if ( item != null && item.getItem() instanceof ItemMirrorPrint )
if ( item.getItem() instanceof ItemMirrorPrint )
{
return ItemType.MIRROR_DESIGN;
}

if ( item != null && item.getItem() instanceof ItemPositivePrint )
if ( item.getItem() instanceof ItemPositivePrint )
{
return ItemType.POSITIVE_DESIGN;
}

if ( item != null && item.getItem() instanceof ItemNegativePrint )
if ( item.getItem() instanceof ItemNegativePrint )
{
return ItemType.NEGATIVE_DESIGN;
}

if ( item != null && item.getItem() instanceof ItemWrench )
if ( item.getItem() instanceof ItemWrench )
{
return ItemType.WRENCH;
}
Expand All @@ -206,7 +206,7 @@ public ItemType getItemType(
public IBitAccess createBitItem(
final ItemStack bitItemStack )
{
if ( bitItemStack == null )
if ( ModUtil.isEmpty(bitItemStack) )
{
return new BitAccess( null, null, new VoxelBlob(), VoxelBlob.NULL_BLOB );
}
Expand Down Expand Up @@ -268,38 +268,40 @@ public void giveBitToPlayer(
final ItemStack is,
Vec3d spawnPos )
{
if ( is != null )
if ( ModUtil.isEmpty(is) )
{
if ( spawnPos == null )
{
spawnPos = new Vec3d( player.posX, player.posY, player.posZ );
}
return;
}

final EntityItem ei = new EntityItem( player.getEntityWorld(), spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord, is );
if ( spawnPos == null )
{
spawnPos = new Vec3d( player.posX, player.posY, player.posZ );
}

if ( is.getItem() == ChiselsAndBits.getItems().itemBlockBit )
{
if ( player.getEntityWorld().isRemote )
{
return;
}
final EntityItem ei = new EntityItem( player.getEntityWorld(), spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord, is );

ModUtil.feedPlayer( player.getEntityWorld(), player, ei );
return;
}
else if ( !player.inventory.addItemStackToInventory( is ) )
if ( is.getItem() == ChiselsAndBits.getItems().itemBlockBit )
{
if ( player.getEntityWorld().isRemote )
{
ei.setEntityItemStack( is );
player.getEntityWorld().spawnEntityInWorld( ei );
return;
}

ModUtil.feedPlayer( player.getEntityWorld(), player, ei );
return;
}
else if ( !player.inventory.addItemStackToInventory( is ) )
{
ei.setEntityItemStack( is );
player.getEntityWorld().spawnEntityInWorld( ei );
}
}

@Override
public IBitBag getBitbag(
final ItemStack itemstack )
{
if ( itemstack != null )
if ( !ModUtil.isEmpty(itemstack) )
{
final Object o = itemstack.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP );
if ( o instanceof IBitBag )
Expand Down

0 comments on commit 9a5d94b

Please sign in to comment.