Merge pull request #181 from thatsIch/Foreach

Replaced normal for loops with foreach loops which is less error prone w...
This commit is contained in:
Chris 2014-09-29 17:57:13 -07:00
commit cb5f1bc19c
15 changed files with 86 additions and 60 deletions

View file

@ -360,28 +360,32 @@ public abstract class AEBaseContainer extends Container
tis = shiftStoreItem( tis );
// target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++)
for (Object inventorySlot : this.inventorySlots)
{
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
AppEngSlot cs = (AppEngSlot) inventorySlot;
if ( !(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
{
if ( cs.isItemValid( tis ) )
{
selectedSlots.add( cs );
}
}
}
}
else
{
// target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++)
for (Object inventorySlot : this.inventorySlots)
{
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
AppEngSlot cs = (AppEngSlot) inventorySlot;
if ( (cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
{
if ( cs.isItemValid( tis ) )
{
selectedSlots.add( cs );
}
}
}
}
@ -394,15 +398,17 @@ public abstract class AEBaseContainer extends Container
if ( tis != null )
{
// target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++)
for (Object inventorySlot : this.inventorySlots)
{
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
AppEngSlot cs = (AppEngSlot) inventorySlot;
ItemStack dest = cs.getStack();
if ( !(cs.isPlayerSide()) && cs instanceof SlotFake )
{
if ( Platform.isSameItemPrecise( dest, tis ) )
{
return null;
}
else if ( dest == null )
{
cs.putStack( tis.copy() );
@ -563,9 +569,9 @@ public abstract class AEBaseContainer extends Container
if ( Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
for (Object crafter : this.crafters)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
ICrafting icrafting = (ICrafting) crafter;
for (SyncData sd : syncData.values())
sd.tick( icrafting );

View file

@ -242,9 +242,9 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
ItemStack is = workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if ( Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
for (Object crafter : this.crafters)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
ICrafting icrafting = (ICrafting) crafter;
if ( prevStack != is )
{

View file

@ -152,11 +152,11 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
if ( sideLocal != sideRemote )
{
clientCM.putSetting( set, sideLocal );
for (int j = 0; j < this.crafters.size(); ++j)
for (Object crafter : this.crafters)
{
try
{
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) );
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch (IOException e)
{

View file

@ -262,9 +262,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
List<ItemStack> list = new ArrayList<ItemStack>( 3 );
boolean hasValue = false;
for (int x = 0; x < outputSlots.length; x++)
for (OptionalSlotFake outputSlot : outputSlots)
{
ItemStack out = outputSlots[x].getStack();
ItemStack out = outputSlot.getStack();
if ( out != null && out.stackSize > 0 )
{
list.add( out );
@ -395,9 +395,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
{
if ( s == patternSlotOUT && Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
for (Object crafter : this.crafters)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
ICrafting icrafting = (ICrafting) crafter;
for (Object g : inventorySlots)
{

View file

@ -134,9 +134,9 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE
wirelessOut.putStack( term );
// update the two slots in question...
for (int i = 0; i < this.crafters.size(); ++i)
for (Object crafter : this.crafters)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
ICrafting icrafting = (ICrafting) crafter;
icrafting.sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() );
icrafting.sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() );
}

View file

@ -150,10 +150,12 @@ public class MultiCraftingTracker
jobs[slot] = l;
boolean hasStuff = false;
for (int x = 0; x < jobs.length; x++)
for (Future<ICraftingJob> job : jobs)
{
if ( jobs[x] != null )
if ( job != null )
{
hasStuff = true;
}
}
if ( hasStuff == false )

View file

@ -55,9 +55,8 @@ public class NEICraftingHandler implements IOverlayHandler
if ( gui instanceof GuiCraftingTerm || gui instanceof GuiPatternTerm )
{
for (int i = 0; i < ingredients.size(); i++)// identify slots
for (PositionedStack positionedStack : ingredients)
{
PositionedStack positionedStack = ingredients.get( i );
int col = (positionedStack.relx - 25) / 18;
int row = (positionedStack.rely - 6) / 18;
if ( positionedStack.items != null && positionedStack.items.length > 0 )
@ -76,9 +75,13 @@ public class NEICraftingHandler implements IOverlayHandler
for (int x = 0; x < positionedStack.items.length; x++)
{
if ( Platform.isRecipePrioritized( positionedStack.items[x] ) )
{
list.add( 0, positionedStack.items[x] );
}
else
{
list.add( positionedStack.items[x] );
}
}
for (ItemStack is : list)

View file

@ -89,22 +89,26 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
String with = GuiText.With.getLocal() + ": ";
boolean first = true;
for (int x = 0; x < out.length; x++)
for (IAEItemStack anOut : out)
{
if ( out[x] == null )
if ( anOut == null )
{
continue;
}
l.add( (first ? label : and) + out[x].getStackSize() + " " + Platform.getItemDisplayName( out[x] ) );
l.add( (first ? label : and) + anOut.getStackSize() + " " + Platform.getItemDisplayName( anOut ) );
first = false;
}
first = true;
for (int x = 0; x < in.length; x++)
for (IAEItemStack anIn : in)
{
if ( in[x] == null )
if ( anIn == null )
{
continue;
}
l.add( (first ? with : and) + in[x].getStackSize() + " " + Platform.getItemDisplayName( in[x] ) );
l.add( (first ? with : and) + anIn.getStackSize() + " " + Platform.getItemDisplayName( anIn ) );
first = false;
}
}

View file

@ -595,10 +595,12 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
IAEItemStack[] input = details.getInputs();
double sum = 0;
for (int x = 0; x < input.length; x++)
for (IAEItemStack anInput : input)
{
if ( input[x] != null )
sum += input[x].getStackSize();
if ( anInput != null )
{
sum += anInput.getStackSize();
}
}
// power...

View file

@ -35,9 +35,13 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
cols = input.get( 0 ).size();
if ( cols <= 3 && cols >= 1 )
{
for (int x = 0; x < input.size(); x++)
if ( input.get( x ).size() != cols )
for (List<IIngredient> anInput : input)
{
if ( anInput.size() != cols )
{
throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." );
}
}
inputs = input;
this.output = output.get( 0 ).get( 0 );

View file

@ -61,18 +61,19 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
@Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
for ( int y = 0; y < inputs.size(); y++ )
for (IIngredient i : inputs)
{
IIngredient i = inputs.get(y);
if ( !i.isAir() )
if ( !i.isAir() )
{
for (ItemStack r : i.getItemStackSet())
{
for ( ItemStack r : i.getItemStackSet() )
if ( Platform.isSameItemPrecise( r, reqOutput ) )
{
if ( Platform.isSameItemPrecise( r, reqOutput) )
return false;
return false;
}
}
}
}
return Platform.isSameItemPrecise( output.getItemStack(),reqOutput );
}

View file

@ -575,10 +575,8 @@ public class Platform
CraftingManager cm = CraftingManager.getInstance();
List<IRecipe> rl = cm.getRecipeList();
for (int x = 0; x < rl.size(); ++x)
for (IRecipe r : rl)
{
IRecipe r = rl.get( x );
if ( r.matches( par1InventoryCrafting, par2World ) )
{
return r;

View file

@ -89,10 +89,13 @@ public class AdaptorISpecialInventory extends InventoryAdaptor
if ( slots == null )
return false;
int s = slots.length;
for (int x = 0; x < s; x++)
if ( i.getStackInSlot( slots[x] ) != null )
for (int slot : slots)
{
if ( i.getStackInSlot( slot ) != null )
{
return true;
}
}
return false;
}

View file

@ -52,16 +52,18 @@ public class AdaptorList extends InventoryAdaptor
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
{
int s = i.size();
for (int x = 0; x < s; x++)
for (ItemStack is : i)
{
ItemStack is = i.get( x );
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
{
if ( how_many > is.stackSize )
{
how_many = is.stackSize;
}
if ( dest != null && !dest.canInsert( is ) )
{
how_many = 0;
}
if ( how_many > 0 )
{
@ -109,16 +111,18 @@ public class AdaptorList extends InventoryAdaptor
@Override
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination dest)
{
int s = i.size();
for (int x = 0; x < s; x++)
for (ItemStack is : i)
{
ItemStack is = i.get( x );
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
{
if ( how_many > is.stackSize )
{
how_many = is.stackSize;
}
if ( dest != null && !dest.canInsert( is ) )
{
how_many = 0;
}
if ( how_many > 0 )
{
@ -142,10 +146,8 @@ public class AdaptorList extends InventoryAdaptor
ItemStack left = A.copy();
int s = i.size();
for (int x = 0; x < s; x++)
for (ItemStack is : i)
{
ItemStack is = i.get( x );
if ( Platform.isSameItem( is, left ) )
{
is.stackSize += left.stackSize;
@ -166,13 +168,12 @@ public class AdaptorList extends InventoryAdaptor
@Override
public boolean containsItems()
{
int s = i.size();
for (int x = 0; x < s; x++)
for (ItemStack is : i)
{
ItemStack is = i.get( x );
if ( is != null )
{
return true;
}
}
return false;
}

View file

@ -16,11 +16,13 @@ public class WrapperInventoryRange implements IInventory
if ( s.length > 0 )
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length; i++)
for (int value : s)
{
if ( sb.length() > 0 )
{
sb.append( separator );
sb.append( s[i] );
}
sb.append( value );
}
return sb.toString();
}