From fbcee6ca12bb478ecf7bd81ef79722c9249b7dd4 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 1 Feb 2014 16:24:13 -0600 Subject: [PATCH] Facade Creative Tab and Config. --- core/AppEng.java | 2 ++ core/features/AEFeatureHandler.java | 8 ++++- items/parts/ItemFacade.java | 21 +++++++++-- util/Platform.java | 54 ++++++++++++++++++++++++----- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/core/AppEng.java b/core/AppEng.java index 540becf3e..b582e5210 100644 --- a/core/AppEng.java +++ b/core/AppEng.java @@ -112,10 +112,12 @@ public class AppEng AELog.info( "Starting ( PreInit )" ); Configuration.instance = new Configuration( event.getModConfigurationDirectory() ); + FacadeConfig.instance = new FacadeConfig( event.getModConfigurationDirectory() ); if ( Platform.isClient() ) { CreativeTab.init(); + CreativeTabFacade.init(); CommonHelper.proxy.init(); } diff --git a/core/features/AEFeatureHandler.java b/core/features/AEFeatureHandler.java index 9ada9235a..963e35e11 100644 --- a/core/features/AEFeatureHandler.java +++ b/core/features/AEFeatureHandler.java @@ -13,6 +13,8 @@ import appeng.core.AELog; import appeng.core.CommonHelper; import appeng.core.Configuration; import appeng.core.CreativeTab; +import appeng.core.CreativeTabFacade; +import appeng.items.parts.ItemFacade; import appeng.util.Platform; import cpw.mods.fml.common.registry.GameRegistry; @@ -74,9 +76,13 @@ public class AEFeatureHandler implements AEItemDefinition String name = getName( i.getClass(), subname ); i.setTextureName( "appliedenergistics2:" + name ); - i.setCreativeTab( CreativeTab.instance ); i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name ); + if ( i instanceof ItemFacade ) + i.setCreativeTab( CreativeTabFacade.instance ); + else + i.setCreativeTab( CreativeTab.instance ); + GameRegistry.registerItem( i, "item." + name ); AELog.localization( "item", i.getUnlocalizedName() ); } diff --git a/items/parts/ItemFacade.java b/items/parts/ItemFacade.java index ad2807e6f..e7282710b 100644 --- a/items/parts/ItemFacade.java +++ b/items/parts/ItemFacade.java @@ -8,6 +8,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockGlass; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -16,6 +17,7 @@ import net.minecraftforge.common.ForgeDirection; import appeng.api.AEApi; import appeng.block.solids.OreQuartz; import appeng.client.render.BusRenderer; +import appeng.core.FacadeConfig; import appeng.core.features.AEFeature; import appeng.facade.FacadePart; import appeng.facade.IFacadeItem; @@ -59,6 +61,14 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem List subTypes = null; + public ItemStack getCreativeTabIcon() + { + calculateSubTypes(); + if ( subTypes.isEmpty() ) + return new ItemStack( Item.cake ); + return subTypes.get( 0 ); + } + @Override public void getSubItems(int number, CreativeTabs tab, List list) { @@ -89,9 +99,12 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem if ( subTypes == null ) { subTypes = new ArrayList(); - for (Block b : Block.blocksList) + for (int id = 0; id < Block.blocksList.length; id++) { - if ( b != null && (b.isOpaqueCube() && !b.getTickRandomly() && !(b instanceof OreQuartz)) || b instanceof BlockGlass ) + Block b = Block.blocksList[id]; + if ( b != null + && FacadeConfig.instance.checkEnabled( b, b.isOpaqueCube() && !b.getTickRandomly() && !(b instanceof OreQuartz) + || b instanceof BlockGlass ) ) { try { @@ -116,7 +129,11 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem } } } + + if ( FacadeConfig.instance.hasChanged() ) + FacadeConfig.instance.save(); } + } @Override diff --git a/util/Platform.java b/util/Platform.java index 05a41fc65..75d82aff6 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -111,6 +111,31 @@ public class Platform private static HashMap modIDToName; private static HashMap itemTomodID; + private static HashMap itemNames; + + public static String getBlockName(Block id) + { + populateModInfo(); + + String out = itemNames.get( id.blockID ); + + if ( out == null ) + return "Unknown"; + + return out; + } + + public static String getItemName(Item id) + { + populateModInfo(); + + String out = itemNames.get( id.itemID ); + + if ( out == null ) + return "Unknown"; + + return out; + } public static String getMod(String modID) { @@ -125,10 +150,23 @@ public class Platform } public static String getMod(ItemStack is) + { + populateModInfo(); + + String out = itemTomodID.get( is.itemID ); + + if ( out == null ) + return "Unknown"; + + return out; + } + + private static void populateModInfo() { if ( itemTomodID == null ) { itemTomodID = new HashMap(); + itemNames = new HashMap(); ImmutableTable modObjectTable; for (Field f : Block.class.getDeclaredFields()) @@ -138,6 +176,7 @@ public class Platform Object o = f.get( Block.class ); if ( o instanceof Block ) { + itemNames.put( ((Block) o).blockID, f.getName() ); itemTomodID.put( ((Block) o).blockID, "minecraft" ); } } @@ -154,10 +193,14 @@ public class Platform f.setAccessible( false ); ImmutableMap> fish = modObjectTable.rowMap(); - for (Map g : fish.values()) + for (String MODID : fish.keySet()) { + Map g = fish.get( MODID ); for (String key : g.keySet()) - itemTomodID.put( g.get( key ), key ); + { + itemNames.put( g.get( key ), key ); + itemTomodID.put( g.get( key ), MODID ); + } } } catch (Throwable t) @@ -165,12 +208,6 @@ public class Platform } } - String out = itemTomodID.get( is.itemID ); - - if ( out == null ) - return "Unknown"; - - return out; } public static ForgeDirection crossProduct(ForgeDirection forward, ForgeDirection up) @@ -1472,5 +1509,4 @@ public class Platform return !gs.hasPermission( playerID, SecurityPermissions.BUILD ); } - }