Added Facade Crafting.

This commit is contained in:
AlgorithmX2 2014-03-15 15:35:00 -05:00
parent 0e46690c50
commit 06903814ad
4 changed files with 98 additions and 23 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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)
{

View file

@ -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;
}
}