diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index 84c31235..37898f4a 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -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 ) diff --git a/src/main/java/appeng/core/features/AEFeature.java b/src/main/java/appeng/core/features/AEFeature.java index 3bf52271..8a75e99f 100644 --- a/src/main/java/appeng/core/features/AEFeature.java +++ b/src/main/java/appeng/core/features/AEFeature.java @@ -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 ) diff --git a/src/main/java/appeng/recipes/game/DisassembleRecipe.java b/src/main/java/appeng/recipes/game/DisassembleRecipe.java index 484d5842..bf16646b 100644 --- a/src/main/java/appeng/recipes/game/DisassembleRecipe.java +++ b/src/main/java/appeng/recipes/game/DisassembleRecipe.java @@ -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 cellMappings; private final Map 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( 4 ); this.nonCellMappings = new HashMap( 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 cellInv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS ); + // make sure the storage cell stackInSlot empty... + IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory( stackInSlot, null, StorageChannel.ITEMS ); if( cellInv != null ) { IItemList 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 getCellOutput( ItemStack compared ) { for( Map.Entry 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 getNonCellOutput( ItemStack compared ) { for( Map.Entry 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.. {