mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-12 03:13:00 +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:
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@SideOnly( Side.CLIENT)
|
||||
public BlockRenderLayer getBlockLayer()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.*;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class WirelessNetwork implements IPacketNetwork
|
||||
|
||||
private WirelessNetwork()
|
||||
{
|
||||
m_receivers = new HashSet<IPacketReceiver>();
|
||||
m_receivers = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -32,6 +32,7 @@ public class TileSpeaker extends TilePeripheralBase
|
||||
|
||||
// IPeripheralTile implementation
|
||||
|
||||
@Override
|
||||
public IPeripheral getPeripheral( EnumFacing side )
|
||||
{
|
||||
return m_peripheral;
|
||||
|
||||
Reference in New Issue
Block a user