1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-12 19:33:00 +00:00

Remove some unnecessary constructs

- Replace for and while loops with for iterators
 - Remove unused casts
This commit is contained in:
SquidDev
2017-05-07 00:42:00 +01:00
parent dc5517303f
commit 9af15d1e30
64 changed files with 299 additions and 400 deletions

View File

@@ -17,7 +17,6 @@ import dan200.computercraft.core.apis.ILuaAPI;
import dan200.computercraft.shared.turtle.core.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import java.util.HashMap;
@@ -480,7 +479,7 @@ public class TurtleAPI implements ILuaAPI
if( stack != null && stack.stackSize > 0 )
{
Item item = stack.getItem();
String name = ((ResourceLocation)Item.REGISTRY.getNameForObject( item )).toString();
String name = Item.REGISTRY.getNameForObject( item ).toString();
int damage = stack.getItemDamage();
int count = stack.stackSize;

View File

@@ -8,14 +8,11 @@ package dan200.computercraft.shared.turtle.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;

View File

@@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
@@ -28,7 +27,6 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ITickable;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.util.text.*;

View File

@@ -28,7 +28,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.util.text.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
@@ -335,11 +334,11 @@ public class TurtleBrain implements ITurtleAccess
// Write NBT
if( m_upgradeNBTData.containsKey( TurtleSide.Left ) )
{
nbttagcompound.setTag( "leftUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Left ).copy() );
nbttagcompound.setTag( "leftUpgradeNBT", getUpgradeNBTData( TurtleSide.Left ).copy() );
}
if( m_upgradeNBTData.containsKey( TurtleSide.Right ) )
{
nbttagcompound.setTag( "rightUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Right ).copy() );
nbttagcompound.setTag( "rightUpgradeNBT", getUpgradeNBTData( TurtleSide.Right ).copy() );
}
return nbttagcompound;
@@ -371,11 +370,11 @@ public class TurtleBrain implements ITurtleAccess
// NBT
if( m_upgradeNBTData.containsKey( TurtleSide.Left ) )
{
nbttagcompound.setTag( "leftUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Left ).copy() );
nbttagcompound.setTag( "leftUpgradeNBT", getUpgradeNBTData( TurtleSide.Left ).copy() );
}
if( m_upgradeNBTData.containsKey( TurtleSide.Right ) )
{
nbttagcompound.setTag( "rightUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Right ).copy() );
nbttagcompound.setTag( "rightUpgradeNBT", getUpgradeNBTData( TurtleSide.Right ).copy() );
}
// Colour
@@ -738,10 +737,7 @@ public class TurtleBrain implements ITurtleAccess
if( ( (Number) response[ 1 ] ).intValue() == commandID )
{
Object[] returnValues = new Object[ response.length - 2 ];
for( int i = 0; i < returnValues.length; ++i )
{
returnValues[ i ] = response[ i + 2 ];
}
System.arraycopy( response, 2, returnValues, 0, returnValues.length );
return returnValues;
}
}
@@ -1033,10 +1029,7 @@ public class TurtleBrain implements ITurtleAccess
Object[] arguments = new Object[ results.length + 2 ];
arguments[0] = callbackID;
arguments[1] = true;
for( int i=0; i<results.length; ++i )
{
arguments[2+i] = results[i];
}
System.arraycopy( results, 0, arguments, 2, results.length );
computer.queueEvent( "turtle_response", arguments );
}
else
@@ -1140,16 +1133,16 @@ public class TurtleBrain implements ITurtleAccess
}
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
List list = world.getEntitiesWithinAABBExcludingEntity( (Entity)null, aabb );
List list = world.getEntitiesWithinAABBExcludingEntity( null, aabb );
if( !list.isEmpty() )
{
double pushStep = 1.0f / (float) ANIM_DURATION;
double pushStepX = (double) moveDir.getFrontOffsetX() * pushStep;
double pushStepY = (double) moveDir.getFrontOffsetY() * pushStep;
double pushStepZ = (double) moveDir.getFrontOffsetZ() * pushStep;
for( int i = 0; i < list.size(); ++i )
for (Object aList : list)
{
Entity entity = (Entity) list.get( i );
Entity entity = (Entity) aList;
entity.moveEntity(
pushStepX, pushStepY, pushStepZ
);

View File

@@ -21,7 +21,6 @@ import net.minecraftforge.fml.relauncher.ReflectionHelper;
import javax.annotation.Nonnull;
import java.lang.reflect.Method;
import java.util.Iterator;
public class TurtleCompareCommand implements ITurtleCommand
{
@@ -84,10 +83,8 @@ public class TurtleCompareCommand implements ITurtleCommand
java.util.List<ItemStack> drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 );
if( drops != null && drops.size() > 0 )
{
Iterator<ItemStack> it = drops.iterator();
while( it.hasNext() )
for( ItemStack drop : drops )
{
ItemStack drop = it.next();
if( drop.getItem() == Item.getItemFromBlock( lookAtBlock ) )
{
lookAtStack = drop;

View File

@@ -38,9 +38,8 @@ public class TurtleCraftCommand implements ITurtleCommand
if( results != null )
{
// Store the results
for( int i=0; i<results.size(); ++i )
for( ItemStack stack : results )
{
ItemStack stack = results.get( i );
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), turtle.getSelectedSlot() );
if( remainder != null )
{

View File

@@ -12,11 +12,8 @@ import dan200.computercraft.api.turtle.TurtleAnimation;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

View File

@@ -16,7 +16,6 @@ import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
@@ -51,7 +50,7 @@ public class TurtleInspectCommand implements ITurtleCommand
{
IBlockState state = world.getBlockState( newPosition );
Block block = state.getBlock();
String name = ((ResourceLocation)Block.REGISTRY.getNameForObject( block )).toString();
String name = Block.REGISTRY.getNameForObject( block ).toString();
int metadata = block.getMetaFromState( state );
Map<Object, Object> table = new HashMap<Object, Object>();

View File

@@ -72,10 +72,10 @@ public class TurtleMoveCommand implements ITurtleCommand
if( ComputerCraft.turtlesCanPush && m_direction != MoveDirection.Up && m_direction != MoveDirection.Down )
{
// Check there is space for all the pushable entities to be pushed
List list = oldWorld.getEntitiesWithinAABBExcludingEntity( (Entity)null, aabb );
for( int i=0; i<list.size(); ++i )
List list = oldWorld.getEntitiesWithinAABBExcludingEntity( null, aabb );
for( Object aList : list )
{
Entity entity = (Entity)list.get( i );
Entity entity = (Entity) aList;
if( !entity.isDead && entity.preventEntitySpawning )
{
AxisAlignedBB entityBB = entity.getEntityBoundingBox();

View File

@@ -95,14 +95,14 @@ public class TurtleSuckCommand implements ITurtleCommand
{
boolean foundItems = false;
boolean storedItems = false;
for( int i=0; i<list.size(); i++ )
for( Object aList : list )
{
Entity entity = (Entity)list.get(i);
Entity entity = (Entity) aList;
if( entity != null && entity instanceof EntityItem && !entity.isDead )
{
// Suck up the item
foundItems = true;
EntityItem entityItem = (EntityItem)entity;
EntityItem entityItem = (EntityItem) entity;
ItemStack stack = entityItem.getEntityItem().copy();
ItemStack storeStack;
ItemStack leaveStack;

View File

@@ -108,12 +108,11 @@ public class ContainerTurtle extends Container
super.detectAndSendChanges();
int selectedSlot = m_turtle.getSelectedSlot();
for( int i=0; i<listeners.size(); ++i )
for( IContainerListener listener : listeners )
{
IContainerListener icrafting = (IContainerListener)listeners.get(i);
if( m_selectedSlot != selectedSlot )
{
icrafting.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
listener.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
}
}
m_selectedSlot = selectedSlot;
@@ -146,7 +145,7 @@ public class ContainerTurtle extends Container
protected ItemStack tryItemMerge( EntityPlayer player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
{
Slot slot = (Slot)inventorySlots.get( slotNum );
Slot slot = inventorySlots.get( slotNum );
ItemStack originalStack = null;
if( slot != null && slot.getHasStack() )
{

View File

@@ -11,7 +11,6 @@ import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb;
import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;

View File

@@ -5,7 +5,6 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;

View File

@@ -5,7 +5,6 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;

View File

@@ -19,7 +19,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.item.EntityArmorStand;
@@ -37,7 +36,6 @@ import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix4f;
import java.util.Iterator;
public class TurtleTool implements ITurtleUpgrade
{
@@ -271,10 +269,8 @@ public class TurtleTool implements ITurtleUpgrade
java.util.List<ItemStack> items = getBlockDropped( world, newPosition );
if( items != null && items.size() > 0 )
{
Iterator<ItemStack> it = items.iterator();
while( it.hasNext() )
for( ItemStack stack : items )
{
ItemStack stack = it.next();
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), turtle.getSelectedSlot() );
if( remainder != null )
{