Skip to content

Commit

Permalink
Removed Deprecated API methods.
Browse files Browse the repository at this point in the history
Added @MethodsReturnNonnullByDefault and @ParametersAreNonnullByDefault to API.
Several other null fixes, and minor tweaks to help clean up null warnings.
  • Loading branch information
AlgorithmX2 committed Dec 24, 2016
1 parent 3f165c7 commit cbb4e57
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 151 deletions.
40 changes: 7 additions & 33 deletions src/main/java/mod/chiselsandbits/api/IBitAccess.java
@@ -1,5 +1,7 @@
package mod.chiselsandbits.api;

import javax.annotation.Nullable;

import mod.chiselsandbits.api.APIExceptions.SpaceOccupied;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -74,16 +76,6 @@ void setBitAt(
void commitChanges(
boolean triggerUpdates );

/**
* Any time you modify a block you must commit your changes for them to take
* affect, please move to above method and specify true to prepare for
* future removal.
*
* If the {@link IBitAccess} is not in the world this method does nothing.
*/
@Deprecated
void commitChanges();

/**
* Returns an ItemStack for the {@link IBitAccess}
*
Expand All @@ -94,33 +86,15 @@ void commitChanges(
* @param type
* what type of item to give.
* @param crossWorld
* 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.
* 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 ItemStack for bits, which is empty if there are no bits.
*/
ItemStack getBitsAsItem(
EnumFacing side,
@Nullable EnumFacing side,
ItemType type,
boolean crossWorld );

/**
* 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.
*
* Usable for any {@link IBitAccess}
*
* @param side
* angle the player is looking at, can be null.
* @param type
* what type of item to give.
* @return an ItemStack for bits, which is empty if there are no bits.
*/
@Deprecated
ItemStack getBitsAsItem(
EnumFacing side,
ItemType type );

}
43 changes: 21 additions & 22 deletions src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java
@@ -1,5 +1,7 @@
package mod.chiselsandbits.api;

import javax.annotation.Nullable;

import mod.chiselsandbits.api.APIExceptions.CannotBeChiseled;
import mod.chiselsandbits.api.APIExceptions.InvalidBitItem;
import net.minecraft.block.material.Material;
Expand All @@ -24,6 +26,7 @@ public interface IChiselAndBitsAPI
* @param stack
* @return ItemType of the item, or null if it is not any of them.
*/
@Nullable
ItemType getItemType(
ItemStack stack );

Expand Down Expand Up @@ -65,20 +68,21 @@ IBitAccess getBitAccess(
BlockPos pos ) throws CannotBeChiseled;

/**
* Create a bit access from an ItemStack, passing an empty ItemStack creates an empty bit access,
* passing an invalid item returns null.
* 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 ItemStack.
*/
@Nullable
IBitAccess createBitItem(
ItemStack stack );

/**
* Create a brush from an ItemStack, once created you can use it many times.
*
* @param bitItem
* @return A brush for the specified ItemStack, if passed an empty ItemStack an
* air brush is created.
* @return A brush for the specified ItemStack, if passed an empty ItemStack
* an air brush is created.
* @throws InvalidBitItem
*/
IBitBrush createBrush(
Expand All @@ -93,7 +97,7 @@ IBitBrush createBrush(
* @throws InvalidBitItem
*/
IBitBrush createBrushFromState(
IBlockState state ) throws InvalidBitItem;
@Nullable IBlockState state ) throws InvalidBitItem;

/**
* Convert ray trace information into bit location information, note that
Expand All @@ -105,8 +109,7 @@ IBitBrush createBrushFromState(
* @param side
* @param pos
* @param placement
* @return details about the target bit, if any parameters are missing will
* return null.
* @return details about the target bit, no arguments should be null.
*/
IBitLocation getBitPos(
float hitX,
Expand All @@ -120,8 +123,7 @@ IBitLocation getBitPos(
* Get an ItemStack for the bit type of the state...
*
* 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
* it on the ground, or anything else.. CHECK THIS!!!!!
* this ItemStack WILL BE empty.
*
* @param defaultState
* @return the bit.
Expand Down Expand Up @@ -157,6 +159,7 @@ void giveBitToPlayer(
*
* @return internal object to manipulate bag.
*/
@Nullable
IBitBag getBitbag(
ItemStack stack );

Expand All @@ -166,17 +169,10 @@ IBitBag getBitbag(
*
* @formatter:off
*
* Example:
* Example:
*
* try
* {
* api.beginUndoGroup();
* this.manipulateAllTheBlocks();
* }
* finally
* {
* api.endUndoGroup();
* }
* try { api.beginUndoGroup(); this.manipulateAllTheBlocks();
* } finally { api.endUndoGroup(); }
*
*/
void beginUndoGroup(
Expand All @@ -193,11 +189,14 @@ void endUndoGroup(
/**
* Register a custom material as equivalent to another material.
*
* @param newMaterial your custom material
* @param target default MC Material C&B knows about.
* @param newMaterial
* your custom material
* @param target
* default MC Material C&B knows about.
*/
void addEquivilantMaterial(
Material newMaterial,
Material target ); // this should be a material C&B understands, other wise you'll get stone anyway.
Material target ); // this should be a material C&B understands,
// other wise you'll get stone anyway.

}
10 changes: 8 additions & 2 deletions src/main/java/mod/chiselsandbits/api/package-info.java
@@ -1,2 +1,8 @@
@net.minecraftforge.fml.common.API( apiVersion = "12.5.0", owner = "chiselsandbits", provides = "ChiselsAndBitsAPI" )
package mod.chiselsandbits.api;
@net.minecraftforge.fml.common.API( apiVersion = "13.6.0", owner = "chiselsandbits", provides = "ChiselsAndBitsAPI" )
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mod.chiselsandbits.api;

import javax.annotation.ParametersAreNonnullByDefault;

import mcp.MethodsReturnNonnullByDefault;
9 changes: 7 additions & 2 deletions src/main/java/mod/chiselsandbits/bitbag/BagGui.java
Expand Up @@ -65,7 +65,12 @@ protected boolean checkHotbarKeys(
{
if ( theSlot instanceof SlotBit )
{
theSlot = null;
final Slot s = inventorySlots.getSlotFromInventory( getBagContainer().thePlayer.inventory, 0 );

if ( s != null )
{
theSlot = s;
}
}

return super.checkHotbarKeys( keyCode );
Expand Down Expand Up @@ -135,7 +140,7 @@ protected void drawGuiContainerForegroundLayer(
final int mouseX,
final int mouseY )
{
fontRendererObj.drawString( ChiselsAndBits.getItems().itemBitBag.getItemStackDisplayName( null ), 8, 6, 0x404040 );
fontRendererObj.drawString( ChiselsAndBits.getItems().itemBitBag.getItemStackDisplayName( ModUtil.getEmptyStack() ), 8, 6, 0x404040 );
fontRendererObj.drawString( I18n.format( "container.inventory", new Object[0] ), 8, ySize - 93, 0x404040 );

RenderHelper.enableGUIStandardItemLighting();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/mod/chiselsandbits/bitbag/BagInventory.java
Expand Up @@ -20,6 +20,8 @@
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
Expand Down Expand Up @@ -61,7 +63,7 @@ public ItemStack getItemStack()
@Override
public String getName()
{
return null;
return "container.inventory";
}

@Override
Expand All @@ -73,7 +75,7 @@ public boolean hasCustomName()
@Override
public ITextComponent getDisplayName()
{
return null;
return hasCustomName() ? new TextComponentString( getName() ) : new TextComponentTranslation( getName(), new Object[0] );
}

@Override
Expand Down
Expand Up @@ -382,6 +382,12 @@ boolean addAllPossibleBits(
if ( ChiselsAndBits.getApi().getItemType( stackInSlot ) == ItemType.BIT_BAG )
{
final IBitBag bag = ChiselsAndBits.getApi().getBitbag( stackInSlot );

if ( bag == null )
{
continue;
}

for ( int y = 0; y < bag.getSlots(); ++y )
{
bag.insertItem( y, insertItem( 0, bag.extractItem( y, bag.getSlotLimit( y ), false ), false ), false );
Expand Down
Expand Up @@ -333,8 +333,8 @@ public static BlockBitInfo createFromState(
// is it perfect?
if ( test_a && test_b && test_c && test_d && !isFluid )
{
final float blockHardness = blk.getBlockHardness( null, null, null );
final float resistance = blk.getExplosionResistance( null );
final float blockHardness = blk.blockHardness;
final float resistance = blk.blockResistance;

return new BlockBitInfo( true, blockHardness, resistance );
}
Expand All @@ -344,7 +344,7 @@ public static BlockBitInfo createFromState(
// hardness... say like stone?

final Block stone = Blocks.STONE;
return new BlockBitInfo( ChiselsAndBits.getConfig().compatabilityMode, stone.getBlockHardness( null, null, null ), stone.getExplosionResistance( null ) );
return new BlockBitInfo( ChiselsAndBits.getConfig().compatabilityMode, blk.blockHardness, blk.blockResistance );
}
}
catch ( final Exception err )
Expand Down
Expand Up @@ -1224,6 +1224,7 @@ public IBlockState getPrimaryState(
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return Blocks.STONE.getDefaultState();
}
}
Expand Down

0 comments on commit cbb4e57

Please sign in to comment.