1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-20 07:05:14 +00:00

Java 8. Java 8. Does whatever Java 8 can.

Default methods, everywhere.
Arrow types, switch on strings.
Lambdas!
Here comes Java 8.
This commit is contained in:
SquidDev
2017-06-12 21:08:35 +01:00
parent 08099f08f2
commit d29ffed383
76 changed files with 747 additions and 665 deletions

View File

@@ -88,7 +88,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric )
{
TileGeneric generic = (TileGeneric)tile;
TileGeneric generic = (TileGeneric) tile;
generic.getDroppedItems( drops, creative );
}
@@ -234,7 +234,7 @@ public abstract class BlockGeneric extends Block implements
TileGeneric generic = (TileGeneric)tile;
// Get collision bounds
List<AxisAlignedBB> collision = new ArrayList<AxisAlignedBB>( 1 );
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
generic.getCollisionBounds( collision );
// Return the union of the collision bounds
@@ -262,7 +262,7 @@ public abstract class BlockGeneric extends Block implements
TileGeneric generic = (TileGeneric)tile;
// Get collision bounds
List<AxisAlignedBB> collision = new ArrayList<AxisAlignedBB>( 1 );
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
generic.getCollisionBounds( collision );
// Add collision bounds to list

View File

@@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.apis;
import com.google.common.collect.ImmutableMap;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaTask;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ILuaAPI;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
@@ -81,7 +80,7 @@ public class CommandAPI implements ILuaAPI
private Map<Object, Object> createOutput( String output )
{
Map<Object, Object> result = new HashMap<Object, Object>( 1 );
Map<Object, Object> result = new HashMap<>( 1 );
result.put( 1, output );
return result;
}
@@ -123,11 +122,11 @@ public class CommandAPI implements ILuaAPI
String name = Block.REGISTRY.getNameForObject( block ).toString();
int metadata = block.getMetaFromState( state );
Map<Object, Object> table = new HashMap<Object, Object>();
Map<Object, Object> table = new HashMap<>();
table.put( "name", name );
table.put( "metadata", metadata );
Map<Object, Object> stateTable = new HashMap<Object, Object>();
Map<Object, Object> stateTable = new HashMap<>();
for( ImmutableMap.Entry<IProperty<?>, Comparable<?>> entry : state.getActualState( world, pos ).getProperties().entrySet() )
{
String propertyName = entry.getKey().getName();
@@ -155,68 +154,50 @@ public class CommandAPI implements ILuaAPI
{
// exec
final String command = getString( arguments, 0 );
return context.executeMainThreadTask( new ILuaTask()
{
@Override
public Object[] execute() throws LuaException
{
return doCommand( command );
}
} );
return context.executeMainThreadTask( () -> doCommand( command ) );
}
case 1:
{
// execAsync
final String command = getString( arguments, 0 );
long taskID = context.issueMainThreadTask( new ILuaTask()
{
@Override
public Object[] execute() throws LuaException
{
return doCommand( command );
}
} );
long taskID = context.issueMainThreadTask( () -> doCommand( command ) );
return new Object[] { taskID };
}
case 2:
{
// list
return context.executeMainThreadTask( new ILuaTask()
return context.executeMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
int i = 1;
Map<Object, Object> result = new HashMap<>();
MinecraftServer server = m_computer.getWorld().getMinecraftServer();
if( server != null )
{
int i = 1;
Map<Object, Object> result = new HashMap<Object, Object>();
MinecraftServer server = m_computer.getWorld().getMinecraftServer();
if( server != null )
ICommandManager commandManager = server.getCommandManager();
ICommandSender commmandSender = m_computer.getCommandSender();
Map<String, ICommand> commands = commandManager.getCommands();
for( Map.Entry<String, ICommand> entry : commands.entrySet() )
{
ICommandManager commandManager = server.getCommandManager();
ICommandSender commmandSender = m_computer.getCommandSender();
Map<String, ICommand> commands = commandManager.getCommands();
for( Map.Entry<String, ICommand> entry : commands.entrySet() )
String name = entry.getKey();
ICommand command = entry.getValue();
try
{
String name = entry.getKey();
ICommand command = entry.getValue();
try
if( command.checkPermission( server, commmandSender ) )
{
if( command.checkPermission( server, commmandSender ) )
{
result.put( i++, name );
}
result.put( i++, name );
}
catch( Throwable t )
}
catch( Throwable t )
{
// Ignore buggy command
if( ComputerCraft.logPeripheralErrors )
{
// Ignore buggy command
if( ComputerCraft.logPeripheralErrors )
{
ComputerCraft.log.error( "Error checking permissions of command.", t );
}
ComputerCraft.log.error( "Error checking permissions of command.", t );
}
}
}
return new Object[]{ result };
}
return new Object[]{ result };
} );
}
case 3:
@@ -235,46 +216,42 @@ public class CommandAPI implements ILuaAPI
final int maxx = getInt( arguments, 3 );
final int maxy = getInt( arguments, 4 );
final int maxz = getInt( arguments, 5 );
return context.executeMainThreadTask( new ILuaTask()
return context.executeMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
// Get the details of the block
World world = m_computer.getWorld();
BlockPos min = new BlockPos(
Math.min( minx, maxx ),
Math.min( miny, maxy ),
Math.min( minz, maxz )
);
BlockPos max = new BlockPos(
Math.max( minx, maxx ),
Math.max( miny, maxy ),
Math.max( minz, maxz )
);
if( !WorldUtil.isBlockInWorld( world, min ) || !WorldUtil.isBlockInWorld( world, max ) )
{
// Get the details of the block
World world = m_computer.getWorld();
BlockPos min = new BlockPos(
Math.min( minx, maxx ),
Math.min( miny, maxy ),
Math.min( minz, maxz )
);
BlockPos max = new BlockPos(
Math.max( minx, maxx ),
Math.max( miny, maxy ),
Math.max( minz, maxz )
);
if( !WorldUtil.isBlockInWorld( world, min ) || !WorldUtil.isBlockInWorld( world, max ) )
throw new LuaException( "Co-ordinates out or range" );
}
if( ( max.getX() - min.getX() + 1 ) * ( max.getY() - min.getY() + 1 ) * ( max.getZ() - min.getZ() + 1 ) > 4096 )
{
throw new LuaException( "Too many blocks" );
}
int i=1;
Map<Object, Object> results = new HashMap<>();
for( int y=min.getY(); y<= max.getY(); ++y )
{
for( int z = min.getZ(); z <= max.getZ(); ++z )
{
throw new LuaException( "Co-ordinates out or range" );
}
if( ( max.getX() - min.getX() + 1 ) * ( max.getY() - min.getY() + 1 ) * ( max.getZ() - min.getZ() + 1 ) > 4096 )
{
throw new LuaException( "Too many blocks" );
}
int i=1;
Map<Object, Object> results = new HashMap<Object, Object>();
for( int y=min.getY(); y<= max.getY(); ++y )
{
for( int z = min.getZ(); z <= max.getZ(); ++z )
for( int x = min.getX(); x <= max.getX(); ++x )
{
for( int x = min.getX(); x <= max.getX(); ++x )
{
BlockPos pos = new BlockPos( x, y, z );
results.put( i++, getBlockInfo( world, pos ) );
}
BlockPos pos = new BlockPos( x, y, z );
results.put( i++, getBlockInfo( world, pos ) );
}
}
return new Object[]{ results };
}
return new Object[]{ results };
} );
}
case 5:
@@ -283,22 +260,18 @@ public class CommandAPI implements ILuaAPI
final int x = getInt( arguments, 0 );
final int y = getInt( arguments, 1 );
final int z = getInt( arguments, 2 );
return context.executeMainThreadTask( new ILuaTask()
return context.executeMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
// Get the details of the block
World world = m_computer.getWorld();
BlockPos position = new BlockPos( x, y, z );
if( WorldUtil.isBlockInWorld( world, position ) )
{
// Get the details of the block
World world = m_computer.getWorld();
BlockPos position = new BlockPos( x, y, z );
if( WorldUtil.isBlockInWorld( world, position ) )
{
return new Object[]{ getBlockInfo( world, position ) };
}
else
{
throw new LuaException( "co-ordinates out or range" );
}
return new Object[]{ getBlockInfo( world, position ) };
}
else
{
throw new LuaException( "co-ordinates out or range" );
}
} );
}

