2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.items.parts;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockGlass;
|
|
|
|
import net.minecraft.block.BlockStainedGlass;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.client.MinecraftForgeClient;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.exceptions.MissingDefinition;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.parts.IAlphaPassItem;
|
|
|
|
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;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem
|
|
|
|
{
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private List<ItemStack> subTypes = null;
|
|
|
|
|
|
|
|
public ItemFacade()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.Facades ) );
|
|
|
|
this.setHasSubtypes( true );
|
2014-09-24 02:26:27 +02:00
|
|
|
if ( Platform.isClient() )
|
2015-01-01 22:13:10 +01:00
|
|
|
MinecraftForgeClient.registerItemRenderer( this, BusRenderer.INSTANCE );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
2014-09-24 02:26:27 +02:00
|
|
|
public int getSpriteNumber()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean onItemUse( ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public String getItemStackDisplayName( ItemStack is )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack in = this.getTextureItem( is );
|
|
|
|
if ( in != null )
|
|
|
|
{
|
|
|
|
return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( Throwable ignored )
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
return super.getItemStackDisplayName( is );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void getSubItems( Item number, CreativeTabs tab, List list )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.calculateSubTypes();
|
|
|
|
list.addAll( this.subTypes );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Override
|
|
|
|
public FacadePart createPartFromItemStack( ItemStack is, ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
ItemStack in = this.getTextureItem( is );
|
|
|
|
if ( in != null )
|
|
|
|
return new FacadePart( is, side );
|
|
|
|
return null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemStack getTextureItem( ItemStack is )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
Block blk = this.getBlock( is );
|
2014-09-24 02:26:27 +02:00
|
|
|
if ( blk != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
return new ItemStack( blk, 1, this.getMeta( is ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +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
|
|
|
|
public Block getBlock( ItemStack is )
|
|
|
|
{
|
|
|
|
NBTTagCompound data = is.getTagCompound();
|
|
|
|
if ( data != null )
|
|
|
|
{
|
|
|
|
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] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Blocks.glass;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<ItemStack> getFacades()
|
|
|
|
{
|
|
|
|
this.calculateSubTypes();
|
|
|
|
return this.subTypes;
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
private void calculateSubTypes()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.subTypes == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.subTypes = new ArrayList<ItemStack>();
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( Object blk : Block.blockRegistry )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
Block b = (Block) blk;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Item item = Item.getItemFromBlock( b );
|
|
|
|
|
2014-09-28 22:20:14 +02:00
|
|
|
List<ItemStack> tmpList = new ArrayList<ItemStack>();
|
2014-09-24 02:26:27 +02:00
|
|
|
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack l : tmpList )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack facade = this.createFacadeForItem( l, false );
|
2014-09-24 02:26:27 +02:00
|
|
|
if ( facade != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.subTypes.add( facade );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
catch ( Throwable t )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
// just absorb..
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( FacadeConfig.instance.hasChanged() )
|
|
|
|
FacadeConfig.instance.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemStack createFacadeForItem( ItemStack l, boolean returnItem )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
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 || b instanceof BlockStainedGlass;
|
|
|
|
boolean disableOre = b instanceof OreQuartz;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
boolean defaultValue = ( b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre ) || enableGlass;
|
2014-09-24 02:26:27 +02:00
|
|
|
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 );
|
|
|
|
UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor( l.getItem() );
|
|
|
|
data.setString( "modid", ui.modId );
|
|
|
|
data.setString( "itemname", ui.name );
|
|
|
|
is.setTagCompound( data );
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemStack getCreativeTabIcon()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.calculateSubTypes();
|
|
|
|
if ( this.subTypes.isEmpty() )
|
|
|
|
return new ItemStack( Items.cake );
|
|
|
|
return this.subTypes.get( 0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemStack createFromIDs( int[] ids )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack facadeStack : AEApi.instance().definitions().items().facade().maybeStack( 1 ).asSet() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
NBTTagCompound facadeTag = new NBTTagCompound();
|
|
|
|
facadeTag.setIntArray( "x", ids.clone() );
|
|
|
|
facadeStack.setTagCompound( facadeTag );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
return facadeStack;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
throw new MissingDefinition( "Tried to create a facade, while facades are being deactivated." );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean useAlphaPass( ItemStack is )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack out = this.getTextureItem( is );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
if ( out == null || out.getItem() == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Block blk = Block.getBlockFromItem( out.getItem() );
|
|
|
|
if ( blk != null && blk.canRenderInPass( 1 ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|