Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
+168 -172
View File
@@ -41,113 +41,30 @@ import appeng.util.ItemSorters;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper>
{
final ItemStack patternItem;
private final IAEItemStack pattern;
final InventoryCrafting crafting = new InventoryCrafting( new ContainerNull(), 3, 3 );
final InventoryCrafting testFrame = new InventoryCrafting( new ContainerNull(), 3, 3 );
final ItemStack correctOutput;
final IRecipe standardRecipe;
final IAEItemStack[] condensedInputs;
final IAEItemStack[] condensedOutputs;
final IAEItemStack[] inputs;
final IAEItemStack[] outputs;
final boolean isCrafting;
public int priority = 0;
static class TestLookup
{
final int slot;
final int ref;
final int hash;
public TestLookup(int slot, ItemStack i)
{
this( slot, i.getItem(), i.getItemDamage() );
}
public TestLookup(int slot, Item item, int dmg)
{
this.slot = slot;
this.ref = (dmg << Platform.DEF_OFFSET) | (Item.getIdFromItem( item ) & 0xffff);
int offset = 3 * slot;
this.hash = (this.ref << offset) | (this.ref >> (offset + 32));
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals(Object obj)
{
final boolean equality;
if ( obj instanceof TestLookup )
{
TestLookup b = (TestLookup) obj;
equality = b.slot == this.slot && b.ref == this.ref;
}
else
{
equality = false;
}
return equality;
}
}
enum TestStatus
{
ACCEPT, DECLINE, TEST
}
final HashSet<TestLookup> failCache = new HashSet<TestLookup>();
final HashSet<TestLookup> passCache = new HashSet<TestLookup>();
private final IAEItemStack pattern;
public int priority = 0;
private void markItemAs(int slotIndex, ItemStack i, TestStatus b)
{
if ( b == TestStatus.TEST || i.hasTagCompound() )
return;
(b == TestStatus.ACCEPT ? this.passCache : this.failCache).add( new TestLookup( slotIndex, i ) );
}
private TestStatus getStatus(int slotIndex, ItemStack i)
{
if ( this.crafting.getStackInSlot( slotIndex ) == null )
return i == null ? TestStatus.ACCEPT : TestStatus.DECLINE;
if ( i == null )
return TestStatus.DECLINE;
if ( i.hasTagCompound() )
return TestStatus.TEST;
if ( this.passCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.ACCEPT;
if ( this.failCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.DECLINE;
return TestStatus.TEST;
}
public PatternHelper(ItemStack is, World w)
public PatternHelper( ItemStack is, World w )
{
NBTTagCompound encodedValue = is.getTagCompound();
if ( encodedValue == null )
if( encodedValue == null )
throw new RuntimeException( "No pattern here!" );
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
@@ -159,12 +76,12 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
List<IAEItemStack> in = new ArrayList<IAEItemStack>();
List<IAEItemStack> out = new ArrayList<IAEItemStack>();
for (int x = 0; x < inTag.tagCount(); x++)
for( int x = 0; x < inTag.tagCount(); x++ )
{
ItemStack gs = ItemStack.loadItemStackFromNBT( inTag.getCompoundTagAt( x ) );
this.crafting.setInventorySlotContents( x, gs );
if ( gs != null && (!this.isCrafting || !gs.hasTagCompound()) )
if( gs != null && ( !this.isCrafting || !gs.hasTagCompound() ) )
{
this.markItemAs( x, gs, TestStatus.ACCEPT );
}
@@ -173,10 +90,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.testFrame.setInventorySlotContents( x, gs );
}
if ( this.isCrafting )
if( this.isCrafting )
{
this.standardRecipe = Platform.findMatchingRecipe( this.crafting, w );
if ( this.standardRecipe != null )
if( this.standardRecipe != null )
{
this.correctOutput = this.standardRecipe.getCraftingResult( this.crafting );
out.add( AEApi.instance().storage().createItemStack( this.correctOutput ) );
@@ -189,10 +106,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.standardRecipe = null;
this.correctOutput = null;
for (int x = 0; x < outTag.tagCount(); x++)
for( int x = 0; x < outTag.tagCount(); x++ )
{
ItemStack gs = ItemStack.loadItemStackFromNBT( outTag.getCompoundTagAt( x ) );
if ( gs != null )
if( gs != null )
out.add( AEApi.instance().storage().createItemStack( gs ) );
}
}
@@ -201,37 +118,37 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.inputs = in.toArray( new IAEItemStack[in.size()] );
HashMap<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<IAEItemStack, IAEItemStack>();
for (IAEItemStack io : this.outputs)
for( IAEItemStack io : this.outputs )
{
if ( io == null )
if( io == null )
continue;
IAEItemStack g = tmpOutputs.get( io );
if ( g == null )
if( g == null )
tmpOutputs.put( io, io.copy() );
else
g.add( io );
}
HashMap<IAEItemStack, IAEItemStack> tmpInputs = new HashMap<IAEItemStack, IAEItemStack>();
for (IAEItemStack io : this.inputs)
for( IAEItemStack io : this.inputs )
{
if ( io == null )
if( io == null )
continue;
IAEItemStack g = tmpInputs.get( io );
if ( g == null )
if( g == null )
tmpInputs.put( io, io.copy() );
else
g.add( io );
}
if ( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
if( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
throw new RuntimeException( "No pattern here!" );
int offset = 0;
this.condensedInputs = new IAEItemStack[tmpInputs.size()];
for (IAEItemStack io : tmpInputs.values())
for( IAEItemStack io : tmpInputs.values() )
{
this.condensedInputs[offset] = io;
offset++;
@@ -239,44 +156,58 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
offset = 0;
this.condensedOutputs = new IAEItemStack[tmpOutputs.size()];
for (IAEItemStack io : tmpOutputs.values())
for( IAEItemStack io : tmpOutputs.values() )
{
this.condensedOutputs[offset] = io;
offset++;
}
}
@Override
synchronized public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
private void markItemAs( int slotIndex, ItemStack i, TestStatus b )
{
if ( !this.isCrafting )
if( b == TestStatus.TEST || i.hasTagCompound() )
return;
( b == TestStatus.ACCEPT ? this.passCache : this.failCache ).add( new TestLookup( slotIndex, i ) );
}
@Override
public ItemStack getPattern()
{
return this.patternItem;
}
@Override
synchronized public boolean isValidItemForSlot( int slotIndex, ItemStack i, World w )
{
if( !this.isCrafting )
{
throw new RuntimeException( "Only crafting recipes supported." );
}
TestStatus result = this.getStatus( slotIndex, i );
switch (result)
switch( result )
{
case ACCEPT:
return true;
case DECLINE:
return false;
case TEST:
default:
break;
case ACCEPT:
return true;
case DECLINE:
return false;
case TEST:
default:
break;
}
for (int x = 0; x < this.crafting.getSizeInventory(); x++)
for( int x = 0; x < this.crafting.getSizeInventory(); x++ )
this.testFrame.setInventorySlotContents( x, this.crafting.getStackInSlot( x ) );
this.testFrame.setInventorySlotContents( slotIndex, i );
if ( this.standardRecipe.matches( this.testFrame, w ) )
if( this.standardRecipe.matches( this.testFrame, w ) )
{
ItemStack testOutput = this.standardRecipe.getCraftingResult( this.testFrame );
if ( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
if( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
{
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
@@ -287,7 +218,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
{
ItemStack testOutput = CraftingManager.getInstance().findMatchingRecipe( this.testFrame, w );
if ( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
if( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
{
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
@@ -299,30 +230,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return false;
}
@Override
public ItemStack getOutput(InventoryCrafting craftingInv, World w)
{
if ( !this.isCrafting )
throw new RuntimeException( "Only crafting recipes supported." );
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
{
if ( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) )
return null;
}
if ( this.outputs != null && this.outputs.length > 0 )
return this.outputs[0].getItemStack();
return null;
}
@Override
public boolean canSubstitute()
{
return false;
}
@Override
public boolean isCraftable()
{
@@ -335,18 +242,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return this.inputs;
}
@Override
public IAEItemStack[] getOutputs()
{
return this.outputs;
}
@Override
public ItemStack getPattern()
{
return this.patternItem;
}
@Override
public IAEItemStack[] getCondensedInputs()
{
@@ -360,7 +255,69 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
}
@Override
public int compareTo(PatternHelper o)
public IAEItemStack[] getOutputs()
{
return this.outputs;
}
@Override
public boolean canSubstitute()
{
return false;
}
@Override
public ItemStack getOutput( InventoryCrafting craftingInv, World w )
{
if( !this.isCrafting )
throw new RuntimeException( "Only crafting recipes supported." );
for( int x = 0; x < craftingInv.getSizeInventory(); x++ )
{
if( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) )
return null;
}
if( this.outputs != null && this.outputs.length > 0 )
return this.outputs[0].getItemStack();
return null;
}
private TestStatus getStatus( int slotIndex, ItemStack i )
{
if( this.crafting.getStackInSlot( slotIndex ) == null )
return i == null ? TestStatus.ACCEPT : TestStatus.DECLINE;
if( i == null )
return TestStatus.DECLINE;
if( i.hasTagCompound() )
return TestStatus.TEST;
if( this.passCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.ACCEPT;
if( this.failCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.DECLINE;
return TestStatus.TEST;
}
@Override
public int getPriority()
{
return this.priority;
}
@Override
public void setPriority( int priority )
{
this.priority = priority;
}
@Override
public int compareTo( PatternHelper o )
{
return ItemSorters.compareInt( o.priority, this.priority );
}
@@ -371,28 +328,67 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return this.pattern.hashCode();
}
@Override
public boolean equals(Object obj)
enum TestStatus
{
if ( obj == null )
ACCEPT, DECLINE, TEST
}
static class TestLookup
{
final int slot;
final int ref;
final int hash;
public TestLookup( int slot, ItemStack i )
{
this( slot, i.getItem(), i.getItemDamage() );
}
public TestLookup( int slot, Item item, int dmg )
{
this.slot = slot;
this.ref = ( dmg << Platform.DEF_OFFSET ) | ( Item.getIdFromItem( item ) & 0xffff );
int offset = 3 * slot;
this.hash = ( this.ref << offset ) | ( this.ref >> ( offset + 32 ) );
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals( Object obj )
{
final boolean equality;
if( obj instanceof TestLookup )
{
TestLookup b = (TestLookup) obj;
equality = b.slot == this.slot && b.ref == this.ref;
}
else
{
equality = false;
}
return equality;
}
}
@Override
public boolean equals( Object obj )
{
if( obj == null )
return false;
if ( this.getClass() != obj.getClass() )
if( this.getClass() != obj.getClass() )
return false;
PatternHelper other = (PatternHelper) obj;
if ( this.pattern != null && other.pattern != null )
if( this.pattern != null && other.pattern != null )
return this.pattern.equals( other.pattern );
return false;
}
@Override
public void setPriority(int priority)
{
this.priority = priority;
}
@Override
public int getPriority()
{
return this.priority;
}
}