2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.parts;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockGlass;
|
2014-05-04 22:46:38 +02:00
|
|
|
import net.minecraft.block.BlockStainedGlass;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2014-02-01 23:24:13 +01:00
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.client.MinecraftForgeClient;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-05-04 22:46:38 +02:00
|
|
|
import appeng.api.parts.IAlphaPassItem;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.block.solids.OreQuartz;
|
|
|
|
import appeng.client.render.BusRenderer;
|
2014-02-01 23:24:13 +01:00
|
|
|
import appeng.core.FacadeConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.facade.FacadePart;
|
|
|
|
import appeng.facade.IFacadeItem;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
2014-05-11 18:41:31 +02:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-05-04 22:46:38 +02:00
|
|
|
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public ItemFacade() {
|
|
|
|
super( ItemFacade.class );
|
2014-09-20 23:26:30 +02:00
|
|
|
setFeature( EnumSet.of( AEFeature.Facades ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
setHasSubtypes( true );
|
|
|
|
if ( Platform.isClient() )
|
2014-02-09 02:34:52 +01:00
|
|
|
MinecraftForgeClient.registerItemRenderer( this, BusRenderer.instance );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getSpriteNumber()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side)
|
|
|
|
{
|
|
|
|
ItemStack in = getTextureItem( is );
|
|
|
|
if ( in != null )
|
|
|
|
return new FacadePart( is, side );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ItemStack> subTypes = null;
|
|
|
|
|
2014-08-14 03:26:41 +02:00
|
|
|
public List<ItemStack> getFacades()
|
|
|
|
{
|
|
|
|
calculateSubTypes();
|
|
|
|
return subTypes;
|
|
|
|
}
|
|
|
|
|
2014-02-01 23:24:13 +01:00
|
|
|
public ItemStack getCreativeTabIcon()
|
|
|
|
{
|
|
|
|
calculateSubTypes();
|
|
|
|
if ( subTypes.isEmpty() )
|
2014-02-09 02:34:52 +01:00
|
|
|
return new ItemStack( Items.cake );
|
2014-02-01 23:24:13 +01:00
|
|
|
return subTypes.get( 0 );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void getSubItems(Item number, CreativeTabs tab, List list)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
calculateSubTypes();
|
|
|
|
list.addAll( subTypes );
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack createFromInts(int[] ids)
|
|
|
|
{
|
|
|
|
ItemStack is = new ItemStack( AEApi.instance().items().itemFacade.item() );
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
2014-01-26 07:44:50 +01:00
|
|
|
data.setIntArray( "x", ids.clone() );
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setTagCompound( data );
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getTextureItem(ItemStack is)
|
|
|
|
{
|
|
|
|
Block blk = getBlock( is );
|
|
|
|
if ( blk != null )
|
|
|
|
return new ItemStack( blk, 1, getMeta( is ) );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void calculateSubTypes()
|
|
|
|
{
|
|
|
|
if ( subTypes == null )
|
|
|
|
{
|
|
|
|
subTypes = new ArrayList();
|
2014-02-09 02:34:52 +01:00
|
|
|
for (Object blk : Block.blockRegistry)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
Block b = (Block) blk;
|
2014-03-15 07:58:21 +01:00
|
|
|
try
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-03-15 07:58:21 +01:00
|
|
|
Item item = Item.getItemFromBlock( b );
|
|
|
|
|
|
|
|
List<ItemStack> tmpList = new ArrayList();
|
|
|
|
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
|
|
|
|
for (ItemStack l : tmpList)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-03-15 21:35:00 +01:00
|
|
|
ItemStack facade = createFacadeForItem( l, false );
|
2014-03-20 02:33:28 +01:00
|
|
|
if ( facade != null )
|
|
|
|
subTypes.add( facade );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-03-15 07:58:21 +01:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
// just absorb..
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-01 23:24:13 +01:00
|
|
|
|
|
|
|
if ( FacadeConfig.instance.hasChanged() )
|
|
|
|
FacadeConfig.instance.save();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-01 23:24:13 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-03-15 21:35:00 +01:00
|
|
|
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 );
|
2014-05-04 22:46:38 +02:00
|
|
|
boolean enableGlass = b instanceof BlockGlass || b instanceof BlockStainedGlass;
|
2014-03-15 21:35:00 +01:00
|
|
|
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 );
|
2014-05-11 18:41:31 +02:00
|
|
|
UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor( l.getItem() );
|
|
|
|
data.setString( "modid", ui.modId );
|
|
|
|
data.setString( "itemname", ui.name );
|
2014-03-15 21:35:00 +01:00
|
|
|
is.setTagCompound( data );
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public Block getBlock(ItemStack is)
|
|
|
|
{
|
|
|
|
NBTTagCompound data = is.getTagCompound();
|
|
|
|
if ( data != null )
|
|
|
|
{
|
2014-05-11 18:41:31 +02:00
|
|
|
if ( data.hasKey( "modid" ) && data.hasKey( "itemname" ) )
|
|
|
|
{
|
|
|
|
return GameRegistry.findBlock( data.getString( "modid" ), data.getString( "itemname" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int[] blk = data.getIntArray( "x" );
|
|
|
|
if ( blk != null && blk.length == 2 )
|
|
|
|
return Block.getBlockById( blk[0] );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
return Blocks.glass;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMeta(ItemStack is)
|
|
|
|
{
|
|
|
|
NBTTagCompound data = is.getTagCompound();
|
|
|
|
if ( data != null )
|
|
|
|
{
|
|
|
|
int[] blk = data.getIntArray( "x" );
|
|
|
|
if ( blk != null && blk.length == 2 )
|
|
|
|
return blk[1];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public String getItemStackDisplayName(ItemStack is)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack in = getTextureItem( is );
|
|
|
|
if ( in != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
return super.getItemStackDisplayName( is );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-04 22:46:38 +02:00
|
|
|
@Override
|
|
|
|
public boolean useAlphaPass(ItemStack is)
|
|
|
|
{
|
|
|
|
ItemStack out = getTextureItem( is );
|
2014-05-12 00:01:48 +02:00
|
|
|
|
|
|
|
if ( out == null || out.getItem() == null )
|
|
|
|
return false;
|
|
|
|
|
2014-05-04 22:46:38 +02:00
|
|
|
Block blk = Block.getBlockFromItem( out.getItem() );
|
|
|
|
if ( blk != null && blk.canRenderInPass( 1 ) )
|
|
|
|
return true;
|
2014-05-12 00:01:48 +02:00
|
|
|
|
2014-05-04 22:46:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|