Merge pull request #1337 from thatsIch/e-1333-recipe-sorter
Fixes #1333: Updated old code parts related to recipes
This commit is contained in:
commit
23aa8fd72d
|
@ -22,7 +22,6 @@ package appeng.core;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.util.WeightedRandomChestContent;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.ChestGenHooks;
|
||||
|
@ -562,10 +561,16 @@ public final class Registration
|
|||
registration.registerAchievements();
|
||||
|
||||
if( AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting ) )
|
||||
CraftingManager.getInstance().getRecipeList().add( new DisassembleRecipe() );
|
||||
{
|
||||
GameRegistry.addRecipe( new DisassembleRecipe() );
|
||||
RecipeSorter.register( "appliedenergistics2:disassemble", DisassembleRecipe.class, Category.SHAPELESS, "after:minecraft:shapeless" );
|
||||
}
|
||||
|
||||
if( AEConfig.instance.isFeatureEnabled( AEFeature.enableFacadeCrafting ) )
|
||||
CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() );
|
||||
{
|
||||
GameRegistry.addRecipe( new FacadeRecipe() );
|
||||
RecipeSorter.register( "appliedenergistics2:facade", FacadeRecipe.class, Category.SHAPED, "after:minecraft:shaped" );
|
||||
}
|
||||
}
|
||||
|
||||
public void postInit( FMLPostInitializationEvent event )
|
||||
|
|
|
@ -79,9 +79,7 @@ public enum AEFeature
|
|||
|
||||
AEFeature( String cat )
|
||||
{
|
||||
this.category = cat;
|
||||
this.isVisible = !this.name().equals( "Core" );
|
||||
this.defaultValue = true;
|
||||
this(cat, true);
|
||||
}
|
||||
|
||||
AEFeature( String cat, boolean defaultValue )
|
||||
|
|
|
@ -21,12 +21,17 @@ package appeng.recipes.game;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
|
@ -39,109 +44,116 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class DisassembleRecipe implements IRecipe
|
||||
public final class DisassembleRecipe implements IRecipe
|
||||
{
|
||||
private static final ItemStack MISMATCHED_STACK = null;
|
||||
|
||||
private final IMaterials mats;
|
||||
private final IItems items;
|
||||
private final IBlocks blocks;
|
||||
private final Map<IItemDefinition, IItemDefinition> cellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> nonCellMappings;
|
||||
|
||||
public DisassembleRecipe()
|
||||
{
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IBlocks blocks = definitions.blocks();
|
||||
final IItems items = definitions.items();
|
||||
final IMaterials mats = definitions.materials();
|
||||
|
||||
this.blocks = definitions.blocks();
|
||||
this.items = definitions.items();
|
||||
this.mats = definitions.materials();
|
||||
this.cellMappings = new HashMap<IItemDefinition, IItemDefinition>( 4 );
|
||||
this.nonCellMappings = new HashMap<IItemDefinition, IItemDefinition>( 5 );
|
||||
|
||||
this.cellMappings.put( this.items.cell1k(), this.mats.cell1kPart() );
|
||||
this.cellMappings.put( this.items.cell4k(), this.mats.cell4kPart() );
|
||||
this.cellMappings.put( this.items.cell16k(), this.mats.cell16kPart() );
|
||||
this.cellMappings.put( this.items.cell64k(), this.mats.cell64kPart() );
|
||||
this.cellMappings.put( items.cell1k(), mats.cell1kPart() );
|
||||
this.cellMappings.put( items.cell4k(), mats.cell4kPart() );
|
||||
this.cellMappings.put( items.cell16k(), mats.cell16kPart() );
|
||||
this.cellMappings.put( items.cell64k(), mats.cell64kPart() );
|
||||
|
||||
this.nonCellMappings.put( this.items.encodedPattern(), this.mats.blankPattern() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage1k(), this.mats.cell1kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage4k(), this.mats.cell4kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage16k(), this.mats.cell16kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage64k(), this.mats.cell64kPart() );
|
||||
this.nonCellMappings.put( items.encodedPattern(), mats.blankPattern() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage1k(), mats.cell1kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage4k(), mats.cell4kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage16k(), mats.cell16kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage64k(), mats.cell64kPart() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( InventoryCrafting inv, World w )
|
||||
{
|
||||
return this.getOutput( inv, false ) != null;
|
||||
return this.getOutput( inv ) != null;
|
||||
}
|
||||
|
||||
private ItemStack getOutput( InventoryCrafting inv, boolean createFacade )
|
||||
@Nullable
|
||||
private ItemStack getOutput( IInventory inventory )
|
||||
{
|
||||
ItemStack hasCell = null;
|
||||
int itemCount = 0;
|
||||
ItemStack output = MISMATCHED_STACK;
|
||||
|
||||
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
for( int slotIndex = 0; slotIndex < inventory.getSizeInventory(); slotIndex++ )
|
||||
{
|
||||
ItemStack is = inv.getStackInSlot( x );
|
||||
if( is != null )
|
||||
ItemStack stackInSlot = inventory.getStackInSlot( slotIndex );
|
||||
if( stackInSlot != null )
|
||||
{
|
||||
if( hasCell != null )
|
||||
return null;
|
||||
// needs a single input in the recipe
|
||||
itemCount++;
|
||||
if ( itemCount > 1 )
|
||||
return MISMATCHED_STACK;
|
||||
|
||||
hasCell = this.getCellOutput( is );
|
||||
|
||||
// make sure the storage cell is empty...
|
||||
if( hasCell != null )
|
||||
// handle storage cells
|
||||
for( ItemStack storageCellStack : this.getCellOutput( stackInSlot ).asSet() )
|
||||
{
|
||||
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
// make sure the storage cell stackInSlot empty...
|
||||
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory( stackInSlot, null, StorageChannel.ITEMS );
|
||||
if( cellInv != null )
|
||||
{
|
||||
IItemList<IAEItemStack> list = cellInv.getAvailableItems( StorageChannel.ITEMS.createList() );
|
||||
if( !list.isEmpty() )
|
||||
return null;
|
||||
}
|
||||
|
||||
output = storageCellStack;
|
||||
}
|
||||
|
||||
hasCell = this.getNonCellOutput( is );
|
||||
|
||||
if( hasCell == null )
|
||||
return null;
|
||||
// handle crafting storage blocks
|
||||
for( ItemStack craftingStorageStack : this.getNonCellOutput( stackInSlot ).asSet() )
|
||||
{
|
||||
output = craftingStorageStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasCell;
|
||||
return output;
|
||||
}
|
||||
|
||||
private ItemStack getCellOutput( ItemStack compared )
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getCellOutput( ItemStack compared )
|
||||
{
|
||||
for( Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet() )
|
||||
{
|
||||
if( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 ).get();
|
||||
return entry.getValue().maybeStack( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
private ItemStack getNonCellOutput( ItemStack compared )
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getNonCellOutput( ItemStack compared )
|
||||
{
|
||||
for( Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet() )
|
||||
{
|
||||
if( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 ).get();
|
||||
return entry.getValue().maybeStack( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getCraftingResult( InventoryCrafting inv )
|
||||
{
|
||||
return this.getOutput( inv, true );
|
||||
return this.getOutput( inv );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,6 +162,7 @@ public class DisassembleRecipe implements IRecipe
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() // no default output..
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue