1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-13 11:40:29 +00:00

Update to 1.11.2

This commit is contained in:
SquidDev 2017-05-11 01:08:26 +01:00
parent f480965e67
commit 35425f0f61
94 changed files with 844 additions and 679 deletions

View File

@ -28,7 +28,7 @@ group = "dan200.computercraft"
archivesBaseName = "ComputerCraft"
minecraft {
version = "1.9.4-12.17.0.1959"
version = "1.11.2-13.20.0.2294"
runDir = "run"
replace '${version}', project.version
@ -37,7 +37,7 @@ minecraft {
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not allways work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20160518"
mappings = "snapshot_20161227"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

View File

@ -58,6 +58,7 @@ import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -75,6 +76,7 @@ import net.minecraftforge.fml.relauncher.Side;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@ -96,7 +98,7 @@ import java.util.zip.ZipFile;
)
public class ComputerCraft
{
public static final String MOD_ID = "ComputerCraft";
public static final String MOD_ID = "computercraft";
public static final String LOWER_ID = "computercraft";
// GUI IDs
@ -462,7 +464,7 @@ public class ComputerCraft
proxy.playRecord( record, recordInfo, world, pos );
}
public static String getRecordInfo( ItemStack recordStack )
public static String getRecordInfo( @Nonnull ItemStack recordStack )
{
return proxy.getRecordInfo( recordStack );
}
@ -714,9 +716,9 @@ public class ComputerCraft
return combinedSignal;
}
public static IMedia getMedia( ItemStack stack )
public static IMedia getMedia( @Nonnull ItemStack stack )
{
if( stack != null )
if( !stack.isEmpty() )
{
// Try the handlers in order:
for( IMediaProvider mediaProvider : mediaProviders )
@ -744,14 +746,14 @@ public class ComputerCraft
return pocketUpgrades.get( id );
}
public static IPocketUpgrade getPocketUpgrade( ItemStack stack )
public static IPocketUpgrade getPocketUpgrade( @Nonnull ItemStack stack )
{
if( stack == null ) return null;
if( stack.isEmpty() ) return null;
for (IPocketUpgrade upgrade : pocketUpgrades.values())
{
ItemStack craftingStack = upgrade.getCraftingItem();
if( craftingStack != null && InventoryUtil.areItemsStackable( stack, craftingStack ) )
if( !craftingStack.isEmpty() && InventoryUtil.areItemsStackable( stack, craftingStack ) )
{
return upgrade;
}
@ -1010,12 +1012,12 @@ public class ComputerCraft
return turtleProxy.getTurtleUpgrade( legacyID );
}
public static ITurtleUpgrade getTurtleUpgrade( ItemStack item )
public static ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack item )
{
return turtleProxy.getTurtleUpgrade( item );
}
public static void addAllUpgradedTurtles( List<ItemStack> list )
public static void addAllUpgradedTurtles( NonNullList<ItemStack> list )
{
turtleProxy.addAllUpgradedTurtles( list );
}

View File

@ -48,9 +48,9 @@ public interface IPocketUpgrade
* pocket computer which holds this upgrade. This item stack is also used to determine the upgrade given by
* {@code pocket.equip()}/{@code pocket.unequip()}.
*
* @return The item stack used for crafting. This can be {@code null} if crafting is disabled.
* @return The item stack used for crafting. This can be {@link ItemStack#EMPTY} if crafting is disabled.
*/
@Nullable
@Nonnull
ItemStack getCraftingItem();
/**

View File

@ -76,9 +76,9 @@ public interface ITurtleUpgrade
* with to create a turtle which holds this upgrade. This item stack is also used
* to determine the upgrade given by {@code turtle.equip()}
*
* @return The item stack to craft with, or {@code null} if it cannot be crafted.
* @return The item stack to craft with, or {@link ItemStack#EMPTY} if it cannot be crafted.
*/
@Nullable
@Nonnull
ItemStack getCraftingItem();
/**

View File

@ -41,6 +41,19 @@ public class GuiConfigCC extends GuiConfig
}
@Override
public boolean hasConfigGui()
{
return true;
}
@Override
public GuiScreen createConfigGui( GuiScreen parentScreen )
{
return new GuiConfigCC( parentScreen );
}
@Override
@Deprecated
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiConfigCC.class;
@ -53,6 +66,7 @@ public class GuiConfigCC extends GuiConfig
}
@Override
@Deprecated
public RuntimeOptionGuiHandler getHandlerFor( RuntimeOptionCategoryElement runtimeOptionCategoryElement )
{
return null;

View File

@ -16,6 +16,8 @@ import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nonnull;
public abstract class Widget extends Gui
{
private WidgetContainer m_parent;
@ -322,9 +324,9 @@ public abstract class Widget extends Gui
}
}
protected void drawItemStack( int x, int y, ItemStack stack )
protected void drawItemStack( int x, int y, @Nonnull ItemStack stack )
{
if( stack != null )
if( !stack.isEmpty() )
{
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
GlStateManager.enableLighting();

View File

@ -301,7 +301,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
}
@Override
public String getRecordInfo( ItemStack recordStack )
public String getRecordInfo( @Nonnull ItemStack recordStack )
{
List<String> info = new ArrayList<String>( 1 );
recordStack.getItem().addInformation( recordStack, null, info, false );
@ -351,7 +351,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
public Object getPrintoutGUI( EntityPlayer player, EnumHand hand )
{
ContainerHeldItem container = new ContainerHeldItem( player, hand );
if( container.getStack() != null && container.getStack().getItem() instanceof ItemPrintout )
if( container.getStack().getItem() instanceof ItemPrintout )
{
return new GuiPrintout( container );
}
@ -362,7 +362,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
ContainerPocketComputer container = new ContainerPocketComputer( player, hand );
if( container.getStack() != null && container.getStack().getItem() instanceof ItemPocketComputer )
if( container.getStack().getItem() instanceof ItemPocketComputer )
{
return new GuiPocketComputer( container );
}

View File

@ -103,7 +103,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
{
@Nonnull
@Override
public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
ComputerFamily family = turtle.getFamily( stack );

View File

@ -62,7 +62,8 @@ public abstract class BlockGeneric extends Block implements
@Nonnull
@Override
public final IBlockState onBlockPlaced( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer )
@Deprecated
public final IBlockState getStateForPlacement( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer )
{
return getDefaultBlockState( damage, side );
}
@ -102,7 +103,7 @@ public abstract class BlockGeneric extends Block implements
}
}
public final void dropItem( World world, BlockPos pos, ItemStack stack )
public final void dropItem( World world, BlockPos pos, @Nonnull ItemStack stack )
{
Block.spawnAsEntity( world, pos, stack );
}
@ -130,17 +131,11 @@ public abstract class BlockGeneric extends Block implements
TileGeneric generic = (TileGeneric)tile;
return generic.getPickedItem();
}
return null;
return ItemStack.EMPTY;
}
@Override
public final ItemStack createStackedBlock( @Nonnull IBlockState state )
{
return null;
}
@Override
public final boolean onBlockActivated( World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ )
public final boolean onBlockActivated( World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric )
@ -153,7 +148,7 @@ public abstract class BlockGeneric extends Block implements
@Override
@Deprecated
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block )
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighorPos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric )
@ -187,7 +182,7 @@ public abstract class BlockGeneric extends Block implements
}
@Override
public final boolean canBeReplacedByLeaves( IBlockState state, IBlockAccess world, BlockPos pos )
public final boolean canBeReplacedByLeaves( @Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos )
{
return false; // Generify me if anyone ever feels the need to change this
}
@ -196,7 +191,7 @@ public abstract class BlockGeneric extends Block implements
public float getExplosionResistance( World world, BlockPos pos, @Nonnull Entity exploder, Explosion explosion )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
if( generic.isImmuneToExplosion( exploder ) )
@ -213,7 +208,7 @@ public abstract class BlockGeneric extends Block implements
public final AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess world, BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
return generic.getBounds();
@ -231,10 +226,10 @@ public abstract class BlockGeneric extends Block implements
@Override
@Deprecated
public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos )
public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
@ -259,10 +254,10 @@ public abstract class BlockGeneric extends Block implements
@Override
@Deprecated
public final void addCollisionBoxToList( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB bigBox, @Nonnull List<AxisAlignedBB> list, Entity entity )
public final void addCollisionBoxToList( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB bigBox, @Nonnull List<AxisAlignedBB> list, Entity entity, boolean p_185477_7_ )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
@ -305,7 +300,7 @@ public abstract class BlockGeneric extends Block implements
public final int getStrongPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
return generic.getRedstoneOutput( oppositeSide.getOpposite() );
@ -334,7 +329,7 @@ public abstract class BlockGeneric extends Block implements
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() )
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric)tile;
return generic.getBundledRedstoneOutput( side );

View File

@ -6,11 +6,11 @@ import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ColourableRecipe implements IRecipe
{
@ -22,7 +22,7 @@ public class ColourableRecipe implements IRecipe
for( int i = 0; i < inv.getSizeInventory(); i++ )
{
ItemStack stack = inv.getStackInSlot( i );
if( stack == null ) continue;
if( stack.isEmpty() ) continue;
if( stack.getItem() instanceof IColouredItem )
{
@ -42,11 +42,11 @@ public class ColourableRecipe implements IRecipe
return hasColourable && hasDye;
}
@Nullable
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
{
ItemStack colourable = null;
ItemStack colourable = ItemStack.EMPTY;
ColourTracker tracker = new ColourTracker();
@ -54,7 +54,7 @@ public class ColourableRecipe implements IRecipe
{
ItemStack stack = inv.getStackInSlot( i );
if( stack == null ) continue;
if( stack.isEmpty() ) continue;
if( stack.getItem() instanceof IColouredItem )
{
@ -70,9 +70,9 @@ public class ColourableRecipe implements IRecipe
}
}
if( colourable == null )
if( colourable.isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
return ((IColouredItem) colourable.getItem()).setColour( colourable, tracker.getColour() );
@ -84,22 +84,22 @@ public class ColourableRecipe implements IRecipe
return 2;
}
@Nullable
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
return null;
return ItemStack.EMPTY;
}
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inv )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inv.getSizeInventory() ];
for( int i = 0; i < results.length; ++i )
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inv.getStackInSlot( i );
results[ i ] = ForgeHooks.getContainerItem( stack );
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -34,7 +34,7 @@ public abstract class TileGeneric extends TileEntity
public void requestTileEntityUpdate()
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.RequestTileEntityUpdate;
@ -52,7 +52,7 @@ public abstract class TileGeneric extends TileEntity
@Nullable
public BlockGeneric getBlock()
{
Block block = worldObj.getBlockState( getPos() ).getBlock();
Block block = getWorld().getBlockState( getPos() ).getBlock();
if( block != null && block instanceof BlockGeneric )
{
return (BlockGeneric)block;
@ -62,21 +62,21 @@ public abstract class TileGeneric extends TileEntity
protected final IBlockState getBlockState()
{
return worldObj.getBlockState( getPos() );
return getWorld().getBlockState( getPos() );
}
public final void updateBlock()
{
markDirty();
BlockPos pos = getPos();
IBlockState state = worldObj.getBlockState( pos );
worldObj.markBlockRangeForRenderUpdate( pos, pos );
worldObj.notifyBlockUpdate( getPos(), state, state, 3 );
IBlockState state = getWorld().getBlockState( pos );
getWorld().markBlockRangeForRenderUpdate( pos, pos );
getWorld().notifyBlockUpdate( getPos(), state, state, 3 );
}
protected final void setBlockState( IBlockState newState )
{
worldObj.setBlockState( getPos(), newState, 3 );
getWorld().setBlockState( getPos(), newState, 3 );
}
public void getDroppedItems( @Nonnull List<ItemStack> drops, boolean creative )
@ -151,13 +151,13 @@ public abstract class TileGeneric extends TileEntity
{
if( player != null && player.isEntityAlive() )
{
if( worldObj.getTileEntity( getPos() ) == this )
if( getWorld().getTileEntity( getPos() ) == this )
{
if( !ignoreRange )
{
double range = getInteractRange( player );
BlockPos pos = getPos();
return player.getEntityWorld() == worldObj &&
return player.getEntityWorld() == getWorld() &&
player.getDistanceSq( (double)pos.getX() + 0.5, (double)pos.getY() + 0.5, (double)pos.getZ() + 0.5 ) <= ( range * range );
}
return true;
@ -181,7 +181,7 @@ public abstract class TileGeneric extends TileEntity
public final void sendBlockEvent( int eventID, int eventParameter )
{
worldObj.addBlockEvent( getPos(), worldObj.getBlockState( getPos() ).getBlock(), eventID, eventParameter );
getWorld().addBlockEvent( getPos(), getWorld().getBlockState( getPos() ).getBlock(), eventID, eventParameter );
}
public void onBlockEvent( int eventID, int eventParameter )

View File

@ -132,13 +132,13 @@ public class BlockCommandComputer extends BlockComputerBase
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemstack )
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack itemstack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCommandComputer )
{
tile.setWorldObj( world ); // Not sure why this is necessary
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}

View File

@ -164,13 +164,13 @@ public class BlockComputer extends BlockComputerBase
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack )
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack stack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileComputer )
{
tile.setWorldObj( world ); // Not sure why this is necessary
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}

View File

@ -70,13 +70,13 @@ public class TileCommandComputer extends TileComputer
}
@Override
public void addChatMessage( @Nonnull ITextComponent chatComponent )
public void sendMessage( @Nonnull ITextComponent chatComponent )
{
m_outputTable.put( m_outputTable.size() + 1, chatComponent.getUnformattedText() );
}
@Override
public boolean canCommandSenderUseCommand( int level, String command )
public boolean canUseCommand( int level, String command )
{
return level <= 2;
}
@ -179,7 +179,7 @@ public class TileCommandComputer extends TileComputer
MinecraftServer server = player.getServer();
if( server == null || !server.isCommandBlockEnabled() )
{
player.addChatMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
player.sendMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
return false;
}
else if( ComputerCraft.canPlayerUseCommands( player ) && player.capabilities.isCreativeMode )
@ -188,7 +188,7 @@ public class TileCommandComputer extends TileComputer
}
else
{
player.addChatMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
player.sendMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
return false;
}
}

View File

@ -35,7 +35,7 @@ public class TileComputer extends TileComputerBase
{
ComputerFamily family = getFamily();
ServerComputer computer = new ServerComputer(
worldObj,
getWorld(),
id,
m_label,
instanceID,

View File

@ -62,7 +62,7 @@ public abstract class TileComputerBase extends TileGeneric
{
if( m_instanceID >= 0 )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ComputerCraft.serverComputerRegistry.remove( m_instanceID );
}
@ -76,7 +76,7 @@ public abstract class TileComputerBase extends TileGeneric
unload();
for( EnumFacing dir : EnumFacing.VALUES )
{
RedstoneUtil.propogateRedstoneOutput( worldObj, getPos(), dir );
RedstoneUtil.propogateRedstoneOutput( getWorld(), getPos(), dir );
}
}
@ -102,7 +102,7 @@ public abstract class TileComputerBase extends TileGeneric
protected boolean onDefaultComputerInteract( EntityPlayer player )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( isUsable( player, false ) )
{
@ -117,10 +117,10 @@ public abstract class TileComputerBase extends TileGeneric
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
{
ItemStack currentItem = player.getHeldItem( EnumHand.MAIN_HAND );
if( currentItem != null && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) )
if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) )
{
// Label to rename computer
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( currentItem.hasDisplayName() )
{
@ -130,7 +130,7 @@ public abstract class TileComputerBase extends TileGeneric
{
setLabel( null );
}
currentItem.stackSize--;
currentItem.shrink( 1 );
}
return true;
}
@ -156,7 +156,7 @@ public abstract class TileComputerBase extends TileGeneric
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
if( !isRedstoneBlockedOnSide( localDir ) )
{
if( worldObj != null && !worldObj.isRemote )
if( getWorld() != null && !getWorld().isRemote )
{
ServerComputer computer = getServerComputer();
if( computer != null )
@ -181,7 +181,7 @@ public abstract class TileComputerBase extends TileGeneric
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
if( !isRedstoneBlockedOnSide( localDir ) )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ServerComputer computer = getServerComputer();
if( computer != null )
@ -208,7 +208,7 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public void update()
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ServerComputer computer = createServerComputer();
if( computer != null )
@ -323,18 +323,18 @@ public abstract class TileComputerBase extends TileGeneric
int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
if( !isRedstoneBlockedOnSide( localDir ) )
{
computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) );
computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) );
computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( getWorld(), offset, offsetSide ) );
computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( getWorld(), offset, offsetSide ) );
}
if( !isPeripheralBlockedOnSide( localDir ) )
{
computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) );
computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( getWorld(), offset, offsetSide ) );
}
}
public void updateInput()
{
if( worldObj == null || worldObj.isRemote )
if( getWorld() == null || getWorld().isRemote )
{
return;
}
@ -353,7 +353,7 @@ public abstract class TileComputerBase extends TileGeneric
public void updateInput( BlockPos neighbour )
{
if( worldObj == null || worldObj.isRemote )
if( getWorld() == null || getWorld().isRemote )
{
return;
}
@ -380,7 +380,7 @@ public abstract class TileComputerBase extends TileGeneric
updateBlock();
for( EnumFacing dir : EnumFacing.VALUES )
{
RedstoneUtil.propogateRedstoneOutput( worldObj, getPos(), dir );
RedstoneUtil.propogateRedstoneOutput( getWorld(), getPos(), dir );
}
}
@ -399,7 +399,7 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public void setComputerID( int id )
{
if( !worldObj.isRemote && m_computerID != id )
if( !getWorld().isRemote && m_computerID != id )
{
m_computerID = id;
ServerComputer computer = getServerComputer();
@ -414,7 +414,7 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public void setLabel( String label )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
createServerComputer().setLabel( label );
}
@ -423,7 +423,7 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public IComputer createComputer()
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
return createClientComputer();
}
@ -436,7 +436,7 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public IComputer getComputer()
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
return getClientComputer();
}
@ -452,14 +452,14 @@ public abstract class TileComputerBase extends TileGeneric
BlockComputerBase block = getBlock();
if( block != null )
{
return block.getFamily( worldObj, getPos() );
return block.getFamily( getWorld(), getPos() );
}
return ComputerFamily.Normal;
}
public ServerComputer createServerComputer()
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
boolean changed = false;
if( m_instanceID < 0 )
@ -485,7 +485,7 @@ public abstract class TileComputerBase extends TileGeneric
public ServerComputer getServerComputer()
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
return ComputerCraft.serverComputerRegistry.get( m_instanceID );
}
@ -494,7 +494,7 @@ public abstract class TileComputerBase extends TileGeneric
public ClientComputer createClientComputer()
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
if( m_instanceID >= 0 )
{
@ -510,7 +510,7 @@ public abstract class TileComputerBase extends TileGeneric
public ClientComputer getClientComputer()
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
return ComputerCraft.clientComputerRegistry.get( m_instanceID );
}

View File

@ -169,7 +169,7 @@ public class ClientComputer extends ClientTerminal
m_blinking = nbttagcompound.getBoolean( "blinking" );
if( nbttagcompound.hasKey( "userData" ) )
{
m_userData = (NBTTagCompound)(nbttagcompound.getCompoundTag( "userData" )).copy();
m_userData = nbttagcompound.getCompoundTag( "userData" ).copy();
}
else
{

View File

@ -13,8 +13,11 @@ import dan200.computercraft.shared.computer.core.IComputer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class ComputerItemFactory
{
@Nonnull
public static ItemStack create( IComputerTile computerTile )
{
IComputer computer = computerTile.getComputer();
@ -30,6 +33,7 @@ public class ComputerItemFactory
}
}
@Nonnull
public static ItemStack create( int id, String label, ComputerFamily family )
{
ItemComputer computer = ((ItemComputer)Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
@ -46,6 +50,6 @@ public class ComputerItemFactory
return commandComputer.create( id, label, family );
}
}
return null;
return ItemStack.EMPTY;
}
}

View File

@ -9,9 +9,11 @@ package dan200.computercraft.shared.computer.items;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IComputerItem
{
int getComputerID( ItemStack stack );
String getLabel( ItemStack stack );
ComputerFamily getFamily( ItemStack stack );
int getComputerID( @Nonnull ItemStack stack );
String getLabel( @Nonnull ItemStack stack );
ComputerFamily getFamily( @Nonnull ItemStack stack );
}

View File

@ -13,10 +13,10 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemCommandComputer extends ItemComputer
{
@ -53,7 +53,7 @@ public class ItemCommandComputer extends ItemComputer
}
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Command ) );
}
@ -61,7 +61,7 @@ public class ItemCommandComputer extends ItemComputer
// IComputerItem implementation
@Override
public int getComputerID( ItemStack stack )
public int getComputerID( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() && stack.getTagCompound().hasKey( "computerID" ) )
{

View File

@ -17,13 +17,13 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemComputer extends ItemComputerBase
{
@ -73,7 +73,7 @@ public class ItemComputer extends ItemComputerBase
}
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Normal ) );
list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ) );
@ -95,7 +95,7 @@ public class ItemComputer extends ItemComputerBase
return false;
}
private void setupComputerAfterPlacement( ItemStack stack, IComputerTile computer )
private void setupComputerAfterPlacement( @Nonnull ItemStack stack, IComputerTile computer )
{
// Set ID
int id = getComputerID( stack );
@ -114,7 +114,7 @@ public class ItemComputer extends ItemComputerBase
@Nonnull
@Override
public String getUnlocalizedName( ItemStack stack )
public String getUnlocalizedName( @Nonnull ItemStack stack )
{
switch( getFamily( stack ) )
{
@ -137,7 +137,7 @@ public class ItemComputer extends ItemComputerBase
// IComputerItem implementation
@Override
public int getComputerID( ItemStack stack )
public int getComputerID( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() && stack.getTagCompound().hasKey( "computerID" ) )
{

View File

@ -51,7 +51,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
// IComputerItem implementation
@Override
public abstract int getComputerID( ItemStack stack );
public abstract int getComputerID( @Nonnull ItemStack stack );
@Override
public String getLabel( @Nonnull ItemStack stack )
@ -64,7 +64,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
}
@Override
public final ComputerFamily getFamily( ItemStack stack )
public final ComputerFamily getFamily( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
return getFamily( damage );

View File

@ -25,6 +25,7 @@ public class ContainerHeldItem extends Container
m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
}
@Nonnull
public ItemStack getStack()
{
return m_stack;
@ -36,7 +37,7 @@ public class ContainerHeldItem extends Container
if( player != null && player.isEntityAlive() )
{
ItemStack stack = player.getHeldItem( m_hand );
if( (stack == m_stack) || (stack != null && m_stack != null && stack.getItem() == m_stack.getItem()) )
if( (stack == m_stack) || (!stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem()) )
{
return true;
}

View File

@ -11,12 +11,15 @@ import dan200.computercraft.shared.util.Colour;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nonnull;
public class ItemDiskExpanded extends ItemDiskLegacy
{
public ItemDiskExpanded()
{
}
@Nonnull
public static ItemStack createFromIDAndColour( int id, String label, int colour )
{
ItemStack stack = new ItemStack( ComputerCraft.Items.diskExpanded, 1, 0 );
@ -34,7 +37,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
}
@Override
public int getDiskID( ItemStack stack )
public int getDiskID( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "diskID" ) )
@ -45,7 +48,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
}
@Override
protected void setDiskID( ItemStack stack, int id )
protected void setDiskID( @Nonnull ItemStack stack, int id )
{
if( id >= 0 )
{
@ -60,7 +63,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
}
@Override
public int getColour( ItemStack stack )
public int getColour( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "color" ) )

View File

@ -16,6 +16,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
@ -36,7 +37,7 @@ public class ItemDiskLegacy extends Item
}
@Override
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList<ItemStack> list )
{
for( int colour=0; colour<16; ++colour )
{
@ -47,7 +48,8 @@ public class ItemDiskLegacy extends Item
}
}
}
@Nonnull
public static ItemStack createFromIDAndColour( int id, String label, int colour )
{
if( colour != Colour.Blue.getHex() )
@ -61,7 +63,7 @@ public class ItemDiskLegacy extends Item
return stack;
}
public int getDiskID( ItemStack stack )
public int getDiskID( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
if( damage > 0 )
@ -71,7 +73,7 @@ public class ItemDiskLegacy extends Item
return -1;
}
protected void setDiskID( ItemStack stack, int id )
protected void setDiskID( @Nonnull ItemStack stack, int id )
{
if( id > 0 ) {
stack.setItemDamage( id );
@ -81,7 +83,7 @@ public class ItemDiskLegacy extends Item
}
@Override
public void addInformation( ItemStack stack, EntityPlayer player, List<String> list, boolean debug )
public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List<String> list, boolean debug )
{
if( debug )
{
@ -144,13 +146,13 @@ public class ItemDiskLegacy extends Item
}
@Override
public int getColour( ItemStack stack )
public int getColour( @Nonnull ItemStack stack )
{
return Colour.Blue.getHex();
}
@Override
public boolean doesSneakBypassUse( ItemStack stack, IBlockAccess world, BlockPos pos, EntityPlayer player )
public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IBlockAccess world, BlockPos pos, EntityPlayer player )
{
return true;
}

View File

@ -15,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
@ -42,7 +43,7 @@ public class ItemPrintout extends Item
}
@Override
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList<ItemStack> list )
{
list.add( createSingleFromTitleAndText( null, new String[ LINES_PER_PAGE ], new String[ LINES_PER_PAGE ] ) );
list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) );
@ -50,7 +51,7 @@ public class ItemPrintout extends Item
}
@Override
public void addInformation( ItemStack itemstack, EntityPlayer par2EntityPlayer, List<String> list, boolean flag )
public void addInformation( @Nonnull ItemStack itemstack, EntityPlayer par2EntityPlayer, List<String> list, boolean flag )
{
String title = getTitle( itemstack );
if( title != null && title.length() > 0 )
@ -61,7 +62,7 @@ public class ItemPrintout extends Item
@Nonnull
@Override
public String getUnlocalizedName( ItemStack stack )
public String getUnlocalizedName( @Nonnull ItemStack stack )
{
Type type = getType( stack );
switch( type )
@ -84,15 +85,16 @@ public class ItemPrintout extends Item
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick( @Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand )
public ActionResult<ItemStack> onItemRightClick( World world, EntityPlayer player, @Nonnull EnumHand hand )
{
if( !world.isRemote )
{
ComputerCraft.openPrintoutGUI( player, hand );
}
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
@Nonnull
private static ItemStack createFromTitleAndText( Type type, String title, String[] text, String[] colours )
{
// Calculate damage
@ -153,22 +155,25 @@ public class ItemPrintout extends Item
return stack;
}
@Nonnull
public static ItemStack createSingleFromTitleAndText( String title, String[] text, String[] colours )
{
return createFromTitleAndText( Type.Single, title, text, colours );
}
@Nonnull
public static ItemStack createMultipleFromTitleAndText( String title, String[] text, String[] colours )
{
return createFromTitleAndText( Type.Multiple, title, text, colours );
}
@Nonnull
public static ItemStack createBookFromTitleAndText( String title, String[] text, String[] colours )
{
return createFromTitleAndText( Type.Book, title, text, colours );
}
public static Type getType( ItemStack stack )
public static Type getType( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
switch( damage )
@ -189,7 +194,7 @@ public class ItemPrintout extends Item
}
}
public static String getTitle( ItemStack stack )
public static String getTitle( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "title" ) )
@ -199,7 +204,7 @@ public class ItemPrintout extends Item
return null;
}
public static int getPageCount( ItemStack stack )
public static int getPageCount( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "pages" ) )
@ -209,7 +214,7 @@ public class ItemPrintout extends Item
return 1;
}
public static String[] getText( ItemStack stack )
public static String[] getText( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
int numLines = getPageCount( stack ) * LINES_PER_PAGE;
@ -228,7 +233,7 @@ public class ItemPrintout extends Item
return lines;
}
public static String[] getColours( ItemStack stack )
public static String[] getColours( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
int numLines = getPageCount( stack ) * LINES_PER_PAGE;

View File

@ -16,6 +16,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
@ -36,12 +37,12 @@ public class ItemTreasureDisk extends Item
}
@Override
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList<ItemStack> list )
{
}
@Override
public void addInformation( ItemStack stack, EntityPlayer player, List<String> list, boolean bool )
public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List<String> list, boolean bool )
{
String label = getTitle( stack );
if( label != null && label.length() > 0 )
@ -51,7 +52,7 @@ public class ItemTreasureDisk extends Item
}
@Override
public boolean doesSneakBypassUse( ItemStack stack, IBlockAccess world, BlockPos pos, EntityPlayer player )
public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IBlockAccess world, BlockPos pos, EntityPlayer player )
{
return true;
}
@ -138,7 +139,7 @@ public class ItemTreasureDisk extends Item
// private stuff
public String getTitle( ItemStack stack )
public String getTitle( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "title" ) )
@ -148,7 +149,7 @@ public class ItemTreasureDisk extends Item
return "'alongtimeago' by dan200";
}
public String getSubPath( ItemStack stack )
public String getSubPath( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "subPath" ) )
@ -158,7 +159,7 @@ public class ItemTreasureDisk extends Item
return "dan200/alongtimeago";
}
public int getColour( ItemStack stack )
public int getColour( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "colour" ) )

View File

@ -14,7 +14,9 @@ import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
@ -30,7 +32,7 @@ public class DiskRecipe implements IRecipe
{
ItemStack stack = inv.getStackInSlot( i );
if( stack != null )
if( !stack.isEmpty() )
{
if( stack.getItem() == Items.PAPER )
{
@ -52,6 +54,7 @@ public class DiskRecipe implements IRecipe
return redstoneFound && paperFound;
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
{
@ -61,8 +64,8 @@ public class DiskRecipe implements IRecipe
{
ItemStack stack = inv.getStackInSlot( i );
if( stack == null ) continue;
if( stack.isEmpty() ) continue;
if( stack.getItem() != Items.PAPER && stack.getItem() != Items.REDSTONE )
{
int index = ColourUtils.getStackColour( stack );
@ -82,6 +85,7 @@ public class DiskRecipe implements IRecipe
return 2;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
@ -90,13 +94,13 @@ public class DiskRecipe implements IRecipe
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inv )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inv.getSizeInventory() ];
for( int i = 0; i < results.length; ++i )
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inv.getStackInSlot( i );
results[ i ] = net.minecraftforge.common.ForgeHooks.getContainerItem( stack );
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -12,7 +12,9 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
@ -28,6 +30,7 @@ public class PrintoutRecipe implements IRecipe
return 3;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
@ -37,9 +40,10 @@ public class PrintoutRecipe implements IRecipe
@Override
public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world )
{
return (getCraftingResult( _inventory ) != null);
return !getCraftingResult( _inventory ).isEmpty();
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
@ -55,7 +59,7 @@ public class PrintoutRecipe implements IRecipe
for( int x=0; x<inventory.getWidth(); ++x )
{
ItemStack stack = inventory.getStackInRowAndColumn(x, y);
if( stack != null )
if( !stack.isEmpty() )
{
Item item = stack.getItem();
if( item instanceof ItemPrintout && ItemPrintout.getType( stack ) != ItemPrintout.Type.Book )
@ -89,7 +93,7 @@ public class PrintoutRecipe implements IRecipe
}
else
{
return null;
return ItemStack.EMPTY;
}
}
}
@ -145,18 +149,18 @@ public class PrintoutRecipe implements IRecipe
}
}
return null;
return ItemStack.EMPTY;
}
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ];
for (int i = 0; i < results.length; ++i)
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inventoryCrafting.getStackInSlot(i);
results[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(stack);
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -554,13 +554,13 @@ public class BlockPeripheral extends BlockPeripheralBase
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack )
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack stack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePeripheralBase )
{
tile.setWorldObj( world ); // Not sure why this is necessary
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}

View File

@ -9,7 +9,9 @@ package dan200.computercraft.shared.peripheral.common;
import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IPeripheralItem
{
PeripheralType getPeripheralType( ItemStack stack );
PeripheralType getPeripheralType( @Nonnull ItemStack stack );
}

View File

@ -12,10 +12,10 @@ import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemAdvancedModem extends ItemPeripheralBase
{
@ -26,6 +26,7 @@ public class ItemAdvancedModem extends ItemPeripheralBase
setCreativeTab( ComputerCraft.mainCreativeTab );
}
@Nonnull
public ItemStack create( PeripheralType type, String label, int quantity )
{
ItemStack stack;
@ -39,7 +40,7 @@ public class ItemAdvancedModem extends ItemPeripheralBase
default:
{
// Ignore types we can't handle
return null;
return ItemStack.EMPTY;
}
}
if( label != null )
@ -50,7 +51,7 @@ public class ItemAdvancedModem extends ItemPeripheralBase
}
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
list.add( PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 ) );
}

View File

@ -16,16 +16,12 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemCable extends ItemPeripheralBase
{
@ -36,6 +32,7 @@ public class ItemCable extends ItemPeripheralBase
setCreativeTab( ComputerCraft.mainCreativeTab );
}
@Nonnull
public ItemStack create( PeripheralType type, String label, int quantity )
{
ItemStack stack;
@ -53,7 +50,7 @@ public class ItemCable extends ItemPeripheralBase
}
default:
{
return null;
return ItemStack.EMPTY;
}
}
if( label != null )
@ -64,7 +61,7 @@ public class ItemCable extends ItemPeripheralBase
}
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
list.add( PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ) );
list.add( PeripheralItemFactory.create( PeripheralType.Cable, null, 1 ) );
@ -72,8 +69,9 @@ public class ItemCable extends ItemPeripheralBase
@Nonnull
@Override
public EnumActionResult onItemUse( ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumHand hand, @Nonnull EnumFacing side, float fx, float fy, float fz )
public EnumActionResult onItemUse( @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float fx, float fy, float fz )
{
ItemStack stack = player.getHeldItem( hand );
if( !canPlaceBlockOnSide( world, pos, side, player, stack ) )
{
return EnumActionResult.FAIL;
@ -88,11 +86,11 @@ public class ItemCable extends ItemPeripheralBase
PeripheralType existingType = ComputerCraft.Blocks.cable.getPeripheralType( world, pos );
if( existingType == PeripheralType.WiredModem && type == PeripheralType.Cable )
{
if( stack.stackSize > 0 )
if( !stack.isEmpty() )
{
world.setBlockState( pos, existingState.withProperty( BlockCable.Properties.CABLE, true ), 3 );
world.playSound( null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, ComputerCraft.Blocks.cable.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (ComputerCraft.Blocks.cable.getSoundType().getVolume() + 1.0F ) / 2.0F, ComputerCraft.Blocks.cable.getSoundType().getPitch() * 0.8F);
stack.stackSize--;
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable )
@ -118,11 +116,11 @@ public class ItemCable extends ItemPeripheralBase
PeripheralType offsetExistingType = ComputerCraft.Blocks.cable.getPeripheralType( world, offset );
if( offsetExistingType == PeripheralType.Cable && type == PeripheralType.WiredModem )
{
if( stack.stackSize > 0 )
if( !stack.isEmpty() )
{
world.setBlockState( offset, offsetExistingState.withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.fromFacing( side.getOpposite() ) ), 3 );
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, ComputerCraft.Blocks.cable.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (ComputerCraft.Blocks.cable.getSoundType().getVolume() + 1.0F ) / 2.0F, ComputerCraft.Blocks.cable.getSoundType().getPitch() * 0.8F);
stack.stackSize--;
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable )
@ -138,11 +136,11 @@ public class ItemCable extends ItemPeripheralBase
// Try to add a cable to a modem
if( offsetExistingType == PeripheralType.WiredModem && type == PeripheralType.Cable )
{
if( stack.stackSize > 0 )
if( !stack.isEmpty() )
{
world.setBlockState( offset, offsetExistingState.withProperty( BlockCable.Properties.CABLE, true ), 3 );
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, ComputerCraft.Blocks.cable.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (ComputerCraft.Blocks.cable.getSoundType().getVolume() + 1.0F ) / 2.0F, ComputerCraft.Blocks.cable.getSoundType().getPitch() * 0.8F);
stack.stackSize--;
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable )
@ -157,7 +155,7 @@ public class ItemCable extends ItemPeripheralBase
}
}
return super.onItemUse( stack, player, world, pos, hand, side, fx, fy, fz );
return super.onItemUse( player, world, pos, hand, side, fx, fy, fz );
}
@Override

View File

@ -12,10 +12,10 @@ import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemPeripheral extends ItemPeripheralBase
{
@ -26,6 +26,7 @@ public class ItemPeripheral extends ItemPeripheralBase
setCreativeTab( ComputerCraft.mainCreativeTab );
}
@Nonnull
public ItemStack create( PeripheralType type, String label, int quantity )
{
ItemStack stack;
@ -65,7 +66,7 @@ public class ItemPeripheral extends ItemPeripheralBase
default:
{
// Ignore types we can't handle
return null;
return ItemStack.EMPTY;
}
}
if( label != null )
@ -76,7 +77,7 @@ public class ItemPeripheral extends ItemPeripheralBase
}
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
list.add( PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 ) );
list.add( PeripheralItemFactory.create( PeripheralType.Printer, null, 1 ) );

View File

@ -59,7 +59,7 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera
@Nonnull
@Override
public String getUnlocalizedName( ItemStack stack )
public String getUnlocalizedName( @Nonnull ItemStack stack )
{
PeripheralType type = getPeripheralType( stack );
switch( type )
@ -108,7 +108,7 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera
// IPeripheralItem implementation
@Override
public final PeripheralType getPeripheralType( ItemStack stack )
public final PeripheralType getPeripheralType( @Nonnull ItemStack stack )
{
return getPeripheralType( stack.getItemDamage() );
}

View File

@ -11,13 +11,17 @@ import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class PeripheralItemFactory
{
@Nonnull
public static ItemStack create( IPeripheralTile tile )
{
return create( tile.getPeripheralType(), tile.getLabel(), 1 );
}
@Nonnull
public static ItemStack create( PeripheralType type, String label, int quantity )
{
ItemPeripheral peripheral = ((ItemPeripheral)Item.getItemFromBlock( ComputerCraft.Blocks.peripheral ));
@ -44,6 +48,6 @@ public class PeripheralItemFactory
return advancedModem.create( type, label, quantity );
}
}
return null;
return ItemStack.EMPTY;
}
}

View File

@ -40,46 +40,47 @@ public class ContainerDiskDrive extends Container
@Override
public boolean canInteractWith( @Nonnull EntityPlayer player )
{
return m_diskDrive.isUseableByPlayer( player );
return m_diskDrive.isUsableByPlayer( player );
}
@Nonnull
@Override
public ItemStack transferStackInSlot( EntityPlayer player, int i )
{
ItemStack itemstack = null;
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = inventorySlots.get(i);
if(slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
ItemStack itemstack1 = slot.getStack().copy();
itemstack = itemstack1.copy();
if(i == 0 )
{
if(!mergeItemStack(itemstack1, 1, 37, true))
{
return null;
return ItemStack.EMPTY;
}
}
else if( !mergeItemStack(itemstack1, 0, 1, false) )
{
return null;
return ItemStack.EMPTY;
}
if(itemstack1.stackSize == 0)
if(itemstack1.isEmpty())
{
slot.putStack(null);
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if(itemstack1.stackSize != itemstack.stackSize)
if(itemstack1.getCount() != itemstack.getCount())
{
slot.onPickupFromSlot(player, itemstack1);
slot.onTake(player, itemstack1);
}
else
{
return null;
return ItemStack.EMPTY;
}
}
return itemstack;

View File

@ -60,6 +60,7 @@ public class TileDiskDrive extends TilePeripheralBase
private final Map<IComputerAccess, MountInfo> m_computers;
@Nonnull
private ItemStack m_diskStack;
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this );
private IMount m_diskMount;
@ -73,7 +74,7 @@ public class TileDiskDrive extends TilePeripheralBase
{
m_computers = new HashMap<IComputerAccess, MountInfo>();
m_diskStack = null;
m_diskStack = ItemStack.EMPTY;
m_diskMount = null;
m_recordQueued = false;
@ -100,15 +101,15 @@ public class TileDiskDrive extends TilePeripheralBase
if( player.isSneaking() )
{
// Try to put a disk into the drive
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ItemStack disk = player.getHeldItem( EnumHand.MAIN_HAND );
if( disk != null && getStackInSlot(0) == null )
if( !disk.isEmpty() && getStackInSlot(0).isEmpty() )
{
if( ComputerCraft.getMedia( disk ) != null )
{
setInventorySlotContents( 0, disk );
player.setHeldItem( EnumHand.MAIN_HAND, null );
player.setHeldItem( EnumHand.MAIN_HAND, ItemStack.EMPTY );
return true;
}
}
@ -117,7 +118,7 @@ public class TileDiskDrive extends TilePeripheralBase
else
{
// Open the GUI
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ComputerCraft.openDiskDriveGUI( player, this );
}
@ -150,7 +151,7 @@ public class TileDiskDrive extends TilePeripheralBase
if( nbttagcompound.hasKey( "item" ) )
{
NBTTagCompound item = nbttagcompound.getCompoundTag( "item" );
m_diskStack = ItemStack.loadItemStackFromNBT( item );
m_diskStack = new ItemStack( item );
m_diskMount = null;
}
}
@ -160,7 +161,7 @@ public class TileDiskDrive extends TilePeripheralBase
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound)
{
nbttagcompound = super.writeToNBT(nbttagcompound);
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
NBTTagCompound item = new NBTTagCompound();
m_diskStack.writeToNBT( item );
@ -221,41 +222,50 @@ public class TileDiskDrive extends TilePeripheralBase
return 1;
}
@Override
public boolean isEmpty()
{
return m_diskStack.isEmpty();
}
@Nonnull
@Override
public ItemStack getStackInSlot(int i)
{
return m_diskStack;
}
@Nonnull
@Override
public ItemStack removeStackFromSlot(int i)
{
ItemStack result = m_diskStack;
m_diskStack = null;
m_diskStack = ItemStack.EMPTY;
m_diskMount = null;
return result;
}
@Nonnull
@Override
public ItemStack decrStackSize(int i, int j)
{
if (m_diskStack == null)
if (m_diskStack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
if (m_diskStack.stackSize <= j)
if (m_diskStack.getCount() <= j)
{
ItemStack disk = m_diskStack;
setInventorySlotContents( 0, null );
setInventorySlotContents( 0, ItemStack.EMPTY );
return disk;
}
ItemStack part = m_diskStack.splitStack(j);
if (m_diskStack.stackSize == 0)
if (m_diskStack.isEmpty())
{
setInventorySlotContents( 0, null );
setInventorySlotContents( 0, ItemStack.EMPTY );
}
else
{
@ -265,9 +275,9 @@ public class TileDiskDrive extends TilePeripheralBase
}
@Override
public void setInventorySlotContents( int i, ItemStack itemStack )
public void setInventorySlotContents( int i, @Nonnull ItemStack itemStack )
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
m_diskStack = itemStack;
m_diskMount = null;
@ -284,7 +294,7 @@ public class TileDiskDrive extends TilePeripheralBase
}
// Unmount old disk
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
Set<IComputerAccess> computers = m_computers.keySet();
for( IComputerAccess computer : computers )
@ -310,7 +320,7 @@ public class TileDiskDrive extends TilePeripheralBase
updateAnim();
// Mount new disk
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
Set<IComputerAccess> computers = m_computers.keySet();
for( IComputerAccess computer : computers )
@ -379,7 +389,7 @@ public class TileDiskDrive extends TilePeripheralBase
}
@Override
public boolean isUseableByPlayer( @Nonnull EntityPlayer player )
public boolean isUsableByPlayer( @Nonnull EntityPlayer player )
{
return isUsable( player, false );
}
@ -389,7 +399,7 @@ public class TileDiskDrive extends TilePeripheralBase
{
synchronized( this )
{
setInventorySlotContents( 0, null );
setInventorySlotContents( 0, ItemStack.EMPTY );
}
}
@ -426,7 +436,7 @@ public class TileDiskDrive extends TilePeripheralBase
}
}
public void setDiskStack( ItemStack stack )
public void setDiskStack( @Nonnull ItemStack stack )
{
synchronized( this )
{
@ -507,7 +517,7 @@ public class TileDiskDrive extends TilePeripheralBase
private synchronized void mountDisk( IComputerAccess computer )
{
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
MountInfo info = m_computers.get( computer );
IMedia contents = getDiskMedia();
@ -515,7 +525,7 @@ public class TileDiskDrive extends TilePeripheralBase
{
if( m_diskMount == null )
{
m_diskMount = contents.createDataMount( m_diskStack, worldObj );
m_diskMount = contents.createDataMount( m_diskStack, getWorld() );
}
if( m_diskMount != null )
{
@ -551,7 +561,7 @@ public class TileDiskDrive extends TilePeripheralBase
private synchronized void unmountDisk( IComputerAccess computer )
{
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
MountInfo info = m_computers.get( computer );
assert( info != null );
@ -566,7 +576,7 @@ public class TileDiskDrive extends TilePeripheralBase
private synchronized void updateAnim()
{
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
IMedia contents = getDiskMedia();
if( contents != null ) {
@ -583,16 +593,16 @@ public class TileDiskDrive extends TilePeripheralBase
private synchronized void ejectContents( boolean destroyed )
{
if( worldObj.isRemote )
if( getWorld().isRemote )
{
return;
}
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
// Remove the disks from the inventory
ItemStack disks = m_diskStack;
setInventorySlotContents( 0, null );
setInventorySlotContents( 0, ItemStack.EMPTY );
// Spawn the item in the world
int xOff = 0;
@ -608,15 +618,15 @@ public class TileDiskDrive extends TilePeripheralBase
double x = (double)pos.getX() + 0.5 + ((double)xOff * 0.5);
double y = (double)pos.getY() + 0.75;
double z = (double)pos.getZ() + 0.5 + ((double)zOff * 0.5);
EntityItem entityitem = new EntityItem( worldObj, x, y, z, disks );
EntityItem entityitem = new EntityItem( getWorld(), x, y, z, disks );
entityitem.motionX = (double)xOff * 0.15;
entityitem.motionY = 0.0;
entityitem.motionZ = (double)zOff * 0.15;
worldObj.spawnEntityInWorld(entityitem);
getWorld().spawnEntity(entityitem);
if( !destroyed )
{
worldObj.playBroadcastSound(1000, getPos(), 0);
getWorld().playBroadcastSound(1000, getPos(), 0);
}
}
}
@ -627,11 +637,11 @@ public class TileDiskDrive extends TilePeripheralBase
super.readDescription( nbttagcompound );
if( nbttagcompound.hasKey( "item" ) )
{
m_diskStack = ItemStack.loadItemStackFromNBT( nbttagcompound.getCompoundTag( "item" ) );
m_diskStack = new ItemStack( nbttagcompound.getCompoundTag( "item" ) );
}
else
{
m_diskStack = null;
m_diskStack = ItemStack.EMPTY;
}
updateBlock();
}
@ -640,7 +650,7 @@ public class TileDiskDrive extends TilePeripheralBase
public void writeDescription( @Nonnull NBTTagCompound nbttagcompound )
{
super.writeDescription( nbttagcompound );
if( m_diskStack != null )
if( !m_diskStack.isEmpty() )
{
NBTTagCompound item = new NBTTagCompound();
m_diskStack.writeToNBT( item );
@ -681,17 +691,17 @@ public class TileDiskDrive extends TilePeripheralBase
SoundEvent record = (contents != null) ? contents.getAudio( m_diskStack ) : null;
if( record != null )
{
ComputerCraft.playRecord( record, contents.getAudioTitle( m_diskStack ), worldObj, getPos() );
ComputerCraft.playRecord( record, contents.getAudioTitle( m_diskStack ), getWorld(), getPos() );
}
else
{
ComputerCraft.playRecord( null, null, worldObj, getPos() );
ComputerCraft.playRecord( null, null, getWorld(), getPos() );
}
}
private void stopRecord()
{
ComputerCraft.playRecord( null, null, worldObj, getPos() );
ComputerCraft.playRecord( null, null, getWorld(), getPos() );
}
@Override
@ -700,7 +710,7 @@ public class TileDiskDrive extends TilePeripheralBase
return capability == ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
}
@Nonnull
@Nullable
@Override
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing facing )
{

View File

@ -338,7 +338,7 @@ public class TileCable extends TileModemBase
public void onNeighbourChange()
{
EnumFacing dir = getDirection();
if( !worldObj.isSideSolid(
if( !getWorld().isSideSolid(
getPos().offset( dir ),
dir.getOpposite()
) )
@ -348,14 +348,14 @@ public class TileCable extends TileModemBase
case WiredModem:
{
// Drop everything and remove block
((BlockGeneric)getBlockType()).dropAllItems( worldObj, getPos(), false );
worldObj.setBlockToAir( getPos() );
((BlockGeneric)getBlockType()).dropAllItems( getWorld(), getPos(), false );
getWorld().setBlockToAir( getPos() );
break;
}
case WiredModemWithCable:
{
// Drop the modem and convert to cable
((BlockGeneric)getBlockType()).dropItem( worldObj, getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 ) );
((BlockGeneric)getBlockType()).dropItem( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 ) );
setLabel( null );
setBlockState( getBlockState().withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ) );
break;
@ -378,27 +378,28 @@ public class TileCable extends TileModemBase
double yMax = 0.625;
double zMax = 0.625;
BlockPos pos = getPos();
if( BlockCable.isCable( worldObj, pos.west() ) )
World world = getWorld();
if( BlockCable.isCable( world, pos.west() ) )
{
xMin = 0.0;
}
if( BlockCable.isCable( worldObj, pos.east() ) )
if( BlockCable.isCable( world, pos.east() ) )
{
xMax = 1.0;
}
if( BlockCable.isCable( worldObj, pos.down() ) )
if( BlockCable.isCable( world, pos.down() ) )
{
yMin = 0.0;
}
if( BlockCable.isCable( worldObj, pos.up() ) )
if( BlockCable.isCable( world, pos.up() ) )
{
yMax = 1.0;
}
if( BlockCable.isCable( worldObj, pos.north() ) )
if( BlockCable.isCable( world, pos.north() ) )
{
zMin = 0.0;
}
if( BlockCable.isCable( worldObj, pos.south() ) )
if( BlockCable.isCable( world, pos.south() ) )
{
zMax = 1.0;
}
@ -444,7 +445,7 @@ public class TileCable extends TileModemBase
BlockPos pos = getPos();
for (EnumFacing facing : EnumFacing.VALUES)
{
if( BlockCable.isCable( worldObj, pos.offset( facing ) ) )
if( BlockCable.isCable( getWorld(), pos.offset( facing ) ) )
{
bounds.add( BOXES[ facing.ordinal() ] );
}
@ -457,7 +458,7 @@ public class TileCable extends TileModemBase
{
if( getPeripheralType() == PeripheralType.WiredModemWithCable && !player.isSneaking() )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
// On server, we interacted if a peripheral was found
String oldPeriphName = getConnectedPeripheralName();
@ -468,13 +469,13 @@ public class TileCable extends TileModemBase
{
if( oldPeriphName != null )
{
player.addChatMessage(
player.sendMessage(
new TextComponentTranslation( "gui.computercraft:wired_modem.peripheral_disconnected", oldPeriphName )
);
}
if( periphName != null )
{
player.addChatMessage(
player.sendMessage(
new TextComponentTranslation( "gui.computercraft:wired_modem.peripheral_connected", periphName )
);
}
@ -548,7 +549,7 @@ public class TileCable extends TileModemBase
public void update()
{
super.update();
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
synchronized( m_peripheralsByName )
{
@ -678,7 +679,7 @@ public class TileCable extends TileModemBase
public void networkChanged()
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( !m_destroyed )
{
@ -699,9 +700,9 @@ public class TileCable extends TileModemBase
for( EnumFacing dir : EnumFacing.values() )
{
BlockPos offset = getPos().offset( dir );
if( offset.getY() >= 0 && offset.getY() < worldObj.getHeight() && BlockCable.isCable( worldObj, offset ) )
if( offset.getY() >= 0 && offset.getY() < getWorld().getHeight() && BlockCable.isCable( getWorld(), offset ) )
{
TileEntity tile = worldObj.getTileEntity( offset );
TileEntity tile = getWorld().getTileEntity( offset );
if( tile != null && tile instanceof TileCable )
{
TileCable modem = (TileCable)tile;
@ -954,7 +955,7 @@ public class TileCable extends TileModemBase
if( m_attachedPeripheralID < 0 )
{
m_attachedPeripheralID = IDAssigner.getNextIDFromFile(new File(
ComputerCraft.getWorldDir(worldObj),
ComputerCraft.getWorldDir(getWorld()),
"computer/lastid_" + type + ".txt"
));
}
@ -971,7 +972,7 @@ public class TileCable extends TileModemBase
{
EnumFacing facing = getDirection();
BlockPos neighbour = getPos().offset( facing );
return PeripheralUtil.getPeripheral( worldObj, neighbour, facing.getOpposite() );
return PeripheralUtil.getPeripheral( getWorld(), neighbour, facing.getOpposite() );
}
}
return null;
@ -1034,7 +1035,7 @@ public class TileCable extends TileModemBase
{
int searchID = ++s_nextUniqueSearchID;
Queue<SearchLoc> queue = new LinkedList<SearchLoc>();
enqueue( queue, worldObj, getPos(), 1 );
enqueue( queue, getWorld(), getPos(), 1 );
int visited = 0;
while( queue.peek() != null )

View File

@ -56,14 +56,14 @@ public abstract class TileModemBase extends TilePeripheralBase
public void onNeighbourChange()
{
EnumFacing dir = getDirection();
if( !worldObj.isSideSolid(
if( !getWorld().isSideSolid(
getPos().offset( dir ),
dir.getOpposite()
) )
{
// Drop everything and remove block
((BlockGeneric)getBlockType()).dropAllItems( worldObj, getPos(), false );
worldObj.setBlockToAir( getPos() );
((BlockGeneric)getBlockType()).dropAllItems( getWorld(), getPos(), false );
getWorld().setBlockToAir( getPos() );
}
}
@ -79,7 +79,7 @@ public abstract class TileModemBase extends TilePeripheralBase
public void update()
{
super.update();
if( !worldObj.isRemote && m_modem.pollChanged() )
if( !getWorld().isRemote && m_modem.pollChanged() )
{
updateAnim();
}

View File

@ -86,7 +86,7 @@ public class TileMonitor extends TilePeripheralBase
if( !m_destroyed )
{
m_destroyed = true;
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
contractNeighbours();
}
@ -103,7 +103,7 @@ public class TileMonitor extends TilePeripheralBase
{
if( !player.isSneaking() && getFront() == side )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
monitorTouched( hitX, hitY, hitZ );
}
@ -141,7 +141,7 @@ public class TileMonitor extends TilePeripheralBase
{
super.update();
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( m_sizeChangedQueued )
{
@ -264,7 +264,7 @@ public class TileMonitor extends TilePeripheralBase
private ITerminal getLocalTerminal()
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( m_serverTerminal == null )
{
@ -422,11 +422,12 @@ public class TileMonitor extends TilePeripheralBase
}
int y = pos.getY();
if( worldObj != null && y >= 0 && y < worldObj.getHeight() )
World world = getWorld();
if( world != null && y >= 0 && y < world.getHeight() )
{
if( worldObj.isBlockLoaded( pos ) )
if( world.isBlockLoaded( pos ) )
{
TileEntity tile = worldObj.getTileEntity( pos );
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileMonitor )
{
TileMonitor monitor = (TileMonitor)tile;

View File

@ -100,13 +100,14 @@ public class ContainerPrinter extends Container
@Override
public boolean canInteractWith( @Nonnull EntityPlayer player )
{
return m_printer.isUseableByPlayer( player );
return m_printer.isUsableByPlayer( player );
}
@Nonnull
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int i)
{
ItemStack itemstack = null;
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = inventorySlots.get(i);
if( slot != null && slot.getHasStack() )
{
@ -117,7 +118,7 @@ public class ContainerPrinter extends Container
// Transfer from printer to inventory
if(!mergeItemStack(itemstack1, 13, 49, true))
{
return null;
return ItemStack.EMPTY;
}
}
else
@ -127,34 +128,34 @@ public class ContainerPrinter extends Container
{
if( !mergeItemStack(itemstack1, 0, 1, false) )
{
return null;
return ItemStack.EMPTY;
}
}
else //if is paper
{
if( !mergeItemStack(itemstack1, 1, 13, false) )
{
return null;
return ItemStack.EMPTY;
}
}
}
if(itemstack1.stackSize == 0)
if(itemstack1.isEmpty())
{
slot.putStack(null);
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if(itemstack1.stackSize != itemstack.stackSize)
if(itemstack1.getCount() != itemstack.getCount())
{
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
slot.onTake(par1EntityPlayer, itemstack1);
}
else
{
return null;
return ItemStack.EMPTY;
}
}
return itemstack;

View File

@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
@ -51,7 +52,7 @@ public class TilePrinter extends TilePeripheralBase
// Members
private final ItemStack[] m_inventory;
private final NonNullList<ItemStack> m_inventory;
private final IItemHandlerModifiable m_itemHandlerAll = new InvWrapper( this );
private IItemHandlerModifiable[] m_itemHandlerSides;
@ -61,7 +62,7 @@ public class TilePrinter extends TilePeripheralBase
public TilePrinter()
{
m_inventory = new ItemStack[13];
m_inventory = NonNullList.withSize( 13, ItemStack.EMPTY );
m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
m_pageTitle = "";
m_printing = false;
@ -78,7 +79,7 @@ public class TilePrinter extends TilePeripheralBase
{
if( !player.isSneaking() )
{
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
ComputerCraft.openPrinterGUI( player, this );
}
@ -108,9 +109,9 @@ public class TilePrinter extends TilePeripheralBase
{
NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i );
int j = itemTag.getByte("Slot") & 0xff;
if (j >= 0 && j < m_inventory.length)
if (j >= 0 && j < m_inventory.size())
{
m_inventory[j] = ItemStack.loadItemStackFromNBT(itemTag);
m_inventory.set( j, new ItemStack( itemTag ) );
}
}
}
@ -134,13 +135,13 @@ public class TilePrinter extends TilePeripheralBase
synchronized( m_inventory )
{
NBTTagList nbttaglist = new NBTTagList();
for(int i=0; i<m_inventory.length; ++i)
for(int i=0; i<m_inventory.size(); ++i)
{
if (m_inventory[i] != null)
if( !m_inventory.get( i ).isEmpty() )
{
NBTTagCompound itemtag = new NBTTagCompound();
itemtag.setByte("Slot", (byte)i);
m_inventory[i].writeToNBT(itemtag);
m_inventory.get( i ).writeToNBT( itemtag );
nbttaglist.appendTag(itemtag);
}
}
@ -173,53 +174,66 @@ public class TilePrinter extends TilePeripheralBase
@Override
public int getSizeInventory()
{
return m_inventory.length;
return m_inventory.size();
}
@Override
public boolean isEmpty()
{
for( ItemStack stack : m_inventory )
{
if( !stack.isEmpty() ) return false;
}
return true;
}
@Nonnull
@Override
public ItemStack getStackInSlot(int i)
{
synchronized( m_inventory )
{
return m_inventory[i];
return m_inventory.get( i );
}
}
@Nonnull
@Override
public ItemStack removeStackFromSlot(int i)
{
synchronized( m_inventory )
{
ItemStack result = m_inventory[i];
m_inventory[i] = null;
ItemStack result = m_inventory.get( i );
m_inventory.set( i, ItemStack.EMPTY );
updateAnim();
return result;
}
}
@Nonnull
@Override
public ItemStack decrStackSize(int i, int j)
{
synchronized( m_inventory )
{
if( m_inventory[i] == null )
if( m_inventory.get( i ).isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
if( m_inventory[i].stackSize <= j )
if( m_inventory.get( i ).getCount() <= j )
{
ItemStack itemstack = m_inventory[i];
m_inventory[i] = null;
ItemStack itemstack = m_inventory.get( i );
m_inventory.set( i, ItemStack.EMPTY );
markDirty();
updateAnim();
return itemstack;
}
ItemStack part = m_inventory[i].splitStack(j);
if( m_inventory[i].stackSize == 0 )
ItemStack part = m_inventory.get( i ).splitStack(j);
if( m_inventory.get( i ).isEmpty() )
{
m_inventory[i] = null;
m_inventory.set( i, ItemStack.EMPTY );
updateAnim();
}
markDirty();
@ -228,11 +242,11 @@ public class TilePrinter extends TilePeripheralBase
}
@Override
public void setInventorySlotContents( int i, ItemStack stack )
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
{
synchronized( m_inventory )
{
m_inventory[i] = stack;
m_inventory.set( i, stack );
markDirty();
updateAnim();
}
@ -243,9 +257,9 @@ public class TilePrinter extends TilePeripheralBase
{
synchronized( m_inventory )
{
for( int i=0; i<m_inventory.length; ++i )
for( int i=0; i<m_inventory.size(); ++i )
{
m_inventory[i] = null;
m_inventory.set( i, ItemStack.EMPTY );
}
markDirty();
updateAnim();
@ -310,7 +324,7 @@ public class TilePrinter extends TilePeripheralBase
}
@Override
public boolean isUseableByPlayer( @Nonnull EntityPlayer player )
public boolean isUsableByPlayer( @Nonnull EntityPlayer player )
{
return isUsable( player, false );
}
@ -410,10 +424,10 @@ public class TilePrinter extends TilePeripheralBase
{
synchronized( m_inventory )
{
ItemStack inkStack = m_inventory[0];
if( inkStack != null && isInk(inkStack) )
ItemStack inkStack = m_inventory.get( 0 );
if( !inkStack.isEmpty() && isInk(inkStack) )
{
return inkStack.stackSize;
return inkStack.getCount();
}
}
return 0;
@ -426,10 +440,10 @@ public class TilePrinter extends TilePeripheralBase
{
for( int i=1; i<7; ++i )
{
ItemStack paperStack = m_inventory[i];
if( paperStack != null && isPaper(paperStack) )
ItemStack paperStack = m_inventory.get( i );
if( !paperStack.isEmpty() && isPaper(paperStack) )
{
count += paperStack.stackSize;
count += paperStack.getCount();
}
}
}
@ -444,12 +458,12 @@ public class TilePrinter extends TilePeripheralBase
}
}
private boolean isInk( ItemStack stack )
private boolean isInk( @Nonnull ItemStack stack )
{
return (stack.getItem() == Items.DYE);
}
private boolean isPaper( ItemStack stack )
private boolean isPaper( @Nonnull ItemStack stack )
{
Item item = stack.getItem();
return ( item == Items.PAPER || (item instanceof ItemPrintout && ItemPrintout.getType( stack ) == ItemPrintout.Type.Single) );
@ -459,8 +473,8 @@ public class TilePrinter extends TilePeripheralBase
{
synchronized( m_inventory )
{
ItemStack inkStack = m_inventory[ 0 ];
return inkStack != null && isInk( inkStack ) && getPaperLevel() > 0;
ItemStack inkStack = m_inventory.get( 0 );
return !inkStack.isEmpty() && isInk( inkStack ) && getPaperLevel() > 0;
}
}
@ -468,29 +482,29 @@ public class TilePrinter extends TilePeripheralBase
{
synchronized( m_inventory )
{
ItemStack inkStack = m_inventory[0];
if( inkStack == null || !isInk(inkStack) )
ItemStack inkStack = m_inventory.get( 0 );
if( inkStack.isEmpty() || !isInk(inkStack) )
{
return false;
}
for( int i=1; i<7; ++i )
{
ItemStack paperStack = m_inventory[i];
if( paperStack != null && isPaper(paperStack) )
ItemStack paperStack = m_inventory.get( i );
if( !paperStack.isEmpty() && isPaper(paperStack) )
{
// Decrement ink
inkStack.stackSize--;
if( inkStack.stackSize <= 0 )
inkStack.shrink( 1 );
if( inkStack.isEmpty() )
{
m_inventory[0] = null;
m_inventory.set( 0, ItemStack.EMPTY );
}
// Decrement paper
paperStack.stackSize--;
if( paperStack.stackSize <= 0 )
paperStack.shrink( 1 );
if( paperStack.isEmpty() )
{
m_inventory[i] = null;
m_inventory.set( i, ItemStack.EMPTY );
updateAnim();
}
@ -545,7 +559,7 @@ public class TilePrinter extends TilePeripheralBase
synchronized( m_inventory )
{
ItemStack remainder = InventoryUtil.storeItems( stack, m_itemHandlerAll, 7, 6, 7 );
if( remainder == null )
if( remainder.isEmpty() )
{
m_printing = false;
return true;
@ -561,22 +575,22 @@ public class TilePrinter extends TilePeripheralBase
{
for( int i=0; i<13; ++i )
{
ItemStack stack = m_inventory[i];
if( stack != null )
ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() )
{
// Remove the stack from the inventory
setInventorySlotContents( i, null );
setInventorySlotContents( i, ItemStack.EMPTY );
// Spawn the item in the world
BlockPos pos = getPos();
double x = (double)pos.getX() + 0.5;
double y = (double)pos.getY() + 0.75;
double z = (double)pos.getZ() + 0.5;
EntityItem entityitem = new EntityItem( worldObj, x, y, z, stack );
entityitem.motionX = worldObj.rand.nextFloat() * 0.2 - 0.1;
entityitem.motionY = worldObj.rand.nextFloat() * 0.2 - 0.1;
entityitem.motionZ = worldObj.rand.nextFloat() * 0.2 - 0.1;
worldObj.spawnEntityInWorld(entityitem);
EntityItem entityitem = new EntityItem( getWorld(), x, y, z, stack );
entityitem.motionX = getWorld().rand.nextFloat() * 0.2 - 0.1;
entityitem.motionY = getWorld().rand.nextFloat() * 0.2 - 0.1;
entityitem.motionZ = getWorld().rand.nextFloat() * 0.2 - 0.1;
getWorld().spawnEntity(entityitem);
}
}
}
@ -589,8 +603,8 @@ public class TilePrinter extends TilePeripheralBase
int anim = 0;
for( int i=1;i<7;++i )
{
ItemStack stack = m_inventory[i];
if( stack != null && isPaper(stack) )
ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() && isPaper(stack) )
{
anim += 1;
break;
@ -598,8 +612,8 @@ public class TilePrinter extends TilePeripheralBase
}
for( int i=7;i<13;++i )
{
ItemStack stack = m_inventory[i];
if( stack != null && isPaper(stack) )
ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() && isPaper(stack) )
{
anim += 2;
break;
@ -615,7 +629,7 @@ public class TilePrinter extends TilePeripheralBase
return capability == ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
}
@Nonnull
@Nullable
@Override
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing facing )
{

View File

@ -18,6 +18,7 @@ import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import javax.annotation.Nonnull;
@ -99,12 +100,12 @@ public class PocketAPI implements ILuaAPI
if( previousUpgrade != null )
{
ItemStack stack = previousUpgrade.getCraftingItem();
if( stack != null )
if( !stack.isEmpty() )
{
stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem );
if( stack != null )
if( !stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, player.worldObj, player.posX, player.posY, player.posZ );
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
}
}
@ -138,12 +139,12 @@ public class PocketAPI implements ILuaAPI
m_computer.setUpgrade( null );
ItemStack stack = previousUpgrade.getCraftingItem();
if( stack != null )
if( !stack.isEmpty() )
{
stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem );
if( stack != null )
if( stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, player.worldObj, player.posX, player.posY, player.posZ );
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
}
@ -155,12 +156,12 @@ public class PocketAPI implements ILuaAPI
}
}
private static IPocketUpgrade findUpgrade( ItemStack[] inv, int start, IPocketUpgrade previous )
private static IPocketUpgrade findUpgrade( NonNullList<ItemStack> inv, int start, IPocketUpgrade previous )
{
for (int i = 0; i < inv.length; i++)
for( int i = 0; i < inv.size(); i++ )
{
ItemStack invStack = inv[ (i + start) % inv.length ];
if( invStack != null )
ItemStack invStack = inv.get( (i + start) % inv.size() );
if( !invStack.isEmpty() )
{
IPocketUpgrade newUpgrade = ComputerCraft.getPocketUpgrade( invStack );
@ -168,8 +169,8 @@ public class PocketAPI implements ILuaAPI
{
// Consume an item from this stack and exit the loop
invStack = invStack.copy();
invStack.stackSize--;
inv[ (i + start) % inv.length ] = invStack.stackSize <= 0 ? null : invStack;
invStack.shrink( 1 );
inv.set( (i + start) % inv.size(), invStack.isEmpty() ? ItemStack.EMPTY : invStack );
return newUpgrade;
}

View File

@ -148,7 +148,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
}
}
public synchronized void updateValues( Entity entity, ItemStack stack, IPocketUpgrade upgrade )
public synchronized void updateValues( Entity entity, @Nonnull ItemStack stack, IPocketUpgrade upgrade )
{
if( entity != null )
{

View File

@ -23,7 +23,7 @@ public class ContainerPocketComputer extends ContainerHeldItem
public IComputer getComputer()
{
ItemStack stack = getStack();
if( stack != null && stack.getItem() instanceof ItemPocketComputer )
if( !stack.isEmpty() && stack.getItem() instanceof ItemPocketComputer )
{
return ((ItemPocketComputer) stack.getItem()).getServerComputer( stack );
}

View File

@ -27,10 +27,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.relauncher.Side;
@ -89,16 +86,16 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
@Override
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList<ItemStack> list )
{
getSubItems( list, ComputerFamily.Normal );
getSubItems( list, ComputerFamily.Advanced );
}
private void getSubItems( List<ItemStack> list, ComputerFamily family )
private void getSubItems( NonNullList<ItemStack> list, ComputerFamily family )
{
list.add( PocketComputerItemFactory.create( -1, null, -1, family, null ) );
for (IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades())
for( IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades() )
{
list.add( PocketComputerItemFactory.create( -1, null, -1, family, upgrade ) );
}
@ -163,8 +160,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick( @Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand )
public ActionResult<ItemStack> onItemRightClick( World world, EntityPlayer player, @Nonnull EnumHand hand )
{
ItemStack stack = player.getHeldItem( hand );
if( !world.isRemote )
{
PocketServerComputer computer = createServerComputer( world, player.inventory, player, stack );
@ -189,7 +187,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
@Nonnull
@Override
public String getUnlocalizedName( ItemStack stack )
public String getUnlocalizedName( @Nonnull ItemStack stack )
{
switch( getFamily( stack ) )
{
@ -225,7 +223,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
@Override
public void addInformation( ItemStack stack, EntityPlayer player, List<String> list, boolean debug )
public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List<String> list, boolean debug )
{
if( debug )
{
@ -237,7 +235,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
}
private PocketServerComputer createServerComputer( final World world, IInventory inventory, Entity entity, ItemStack stack )
private PocketServerComputer createServerComputer( final World world, IInventory inventory, Entity entity, @Nonnull ItemStack stack )
{
if( world.isRemote )
{
@ -287,7 +285,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return computer;
}
public ServerComputer getServerComputer( ItemStack stack )
public ServerComputer getServerComputer( @Nonnull ItemStack stack )
{
int instanceID = getInstanceID( stack );
if( instanceID >= 0 )
@ -297,7 +295,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return null;
}
public ClientComputer createClientComputer( ItemStack stack )
public ClientComputer createClientComputer( @Nonnull ItemStack stack )
{
int instanceID = getInstanceID( stack );
if( instanceID >= 0 )
@ -311,7 +309,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return null;
}
private ClientComputer getClientComputer( ItemStack stack )
private ClientComputer getClientComputer( @Nonnull ItemStack stack )
{
int instanceID = getInstanceID( stack );
if( instanceID >= 0 )
@ -324,7 +322,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
// IComputerItem implementation
@Override
public int getComputerID( ItemStack stack )
public int getComputerID( @Nonnull ItemStack stack )
{
NBTTagCompound compound = stack.getTagCompound();
if( compound != null && compound.hasKey( "computerID" ) )
@ -334,7 +332,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return -1;
}
private void setComputerID( ItemStack stack, int computerID )
private void setComputerID( @Nonnull ItemStack stack, int computerID )
{
if( !stack.hasTagCompound() )
{
@ -354,7 +352,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
@Override
public ComputerFamily getFamily( ItemStack stack )
public ComputerFamily getFamily( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
switch( damage )
@ -410,7 +408,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return null;
}
private int getInstanceID( ItemStack stack )
private int getInstanceID( @Nonnull ItemStack stack )
{
NBTTagCompound compound = stack.getTagCompound();
if( compound != null && compound.hasKey( "instanceID" ) )
@ -420,7 +418,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return -1;
}
private void setInstanceID( ItemStack stack, int instanceID )
private void setInstanceID( @Nonnull ItemStack stack, int instanceID )
{
if( !stack.hasTagCompound() )
{
@ -429,7 +427,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
stack.getTagCompound().setInteger( "instanceID", instanceID );
}
private int getSessionID( ItemStack stack )
private int getSessionID( @Nonnull ItemStack stack )
{
NBTTagCompound compound = stack.getTagCompound();
if( compound != null && compound.hasKey( "sessionID" ) )
@ -439,7 +437,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return -1;
}
private void setSessionID( ItemStack stack, int sessionID )
private void setSessionID( @Nonnull ItemStack stack, int sessionID )
{
if( !stack.hasTagCompound() )
{
@ -449,7 +447,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
@SideOnly(Side.CLIENT)
public ComputerState getState( ItemStack stack )
public ComputerState getState( @Nonnull ItemStack stack )
{
ClientComputer computer = getClientComputer( stack );
if( computer != null && computer.isOn() )
@ -460,7 +458,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
}
@SideOnly(Side.CLIENT)
public int getLightState( ItemStack stack )
public int getLightState( @Nonnull ItemStack stack )
{
ClientComputer computer = getClientComputer( stack );
if( computer != null && computer.isOn() )
@ -474,7 +472,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return -1;
}
public IPocketUpgrade getUpgrade( ItemStack stack )
public IPocketUpgrade getUpgrade( @Nonnull ItemStack stack )
{
NBTTagCompound compound = stack.getTagCompound();
if( compound != null )
@ -497,7 +495,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
return null;
}
public void setUpgrade( ItemStack stack, IPocketUpgrade upgrade )
public void setUpgrade( @Nonnull ItemStack stack, IPocketUpgrade upgrade )
{
NBTTagCompound compound = stack.getTagCompound();
if( compound == null ) stack.setTagCompound( compound = new NBTTagCompound() );
@ -514,7 +512,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
compound.removeTag( "upgrade_info" );
}
public NBTTagCompound getUpgradeInfo( ItemStack stack )
public NBTTagCompound getUpgradeInfo( @Nonnull ItemStack stack )
{
NBTTagCompound tag = stack.getTagCompound();
if( tag == null )

View File

@ -11,8 +11,11 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class PocketComputerItemFactory
{
@Nonnull
public static ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
{
ItemPocketComputer computer = ComputerCraft.Items.pocketComputer;
@ -24,6 +27,6 @@ public class PocketComputerItemFactory
return computer.create( id, label, colour, family, upgrade );
}
}
return null;
return ItemStack.EMPTY;
}
}

View File

@ -41,7 +41,7 @@ public class PocketModem implements IPocketUpgrade
: "upgrade.computercraft:wireless_modem.adjective";
}
@Nullable
@Nonnull
@Override
public ItemStack getCraftingItem()
{

View File

@ -40,7 +40,7 @@ public class PocketSpeaker implements IPocketUpgrade
return "upgrade.computercraft:speaker.adjective";
}
@Nullable
@Nonnull
@Override
public ItemStack getCraftingItem()
{

View File

@ -14,7 +14,9 @@ import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
@ -30,6 +32,7 @@ public class PocketComputerUpgradeRecipe implements IRecipe
return 2;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
@ -39,14 +42,15 @@ public class PocketComputerUpgradeRecipe implements IRecipe
@Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
{
return (getCraftingResult( inventory ) != null);
return !getCraftingResult( inventory ).isEmpty();
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
// Scan the grid for a pocket computer
ItemStack computer = null;
ItemStack computer = ItemStack.EMPTY;
int computerX = -1;
int computerY = -1;
for (int y = 0; y < inventory.getHeight(); ++y)
@ -54,7 +58,7 @@ public class PocketComputerUpgradeRecipe implements IRecipe
for (int x = 0; x < inventory.getWidth(); ++x)
{
ItemStack item = inventory.getStackInRowAndColumn( x, y );
if( item != null && item.getItem() instanceof ItemPocketComputer )
if( !item.isEmpty() && item.getItem() instanceof ItemPocketComputer )
{
computer = item;
computerX = x;
@ -62,21 +66,21 @@ public class PocketComputerUpgradeRecipe implements IRecipe
break;
}
}
if( computer != null )
if( !computer.isEmpty() )
{
break;
}
}
if( computer == null )
if( computer.isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
ItemPocketComputer itemComputer = (ItemPocketComputer)computer.getItem();
if( itemComputer.getUpgrade( computer ) != null )
{
return null;
return ItemStack.EMPTY;
}
// Check for upgrades around the item
@ -93,18 +97,18 @@ public class PocketComputerUpgradeRecipe implements IRecipe
else if( x == computerX && y == computerY - 1 )
{
upgrade = ComputerCraft.getPocketUpgrade( item );
if( upgrade == null ) return null;
if( upgrade == null ) return ItemStack.EMPTY;
}
else if( item != null )
else if( !item.isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
}
}
if( upgrade == null )
{
return null;
return ItemStack.EMPTY;
}
// Construct the new stack
@ -117,13 +121,13 @@ public class PocketComputerUpgradeRecipe implements IRecipe
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ];
for (int i = 0; i < results.length; ++i)
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inventoryCrafting.getStackInSlot(i);
results[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(stack);
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -37,6 +37,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
@ -46,6 +47,7 @@ import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.RecipeSorter;
import javax.annotation.Nonnull;
import java.util.*;
public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
@ -66,7 +68,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
@Override
public void preInit()
{
EntityRegistry.registerModEntity(TurtlePlayer.class, "turtlePlayer", 0, ComputerCraft.instance, Integer.MAX_VALUE, Integer.MAX_VALUE, false);
EntityRegistry.registerModEntity(
new ResourceLocation( ComputerCraft.MOD_ID, "turtle_player" ), TurtlePlayer.class, "turtle_player",
0, ComputerCraft.instance, Integer.MAX_VALUE, Integer.MAX_VALUE, false
);
registerItems();
}
@ -106,7 +111,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
}
@Override
public ITurtleUpgrade getTurtleUpgrade( ItemStack stack )
public ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack stack )
{
for( ITurtleUpgrade upgrade : m_turtleUpgrades.values() )
{
@ -143,10 +148,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
}
}
private void addAllUpgradedTurtles( ComputerFamily family, List<ItemStack> list )
private void addAllUpgradedTurtles( ComputerFamily family, NonNullList<ItemStack> list )
{
ItemStack basicStack = TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null );
if( basicStack != null )
if( !basicStack.isEmpty() )
{
list.add( basicStack );
}
@ -166,7 +171,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
if ( isUpgradeSuitableForFamily( family, upgrade ) )
{
ItemStack stack = TurtleItemFactory.create( -1, null, -1, family, upgrade, null, 0, null );
if( stack != null )
if( !stack.isEmpty() )
{
list.add( stack );
}
@ -174,7 +179,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
}
@Override
public void addAllUpgradedTurtles( List<ItemStack> list )
public void addAllUpgradedTurtles( NonNullList<ItemStack> list )
{
addAllUpgradedTurtles( ComputerFamily.Normal, list );
addAllUpgradedTurtles( ComputerFamily.Advanced, list );
@ -276,7 +281,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
}
ItemStack baseTurtle = TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null );
if( baseTurtle != null )
if( !baseTurtle.isEmpty() )
{
ItemStack craftedTurtle = TurtleItemFactory.create( -1, null, -1, family, upgrade, null, 0, null );
ItemStack craftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, null, upgrade, 0, null );
@ -405,15 +410,15 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
String key = mapping.resourceLocation.getResourcePath();
if( key.equals( "CC-Turtle" ) )
if( key.equalsIgnoreCase( "CC-Turtle" ) )
{
remap( mapping, ComputerCraft.Blocks.turtle );
}
else if( key.equals( "CC-TurtleExpanded" ) )
else if( key.equalsIgnoreCase( "CC-TurtleExpanded" ) )
{
remap( mapping, ComputerCraft.Blocks.turtleExpanded );
}
else if( key.equals( "CC-TurtleAdvanced" ) )
else if( key.equalsIgnoreCase( "CC-TurtleAdvanced" ) )
{
remap( mapping, ComputerCraft.Blocks.turtleAdvanced );
}

View File

@ -85,6 +85,7 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.RecipeSorter;
import javax.annotation.Nonnull;
import java.io.File;
public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
@ -126,7 +127,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public abstract Object getFixedWidthFontRenderer();
@Override
public String getRecordInfo( ItemStack recordStack )
public String getRecordInfo( @Nonnull ItemStack recordStack )
{
Item item = recordStack.getItem();
if (item instanceof ItemRecord)
@ -500,27 +501,27 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
String key = mapping.resourceLocation.getResourcePath();
if( key.equals( "CC-Computer" ) )
if( key.equalsIgnoreCase( "CC-Computer" ) )
{
remap( mapping, ComputerCraft.Blocks.computer );
}
else if( key.equals( "CC-Peripheral" ) )
else if( key.equalsIgnoreCase( "CC-Peripheral" ) )
{
remap( mapping, ComputerCraft.Blocks.peripheral );
}
else if( key.equals( "CC-Cable" ) )
else if( key.equalsIgnoreCase( "CC-Cable" ) )
{
remap( mapping, ComputerCraft.Blocks.cable );
}
else if( key.equals( "diskExpanded" ) )
else if( key.equalsIgnoreCase( "diskExpanded" ) )
{
mapping.remap( ComputerCraft.Items.diskExpanded );
}
else if( key.equals( "treasureDisk" ) )
else if( key.equalsIgnoreCase( "treasureDisk" ) )
{
mapping.remap( ComputerCraft.Items.treasureDisk );
}
else if( key.equals( "pocketComputer" ) )
else if( key.equalsIgnoreCase( "pocketComputer" ) )
{
mapping.remap( ComputerCraft.Items.pocketComputer );
}

View File

@ -11,8 +11,9 @@ import dan200.computercraft.shared.util.IEntityDropConsumer;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import net.minecraft.util.NonNullList;
import java.util.List;
import javax.annotation.Nonnull;
public interface ICCTurtleProxy
{
@ -23,8 +24,8 @@ public interface ICCTurtleProxy
void registerTurtleUpgrade( ITurtleUpgrade upgrade );
ITurtleUpgrade getTurtleUpgrade( String id );
ITurtleUpgrade getTurtleUpgrade( int legacyId );
ITurtleUpgrade getTurtleUpgrade( ItemStack item );
void addAllUpgradedTurtles( List<ItemStack> list );
ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack item );
void addAllUpgradedTurtles( NonNullList<ItemStack> list );
void setEntityDropConsumer( Entity entity, IEntityDropConsumer consumer );
void clearEntityDropConsumer( Entity entity );

View File

@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import javax.annotation.Nonnull;
import java.io.File;
public interface IComputerCraftProxy
@ -34,7 +35,7 @@ public interface IComputerCraftProxy
void deleteDisplayLists( int list, int range );
Object getFixedWidthFontRenderer();
String getRecordInfo( ItemStack item );
String getRecordInfo( @Nonnull ItemStack item );
void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos );
Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );

View File

@ -250,9 +250,9 @@ public class TurtleAPI implements ILuaAPI
// getItemCount
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
if( stack != null )
if( !stack.isEmpty() )
{
return new Object[] { stack.stackSize };
return new Object[] { stack.getCount() };
}
else
{
@ -264,10 +264,10 @@ public class TurtleAPI implements ILuaAPI
// getItemSpace
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
if( stack != null )
if( !stack.isEmpty() )
{
return new Object[] {
Math.min( stack.getMaxStackSize(), 64 ) - stack.stackSize
Math.min( stack.getMaxStackSize(), 64 ) - stack.getCount()
};
}
return new Object[] { 64 };
@ -428,12 +428,12 @@ public class TurtleAPI implements ILuaAPI
// getItemDetail
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
if( stack != null && stack.stackSize > 0 )
if( !stack.isEmpty() )
{
Item item = stack.getItem();
String name = Item.REGISTRY.getNameForObject( item ).toString();
int damage = stack.getItemDamage();
int count = stack.stackSize;
int count = stack.getCount();
Map<Object, Object> table = new HashMap<Object, Object>();
table.put( "name", name );

View File

@ -152,13 +152,13 @@ public class BlockTurtle extends BlockComputerBase
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemstack )
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack itemstack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileTurtle )
{
tile.setWorldObj( world ); // Not sure why this is necessary
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}

View File

@ -29,10 +29,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@ -68,8 +65,8 @@ public class TileTurtle extends TileComputerBase
MOVED
}
private ItemStack[] m_inventory;
private ItemStack[] m_previousInventory;
private NonNullList<ItemStack> m_inventory;
private NonNullList<ItemStack> m_previousInventory;
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this );
private boolean m_inventoryChanged;
private TurtleBrain m_brain;
@ -77,8 +74,8 @@ public class TileTurtle extends TileComputerBase
public TileTurtle()
{
m_inventory = new ItemStack[ INVENTORY_SIZE ];
m_previousInventory = new ItemStack[ getSizeInventory() ];
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
m_inventoryChanged = false;
m_brain = createBrain();
m_moveState = MoveState.NOT_MOVED;
@ -97,7 +94,7 @@ public class TileTurtle extends TileComputerBase
protected final ServerComputer createComputer( int instanceID, int id, int termWidth, int termHeight )
{
ServerComputer computer = new ServerComputer(
worldObj,
getWorld(),
id,
m_label,
instanceID,
@ -126,15 +123,15 @@ public class TileTurtle extends TileComputerBase
super.destroy();
// Drop contents
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
int size = getSizeInventory();
for( int i=0; i<size; ++i )
{
ItemStack stack = getStackInSlot( i );
if( stack != null )
if( !stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, worldObj, getPos() );
WorldUtil.dropItemStack( stack, getWorld(), getPos() );
}
}
}
@ -144,7 +141,7 @@ public class TileTurtle extends TileComputerBase
// Just turn off any redstone we had on
for( EnumFacing dir : EnumFacing.VALUES )
{
RedstoneUtil.propogateRedstoneOutput( worldObj, getPos(), dir );
RedstoneUtil.propogateRedstoneOutput( getWorld(), getPos(), dir );
}
}
}
@ -182,12 +179,12 @@ public class TileTurtle extends TileComputerBase
// Apply dye
ItemStack currentItem = player.getHeldItem( EnumHand.MAIN_HAND );
if( currentItem != null )
if( !currentItem.isEmpty() )
{
if( currentItem.getItem() == Items.DYE )
{
// Dye to change turtle colour
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
int dye = (currentItem.getItemDamage() & 0xf);
if( m_brain.getDyeColour() != dye )
@ -195,7 +192,7 @@ public class TileTurtle extends TileComputerBase
m_brain.setDyeColour( dye );
if( !player.capabilities.isCreativeMode )
{
currentItem.stackSize--;
currentItem.shrink( 1 );
}
}
}
@ -204,7 +201,7 @@ public class TileTurtle extends TileComputerBase
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 )
{
// Water to remove turtle colour
if( !worldObj.isRemote )
if( !getWorld().isRemote )
{
if( m_brain.getColour() != -1 )
{
@ -279,7 +276,7 @@ public class TileTurtle extends TileComputerBase
m_brain.update();
synchronized( m_inventory )
{
if( !worldObj.isRemote && m_inventoryChanged )
if( !getWorld().isRemote && m_inventoryChanged )
{
IComputer computer = getComputer();
if( computer != null )
@ -290,7 +287,7 @@ public class TileTurtle extends TileComputerBase
m_inventoryChanged = false;
for( int n=0; n<getSizeInventory(); ++n )
{
m_previousInventory[n] = InventoryUtil.copyItem( getStackInSlot( n ) );
m_previousInventory.set( n, InventoryUtil.copyItem( getStackInSlot( n ) ) );
}
}
}
@ -338,16 +335,16 @@ public class TileTurtle extends TileComputerBase
// Read inventory
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
m_inventory = new ItemStack[ INVENTORY_SIZE ];
m_previousInventory = new ItemStack[ getSizeInventory() ];
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
for( int i=0; i<nbttaglist.tagCount(); ++i )
{
NBTTagCompound itemtag = nbttaglist.getCompoundTagAt( i );
int slot = itemtag.getByte("Slot") & 0xff;
if( slot >= 0 && slot < getSizeInventory() )
{
m_inventory[slot] = ItemStack.loadItemStackFromNBT( itemtag );
m_previousInventory[slot] = InventoryUtil.copyItem( m_inventory[slot] );
m_inventory.set( slot, new ItemStack( itemtag ) );
m_previousInventory.set( slot, InventoryUtil.copyItem( m_inventory.get( slot ) ) );
}
}
@ -365,11 +362,11 @@ public class TileTurtle extends TileComputerBase
NBTTagList nbttaglist = new NBTTagList();
for( int i=0; i<INVENTORY_SIZE; ++i )
{
if( m_inventory[i] != null )
if( !m_inventory.get(i).isEmpty() )
{
NBTTagCompound itemtag = new NBTTagCompound();
itemtag.setByte( "Slot", (byte)i );
m_inventory[i].writeToNBT(itemtag);
m_inventory.get(i).writeToNBT(itemtag);
nbttaglist.appendTag(itemtag);
}
}
@ -459,6 +456,17 @@ public class TileTurtle extends TileComputerBase
return INVENTORY_SIZE;
}
@Override
public boolean isEmpty()
{
for( ItemStack stack : m_inventory )
{
if( !stack.isEmpty() ) return false;
}
return true;
}
@Nonnull
@Override
public ItemStack getStackInSlot( int slot )
{
@ -466,42 +474,44 @@ public class TileTurtle extends TileComputerBase
{
synchronized( m_inventory )
{
return m_inventory[ slot ];
return m_inventory.get( slot );
}
}
return null;
return ItemStack.EMPTY;
}
@Nonnull
@Override
public ItemStack removeStackFromSlot( int slot )
{
synchronized( m_inventory )
{
ItemStack result = getStackInSlot( slot );
setInventorySlotContents( slot, null );
setInventorySlotContents( slot, ItemStack.EMPTY );
return result;
}
}
@Nonnull
@Override
public ItemStack decrStackSize( int slot, int count )
{
if( count == 0 )
{
return null;
return ItemStack.EMPTY;
}
synchronized( m_inventory )
{
ItemStack stack = getStackInSlot( slot );
if( stack == null )
if( stack.isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
if( stack.stackSize <= count )
if( stack.getCount() <= count )
{
setInventorySlotContents( slot, null );
setInventorySlotContents( slot, ItemStack.EMPTY );
return stack;
}
@ -512,15 +522,15 @@ public class TileTurtle extends TileComputerBase
}
@Override
public void setInventorySlotContents( int i, ItemStack stack )
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
{
if( i >= 0 && i < INVENTORY_SIZE )
{
synchronized( m_inventory )
{
if( !InventoryUtil.areItemsEqual( stack, m_inventory[ i ] ) )
if( !InventoryUtil.areItemsEqual( stack, m_inventory.get( i ) ) )
{
m_inventory[ i ] = stack;
m_inventory.set( i, stack );
onInventoryDefinitelyChanged();
}
}
@ -535,9 +545,9 @@ public class TileTurtle extends TileComputerBase
boolean changed = false;
for( int i = 0; i < INVENTORY_SIZE; ++i )
{
if( m_inventory[i] != null )
if( !m_inventory.get( i ).isEmpty() )
{
m_inventory[i] = null;
m_inventory.set( i, ItemStack.EMPTY );
changed = true;
}
}
@ -625,7 +635,7 @@ public class TileTurtle extends TileComputerBase
{
for( int n=0; n<getSizeInventory(); ++n )
{
if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory[n] ) )
if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) )
{
m_inventoryChanged = true;
break;
@ -636,7 +646,7 @@ public class TileTurtle extends TileComputerBase
}
@Override
public boolean isUseableByPlayer( @Nonnull EntityPlayer player )
public boolean isUsableByPlayer( @Nonnull EntityPlayer player )
{
return isUsable( player, false );
}
@ -727,7 +737,7 @@ public class TileTurtle extends TileComputerBase
return capability == ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
}
@Nonnull
@Nullable
@Override
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing facing )
{

View File

@ -20,6 +20,7 @@ import dan200.computercraft.shared.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -286,11 +287,11 @@ public class TurtleBrain implements ITurtleAccess
m_upgradeNBTData.clear();
if( nbttagcompound.hasKey( "leftUpgradeNBT" ) )
{
m_upgradeNBTData.put( TurtleSide.Left, (NBTTagCompound) nbttagcompound.getCompoundTag( "leftUpgradeNBT" ).copy() );
m_upgradeNBTData.put( TurtleSide.Left, nbttagcompound.getCompoundTag( "leftUpgradeNBT" ).copy() );
}
if( nbttagcompound.hasKey( "rightUpgradeNBT" ) )
{
m_upgradeNBTData.put( TurtleSide.Right, (NBTTagCompound) nbttagcompound.getCompoundTag( "rightUpgradeNBT" ).copy() );
m_upgradeNBTData.put( TurtleSide.Right, nbttagcompound.getCompoundTag( "rightUpgradeNBT" ).copy() );
}
}
@ -420,11 +421,11 @@ public class TurtleBrain implements ITurtleAccess
m_upgradeNBTData.clear();
if( nbttagcompound.hasKey( "leftUpgradeNBT" ) )
{
m_upgradeNBTData.put( TurtleSide.Left, (NBTTagCompound) nbttagcompound.getCompoundTag( "leftUpgradeNBT" ).copy() );
m_upgradeNBTData.put( TurtleSide.Left, nbttagcompound.getCompoundTag( "leftUpgradeNBT" ).copy() );
}
if( nbttagcompound.hasKey( "rightUpgradeNBT" ) )
{
m_upgradeNBTData.put( TurtleSide.Right, (NBTTagCompound)nbttagcompound.getCompoundTag( "rightUpgradeNBT" ).copy() );
m_upgradeNBTData.put( TurtleSide.Right, nbttagcompound.getCompoundTag( "rightUpgradeNBT" ).copy() );
}
// Colour
@ -515,7 +516,7 @@ public class TurtleBrain implements ITurtleAccess
{
// Copy the old turtle state into the new turtle
TileTurtle newTurtle = (TileTurtle)newTile;
newTurtle.setWorldObj( world );
newTurtle.setWorld( world );
newTurtle.setPos( pos );
newTurtle.transferStateFrom( oldOwner );
newTurtle.createServerComputer().setWorld( world );
@ -1160,7 +1161,7 @@ public class TurtleBrain implements ITurtleAccess
double pushStepZ = (double) moveDir.getFrontOffsetZ() * pushStep;
for (Entity entity : list)
{
entity.moveEntity( pushStepX, pushStepY, pushStepZ );
entity.move( MoverType.PISTON, pushStepX, pushStepY, pushStepZ );
}
}
}

View File

@ -21,6 +21,7 @@ import net.minecraftforge.fml.relauncher.ReflectionHelper;
import javax.annotation.Nonnull;
import java.lang.reflect.Method;
import java.util.List;
public class TurtleCompareCommand implements ITurtleCommand
{
@ -46,7 +47,7 @@ public class TurtleCompareCommand implements ITurtleCommand
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
ItemStack lookAtStack = null;
ItemStack lookAtStack = ItemStack.EMPTY;
if( WorldUtil.isBlockInWorld( world, newPosition ) )
{
if( !world.isAirBlock( newPosition ) )
@ -61,8 +62,8 @@ public class TurtleCompareCommand implements ITurtleCommand
try
{
Method method = ReflectionHelper.findMethod(
Block.class, lookAtBlock,
new String[] { "func_180643_i", "createStackedBlock" },
Block.class,
"func_180643_i", "getSilkTouchDrop",
IBlockState.class
);
lookAtStack = (ItemStack) method.invoke( lookAtBlock, lookAtState );
@ -74,9 +75,9 @@ public class TurtleCompareCommand implements ITurtleCommand
// See if the block drops anything with the same ID as itself
// (try 5 times to try and beat random number generators)
for( int i=0; (i<5) && (lookAtStack == null); ++i )
for( int i=0; (i<5) && lookAtStack.isEmpty(); ++i )
{
java.util.List<ItemStack> drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 );
List<ItemStack> drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 );
if( drops != null && drops.size() > 0 )
{
for( ItemStack drop : drops )
@ -91,7 +92,7 @@ public class TurtleCompareCommand implements ITurtleCommand
}
// Last resort: roll our own (which will probably be wrong)
if( lookAtStack == null )
if( lookAtStack.isEmpty() )
{
Item item = Item.getItemFromBlock( lookAtBlock );
if( item != null && item.getHasSubtypes() )
@ -108,11 +109,11 @@ public class TurtleCompareCommand implements ITurtleCommand
}
// Compare them
if( selectedStack == null && lookAtStack == null )
if( selectedStack.isEmpty() && lookAtStack.isEmpty() )
{
return TurtleCommandResult.success();
}
else if( selectedStack != null && lookAtStack != null )
else if( !selectedStack.isEmpty() && lookAtStack != null )
{
if( selectedStack.getItem() == lookAtStack.getItem() )
{

View File

@ -41,7 +41,7 @@ public class TurtleCraftCommand implements ITurtleCommand
for( ItemStack stack : results )
{
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
// Drop the remainder
BlockPos position = turtle.getPosition();

View File

@ -12,10 +12,9 @@ import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
@ -48,7 +47,7 @@ public class TurtleDropCommand implements ITurtleCommand
// Get things to drop
ItemStack stack = InventoryUtil.takeItems( m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack == null )
if( stack.isEmpty() )
{
return TurtleCommandResult.failure( "No items to drop" );
}
@ -64,7 +63,7 @@ public class TurtleDropCommand implements ITurtleCommand
{
// Drop the item into the inventory
ItemStack remainder = InventoryUtil.storeItems( stack, inventory );
if( remainder != null )
if( !remainder.isEmpty() )
{
// Put the remainder back in the turtle
InventoryUtil.storeItems( remainder, turtle.getItemHandler(), turtle.getSelectedSlot() );

View File

@ -11,7 +11,6 @@ import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
@ -36,7 +35,7 @@ public class TurtleEquipCommand implements ITurtleCommand
ItemStack newUpgradeStack;
IItemHandler inventory = turtle.getItemHandler();
ItemStack selectedStack = inventory.getStackInSlot( turtle.getSelectedSlot() );
if( selectedStack != null )
if( !selectedStack.isEmpty() )
{
newUpgradeStack = selectedStack.copy();
newUpgrade = ComputerCraft.getTurtleUpgrade( newUpgradeStack );
@ -57,7 +56,7 @@ public class TurtleEquipCommand implements ITurtleCommand
if( oldUpgrade != null )
{
ItemStack craftingItem = oldUpgrade.getCraftingItem();
oldUpgradeStack = (craftingItem != null) ? craftingItem.copy() : null;
oldUpgradeStack = !craftingItem.isEmpty() ? craftingItem.copy() : null;
}
else
{
@ -74,7 +73,7 @@ public class TurtleEquipCommand implements ITurtleCommand
{
// Store old upgrades item
ItemStack remainder = InventoryUtil.storeItems( oldUpgradeStack, inventory, turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
// If there's no room for the items, drop them
BlockPos position = turtle.getPosition();

View File

@ -89,7 +89,7 @@ public class TurtleMoveCommand implements ITurtleCommand
(double) direction.getFrontOffsetY(),
(double) direction.getFrontOffsetZ()
);
if( !oldWorld.getCollisionBoxes( pushedBB ).isEmpty() )
if( !oldWorld.getCollisionBoxes( null, pushedBB ).isEmpty() )
{
return TurtleCommandResult.failure( "Movement obstructed" );
}

View File

@ -55,7 +55,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
{
// Get thing to place
ItemStack stack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() );
if( stack == null )
if( stack.isEmpty() )
{
return TurtleCommandResult.failure( "No items to place" );
}
@ -112,7 +112,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
}
public static ItemStack deploy( ItemStack stack, ITurtleAccess turtle, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
{
// Create a fake player, and orient it appropriately
BlockPos playerPosition = WorldUtil.moveCoords( turtle.getPosition(), direction );
@ -204,7 +204,8 @@ public class TurtlePlaceCommand implements ITurtleCommand
turtlePlayer.prevRotationYawHead = turtlePlayer.rotationYawHead;
}
private static ItemStack deployOnEntity( ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
@Nonnull
private static ItemStack deployOnEntity( @Nonnull ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
{
// See if there is an entity present
final World world = turtle.getWorld();
@ -227,10 +228,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
{
@Override
public void consumeDrop( Entity entity, ItemStack drop )
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
{
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
@ -239,25 +240,34 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Place on the entity
boolean placed = false;
if( !ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, stack, EnumHand.MAIN_HAND ) &&
hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, stackCopy, EnumHand.MAIN_HAND ) == EnumActionResult.SUCCESS )
EnumActionResult cancelResult = ForgeHooks.onInteractEntityAtAction( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND );
if( cancelResult == null )
{
cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, EnumHand.MAIN_HAND );
}
if( cancelResult == EnumActionResult.SUCCESS )
{
placed = true;
turtlePlayer.loadInventory( stackCopy );
}
else if( !ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, stack, EnumHand.MAIN_HAND ) )
else
{
// See EntityPlayer.interact
if( hitEntity.processInitialInteract( turtlePlayer, stackCopy, EnumHand.MAIN_HAND ) )
// See EntityPlayer.interactOn
cancelResult = ForgeHooks.onInteractEntityAction( turtlePlayer, hitEntity, EnumHand.MAIN_HAND );
if( cancelResult == EnumActionResult.SUCCESS )
{
placed = true;
}
else if( hitEntity instanceof EntityLivingBase )
else if( cancelResult == null )
{
placed = stackCopy.interactWithEntity( turtlePlayer, (EntityLivingBase) hitEntity, EnumHand.MAIN_HAND );
if( placed )
if( hitEntity.processInitialInteract( turtlePlayer, EnumHand.MAIN_HAND ) )
{
turtlePlayer.loadInventory( stackCopy );
placed = true;
}
else if( hitEntity instanceof EntityLivingBase )
{
placed = stackCopy.interactWithEntity( turtlePlayer, (EntityLivingBase) hitEntity, EnumHand.MAIN_HAND );
if( placed ) turtlePlayer.loadInventory( stackCopy );
}
}
}
@ -267,21 +277,21 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Put everything we collected into the turtles inventory, then return
ItemStack remainder = turtlePlayer.unloadInventory( turtle );
if( !placed && (remainder != null && ItemStack.areItemStacksEqual( stack, remainder )) )
if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) )
{
return stack;
}
else if( remainder != null && remainder.stackSize > 0 )
else if( !remainder.isEmpty() )
{
return remainder;
}
else
{
return null;
return ItemStack.EMPTY;
}
}
private static boolean canDeployOnBlock( ItemStack stack, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, EnumFacing side, boolean allowReplaceable, String[] o_errorMessage )
private static boolean canDeployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, EnumFacing side, boolean allowReplaceable, String[] o_errorMessage )
{
World world = turtle.getWorld();
if( WorldUtil.isBlockInWorld( world, position ) &&
@ -330,7 +340,8 @@ public class TurtlePlaceCommand implements ITurtleCommand
return false;
}
private static ItemStack deployOnBlock( ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing side, Object[] extraArguments, boolean allowReplace, String[] o_errorMessage )
@Nonnull
private static ItemStack deployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing side, Object[] extraArguments, boolean allowReplace, String[] o_errorMessage )
{
// Check if there's something suitable to place onto
if( !canDeployOnBlock( stack, turtle, turtlePlayer, position, side, allowReplace, o_errorMessage ) )
@ -362,10 +373,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
// See PlayerInteractionManager.processRightClickBlock
PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock( turtlePlayer, EnumHand.MAIN_HAND, stackCopy, position, side, new Vec3d( hitX, hitY, hitZ ) );
PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock( turtlePlayer, EnumHand.MAIN_HAND, position, side, new Vec3d( hitX, hitY, hitZ ) );
if( !event.isCanceled() )
{
if( item.onItemUseFirst( stackCopy, turtlePlayer, turtle.getWorld(), position, side, hitX, hitY, hitZ, EnumHand.MAIN_HAND ) == EnumActionResult.SUCCESS )
if( item.onItemUseFirst( turtlePlayer, turtle.getWorld(), position, side, hitX, hitY, hitZ, EnumHand.MAIN_HAND ) == EnumActionResult.SUCCESS )
{
placed = true;
turtlePlayer.loadInventory( stackCopy );
@ -378,14 +389,21 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
}
if( !placed && (item instanceof ItemBucket || item instanceof ItemBoat || item instanceof ItemLilyPad || item instanceof ItemGlassBottle)
&& ForgeHooks.onItemRightClick( turtlePlayer, EnumHand.MAIN_HAND, stackCopy ) )
if( !placed && (item instanceof ItemBucket || item instanceof ItemBoat || item instanceof ItemLilyPad || item instanceof ItemGlassBottle) )
{
ActionResult<ItemStack> result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, EnumHand.MAIN_HAND );
if( result.getType() == EnumActionResult.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) )
EnumActionResult actionResult = ForgeHooks.onItemRightClickAction( turtlePlayer, EnumHand.MAIN_HAND );
if( actionResult == EnumActionResult.SUCCESS )
{
placed = true;
turtlePlayer.loadInventory( result.getResult() );
}
else if( actionResult == null )
{
ActionResult<ItemStack> result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, EnumHand.MAIN_HAND );
if( result.getType() == EnumActionResult.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) )
{
placed = true;
turtlePlayer.loadInventory( result.getResult() );
}
}
}
@ -433,17 +451,17 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Put everything we collected into the turtles inventory, then return
ItemStack remainder = turtlePlayer.unloadInventory( turtle );
if( !placed && (remainder != null && ItemStack.areItemStacksEqual( stack, remainder )) )
if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) )
{
return stack;
}
else if( remainder != null && remainder.stackSize > 0 )
else if( !remainder.isEmpty() )
{
return remainder;
}
else
{
return null;
return ItemStack.EMPTY;
}
}
}

View File

@ -13,8 +13,9 @@ import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
@ -28,12 +29,18 @@ public class TurtlePlayer extends FakePlayer
"ComputerCraft"
);
@Deprecated
public TurtlePlayer( World world )
{
this( (WorldServer) world );
}
public TurtlePlayer( WorldServer world )
{
super( world, s_profile );
}
public void loadInventory( ItemStack currentStack )
public void loadInventory( @Nonnull ItemStack currentStack )
{
// Load up the fake inventory
inventory.currentItem = 0;
@ -44,7 +51,7 @@ public class TurtlePlayer extends FakePlayer
{
// Get the item we placed with
ItemStack results = inventory.getStackInSlot( 0 );
inventory.setInventorySlotContents( 0, null );
inventory.setInventorySlotContents( 0, ItemStack.EMPTY );
// Store (or drop) anything else we found
BlockPos dropPosition = turtle.getPosition();
@ -52,14 +59,14 @@ public class TurtlePlayer extends FakePlayer
for( int i=0; i<inventory.getSizeInventory(); ++i )
{
ItemStack stack = inventory.getStackInSlot( i );
if( stack != null )
if( !stack.isEmpty() )
{
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection );
}
inventory.setInventorySlotContents( i, null );
inventory.setInventorySlotContents( i, ItemStack.EMPTY );
}
}
inventory.markDirty();

View File

@ -33,7 +33,7 @@ public class TurtleRefuelCommand implements ITurtleCommand
{
// If limit is zero, just check the item is combustible
ItemStack dummyStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() );
if( dummyStack != null )
if( !dummyStack.isEmpty() )
{
return refuel( turtle, dummyStack, true );
}
@ -43,7 +43,7 @@ public class TurtleRefuelCommand implements ITurtleCommand
// Otherwise, refuel for real
// Remove items from inventory
ItemStack stack = InventoryUtil.takeItems( m_limit, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack != null )
if( !stack.isEmpty() )
{
TurtleCommandResult result = refuel( turtle, stack, false );
if( !result.isSuccess() )
@ -57,12 +57,12 @@ public class TurtleRefuelCommand implements ITurtleCommand
return TurtleCommandResult.failure( "No items to combust" );
}
private int getFuelPerItem( ItemStack stack )
private int getFuelPerItem( @Nonnull ItemStack stack )
{
return (TileEntityFurnace.getItemBurnTime( stack ) * 5) / 100;
}
private TurtleCommandResult refuel( ITurtleAccess turtle, ItemStack stack, boolean testOnly )
private TurtleCommandResult refuel( ITurtleAccess turtle, @Nonnull ItemStack stack, boolean testOnly )
{
// Check if item is fuel
int fuelPerItem = getFuelPerItem( stack );
@ -74,14 +74,14 @@ public class TurtleRefuelCommand implements ITurtleCommand
if( !testOnly )
{
// Determine fuel to give and replacement item to leave behind
int fuelToGive = fuelPerItem * stack.stackSize;
int fuelToGive = fuelPerItem * stack.getCount();
ItemStack replacementStack = stack.getItem().getContainerItem( stack );
// Update fuel level
turtle.addFuel( fuelToGive );
// Store the replacement item in the inventory
if( replacementStack != null )
if( !replacementStack.isEmpty() )
{
InventoryUtil.storeItems( replacementStack, turtle.getItemHandler(), turtle.getSelectedSlot() );
}

View File

@ -14,11 +14,10 @@ import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
@ -61,11 +60,11 @@ public class TurtleSuckCommand implements ITurtleCommand
{
// Take from inventory of thing in front
ItemStack stack = InventoryUtil.takeItems( m_quantity, inventory );
if( stack != null )
if( !stack.isEmpty() )
{
// Try to place into the turtle
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
// Put the remainder back in the inventory
InventoryUtil.storeItems( remainder, inventory );
@ -106,7 +105,7 @@ public class TurtleSuckCommand implements ITurtleCommand
ItemStack stack = entityItem.getEntityItem().copy();
ItemStack storeStack;
ItemStack leaveStack;
if( stack.stackSize > m_quantity )
if( stack.getCount() > m_quantity )
{
storeStack = stack.splitStack( m_quantity );
leaveStack = stack;
@ -114,27 +113,27 @@ public class TurtleSuckCommand implements ITurtleCommand
else
{
storeStack = stack;
leaveStack = null;
leaveStack = ItemStack.EMPTY;
}
ItemStack remainder = InventoryUtil.storeItems( storeStack, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != storeStack )
{
storedItems = true;
if( remainder == null && leaveStack == null )
if( remainder.isEmpty() && leaveStack.isEmpty() )
{
entityItem.setDead();
}
else if( remainder == null )
else if( remainder.isEmpty() )
{
entityItem.setEntityItemStack( leaveStack );
}
else if( leaveStack == null )
else if( leaveStack.isEmpty() )
{
entityItem.setEntityItemStack( remainder );
}
else
{
leaveStack.stackSize += remainder.stackSize;
leaveStack.grow( remainder.getCount() );
entityItem.setEntityItemStack( leaveStack );
}
break;

View File

@ -32,7 +32,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
{
// Take stack
ItemStack stack = InventoryUtil.takeItems( m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack == null )
if( stack.isEmpty() )
{
turtle.playAnimation( TurtleAnimation.Wait );
return TurtleCommandResult.success();
@ -40,7 +40,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
// Store stack
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), m_slot, 1, m_slot );
if( remainder != null )
if( !remainder.isEmpty() )
{
// Put the remainder back
InventoryUtil.storeItems( remainder, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );

View File

@ -88,21 +88,23 @@ public class TurtleVisionCamera extends EntityLivingBase
// EntityLivingBase overrides:
@Nonnull
@Override
public ItemStack getHeldItem( EnumHand hand )
{
return null;
return ItemStack.EMPTY;
}
@Override
public void setItemStackToSlot( @Nonnull EntityEquipmentSlot slot, ItemStack stack)
public void setItemStackToSlot( @Nonnull EntityEquipmentSlot slot, @Nonnull ItemStack stack )
{
}
@Nonnull
@Override
public ItemStack getItemStackFromSlot( @Nonnull EntityEquipmentSlot slot)
public ItemStack getItemStackFromSlot( @Nonnull EntityEquipmentSlot slot )
{
return null;
return ItemStack.EMPTY;
}
@Nonnull

View File

@ -138,45 +138,47 @@ public class ContainerTurtle extends Container
TileTurtle turtle = ((TurtleBrain)m_turtle).getOwner();
if( turtle != null )
{
return turtle.isUseableByPlayer( player );
return turtle.isUsableByPlayer( player );
}
return false;
}
@Nonnull
protected ItemStack tryItemMerge( EntityPlayer player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
{
Slot slot = inventorySlots.get( slotNum );
ItemStack originalStack = null;
ItemStack originalStack = ItemStack.EMPTY;
if( slot != null && slot.getHasStack() )
{
ItemStack clickedStack = slot.getStack();
originalStack = clickedStack.copy();
if( !mergeItemStack( clickedStack, firstSlot, lastSlot, reverse ) )
{
return null;
return ItemStack.EMPTY;
}
if( clickedStack.stackSize == 0 )
if( clickedStack.isEmpty() )
{
slot.putStack( null );
slot.putStack( ItemStack.EMPTY );
}
else
{
slot.onSlotChanged();
}
if( clickedStack.stackSize != originalStack.stackSize )
if( clickedStack.getCount() != originalStack.getCount() )
{
slot.onPickupFromSlot( player, clickedStack );
slot.onTake( player, clickedStack );
}
else
{
return null;
return ItemStack.EMPTY;
}
}
return originalStack;
}
@Nonnull
@Override
public ItemStack transferStackInSlot( EntityPlayer player, int slotNum )
{
@ -188,7 +190,7 @@ public class ContainerTurtle extends Container
{
return tryItemMerge( player, slotNum, 0, 16, false );
}
return null;
return ItemStack.EMPTY;
}
@Nullable

View File

@ -13,9 +13,12 @@ import dan200.computercraft.shared.computer.items.IComputerItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public interface ITurtleItem extends IComputerItem, IColouredItem
{
ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
int getFuelLevel( ItemStack stack );
ResourceLocation getOverlay( ItemStack stack );
int getColour( @Nonnull ItemStack stack );
}

View File

@ -22,14 +22,13 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtleItem
{
@ -43,9 +42,9 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
public abstract ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay );
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
List<ItemStack> all = new ArrayList<ItemStack>();
NonNullList<ItemStack> all = NonNullList.create();
ComputerCraft.addAllUpgradedTurtles( all );
for( ItemStack stack : all )
{
@ -72,7 +71,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
return false;
}
public void setupTurtleAfterPlacement( ItemStack stack, ITurtleTile turtle )
public void setupTurtleAfterPlacement( @Nonnull ItemStack stack, ITurtleTile turtle )
{
// Set ID
int id = getComputerID( stack );
@ -115,7 +114,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
@Nonnull
@Override
public String getUnlocalizedName( ItemStack stack )
public String getUnlocalizedName( @Nonnull ItemStack stack )
{
ComputerFamily family = getFamily( stack );
switch( family )

View File

@ -16,6 +16,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public class ItemTurtleLegacy extends ItemTurtleBase
{
public ItemTurtleLegacy( Block block )
@ -81,7 +83,7 @@ public class ItemTurtleLegacy extends ItemTurtleBase
// IComputerItem implementation
@Override
public int getComputerID( ItemStack stack )
public int getComputerID( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() && stack.getTagCompound().hasKey( "computerID" ) )
{
@ -103,7 +105,7 @@ public class ItemTurtleLegacy extends ItemTurtleBase
// ITurtleItem implementation
@Override
public ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side )
public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, TurtleSide side )
{
int damage = stack.getItemDamage();
switch( side )
@ -129,16 +131,16 @@ public class ItemTurtleLegacy extends ItemTurtleBase
}
@Override
public int getColour( ItemStack stack )
public int getColour( @Nonnull ItemStack stack )
{
return -1;
}
@Override
public ResourceLocation getOverlay( ItemStack stack ) { return null; }
public ResourceLocation getOverlay( @Nonnull ItemStack stack ) { return null; }
@Override
public int getFuelLevel( ItemStack stack )
public int getFuelLevel( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() )
{

View File

@ -18,6 +18,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.Constants;
import javax.annotation.Nonnull;
public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
{
public ItemTurtleNormal( Block block )
@ -87,7 +89,7 @@ public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
// IComputerItem implementation
@Override
public int getComputerID( ItemStack stack )
public int getComputerID( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() )
{
@ -109,7 +111,7 @@ public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
// ITurtleItem implementation
@Override
public ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side )
public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, TurtleSide side )
{
if( stack.hasTagCompound() )
{
@ -152,14 +154,14 @@ public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
}
@Override
public int getColour( ItemStack stack )
public int getColour( @Nonnull ItemStack stack )
{
NBTTagCompound tag = stack.getTagCompound();
return tag == null ? -1 : ColourUtils.getHexColour( tag );
}
@Override
public ResourceLocation getOverlay( ItemStack stack )
public ResourceLocation getOverlay( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() )
{
@ -175,7 +177,7 @@ public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
}
@Override
public int getFuelLevel( ItemStack stack )
public int getFuelLevel( @Nonnull ItemStack stack )
{
if( stack.hasTagCompound() )
{

View File

@ -12,15 +12,17 @@ import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.turtle.blocks.ITurtleTile;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ReflectionUtil;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public class TurtleItemFactory
{
@Nonnull
public static ItemStack create( ITurtleTile turtle )
{
ITurtleUpgrade leftUpgrade = turtle.getAccess().getUpgrade( TurtleSide.Left );
@ -47,6 +49,7 @@ public class TurtleItemFactory
return create( -1, null, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, 0, turtle.getOverlay() );
}
@Nonnull
public static ItemStack create( int id, String label, int colour, ComputerFamily family, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
{
switch( family )
@ -81,9 +84,9 @@ public class TurtleItemFactory
ItemTurtleBase beginnersItem = ((ItemTurtleBase)Item.getItemFromBlock( beginnersBlock ));
return beginnersItem.create( id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay );
}
return null;
return ItemStack.EMPTY;
}
}
return null;
return ItemStack.EMPTY;
}
}

View File

@ -13,7 +13,9 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
@ -34,6 +36,7 @@ public class TurtleRecipe implements IRecipe
return 9;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
@ -43,9 +46,10 @@ public class TurtleRecipe implements IRecipe
@Override
public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world )
{
return (getCraftingResult( _inventory ) != null);
return !getCraftingResult( _inventory ).isEmpty();
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
@ -57,7 +61,7 @@ public class TurtleRecipe implements IRecipe
for( int x=0; x<3; ++x )
{
ItemStack item = inventory.getStackInRowAndColumn(x, y);
if( item != null && item.getItem() == m_recipe[ x + y*3 ] )
if( !item.isEmpty() && item.getItem() == m_recipe[ x + y*3 ] )
{
if( item.getItem() instanceof IComputerItem )
{
@ -69,13 +73,13 @@ public class TurtleRecipe implements IRecipe
}
else
{
return null;
return ItemStack.EMPTY;
}
}
}
else
{
return null;
return ItemStack.EMPTY;
}
}
}
@ -94,13 +98,13 @@ public class TurtleRecipe implements IRecipe
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ];
for (int i = 0; i < results.length; ++i)
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inventoryCrafting.getStackInSlot(i);
results[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(stack);
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -17,8 +17,10 @@ import dan200.computercraft.shared.util.Colour;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
@ -34,6 +36,7 @@ public class TurtleUpgradeRecipe implements IRecipe
return 3;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
{
@ -43,60 +46,61 @@ public class TurtleUpgradeRecipe implements IRecipe
@Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
{
return (getCraftingResult( inventory ) != null);
return !getCraftingResult( inventory ).isEmpty();
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
// Scan the grid for a row containing a turtle and 1 or 2 items
ItemStack leftItem = null;
ItemStack turtle = null;
ItemStack rightItem = null;
ItemStack leftItem = ItemStack.EMPTY;
ItemStack turtle = ItemStack.EMPTY;
ItemStack rightItem = ItemStack.EMPTY;
for( int y=0; y<inventory.getHeight(); ++y )
{
if( turtle == null )
if( turtle.isEmpty() )
{
// Search this row for potential turtles
boolean finishedRow = false;
for( int x=0; x<inventory.getWidth(); ++x )
{
ItemStack item = inventory.getStackInRowAndColumn(x, y);
if( item != null ) {
if( !item.isEmpty() ) {
if( finishedRow ) {
return null;
return ItemStack.EMPTY;
}
if( item.getItem() instanceof ITurtleItem ) {
// Item is a turtle
if( turtle == null ) {
if( turtle.isEmpty() ) {
turtle = item;
} else {
return null;
return ItemStack.EMPTY;
}
} else {
// Item is not a turtle
if( turtle == null && leftItem == null ) {
if( turtle.isEmpty() && leftItem.isEmpty() ) {
leftItem = item;
} else if( turtle != null && rightItem == null ) {
} else if( !turtle.isEmpty() && rightItem.isEmpty() ) {
rightItem = item;
} else {
return null;
return ItemStack.EMPTY;
}
}
} else {
// Item is empty
if( leftItem != null || turtle != null ) {
if( !leftItem.isEmpty() || !turtle.isEmpty() ) {
finishedRow = true;
}
}
}
// If we found anything, check we found a turtle too
if( turtle == null && (leftItem != null || rightItem != null) )
if( turtle.isEmpty() && (!leftItem.isEmpty() || !rightItem.isEmpty()) )
{
return null;
return ItemStack.EMPTY;
}
}
else
@ -105,17 +109,17 @@ public class TurtleUpgradeRecipe implements IRecipe
for( int x=0; x<inventory.getWidth(); ++x )
{
ItemStack item = inventory.getStackInRowAndColumn(x, y);
if( item != null ) {
return null;
if( !item.isEmpty() ) {
return ItemStack.EMPTY;
}
}
}
}
// See if we found a turtle + one or more items
if( turtle == null || (leftItem == null && rightItem == null))
if( turtle.isEmpty() || (leftItem.isEmpty() && rightItem.isEmpty()) )
{
return null;
return ItemStack.EMPTY;
}
// At this point we have a turtle + 1 or 2 items
@ -131,20 +135,20 @@ public class TurtleUpgradeRecipe implements IRecipe
ItemStack[] items = new ItemStack[]{ rightItem, leftItem };
for( int i=0; i<2; ++i )
{
if( items[i] != null )
if( !items[i].isEmpty() )
{
ITurtleUpgrade itemUpgrade = ComputerCraft.getTurtleUpgrade( items[ i ] );
if( itemUpgrade == null )
{
return null;
return ItemStack.EMPTY;
}
if( upgrades[i] != null )
{
return null;
return ItemStack.EMPTY;
}
if( !CCTurtleProxyCommon.isUpgradeSuitableForFamily( family, itemUpgrade ) )
{
return null;
return ItemStack.EMPTY;
}
upgrades[i] = itemUpgrade;
}
@ -161,13 +165,13 @@ public class TurtleUpgradeRecipe implements IRecipe
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{
ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ];
for (int i = 0; i < results.length; ++i)
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i )
{
ItemStack stack = inventoryCrafting.getStackInSlot(i);
results[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(stack);
ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) );
}
return results;
}

View File

@ -69,6 +69,7 @@ public class TurtleCraftingTable implements ITurtleUpgrade
return TurtleUpgradeType.Peripheral;
}
@Nonnull
@Override
public ItemStack getCraftingItem()
{
@ -85,7 +86,7 @@ public class TurtleCraftingTable implements ITurtleUpgrade
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir )
{
return null;
return TurtleCommandResult.failure();
}
@SideOnly( Side.CLIENT )

View File

@ -13,8 +13,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
@ -35,6 +36,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
m_yStart = 0;
}
@Nonnull
private ItemStack tryCrafting( int xStart, int yStart )
{
m_xStart = xStart;
@ -48,9 +50,9 @@ public class TurtleInventoryCrafting extends InventoryCrafting
if( x < m_xStart || x >= m_xStart + 3 ||
y < m_yStart || y >= m_yStart + 3 )
{
if( m_turtle.getInventory().getStackInSlot( x + y * TileTurtle.INVENTORY_WIDTH ) != null )
if( !m_turtle.getInventory().getStackInSlot( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
}
}
@ -69,21 +71,21 @@ public class TurtleInventoryCrafting extends InventoryCrafting
// Find out what we can craft
ItemStack result = tryCrafting( 0, 0 );
if( result == null )
if( result.isEmpty() )
{
result = tryCrafting( 0, 1 );
}
if( result == null )
if( result.isEmpty() )
{
result = tryCrafting( 1, 0 );
}
if( result == null )
if( result.isEmpty() )
{
result = tryCrafting( 1, 1 );
}
// Craft it
if( result != null )
if( !result.isEmpty() )
{
// Special case: craft(0) just returns an empty list if crafting was possible
ArrayList<ItemStack> results = new ArrayList<ItemStack>();
@ -101,17 +103,17 @@ public class TurtleInventoryCrafting extends InventoryCrafting
for( int n=0; n<size; ++n )
{
ItemStack stack = getStackInSlot( n );
if( stack != null && (minStackSize == 0 || minStackSize > stack.stackSize) )
if( !stack.isEmpty() && (minStackSize == 0 || minStackSize > stack.getCount()) )
{
minStackSize = stack.stackSize;
minStackSize = stack.getCount();
}
}
if( minStackSize > 1 )
{
numToCraft = Math.min( minStackSize, result.getMaxStackSize() / result.stackSize );
numToCraft = Math.min( minStackSize, result.getMaxStackSize() / result.getCount() );
numToCraft = Math.min( numToCraft, maxCount );
result.stackSize = result.stackSize * numToCraft;
result.setCount( result.getCount() * numToCraft );
}
}
@ -121,21 +123,21 @@ public class TurtleInventoryCrafting extends InventoryCrafting
results.add( result );
// Consume resources from the inventory
ItemStack[] remainingItems = CraftingManager.getInstance().getRemainingItems( this, world );
NonNullList<ItemStack> remainingItems = CraftingManager.getInstance().getRemainingItems( this, world );
for( int n=0; n<size; ++n )
{
ItemStack stack = getStackInSlot( n );
if( stack != null )
if( !stack.isEmpty() )
{
decrStackSize( n, numToCraft );
ItemStack replacement = remainingItems[n];
if( replacement != null )
ItemStack replacement = remainingItems.get(n);
if( !replacement.isEmpty() )
{
if( !(replacement.isItemStackDamageable() && replacement.getItemDamage() >= replacement.getMaxDamage()) )
{
replacement.stackSize = Math.min( numToCraft, replacement.getMaxStackSize() );
if( getStackInSlot( n ) == null )
replacement.setCount( Math.min( numToCraft, replacement.getMaxStackSize() ) );
if( getStackInSlot( n ).isEmpty() )
{
setInventorySlotContents( n, replacement );
}
@ -153,6 +155,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
return null;
}
@Nonnull
@Override
public ItemStack getStackInRowAndColumn(int x, int y)
{
@ -160,7 +163,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
{
return getStackInSlot( x + y * getWidth() );
}
return null;
return ItemStack.EMPTY;
}
@Override
@ -195,6 +198,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
return getWidth() * getHeight();
}
@Nonnull
@Override
public ItemStack getStackInSlot( int i )
{
@ -222,6 +226,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
return new TextComponentString( "" );
}
@Nonnull
@Override
public ItemStack removeStackFromSlot( int i )
{
@ -229,6 +234,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
return m_turtle.getInventory().removeStackFromSlot( i );
}
@Nonnull
@Override
public ItemStack decrStackSize( int i, int size )
{
@ -237,7 +243,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
}
@Override
public void setInventorySlotContents( int i, ItemStack stack )
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
{
i = modifyIndex( i );
m_turtle.getInventory().setInventorySlotContents( i, stack );
@ -256,7 +262,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
}
@Override
public boolean isUseableByPlayer( EntityPlayer player )
public boolean isUsableByPlayer( EntityPlayer player )
{
return true;
}
@ -272,7 +278,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
}
@Override
public boolean isItemValidForSlot( int i, ItemStack stack )
public boolean isItemValidForSlot( int i, @Nonnull ItemStack stack )
{
i = modifyIndex( i );
return m_turtle.getInventory().isItemValidForSlot( i, stack );
@ -301,7 +307,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
for( int i=0; i<getSizeInventory(); ++i )
{
int j = modifyIndex( i );
m_turtle.getInventory().setInventorySlotContents( j, null );
m_turtle.getInventory().setInventorySlotContents( j, ItemStack.EMPTY );
}
}
}

View File

@ -130,6 +130,7 @@ public class TurtleModem implements ITurtleUpgrade
return TurtleUpgradeType.Peripheral;
}
@Nonnull
@Override
public ItemStack getCraftingItem()
{
@ -153,7 +154,7 @@ public class TurtleModem implements ITurtleUpgrade
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir )
{
return null;
return TurtleCommandResult.failure();
}
@SideOnly( Side.CLIENT )

View File

@ -114,6 +114,7 @@ public class TurtleSpeaker implements ITurtleUpgrade
return TurtleUpgradeType.Peripheral;
}
@Nonnull
@Override
public ItemStack getCraftingItem()
{

View File

@ -88,6 +88,7 @@ public class TurtleTool implements ITurtleUpgrade
return TurtleUpgradeType.Tool;
}
@Nonnull
@Override
public ItemStack getCraftingItem()
{
@ -187,10 +188,10 @@ public class TurtleTool implements ITurtleUpgrade
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
{
@Override
public void consumeDrop( Entity entity, ItemStack drop )
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
{
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
@ -283,7 +284,7 @@ public class TurtleTool implements ITurtleUpgrade
for( ItemStack stack : items )
{
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( remainder != null )
if( !remainder.isEmpty() )
{
// If there's no room for the items, drop them
WorldUtil.dropItemStack( remainder, world, position, direction );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.util;
import dan200.computercraft.ComputerCraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
@ -21,9 +21,9 @@ public class CreativeTabMain extends CreativeTabs
@Nonnull
@Override
public Item getTabIconItem()
public ItemStack getTabIconItem()
{
return Item.getItemFromBlock( ComputerCraft.Blocks.computer );
return new ItemStack( ComputerCraft.Blocks.computer );
}
@Nonnull

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.util;
import dan200.computercraft.ComputerCraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
@ -21,9 +21,9 @@ public class CreativeTabTreasure extends CreativeTabs
@Nonnull
@Override
public Item getTabIconItem()
public ItemStack getTabIconItem()
{
return ComputerCraft.Items.treasureDisk;
return new ItemStack( ComputerCraft.Items.treasureDisk );
}
@Nonnull

View File

@ -88,7 +88,7 @@ public class DirectionUtil
public static EnumFacing fromEntityRot( EntityLivingBase player )
{
int rot = MathHelper.floor_float( ( player.rotationYaw / 90.0f ) + 0.5f ) & 0x3;
int rot = MathHelper.floor( ( player.rotationYaw / 90.0f ) + 0.5f ) & 0x3;
switch( rot ) {
case 0: return EnumFacing.NORTH;
case 1: return EnumFacing.EAST;

View File

@ -8,7 +8,9 @@ package dan200.computercraft.shared.util;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IEntityDropConsumer
{
void consumeDrop( Entity dropper, ItemStack drop );
void consumeDrop( Entity dropper, @Nonnull ItemStack drop );
}

View File

@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
public class ImpostorRecipe extends ShapedRecipes
{
public ImpostorRecipe( int width, int height, ItemStack[] ingredients, ItemStack result )
public ImpostorRecipe( int width, int height, ItemStack[] ingredients, @Nonnull ItemStack result )
{
super( width, height, ingredients, result );
}
@ -25,9 +25,10 @@ public class ImpostorRecipe extends ShapedRecipes
return false;
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting _inventory )
{
return null;
return ItemStack.EMPTY;
}
}

View File

@ -11,12 +11,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
public class ImpostorShapelessRecipe extends ShapelessRecipes
{
public ImpostorShapelessRecipe( ItemStack result, ItemStack[] ingredients )
public ImpostorShapelessRecipe( @Nonnull ItemStack result, ItemStack[] ingredients )
{
super( result, new ArrayList<ItemStack>(Arrays.asList( ingredients )));
}
@ -27,9 +28,10 @@ public class ImpostorShapelessRecipe extends ShapelessRecipes
return false;
}
@Nonnull
@Override
public ItemStack getCraftingResult( InventoryCrafting _inventory )
{
return null;
return ItemStack.EMPTY;
}
}

View File

@ -22,27 +22,26 @@ import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
public class InventoryUtil
{
// Methods for comparing things:
public static boolean areItemsEqual( ItemStack a, ItemStack b )
public static boolean areItemsEqual( @Nonnull ItemStack a, @Nonnull ItemStack b )
{
return a == b || ItemStack.areItemStacksEqual( a, b );
}
public static boolean areItemsStackable( ItemStack a, ItemStack b )
public static boolean areItemsStackable( @Nonnull ItemStack a, @Nonnull ItemStack b )
{
return a == b || ItemHandlerHelper.canItemStacksStack( a, b );
}
public static ItemStack copyItem( ItemStack a )
@Nonnull
public static ItemStack copyItem( @Nonnull ItemStack a )
{
if( a != null )
{
return a.copy();
}
return null;
return a.copy();
}
// Methods for finding inventories:
@ -96,19 +95,22 @@ public class InventoryUtil
// Methods for placing into inventories:
public static ItemStack storeItems( ItemStack itemstack, IItemHandler inventory, int start, int range, int begin )
@Nonnull
public static ItemStack storeItems( @Nonnull ItemStack itemstack, IItemHandler inventory, int start, int range, int begin )
{
int[] slots = makeSlotList( start, range, begin );
return storeItems( itemstack, inventory, slots );
}
public static ItemStack storeItems( ItemStack itemstack, IItemHandler inventory, int begin )
@Nonnull
public static ItemStack storeItems( @Nonnull ItemStack itemstack, IItemHandler inventory, int begin )
{
int[] slots = makeSlotList( 0, inventory.getSlots(), begin );
return storeItems( itemstack, inventory, slots );
}
public static ItemStack storeItems( ItemStack itemstack, IItemHandler inventory )
@Nonnull
public static ItemStack storeItems( @Nonnull ItemStack itemstack, IItemHandler inventory )
{
int[] slots = makeSlotList( 0, inventory.getSlots(), 0 ); // TODO: optimise this out?
return storeItems( itemstack, inventory, slots );
@ -116,18 +118,21 @@ public class InventoryUtil
// Methods for taking out of inventories
@Nonnull
public static ItemStack takeItems( int count, IItemHandler inventory, int start, int range, int begin )
{
int[] slots = makeSlotList( start, range, begin );
return takeItems( count, inventory, slots );
}
@Nonnull
public static ItemStack takeItems( int count, IItemHandler inventory, int begin )
{
int[] slots = makeSlotList( 0, inventory.getSlots(), begin );
return takeItems( count, inventory, slots );
}
@Nonnull
public static ItemStack takeItems( int count, IItemHandler inventory )
{
int[] slots = makeSlotList( 0, inventory.getSlots(), 0 );
@ -151,57 +156,59 @@ public class InventoryUtil
return slots;
}
private static ItemStack storeItems( ItemStack stack, IItemHandler inventory, int[] slots )
@Nonnull
private static ItemStack storeItems( @Nonnull ItemStack stack, IItemHandler inventory, int[] slots )
{
if( slots == null || slots.length == 0 )
{
return stack;
}
if( stack == null || stack.stackSize == 0 )
if( stack.isEmpty() )
{
return null;
return ItemStack.EMPTY;
}
// Inspect the slots in order and try to find empty or stackable slots
ItemStack remainder = stack.copy();
for( int slot : slots )
{
if( remainder == null ) break;
if( remainder.isEmpty() ) break;
remainder = inventory.insertItem( slot, remainder, false );
}
return areItemsEqual( stack, remainder ) ? stack : remainder;
}
@Nonnull
private static ItemStack takeItems( int count, IItemHandler inventory, int[] slots )
{
if( slots == null )
{
return null;
return ItemStack.EMPTY;
}
// Combine multiple stacks from inventory into one if necessary
ItemStack partialStack = null;
ItemStack partialStack = ItemStack.EMPTY;
int countRemaining = count;
for( int slot : slots )
{
if( countRemaining <= 0 ) break;
ItemStack stack = inventory.getStackInSlot( slot );
if( stack != null )
if( !stack.isEmpty() )
{
if( partialStack == null || areItemsStackable( stack, partialStack ) )
if( partialStack.isEmpty() || areItemsStackable( stack, partialStack ) )
{
ItemStack extracted = inventory.extractItem( slot, countRemaining, false );
if( extracted != null )
if( !extracted.isEmpty() )
{
countRemaining -= extracted.stackSize;
if( partialStack == null )
countRemaining -= extracted.getCount();
if( partialStack.isEmpty() )
{
partialStack = extracted;
}
else
{
partialStack.stackSize += extracted.stackSize;
partialStack.grow( extracted.getCount() );
}
}
}

View File

@ -76,7 +76,7 @@ public class RedstoneUtil
IBlockState neighbour = world.getBlockState( neighbourPos );
if( neighbour.getBlock() != Blocks.AIR )
{
world.notifyBlockOfStateChange( neighbourPos, block.getBlock() );
world.neighborChanged( neighbourPos, block.getBlock(), pos );
if( neighbour.getBlock().isNormalCube( neighbour, world, neighbourPos ) )
{
world.notifyNeighborsOfStateExcept( neighbourPos, neighbour.getBlock(), side.getOpposite() );

View File

@ -14,6 +14,7 @@ import net.minecraft.util.math.*;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import java.util.List;
public class WorldUtil
@ -112,12 +113,12 @@ public class WorldUtil
return null;
}
public static void dropItemStack( ItemStack stack, World world, BlockPos pos )
public static void dropItemStack( @Nonnull ItemStack stack, World world, BlockPos pos )
{
dropItemStack( stack, world, pos, null );
}
public static void dropItemStack( ItemStack stack, World world, BlockPos pos, EnumFacing direction )
public static void dropItemStack( @Nonnull ItemStack stack, World world, BlockPos pos, EnumFacing direction )
{
double xDir;
double yDir;
@ -141,18 +142,18 @@ public class WorldUtil
dropItemStack( stack, world, xPos, yPos, zPos, xDir, yDir, zDir );
}
public static void dropItemStack( ItemStack stack, World world, double xPos, double yPos, double zPos )
public static void dropItemStack( @Nonnull ItemStack stack, World world, double xPos, double yPos, double zPos )
{
dropItemStack( stack, world, xPos, yPos, zPos, 0.0, 0.0, 0.0 );
}
public static void dropItemStack( ItemStack stack, World world, double xPos, double yPos, double zPos, double xDir, double yDir, double zDir )
public static void dropItemStack( @Nonnull ItemStack stack, World world, double xPos, double yPos, double zPos, double xDir, double yDir, double zDir )
{
EntityItem entityItem = new EntityItem( world, xPos, yPos, zPos, stack.copy() );
entityItem.motionX = xDir * 0.7 + world.rand.nextFloat() * 0.2 - 0.1;
entityItem.motionY = yDir * 0.7 + world.rand.nextFloat() * 0.2 - 0.1;
entityItem.motionZ = zDir * 0.7 + world.rand.nextFloat() * 0.2 - 0.1;
entityItem.setDefaultPickupDelay();
world.spawnEntityInWorld( entityItem );
world.spawnEntity( entityItem );
}
}

View File

@ -1,6 +1,6 @@
[
{
"modid" : "ComputerCraft",
"modid" : "computercraft",
"name" : "ComputerCraft",
"version" : "${version}",
"mcversion" : "${mcversion}",