mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-09-28 20:01:43 +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:
@@ -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 );
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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" );
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TurtleVisionCamera extends EntityLivingBase
|
||||
{
|
||||
super( world );
|
||||
m_turtle = turtle;
|
||||
m_armor = new ArrayList<ItemStack>();
|
||||
m_armor = new ArrayList<>();
|
||||
applyPos();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
-10
@@ -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 )
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user