mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-17 21:55:12 +00:00
Update to 1.11.2
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 ) );
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user