2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.features;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-05-10 07:00:02 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.util.AEItemDefinition;
|
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.block.AEBaseItemBlock;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-03-09 04:35:53 +01:00
|
|
|
import appeng.core.CommonHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.CreativeTab;
|
2014-02-01 23:24:13 +01:00
|
|
|
import appeng.core.CreativeTabFacade;
|
|
|
|
import appeng.items.parts.ItemFacade;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
|
|
|
|
public class AEFeatureHandler implements AEItemDefinition
|
|
|
|
{
|
|
|
|
|
|
|
|
private final EnumSet<AEFeature> myFeatures;
|
|
|
|
|
|
|
|
private final String subname;
|
|
|
|
private IAEFeature obj;
|
|
|
|
|
|
|
|
private Item ItemData;
|
|
|
|
private Block BlockData;
|
|
|
|
|
|
|
|
public AEFeatureHandler(EnumSet<AEFeature> featureSet, IAEFeature _obj, String _subname) {
|
|
|
|
myFeatures = featureSet;
|
|
|
|
obj = _obj;
|
|
|
|
subname = _subname;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register()
|
|
|
|
{
|
|
|
|
if ( isFeatureAvailable() )
|
|
|
|
{
|
|
|
|
if ( obj instanceof Item )
|
|
|
|
initItem( (Item) obj );
|
|
|
|
if ( obj instanceof Block )
|
|
|
|
initBlock( (Block) obj );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getName(Class o, String subname)
|
|
|
|
{
|
|
|
|
String name = o.getSimpleName();
|
|
|
|
|
2014-05-06 07:16:29 +02:00
|
|
|
if ( name.startsWith( "ItemMultiPart" ) )
|
|
|
|
name = name.replace( "ItemMultiPart", "ItemPart" );
|
|
|
|
else if ( name.startsWith( "ItemMultiMaterial" ) )
|
|
|
|
name = name.replace( "ItemMultiMaterial", "ItemMaterial" );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( subname != null )
|
|
|
|
{
|
|
|
|
// simple hack to allow me to do get nice names for these without
|
|
|
|
// mode code outside of AEBaseItem
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( subname.startsWith( "P2PTunnel" ) )
|
|
|
|
return "ItemPart.P2PTunnel";
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( subname.equals( "CertusQuartzTools" ) )
|
|
|
|
return name.replace( "Quartz", "CertusQuartz" );
|
|
|
|
if ( subname.equals( "NetherQuartzTools" ) )
|
|
|
|
return name.replace( "Quartz", "NetherQuartz" );
|
|
|
|
|
|
|
|
name += "." + subname;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initItem(Item i)
|
|
|
|
{
|
|
|
|
ItemData = i;
|
|
|
|
|
|
|
|
String name = getName( i.getClass(), subname );
|
|
|
|
i.setTextureName( "appliedenergistics2:" + name );
|
|
|
|
i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name );
|
|
|
|
|
2014-02-01 23:24:13 +01:00
|
|
|
if ( i instanceof ItemFacade )
|
|
|
|
i.setCreativeTab( CreativeTabFacade.instance );
|
|
|
|
else
|
|
|
|
i.setCreativeTab( CreativeTab.instance );
|
|
|
|
|
2014-05-06 07:16:29 +02:00
|
|
|
if ( name.equals( "ItemMaterial" ) )
|
|
|
|
name = "ItemMultiMaterial";
|
|
|
|
else if ( name.equals( "ItemPart" ) )
|
|
|
|
name = "ItemMultiPart";
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
GameRegistry.registerItem( i, "item." + name );
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initBlock(Block b)
|
|
|
|
{
|
|
|
|
BlockData = b;
|
|
|
|
|
|
|
|
String name = getName( b.getClass(), subname );
|
|
|
|
b.setCreativeTab( CreativeTab.instance );
|
2014-02-09 02:34:52 +01:00
|
|
|
b.setBlockName( /* "tile." */"appliedenergistics2." + name );
|
|
|
|
b.setBlockTextureName( "appliedenergistics2:" + name );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( Platform.isClient() && BlockData instanceof AEBaseBlock )
|
|
|
|
{
|
|
|
|
AEBaseBlock bb = (AEBaseBlock) b;
|
|
|
|
CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb );
|
|
|
|
}
|
|
|
|
|
|
|
|
Class itemBlock = AEBaseItemBlock.class;
|
|
|
|
if ( b instanceof AEBaseBlock )
|
|
|
|
itemBlock = ((AEBaseBlock) b).getItemBlockClass();
|
|
|
|
|
|
|
|
GameRegistry.registerBlock( b, itemBlock, "tile." + name );
|
|
|
|
}
|
|
|
|
|
|
|
|
public EnumSet<AEFeature> getFeatures()
|
|
|
|
{
|
|
|
|
return myFeatures.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFeatureAvailable()
|
|
|
|
{
|
|
|
|
boolean enabled = true;
|
|
|
|
|
|
|
|
for (AEFeature f : myFeatures)
|
2014-02-09 06:08:27 +01:00
|
|
|
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block block()
|
|
|
|
{
|
|
|
|
return BlockData;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends TileEntity> entity()
|
|
|
|
{
|
|
|
|
if ( BlockData instanceof AEBaseBlock )
|
|
|
|
{
|
|
|
|
AEBaseBlock bb = (AEBaseBlock) BlockData;
|
|
|
|
return bb.getTileEntityClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Item item()
|
|
|
|
{
|
2014-03-09 04:35:53 +01:00
|
|
|
if ( ItemData == null && BlockData != null )
|
|
|
|
return Item.getItemFromBlock( BlockData );
|
2013-12-27 23:59:59 +01:00
|
|
|
return ItemData;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack stack(int stackSize)
|
|
|
|
{
|
|
|
|
if ( isFeatureAvailable() )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
ItemStack rv = null;
|
|
|
|
|
|
|
|
if ( ItemData != null )
|
|
|
|
rv = new ItemStack( ItemData );
|
|
|
|
else
|
|
|
|
rv = new ItemStack( BlockData );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
rv.stackSize = stackSize;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-05-10 07:00:02 +02:00
|
|
|
public boolean sameAsStack(ItemStack is)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( isFeatureAvailable() )
|
2014-02-09 02:34:52 +01:00
|
|
|
return Platform.isSameItemType( is, stack( 1 ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-10 07:00:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean sameAsBlock(IBlockAccess world, int x, int y, int z)
|
|
|
|
{
|
|
|
|
if ( isFeatureAvailable() && BlockData != null )
|
|
|
|
return world.getBlock( x, y, z ) == block();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|