Skip to content

Commit

Permalink
Merge pull request #208 from Phylogeny/api_null_stacks
Browse files Browse the repository at this point in the history
Fixed ItemStack NPEs by furthering 1.11 port of the API.
  • Loading branch information
AlgorithmX2 committed Dec 24, 2016
2 parents 918ee73 + b4d18b5 commit 3f165c7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ public class EventBlockBitModification extends Event
private final BlockPos pos;
private final EntityPlayer player;
private final EnumHand hand;
private final ItemStack itemUsed;
private final ItemStack stackUsed;
private final boolean placement;

public EventBlockBitModification(
final World w,
final BlockPos pos,
final EntityPlayer player,
final EnumHand hand,
final ItemStack itemUsed,
final ItemStack stackUsed,
final boolean placement )
{

this.w = w;
this.pos = pos;
this.player = player;
this.hand = hand;
this.itemUsed = itemUsed;
this.stackUsed = stackUsed;
this.placement = placement;
}

Expand All @@ -58,7 +58,7 @@ public EnumHand getHand()

public ItemStack getItemUsed()
{
return itemUsed;
return stackUsed;
}

public boolean isPlacing()
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/mod/chiselsandbits/api/IBitAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void commitChanges(
void commitChanges();

/**
* Returns an item for the {@link IBitAccess}
* Returns an ItemStack for the {@link IBitAccess}
*
* Usable for any {@link IBitAccess}
*
Expand All @@ -94,19 +94,19 @@ void commitChanges(
* @param type
* what type of item to give.
* @param crossWorld
* determines if the NBT for the item is specific to this world
* determines if the NBT for the ItemStack is specific to this world
* or if it is portable, cross world NBT is larger and slower,
* you should only request cross world NBT if you specifically
* need it.
* @return an Item for bits, null if there are no bits.
* @return an ItemStack for bits, which is empty if there are no bits.
*/
ItemStack getBitsAsItem(
EnumFacing side,
ItemType type,
boolean crossWorld );

/**
* Returns an item for the {@link IBitAccess}, this method all ways returns
* Returns an ItemStack for the {@link IBitAccess}, this method all ways returns
* non-cross world NBT, please move to the above method and specify false to
* prepare for future removal.
*
Expand All @@ -116,7 +116,7 @@ ItemStack getBitsAsItem(
* angle the player is looking at, can be null.
* @param type
* what type of item to give.
* @return an Item for bits, null if there are no bits.
* @return an ItemStack for bits, which is empty if there are no bits.
*/
@Deprecated
ItemStack getBitsAsItem(
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/mod/chiselsandbits/api/IBitBrush.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ public interface IBitBrush
IBlockState getState();

/**
* Get the ItemStack for a bit, returns null for air.
* Get the ItemStack for a bit, which is empty for air.
*
* VERY IMPORTANT: C&B lets you disable bits, if this happens the Item in
* this ItemStack WILL BE NULL, if you put this item in an inventory, drop
* this ItemStack WILL BE NULL, if you put this ItemStack in an inventory, drop
* it on the ground, or anything else.. CHECK THIS!!!!!
*
* @param count
* @return ItemStack, or null for air.
* @return ItemStack, which is empty for air.
*/
@Nullable
ItemStack getItemStack(
int count );

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public interface IChiselAndBitsAPI
{

/**
* Determine the Item Type and return it.
* Determine the Item Type of the item in an ItemStack and return it.
*
* @param item
* @param stack
* @return ItemType of the item, or null if it is not any of them.
*/
ItemType getItemType(
ItemStack item );
ItemStack stack );

/**
* Check if a block can support {@link IBitAccess}
Expand Down Expand Up @@ -65,24 +65,24 @@ 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 ItemStack, passing an empty ItemStack creates an empty bit access,
* passing an invalid item returns null.
*
* @return a {@link IBitAccess} for an item.
* @return a {@link IBitAccess} for an ItemStack.
*/
IBitAccess createBitItem(
ItemStack BitItemStack );
ItemStack stack );

/**
* Create a brush from an item, once created you can use it many times.
* Create a brush from an ItemStack, 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 ItemStack, if passed an empty ItemStack an
* air brush is created.
* @throws InvalidBitItem
*/
IBitBrush createBrush(
ItemStack bitItem ) throws InvalidBitItem;
ItemStack stack ) throws InvalidBitItem;

