Skip to content

Commit

Permalink
Defer Naming of BitBag Items to ItemChiseledBit ( resolves #128 )
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Aug 13, 2016
1 parent 9d85fa0 commit ffddb40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
38 changes: 13 additions & 25 deletions src/main/java/mod/chiselsandbits/bitbag/BagInventory.java
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -350,7 +349,6 @@ public List<String> listContents(
for ( int x = 0; x < getSizeInventory(); x++ )
{
final ItemStack is = getStackInSlot( x );

if ( is != null )
{
final IBlockState state = Block.getStateById( ItemChiseledBit.getStackState( is ) );
Expand All @@ -359,32 +357,22 @@ public List<String> listContents(
continue;
}

final Block blk = state.getBlock();
if ( blk == null )
{
continue;
}
final String name = ItemChiseledBit.getBitStateName( state );

final Item what = Item.getItemFromBlock( blk );
if ( what == null )
if ( name != null )
{
continue;
Integer count = contents.get( name );
if ( count == null )
{
count = is.stackSize;
}
else
{
count += is.stackSize;
}

contents.put( name, count );
}

final ItemChiseledBit bit = ChiselsAndBits.getItems().itemBlockBit;
final String name = bit.getBitTypeName( is );

Integer count = contents.get( name );
if ( count == null )
{
count = is.stackSize;
}
else
{
count += is.stackSize;
}

contents.put( name, count );
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/main/java/mod/chiselsandbits/items/ItemChiseledBit.java
Expand Up @@ -101,18 +101,21 @@ public boolean onBlockStartBreak(
return ItemChisel.fromBreakToChisel( ChiselMode.castMode( ChiselModeManager.getChiselMode( player, ChiselToolType.BIT, EnumHand.MAIN_HAND ) ), itemstack, pos, player, EnumHand.MAIN_HAND );
}

public String getBitTypeName(
final ItemStack stack )
public static String getBitStateName(
final IBlockState state )
{
ItemStack target = null;
IBlockState state = null;
Block blk = null;

if ( state == null )
{
return "Null";
}

try
{
// for an unknown reason its possible to generate mod blocks without
// proper state here...
state = Block.getStateById( ItemChiseledBit.getStackState( stack ) );
blk = state.getBlock();

final Item item = Item.getItemFromBlock( blk );
Expand Down Expand Up @@ -175,6 +178,12 @@ public String getBitTypeName(
}
}

public static String getBitTypeName(
final ItemStack stack )
{
return getBitStateName( Block.getStateById( ItemChiseledBit.getStackState( stack ) ) );
}

@Override
public String getItemStackDisplayName(
final ItemStack stack )
Expand Down

0 comments on commit ffddb40

Please sign in to comment.