Added an option to toggle oredict subsitutions for patterns.
It adds a backward compatibility to convert current patterns to use oredict by default, which should be removed with rv4 stable. Closes #1156
This commit is contained in:
@@ -23,6 +23,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -45,20 +47,21 @@ import appeng.util.item.AEItemStack;
|
||||
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper>
|
||||
{
|
||||
|
||||
final ItemStack patternItem;
|
||||
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;
|
||||
final HashSet<TestLookup> failCache = new HashSet<TestLookup>();
|
||||
final HashSet<TestLookup> passCache = new HashSet<TestLookup>();
|
||||
private final ItemStack patternItem;
|
||||
private final InventoryCrafting crafting = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
private final InventoryCrafting testFrame = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
private final ItemStack correctOutput;
|
||||
private final IRecipe standardRecipe;
|
||||
private final IAEItemStack[] condensedInputs;
|
||||
private final IAEItemStack[] condensedOutputs;
|
||||
private final IAEItemStack[] inputs;
|
||||
private final IAEItemStack[] outputs;
|
||||
private final boolean isCrafting;
|
||||
private final boolean canSubstitute;
|
||||
private final Set<TestLookup> failCache = new HashSet<TestLookup>();
|
||||
private final Set<TestLookup> passCache = new HashSet<TestLookup>();
|
||||
private final IAEItemStack pattern;
|
||||
public int priority = 0;
|
||||
private int priority = 0;
|
||||
|
||||
public PatternHelper( final ItemStack is, final World w )
|
||||
{
|
||||
@@ -72,6 +75,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
final NBTTagList inTag = encodedValue.getTagList( "in", 10 );
|
||||
final NBTTagList outTag = encodedValue.getTagList( "out", 10 );
|
||||
this.isCrafting = encodedValue.getBoolean( "crafting" );
|
||||
|
||||
this.canSubstitute = encodedValue.getBoolean( "substitute" );
|
||||
this.patternItem = is;
|
||||
this.pattern = AEItemStack.create( is );
|
||||
|
||||
@@ -81,6 +86,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
for( int x = 0; x < inTag.tagCount(); x++ )
|
||||
{
|
||||
final ItemStack gs = ItemStack.loadItemStackFromNBT( inTag.getCompoundTagAt( x ) );
|
||||
|
||||
this.crafting.setInventorySlotContents( x, gs );
|
||||
|
||||
if( gs != null && ( !this.isCrafting || !gs.hasTagCompound() ) )
|
||||
@@ -95,6 +101,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
if( this.isCrafting )
|
||||
{
|
||||
this.standardRecipe = Platform.findMatchingRecipe( this.crafting, w );
|
||||
|
||||
if( this.standardRecipe != null )
|
||||
{
|
||||
this.correctOutput = this.standardRecipe.getCraftingResult( this.crafting );
|
||||
@@ -113,6 +120,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
for( int x = 0; x < outTag.tagCount(); x++ )
|
||||
{
|
||||
final ItemStack gs = ItemStack.loadItemStackFromNBT( outTag.getCompoundTagAt( x ) );
|
||||
|
||||
if( gs != null )
|
||||
{
|
||||
out.add( AEApi.instance().storage().createItemStack( gs ) );
|
||||
@@ -123,7 +131,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
this.outputs = out.toArray( new IAEItemStack[out.size()] );
|
||||
this.inputs = in.toArray( new IAEItemStack[in.size()] );
|
||||
|
||||
final HashMap<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<IAEItemStack, IAEItemStack>();
|
||||
final Map<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<IAEItemStack, IAEItemStack>();
|
||||
|
||||
for( final IAEItemStack io : this.outputs )
|
||||
{
|
||||
if( io == null )
|
||||
@@ -132,6 +141,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
}
|
||||
|
||||
final IAEItemStack g = tmpOutputs.get( io );
|
||||
|
||||
if( g == null )
|
||||
{
|
||||
tmpOutputs.put( io, io.copy() );
|
||||
@@ -142,7 +152,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
}
|
||||
}
|
||||
|
||||
final HashMap<IAEItemStack, IAEItemStack> tmpInputs = new HashMap<IAEItemStack, IAEItemStack>();
|
||||
final Map<IAEItemStack, IAEItemStack> tmpInputs = new HashMap<IAEItemStack, IAEItemStack>();
|
||||
|
||||
for( final IAEItemStack io : this.inputs )
|
||||
{
|
||||
if( io == null )
|
||||
@@ -151,6 +162,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
}
|
||||
|
||||
final IAEItemStack g = tmpInputs.get( io );
|
||||
|
||||
if( g == null )
|
||||
{
|
||||
tmpInputs.put( io, io.copy() );
|
||||
@@ -168,6 +180,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
|
||||
this.condensedInputs = new IAEItemStack[tmpInputs.size()];
|
||||
int offset = 0;
|
||||
|
||||
for( final IAEItemStack io : tmpInputs.values() )
|
||||
{
|
||||
this.condensedInputs[offset] = io;
|
||||
@@ -176,6 +189,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
|
||||
offset = 0;
|
||||
this.condensedOutputs = new IAEItemStack[tmpOutputs.size()];
|
||||
|
||||
for( final IAEItemStack io : tmpOutputs.values() )
|
||||
{
|
||||
this.condensedOutputs[offset] = io;
|
||||
@@ -287,7 +301,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
@Override
|
||||
public boolean canSubstitute()
|
||||
{
|
||||
return false;
|
||||
return this.canSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -368,17 +382,38 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
return this.pattern.hashCode();
|
||||
}
|
||||
|
||||
enum TestStatus
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final PatternHelper other = (PatternHelper) obj;
|
||||
|
||||
if( this.pattern != null && other.pattern != null )
|
||||
{
|
||||
return this.pattern.equals( other.pattern );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private enum TestStatus
|
||||
{
|
||||
ACCEPT, DECLINE, TEST
|
||||
}
|
||||
|
||||
static class TestLookup
|
||||
private static final class TestLookup
|
||||
{
|
||||
|
||||
final int slot;
|
||||
final int ref;
|
||||
final int hash;
|
||||
private final int slot;
|
||||
private final int ref;
|
||||
private final int hash;
|
||||
|
||||
public TestLookup( final int slot, final ItemStack i )
|
||||
{
|
||||
@@ -407,6 +442,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
if( obj instanceof TestLookup )
|
||||
{
|
||||
final TestLookup b = (TestLookup) obj;
|
||||
|
||||
equality = b.slot == this.slot && b.ref == this.ref;
|
||||
}
|
||||
else
|
||||
@@ -417,23 +453,4 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
return equality;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final PatternHelper other = (PatternHelper) obj;
|
||||
if( this.pattern != null && other.pattern != null )
|
||||
{
|
||||
return this.pattern.equals( other.pattern );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user