View File

@@ -94,16 +94,6 @@ public class ComputerPeripheral
}
}
@Override
public void attach( @Nonnull IComputerAccess computer )
{
}
@Override
public void detach( @Nonnull IComputerAccess computer )
{
}
@Override
public boolean equals( IPeripheral other )
{

View File

@@ -33,7 +33,7 @@ public class TileCommandComputer extends TileComputer
public CommandSender()
{
m_outputTable = new HashMap<Integer, String>();
m_outputTable = new HashMap<>();
}
public void clearOutput()
@@ -48,7 +48,7 @@ public class TileCommandComputer extends TileComputer
public Map<Integer, String> copyOutput()
{
return new HashMap<Integer, String>( m_outputTable );
return new HashMap<>( m_outputTable );
}
// ICommandSender

View File

@@ -153,6 +153,7 @@ public class ClientComputer extends ClientTerminal
ComputerCraft.sendToServer( packet );
}
@Override
public void readDescription( NBTTagCompound nbttagcompound )
{
super.readDescription( nbttagcompound );

View File

@@ -19,7 +19,7 @@ public class ComputerRegistry<TComputer extends IComputer>
protected ComputerRegistry()
{
m_computers = new HashMap<Integer, TComputer>();
m_computers = new HashMap<>();
reset();
}

View File

@@ -337,6 +337,7 @@ public class ServerComputer extends ServerTerminal
// Networking stuff
@Override
public void writeDescription( NBTTagCompound nbttagcompound )
{
super.writeDescription( nbttagcompound );

View File

@@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
@@ -29,6 +28,7 @@ public class ItemCommandComputer extends ItemComputer
setCreativeTab( ComputerCraft.mainCreativeTab );
}
@Override
public ItemStack create( int id, String label, ComputerFamily family )
{
// Ignore types we can't handle

View File

@@ -13,7 +13,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

View File

@@ -12,7 +12,6 @@ import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;

View File

@@ -24,7 +24,6 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.List;

View File

@@ -7,7 +7,6 @@
package dan200.computercraft.shared.peripheral.commandblock;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaTask;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@@ -55,52 +54,37 @@ public class CommandBlockPeripheral implements IPeripheral
case 0:
{
// getCommand
return context.executeMainThreadTask( new ILuaTask()
{
@Override
public Object[] execute() throws LuaException
{
return new Object[] {
m_commandBlock.getCommandBlockLogic().getCommand()
};
}
return context.executeMainThreadTask( () -> new Object[] {
m_commandBlock.getCommandBlockLogic().getCommand()
} );
}
case 1:
{
// setCommand
final String command = getString( arguments, 0 );
context.issueMainThreadTask( new ILuaTask()
context.issueMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
{
BlockPos pos = m_commandBlock.getPos();
m_commandBlock.getCommandBlockLogic().setCommand( command );
m_commandBlock.getWorld().markBlockRangeForRenderUpdate( pos, pos );
return null;
}
BlockPos pos = m_commandBlock.getPos();
m_commandBlock.getCommandBlockLogic().setCommand( command );
m_commandBlock.getWorld().markBlockRangeForRenderUpdate( pos, pos );
return null;
} );
return null;
}
case 2:
{
// runCommand
return context.executeMainThreadTask( new ILuaTask()
return context.executeMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
m_commandBlock.getCommandBlockLogic().trigger( m_commandBlock.getWorld() );
int result = m_commandBlock.getCommandBlockLogic().getSuccessCount();
if( result > 0 )
{
m_commandBlock.getCommandBlockLogic().trigger( m_commandBlock.getWorld() );
int result = m_commandBlock.getCommandBlockLogic().getSuccessCount();
if( result > 0 )
{
return new Object[] { true };
}
else
{
return new Object[] { false, "Command failed" };
}
return new Object[] { true };
}
else
{
return new Object[] { false, "Command failed" };
}
} );
}
@@ -108,16 +92,6 @@ public class CommandBlockPeripheral implements IPeripheral
return null;
}
@Override
public void attach( @Nonnull IComputerAccess computer )
{
}
@Override
public void detach( @Nonnull IComputerAccess computer )
{
}
@Override
public boolean equals( IPeripheral other )
{

View File

@@ -51,6 +51,7 @@ public class BlockPeripheral extends BlockPeripheralBase
);
}
@Override
@Nonnull
@SideOnly( Side.CLIENT)
public BlockRenderLayer getBlockLayer()

