mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-14 20:17:11 +00:00
Update to 1.11.2
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -114,6 +114,7 @@ public class TurtleSpeaker implements ITurtleUpgrade
|
||||
return TurtleUpgradeType.Peripheral;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingItem()
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user