2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.parts;
|
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.HashMap;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.List;
|
2014-01-03 19:30:08 +01:00
|
|
|
import java.util.Map.Entry;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-03 19:30:08 +01:00
|
|
|
import net.minecraft.util.Icon;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.api.AEApi;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IItemGroup;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPart;
|
2014-01-03 19:30:08 +01:00
|
|
|
import appeng.api.parts.IPartItem;
|
|
|
|
import appeng.core.Configuration;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.features.AEFeatureHandler;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.core.localization.GuiText;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
class PartTypeIst
|
|
|
|
{
|
|
|
|
|
|
|
|
PartType part;
|
|
|
|
int varient;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
Icon ico;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
HashMap<Integer, PartTypeIst> dmgToPart = new HashMap();
|
|
|
|
|
|
|
|
public ItemPart() {
|
|
|
|
super( ItemPart.class );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Core ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
AEApi.instance().partHelper().setItemBusRenderer( this );
|
2014-01-03 19:30:08 +01:00
|
|
|
setHasSubtypes( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack createPart(PartType mat, Enum varient)
|
|
|
|
{
|
2014-01-28 21:08:51 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack is = new ItemStack( this );
|
|
|
|
PartType t = getTypeByStack( is );
|
|
|
|
t.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
|
|
|
}
|
|
|
|
catch (Throwable e)
|
|
|
|
{
|
|
|
|
return null; // part not supported..
|
|
|
|
}
|
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
String name = varient == null ? mat.name() : mat.name() + "." + varient.name();
|
|
|
|
int varID = varient == null ? 0 : varient.ordinal();
|
|
|
|
|
|
|
|
// verify
|
|
|
|
for (PartTypeIst p : dmgToPart.values())
|
|
|
|
{
|
|
|
|
if ( p.part == mat && p.varient == varID )
|
|
|
|
throw new RuntimeException( "Cannot create the same material twice..." );
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean enabled = true;
|
|
|
|
for (AEFeature f : mat.getFeature())
|
|
|
|
enabled = enabled && Configuration.instance.isFeatureEnabled( f );
|
|
|
|
|
|
|
|
if ( enabled )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
int newPartNum = Configuration.instance.get( "parts", name, Configuration.instance.getFreePart() ).getInt();
|
|
|
|
ItemStack output = new ItemStack( this );
|
|
|
|
output.setItemDamage( newPartNum );
|
|
|
|
|
|
|
|
PartTypeIst pti = new PartTypeIst();
|
|
|
|
pti.part = mat;
|
|
|
|
pti.varient = varID;
|
|
|
|
|
|
|
|
dmgToPart.put( newPartNum, pti );
|
|
|
|
return output;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-01-03 19:30:08 +01:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PartType getTypeByStack(ItemStack is)
|
|
|
|
{
|
|
|
|
return dmgToPart.get( is.getItemDamage() ).part;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getSpriteNumber()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-03 19:30:08 +01:00
|
|
|
public Icon getIconFromDamage(int dmg)
|
|
|
|
{
|
|
|
|
Icon ico = dmgToPart.get( dmg ).ico;
|
|
|
|
return ico;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack is)
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
return "item.appliedenergistics2." + getname( is );
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getname(ItemStack is)
|
2014-01-03 19:30:08 +01:00
|
|
|
{
|
|
|
|
return AEFeatureHandler.getName( ItemPart.class, getTypeByStack( is ).name() );
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
|
|
|
public String getItemDisplayName(ItemStack is)
|
|
|
|
{
|
|
|
|
Enum[] varients = getTypeByStack( is ).getVarients();
|
|
|
|
|
|
|
|
if ( varients != null )
|
|
|
|
return super.getItemDisplayName( is ) + " - " + varients[dmgToPart.get( is.getItemDamage() ).varient].toString();
|
|
|
|
|
|
|
|
return super.getItemDisplayName( is );
|
|
|
|
}
|
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
@Override
|
|
|
|
public void registerIcons(IconRegister par1IconRegister)
|
|
|
|
{
|
|
|
|
for (Entry<Integer, PartTypeIst> part : dmgToPart.entrySet())
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
String tex = "appliedenergistics2:" + getname( new ItemStack( this, 1, part.getKey() ) );
|
2014-01-03 19:30:08 +01:00
|
|
|
part.getValue().ico = par1IconRegister.registerIcon( tex );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPart createPartFromItemStack(ItemStack is)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
PartType t = getTypeByStack( is );
|
|
|
|
return t.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (Throwable e)
|
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName()
|
2013-12-27 23:59:59 +01:00
|
|
|
+ " ; Possibly didn't have correct constructor( ItemStack )", e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-03 19:30:08 +01:00
|
|
|
public void getSubItems(int number, CreativeTabs tab, List cList)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
for (Entry<Integer, PartTypeIst> part : dmgToPart.entrySet())
|
|
|
|
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int varientOf(int itemDamage)
|
|
|
|
{
|
|
|
|
return dmgToPart.get( itemDamage ).varient;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
|
|
|
public String getUnlocalizedGroupName(ItemStack is)
|
|
|
|
{
|
|
|
|
switch (getTypeByStack( is ))
|
|
|
|
{
|
|
|
|
case ImportBus:
|
|
|
|
case ExportBus:
|
|
|
|
return GuiText.IOBuses.getUnlocalized();
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|