Add a simple output cache for the client to prevent constant recipe lookups when showing outputs for recipes.
This commit is contained in:
parent
e3c5c9545a
commit
06295ad17f
1 changed files with 10 additions and 1 deletions
|
@ -2,6 +2,7 @@ package appeng.items.misc;
|
|||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
@ -108,17 +109,25 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
|||
}
|
||||
}
|
||||
|
||||
// rather simple client side cacheing.
|
||||
static WeakHashMap<ItemStack, ICraftingPatternDetails> simpleCache = new WeakHashMap<ItemStack, ICraftingPatternDetails>();
|
||||
|
||||
public ItemStack getOutput(ItemStack item)
|
||||
{
|
||||
ICraftingPatternDetails details = simpleCache.get( item );
|
||||
if ( details != null )
|
||||
return details.getCondencedOutputs()[0].getItemStack();
|
||||
|
||||
World w = CommonHelper.proxy.getWorld();
|
||||
if ( w == null )
|
||||
return null;
|
||||
|
||||
ICraftingPatternDetails details = getPatternForItem( item, w );
|
||||
details = getPatternForItem( item, w );
|
||||
|
||||
if ( details == null )
|
||||
return null;
|
||||
|
||||
simpleCache.put( item, details );
|
||||
return details.getCondencedOutputs()[0].getItemStack();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue