From 06903814adca853d35a09a9fabb8a8fac6f3f017 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 15 Mar 2014 15:35:00 -0500 Subject: [PATCH] Added Facade Crafting. --- core/Registration.java | 7 ++++ core/features/AEFeature.java | 2 +- items/parts/ItemFacade.java | 58 +++++++++++++++++++++------------- recipes/game/FacadeRecipe.java | 54 +++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 recipes/game/FacadeRecipe.java diff --git a/core/Registration.java b/core/Registration.java index bfe585f15..414e06b74 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -3,6 +3,7 @@ package appeng.core; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import net.minecraft.item.crafting.CraftingManager; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.ChestGenHooks; @@ -125,6 +126,7 @@ import appeng.me.storage.AEExternalHandler; import appeng.parts.PartPlacement; import appeng.recipes.AEItemResolver; import appeng.recipes.RecipeHandler; +import appeng.recipes.game.FacadeRecipe; import appeng.recipes.game.ShapedRecipe; import appeng.recipes.game.ShapelessRecipe; import appeng.recipes.handlers.Grind; @@ -185,6 +187,7 @@ public class Registration recipeRegistery.addNewCraftHandler( "shaped", Shaped.class ); recipeRegistery.addNewCraftHandler( "shapeless", Shapeless.class ); + RecipeSorter.register( "AE2-Facade", FacadeRecipe.class, Category.SHAPED, "" ); RecipeSorter.register( "AE2-Shaped", ShapedRecipe.class, Category.SHAPED, "" ); RecipeSorter.register( "AE2-Shapeless", ShapelessRecipe.class, Category.SHAPELESS, "" ); @@ -598,6 +601,10 @@ public class Registration mr.whiteListTileEntity( AEBaseTile.class ); recipeHandler.registerHandlers(); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.enableFacadeCrafting ) ) + CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() ); + } private void registerSpatial(boolean force) diff --git a/core/features/AEFeature.java b/core/features/AEFeature.java index 4abffde18..e94732fb8 100644 --- a/core/features/AEFeature.java +++ b/core/features/AEFeature.java @@ -50,7 +50,7 @@ public enum AEFeature Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), - inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false); + enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false); String Category; boolean visible = true; diff --git a/items/parts/ItemFacade.java b/items/parts/ItemFacade.java index 517ac71dd..d72c8d740 100644 --- a/items/parts/ItemFacade.java +++ b/items/parts/ItemFacade.java @@ -112,28 +112,9 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList ); for (ItemStack l : tmpList) { - if ( l.hasTagCompound() ) - continue; - - int metadata = l.getItem().getMetadata( l.getItemDamage() ); - - boolean hasTile = b.hasTileEntity( metadata ); - boolean enableGlass = b instanceof BlockGlass; - boolean disableOre = b instanceof OreQuartz; - - boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass; - if ( FacadeConfig.instance.checkEnabled( b, metadata, defaultValue ) ) - { - ItemStack is = new ItemStack( this ); - NBTTagCompound data = new NBTTagCompound(); - int[] ds = new int[2]; - ds[0] = Item.getIdFromItem( l.getItem() ); - ds[1] = metadata; - data.setIntArray( "x", ds ); - is.setTagCompound( data ); - - subTypes.add( is ); - } + ItemStack facade = createFacadeForItem( l, false ); + if ( l != null ) + subTypes.add( l ); } } catch (Throwable t) @@ -148,6 +129,39 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem } + public ItemStack createFacadeForItem(ItemStack l, boolean returnItem) + { + if ( l == null ) + return null; + + Block b = Block.getBlockFromItem( l.getItem() ); + if ( b == null || l.hasTagCompound() ) + return null; + + int metadata = l.getItem().getMetadata( l.getItemDamage() ); + + boolean hasTile = b.hasTileEntity( metadata ); + boolean enableGlass = b instanceof BlockGlass; + boolean disableOre = b instanceof OreQuartz; + + boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass; + if ( FacadeConfig.instance.checkEnabled( b, metadata, defaultValue ) ) + { + if ( returnItem ) + return l; + + ItemStack is = new ItemStack( this ); + NBTTagCompound data = new NBTTagCompound(); + int[] ds = new int[2]; + ds[0] = Item.getIdFromItem( l.getItem() ); + ds[1] = metadata; + data.setIntArray( "x", ds ); + is.setTagCompound( data ); + return is; + } + return null; + } + @Override public Block getBlock(ItemStack is) { diff --git a/recipes/game/FacadeRecipe.java b/recipes/game/FacadeRecipe.java new file mode 100644 index 000000000..a354bb52f --- /dev/null +++ b/recipes/game/FacadeRecipe.java @@ -0,0 +1,54 @@ +package appeng.recipes.game; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import appeng.api.AEApi; +import appeng.api.util.AEItemDefinition; +import appeng.items.parts.ItemFacade; + +public class FacadeRecipe implements IRecipe +{ + + private AEItemDefinition anchor = AEApi.instance().parts().partCableAnchor; + private ItemFacade facade = (ItemFacade) AEApi.instance().items().itemFacade.item(); + + private ItemStack getOutput(InventoryCrafting inv, boolean createFacade) + { + if ( inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null ) + { + if ( anchor.sameAs( inv.getStackInSlot( 1 ) ) && anchor.sameAs( inv.getStackInSlot( 3 ) ) && anchor.sameAs( inv.getStackInSlot( 5 ) ) + && anchor.sameAs( inv.getStackInSlot( 7 ) ) ) + { + return facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade ); + } + } + return null; + } + + @Override + public boolean matches(InventoryCrafting inv, World w) + { + return getOutput( inv, false ) != null; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting inv) + { + return getOutput( inv, true ); + } + + @Override + public int getRecipeSize() + { + return 9; + } + + @Override + public ItemStack getRecipeOutput() // no default output.. + { + return null; + } + +} \ No newline at end of file