View File

@@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.PeripheralType;
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;

View File

@@ -14,7 +14,6 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
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.*;

View File

@@ -10,12 +10,10 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.PeripheralType;
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;
public class ItemPeripheral extends ItemPeripheralBase
{

View File

@@ -72,7 +72,7 @@ public class TileDiskDrive extends TilePeripheralBase
public TileDiskDrive()
{
m_computers = new HashMap<IComputerAccess, MountInfo>();
m_computers = new HashMap<>();
m_diskStack = ItemStack.EMPTY;
m_diskMount = null;

View File

@@ -131,7 +131,7 @@ public class TileCable extends TileModemBase
synchronized( m_entity.m_peripheralsByName )
{
int idx = 1;
Map<Object,Object> table = new HashMap<Object,Object>();
Map<Object,Object> table = new HashMap<>();
for( String name : m_entity.m_peripheralWrappersByName.keySet() )
{
table.put( idx++, name );
@@ -161,7 +161,7 @@ public class TileCable extends TileModemBase
String[] methodNames = m_entity.getMethodNamesRemote( getString( arguments, 0 ) );
if( methodNames != null )
{
Map<Object,Object> table = new HashMap<Object,Object>();
Map<Object,Object> table = new HashMap<>();
for(int i=0; i<methodNames.length; ++i ) {
table.put( i+1, methodNames[i] );
}
@@ -247,14 +247,14 @@ public class TileCable extends TileModemBase
public TileCable()
{
m_receivers = new HashSet<IPacketReceiver>();
m_transmitQueue = new LinkedList<PacketWrapper>();
m_receivers = new HashSet<>();
m_transmitQueue = new LinkedList<>();
m_peripheralAccessAllowed = false;
m_attachedPeripheralID = -1;
m_peripheralsByName = new HashMap<String, IPeripheral>();
m_peripheralWrappersByName = new HashMap<String, RemotePeripheralWrapper>();
m_peripheralsByName = new HashMap<>();
m_peripheralWrappersByName = new HashMap<>();
m_peripheralsKnown = false;
m_destroyed = false;
@@ -685,13 +685,11 @@ public class TileCable extends TileModemBase
if( !m_destroyed )
{
// If this modem is alive, rebuild the network
searchNetwork( new ICableVisitor() {
public void visit( TileCable modem, int distance )
searchNetwork( ( modem, distance ) ->
{
synchronized( modem.m_peripheralsByName )
{
synchronized( modem.m_peripheralsByName )
{
modem.m_peripheralsKnown = false;
}
modem.m_peripheralsKnown = false;
}
} );
}
@@ -733,13 +731,11 @@ public class TileCable extends TileModemBase
private void dispatchPacket( final PacketWrapper packet )
{
searchNetwork( new ICableVisitor() {
public void visit( TileCable modem, int distance )
searchNetwork( ( modem, distance ) ->
{
if( distance <= packet.m_range)
{
if( distance <= packet.m_range)
{
modem.receivePacket( packet.m_packet, distance );
}
modem.receivePacket( packet.m_packet, distance );
}
} );
}
@@ -778,7 +774,7 @@ public class TileCable extends TileModemBase
assert( m_type != null );
assert( m_methods != null );
m_methodMap = new HashMap<String, Integer>();
m_methodMap = new HashMap<>();
for( int i=0; i<m_methods.length; ++i ) {
if( m_methods[i] != null ) {
m_methodMap.put( m_methods[i], i );
@@ -876,22 +872,20 @@ public class TileCable extends TileModemBase
synchronized( m_peripheralsByName )
{
// Collect the peripherals
final Map<String, IPeripheral> newPeripheralsByName = new HashMap<String, IPeripheral>();
final Map<String, IPeripheral> newPeripheralsByName = new HashMap<>();
if( getPeripheralType() == PeripheralType.WiredModemWithCable )
{
searchNetwork( new ICableVisitor() {
public void visit( TileCable modem, int distance )
searchNetwork( ( modem, distance ) ->
{
if( modem != origin )
{
IPeripheral peripheral = modem.getConnectedPeripheral();
String periphName = modem.getConnectedPeripheralName();
if( peripheral != null && periphName != null )
{
if( modem != origin )
{
IPeripheral peripheral = modem.getConnectedPeripheral();
String periphName = modem.getConnectedPeripheralName();
if( peripheral != null && periphName != null )
{
newPeripheralsByName.put( periphName, peripheral );
}
}
newPeripheralsByName.put( periphName, peripheral );
}
}
} );
}
//System.out.println( newPeripheralsByName.size()+" peripherals discovered" );
@@ -1035,7 +1029,7 @@ public class TileCable extends TileModemBase
private void searchNetwork( ICableVisitor visitor )
{
int searchID = ++s_nextUniqueSearchID;
Queue<SearchLoc> queue = new LinkedList<SearchLoc>();
Queue<SearchLoc> queue = new LinkedList<>();
enqueue( queue, getWorld(), getPos(), 1 );
int visited = 0;

View File

@@ -38,7 +38,7 @@ public class WirelessNetwork implements IPacketNetwork
private WirelessNetwork()
{
m_receivers = new HashSet<IPacketReceiver>();
m_receivers = new HashSet<>();
}
@Override

View File

@@ -65,7 +65,7 @@ public class TileMonitor extends TilePeripheralBase
public TileMonitor()
{
m_computers = new HashSet<IComputerAccess>();
m_computers = new HashSet<>();
m_destroyed = false;
m_ignoreMe = false;

View File

@@ -131,16 +131,6 @@ public class PrinterPeripheral implements IPeripheral
}
}
@Override
public void attach( @Nonnull IComputerAccess computer )
{
}
@Override
public void detach( @Nonnull IComputerAccess computer )
{
}
@Override
public boolean equals( IPeripheral other )
{

View File

@@ -75,17 +75,6 @@ public class SpeakerPeripheral implements IPeripheral {
}
}
@Override
public void attach( @Nonnull IComputerAccess computerAccess )
{
}
@Override
public void detach( @Nonnull IComputerAccess computerAccess )
{
}
@Nonnull
@Override
public String getType()

View File

@@ -32,6 +32,7 @@ public class TileSpeaker extends TilePeripheralBase
// IPeripheralTile implementation
@Override
public IPeripheral getPeripheral( EnumFacing side )
{
return m_peripheral;

View File

@@ -8,7 +8,6 @@ package dan200.computercraft.shared.pocket.apis;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaTask;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.core.apis.ILuaAPI;
@@ -72,84 +71,76 @@ public class PocketAPI implements ILuaAPI
{
case 0:
// equipBack
return context.executeMainThreadTask( new ILuaTask()
return context.executeMainThreadTask( () ->
{
@Override
public Object[] execute() throws LuaException
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
throw new LuaException( "Cannot find player" );
}
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
// Attempt to find the upgrade, starting in the main segment, and then looking in the opposite
// one. We start from the position the item is currently in and loop round to the start.
IPocketUpgrade newUpgrade = findUpgrade( inventory.mainInventory, inventory.currentItem, previousUpgrade );
if( newUpgrade == null )
{
newUpgrade = findUpgrade( inventory.offHandInventory, 0, previousUpgrade );
}
if( newUpgrade == null ) throw new LuaException( "Cannot find a valid upgrade" );
// Remove the current upgrade
if( previousUpgrade != null )
{
ItemStack stack = previousUpgrade.getCraftingItem();
if( !stack.isEmpty() )
{
stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem );
if( !stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
}
}
// Set the new upgrade
m_computer.setUpgrade( newUpgrade );
return null;
throw new LuaException( "Cannot find player" );
}
} );
case 1:
// unequipBack
return context.executeMainThreadTask( new ILuaTask()
{
@Override
public Object[] execute() throws LuaException
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
// Attempt to find the upgrade, starting in the main segment, and then looking in the opposite
// one. We start from the position the item is currently in and loop round to the start.
IPocketUpgrade newUpgrade = findUpgrade( inventory.mainInventory, inventory.currentItem, previousUpgrade );
if( newUpgrade == null )
{
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
throw new LuaException( "Cannot find player" );
}
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
if( previousUpgrade == null ) throw new LuaException( "Nothing to unequip" );
m_computer.setUpgrade( null );
newUpgrade = findUpgrade( inventory.offHandInventory, 0, previousUpgrade );
}
if( newUpgrade == null ) throw new LuaException( "Cannot find a valid upgrade" );
// Remove the current upgrade
if( previousUpgrade != null )
{
ItemStack stack = previousUpgrade.getCraftingItem();
if( !stack.isEmpty() )
{
stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem );
if( stack.isEmpty() )
if( !stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
}
return null;
}
// Set the new upgrade
m_computer.setUpgrade( newUpgrade );
return null;
} );
case 1:
// unequipBack
return context.executeMainThreadTask( () ->
{
if( !(m_computer.getEntity() instanceof EntityPlayer) )
{
throw new LuaException( "Cannot find player" );
}
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
InventoryPlayer inventory = player.inventory;
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
if( previousUpgrade == null ) throw new LuaException( "Nothing to unequip" );
m_computer.setUpgrade( null );
ItemStack stack = previousUpgrade.getCraftingItem();
if( !stack.isEmpty() )
{
stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem );
if( stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.posX, player.posY, player.posZ );
}
}
return null;
} );
default:
return null;

View File

@@ -184,7 +184,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
if( !stop ) ComputerCraft.openPocketComputerGUI( player, hand );
}
return new ActionResult<ItemStack>( EnumActionResult.SUCCESS, stack );
return new ActionResult<>( EnumActionResult.SUCCESS, stack );
}
@Nonnull

View File

@@ -9,7 +9,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -79,10 +78,4 @@ public class PocketModem implements IPocketUpgrade
access.setLight( modem.isActive() ? 0xBA0000 : -1 );
}
}
@Override
public boolean onRightClick( @Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
{
return false;
}
}

View File

@@ -15,7 +15,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -76,12 +75,4 @@ public class PocketSpeaker implements IPocketUpgrade
speaker.update();
}
}
@Override
public boolean onRightClick(@Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
{
return false;
}
}

View File

@@ -51,9 +51,9 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
public CCTurtleProxyCommon()
{
m_legacyTurtleUpgrades = new HashMap<Integer, ITurtleUpgrade>();
m_turtleUpgrades = new HashMap<String, ITurtleUpgrade>();
m_dropConsumers = new WeakHashMap<Entity, IEntityDropConsumer>();
m_legacyTurtleUpgrades = new HashMap<>();
m_turtleUpgrades = new HashMap<>();
m_dropConsumers = new WeakHashMap<>();
}
// ICCTurtleProxy implementation

View File

@@ -179,14 +179,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
processPacket( packet, player );
} else
{
listener.addScheduledTask( new Runnable()
{
@Override
public void run()
{
processPacket( packet, player );
}
} );
listener.addScheduledTask( () -> processPacket( packet, player ) );
}
}
}

View File

@@ -6,7 +6,6 @@
package dan200.computercraft.shared.turtle.apis;
import com.google.common.base.Optional;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.turtle.ITurtleAccess;
@@ -21,6 +20,7 @@ import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static dan200.computercraft.core.apis.ArgumentHelper.*;
@@ -149,7 +149,7 @@ public class TurtleAPI implements ILuaAPI
String side = optString( arguments, index, null );
if( side == null )
{
return Optional.absent();
return Optional.empty();
}
else if( side.equalsIgnoreCase( "left" ) )
{
@@ -435,7 +435,7 @@ public class TurtleAPI implements ILuaAPI
int damage = stack.getItemDamage();
int count = stack.getCount();
Map<Object, Object> table = new HashMap<Object, Object>();
Map<Object, Object> table = new HashMap<>();
table.put( "name", name );
table.put( "damage", damage );
table.put( "count", count );

View File

@@ -6,10 +6,11 @@
package dan200.computercraft.shared.turtle.core;
import com.google.common.base.Optional;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb;
import java.util.Optional;
public class TurtleAttackCommand extends TurtleToolCommand
{
public TurtleAttackCommand( InteractDirection direction, Optional<TurtleSide> side )

View File

@@ -41,7 +41,7 @@ import java.util.*;
public class TurtleBrain implements ITurtleAccess
{
private static int s_nextInstanceID = 0;
private static Map<Integer, WeakReference<TurtleBrain>> s_allClientBrains = new HashMap<Integer, WeakReference<TurtleBrain>>();
private static Map<Integer, WeakReference<TurtleBrain>> s_allClientBrains = new HashMap<>();
public static int assignInstanceID()
{
@@ -75,7 +75,7 @@ public class TurtleBrain implements ITurtleAccess
{
if( getClientBrain( instanceID ) != brain )
{
s_allClientBrains.put( instanceID, new WeakReference<TurtleBrain>( brain ) );
s_allClientBrains.put( instanceID, new WeakReference<>( brain ) );
}
}
}
@@ -127,12 +127,12 @@ public class TurtleBrain implements ITurtleAccess
{
m_owner = turtle;
m_commandQueue = new LinkedList<TurtleCommandQueueEntry>();
m_commandQueue = new LinkedList<>();
m_commandsIssued = 0;
m_upgrades = new HashMap<TurtleSide, ITurtleUpgrade>();
m_peripherals = new HashMap<TurtleSide, IPeripheral>();
m_upgradeNBTData = new HashMap<TurtleSide, NBTTagCompound>();
m_upgrades = new HashMap<>();
m_peripherals = new HashMap<>();
m_upgradeNBTData = new HashMap<>();
m_selectedSlot = 0;
m_fuelLevel = 0;

View File

@@ -6,10 +6,11 @@
package dan200.computercraft.shared.turtle.core;
import com.google.common.base.Optional;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb;
import java.util.Optional;
public class TurtleDigCommand extends TurtleToolCommand
{
public TurtleDigCommand( InteractDirection direction, Optional<TurtleSide> side )

View File

@@ -53,11 +53,11 @@ public class TurtleInspectCommand implements ITurtleCommand
String name = Block.REGISTRY.getNameForObject( block ).toString();
int metadata = block.getMetaFromState( state );
Map<Object, Object> table = new HashMap<Object, Object>();
Map<Object, Object> table = new HashMap<>();
table.put( "name", name );
table.put( "metadata", metadata );
Map<Object, Object> stateTable = new HashMap<Object, Object>();
Map<Object, Object> stateTable = new HashMap<>();
for( ImmutableMap.Entry<IProperty<?>, ?> entry : state.getActualState( world, newPosition ).getProperties().entrySet() )
{
String propertyName = entry.getKey().getName();
@@ -79,10 +79,10 @@ public class TurtleInspectCommand implements ITurtleCommand
if( !FAIL_ON_AIR )
{
Map<Object, Object> table = new HashMap<Object, Object>();
Map<Object, Object> table = new HashMap<>();
table.put( "name", "minecraft:air" );
table.put( "metadata", 0 );
table.put( "state", new HashMap<Object, Object>() );
table.put( "state", new HashMap<>() );
return TurtleCommandResult.success( new Object[]{ table } );
}
return TurtleCommandResult.failure( "No block to inspect" );

View File

@@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.IEntityDropConsumer;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block;
@@ -225,16 +224,12 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Start claiming entity drops
Entity hitEntity = hit.getKey();
Vec3d hitPos = hit.getValue();
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
ComputerCraft.setEntityDropConsumer( hitEntity, ( entity, drop ) ->
{
@Override
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( !remainder.isEmpty() )
{
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( !remainder.isEmpty() )
{
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
} );

View File

@@ -6,10 +6,10 @@
package dan200.computercraft.shared.turtle.core;
import com.google.common.base.Optional;
import dan200.computercraft.api.turtle.*;
import javax.annotation.Nonnull;
import java.util.Optional;
public class TurtleToolCommand implements ITurtleCommand
{

View File

@@ -28,7 +28,7 @@ public class TurtleVisionCamera extends EntityLivingBase
{
super( world );
m_turtle = turtle;
m_armor = new ArrayList<ItemStack>();
m_armor = new ArrayList<>();
applyPos();
}

View File

@@ -20,5 +20,6 @@ public interface ITurtleItem extends IComputerItem, IColouredItem
ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
int getFuelLevel( ItemStack stack );
ResourceLocation getOverlay( ItemStack stack );
@Override
int getColour( @Nonnull ItemStack stack );
}

View File

@@ -18,7 +18,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
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.EnumFacing;

View File

@@ -72,16 +72,6 @@ public class CraftingTablePeripheral
}
}
}
@Override
public void attach( @Nonnull IComputerAccess computer )
{
}
@Override
public void detach( @Nonnull IComputerAccess computer )
{
}
@Override
public boolean equals( IPeripheral other )

View File

@@ -118,9 +118,4 @@ public class TurtleCraftingTable implements ITurtleUpgrade
return Pair.of( modelManager.getModel( m_rightModel ), transform );
}
}
@Override
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
}
}

View File

@@ -88,7 +88,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
if( !result.isEmpty() )
{
// Special case: craft(0) just returns an empty list if crafting was possible
ArrayList<ItemStack> results = new ArrayList<ItemStack>();
ArrayList<ItemStack> results = new ArrayList<>();
if( maxCount == 0 )
{
return results;

View File

@@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand;
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import dan200.computercraft.shared.util.IEntityDropConsumer;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block;
@@ -121,11 +120,6 @@ public class TurtleTool implements ITurtleUpgrade
);
}
@Override
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
}
@Nonnull
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
@@ -186,16 +180,12 @@ public class TurtleTool implements ITurtleUpgrade
// Start claiming entity drops
Entity hitEntity = hit.getKey();
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
ComputerCraft.setEntityDropConsumer( hitEntity, ( entity, drop ) ->
{
@Override
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( !remainder.isEmpty() )
{
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
if( !remainder.isEmpty() )
{
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
}
} );

View File

@@ -73,15 +73,10 @@ public class IDAssigner
{
isr = new InputStreamReader( in );
}
BufferedReader br = new BufferedReader( isr );
try
try( BufferedReader br = new BufferedReader( isr ) )
{
idString = br.readLine();
}
finally
{
br.close();
}
}
catch( IOException e )
{

View File

@@ -99,7 +99,7 @@ public class NBTUtil
{
NBTTagCompound c = (NBTTagCompound)tag;
int len = c.getInteger( "len" );
Map<Object, Object> map = new HashMap<Object, Object>( len );
Map<Object, Object> map = new HashMap<>( len );
for( int i=0; i<len; ++i )
{
Object key = fromNBTTag( c.getTag( "k" + Integer.toString( i ) ) );