/**
* Create a brush from a state, once created you can use it many times.
Expand Down Expand Up @@ -135,7 +135,7 @@ ItemStack getBitItem(
*
* CLIENT: destroys the item.
*
* SERVER: adds item to inv/bag/spawns entity.
* SERVER: adds ItemStack to inv/bag/spawns entity.
*
* @param player
* player to give bits to.
Expand All @@ -148,7 +148,7 @@ ItemStack getBitItem(
*/
void giveBitToPlayer(
EntityPlayer player,
ItemStack itemstack,
ItemStack stack,
Vec3d spawnPos );

/**
Expand All @@ -158,7 +158,7 @@ void giveBitToPlayer(
* @return internal object to manipulate bag.
*/
IBitBag getBitbag(
ItemStack itemstack );
ItemStack stack );

/**
* Begins an undo operation, starting two operations without ending the
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/mod/chiselsandbits/core/api/BitAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public ItemStack getBitsAsItem(
{
if ( type == null )
{
return null;
return ModUtil.getEmptyStack();
}

final BlobStats cb = blob.getVoxelStats();
if ( cb.mostCommonState == 0 )
{
return null;
return ModUtil.getEmptyStack();
}

final NBTBlobConverter c = new NBTBlobConverter();
Expand All @@ -155,7 +155,7 @@ public ItemStack getBitsAsItem(
final NBTTagCompound nbttagcompound = new NBTTagCompound();
c.writeChisleData( nbttagcompound, crossWorld );

final ItemStack itemstack;
final ItemStack stack;

if ( type == ItemType.CHISLED_BLOCK )
{
Expand All @@ -164,38 +164,38 @@ public ItemStack getBitsAsItem(

if ( blk == null )
{
return null;
return ModUtil.getEmptyStack();
}

itemstack = new ItemStack( blk, 1 );
itemstack.setTagInfo( ModUtil.NBT_BLOCKENTITYTAG, nbttagcompound );
stack = new ItemStack( blk, 1 );
stack.setTagInfo( ModUtil.NBT_BLOCKENTITYTAG, nbttagcompound );
}
else
{
switch ( type )
{
case MIRROR_DESIGN:
itemstack = new ItemStack( ChiselsAndBits.getItems().itemMirrorprint );
stack = new ItemStack( ChiselsAndBits.getItems().itemMirrorprint );
break;
case NEGATIVE_DESIGN:
itemstack = new ItemStack( ChiselsAndBits.getItems().itemNegativeprint );
stack = new ItemStack( ChiselsAndBits.getItems().itemNegativeprint );
break;
case POSITIVE_DESIGN:
itemstack = new ItemStack( ChiselsAndBits.getItems().itemPositiveprint );
stack = new ItemStack( ChiselsAndBits.getItems().itemPositiveprint );
break;
default:
return null;
return ModUtil.getEmptyStack();
}

itemstack.setTagCompound( nbttagcompound );
stack.setTagCompound( nbttagcompound );
}

if ( side != null )
{
ModUtil.setSide( itemstack, side );
ModUtil.setSide( stack, side );
}

return itemstack;
return stack;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mod/chiselsandbits/core/api/BitBrush.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public BitBrush(
}

@Override
public @Nullable ItemStack getItemStack(
public ItemStack getItemStack(
final int count )
{
if ( stateID == 0 )
{
return null;
return ModUtil.getEmptyStack();
}

return ItemChiseledBit.createStack( stateID, count, true );
Expand Down

0 comments on commit 3f165c7

Please sign in to comment.