2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.materials;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2014-01-01 10:01:38 +01:00
|
|
|
import java.util.EnumSet;
|
2014-01-03 19:30:08 +01:00
|
|
|
import java.util.HashMap;
|
2014-01-20 17:41:37 +01:00
|
|
|
import java.util.LinkedList;
|
2014-01-01 10:01:38 +01:00
|
|
|
import java.util.List;
|
2014-01-20 17:41:37 +01:00
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2014-01-01 10:01:38 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2014-01-01 10:01:38 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-01-01 10:01:38 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IItemGroup;
|
|
|
|
import appeng.api.implementations.items.IStorageComponent;
|
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-01-01 10:01:38 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.features.AEFeatureHandler;
|
2014-02-09 08:55:44 +01:00
|
|
|
import appeng.core.features.ItemStackSrc;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-01-03 19:30:08 +01:00
|
|
|
HashMap<Integer, MaterialType> dmgToMaterial = new HashMap();
|
2014-01-01 10:01:38 +01:00
|
|
|
|
2014-02-10 04:16:36 +01:00
|
|
|
public static ItemMaterial instance;
|
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
public ItemMaterial() {
|
|
|
|
super( ItemMaterial.class );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Core ) );
|
2014-01-20 17:41:37 +01:00
|
|
|
setHasSubtypes( true );
|
2014-02-10 04:16:36 +01:00
|
|
|
instance = this;
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class SlightlyBetterSort implements Comparator<String>
|
|
|
|
{
|
|
|
|
|
|
|
|
Pattern p;
|
|
|
|
|
|
|
|
public SlightlyBetterSort(Pattern p) {
|
|
|
|
this.p = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(String o1, String o2)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Matcher a = p.matcher( o1 );
|
|
|
|
Matcher b = p.matcher( o2 );
|
|
|
|
if ( a.find() && b.find() )
|
|
|
|
{
|
|
|
|
int ia = Integer.parseInt( a.group( 1 ) );
|
|
|
|
int ib = Integer.parseInt( b.group( 1 ) );
|
|
|
|
return Integer.compare( ia, ib );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
// ek!
|
|
|
|
}
|
|
|
|
return o1.compareTo( o2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
|
|
|
{
|
|
|
|
super.addInformation( par1ItemStack, par2EntityPlayer, par3List, par4 );
|
|
|
|
|
2014-02-17 01:50:25 +01:00
|
|
|
MaterialType mt = getTypeByStack( par1ItemStack );
|
|
|
|
if ( mt == null )
|
|
|
|
return;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
Upgrades u = getType( par1ItemStack );
|
|
|
|
if ( u != null )
|
|
|
|
{
|
|
|
|
List<String> textList = new LinkedList();
|
|
|
|
for (Entry<ItemStack, Integer> j : u.getSupported().entrySet())
|
|
|
|
{
|
|
|
|
String name = null;
|
|
|
|
|
|
|
|
int limit = j.getValue();
|
|
|
|
|
|
|
|
if ( j.getKey().getItem() instanceof IItemGroup )
|
|
|
|
{
|
|
|
|
IItemGroup ig = (IItemGroup) j.getKey().getItem();
|
|
|
|
String str = ig.getUnlocalizedGroupName( j.getKey() );
|
|
|
|
if ( str != null )
|
|
|
|
name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ")" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( name == null )
|
|
|
|
name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ")" : "");
|
|
|
|
|
|
|
|
if ( !textList.contains( name ) )
|
|
|
|
textList.add( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern p = Pattern.compile( "(\\d+)[^\\d]" );
|
|
|
|
SlightlyBetterSort s = new SlightlyBetterSort( p );
|
|
|
|
Collections.sort( textList, s );
|
|
|
|
par3List.addAll( textList );
|
|
|
|
}
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 08:55:44 +01:00
|
|
|
public ItemStackSrc createMaterial(MaterialType mat)
|
2014-01-01 10:01:38 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
String name = mat.name();
|
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
if ( mat.damageValue == -1 )
|
|
|
|
{
|
|
|
|
boolean enabled = true;
|
|
|
|
for (AEFeature f : mat.getFeature())
|
2014-02-09 06:08:27 +01:00
|
|
|
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
2014-01-01 10:01:38 +01:00
|
|
|
|
|
|
|
if ( enabled )
|
|
|
|
{
|
2014-02-09 06:08:27 +01:00
|
|
|
int newMaterialNum = AEConfig.instance.get( "materials", name, AEConfig.instance.getFreeMaterial() ).getInt();
|
2014-01-03 19:30:08 +01:00
|
|
|
mat.damageValue = newMaterialNum;
|
2014-02-09 08:55:44 +01:00
|
|
|
ItemStackSrc output = new ItemStackSrc( this, newMaterialNum );
|
2014-01-03 19:30:08 +01:00
|
|
|
|
|
|
|
dmgToMaterial.put( newMaterialNum, mat );
|
2014-01-01 10:01:38 +01:00
|
|
|
|
|
|
|
if ( mat.getOreName() != null )
|
2014-02-09 08:55:44 +01:00
|
|
|
OreDictionary.registerOre( mat.getOreName(), output.stack( 1 ) );
|
2014-01-01 10:01:38 +01:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new RuntimeException( "Cannot create the same material twice..." );
|
|
|
|
}
|
|
|
|
|
|
|
|
public MaterialType getTypeByStack(ItemStack is)
|
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
return dmgToMaterial.get( is.getItemDamage() );
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public IIcon getIconFromDamage(int dmg)
|
2014-01-01 10:01:38 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return dmgToMaterial.get( dmg ).IIcon;
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
private String nameOf(ItemStack is)
|
|
|
|
{
|
2014-02-17 01:50:25 +01:00
|
|
|
if ( is == null )
|
|
|
|
return "null";
|
|
|
|
|
|
|
|
MaterialType mt = getTypeByStack( is );
|
|
|
|
if ( mt == null )
|
|
|
|
return "null";
|
|
|
|
|
|
|
|
return AEFeatureHandler.getName( ItemMaterial.class, mt.name() );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack is)
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return "item.appliedenergistics2." + nameOf( is );
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void registerIcons(IIconRegister icoRegister)
|
2014-01-01 10:01:38 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
for (MaterialType mat : MaterialType.values())
|
2014-01-01 10:01:38 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
if ( mat.damageValue != -1 )
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
String tex = "appliedenergistics2:" + nameOf( new ItemStack( this, 1, mat.damageValue ) );
|
2014-02-09 02:34:52 +01:00
|
|
|
mat.IIcon = icoRegister.registerIcon( tex );
|
2014-01-03 19:30:08 +01:00
|
|
|
}
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomEntity(ItemStack is)
|
|
|
|
{
|
2014-01-01 10:01:38 +01:00
|
|
|
return getTypeByStack( is ).hasCustomEntity();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Entity createEntity(World w, Entity location, ItemStack itemstack)
|
|
|
|
{
|
2014-01-01 10:01:38 +01:00
|
|
|
Class<? extends Entity> droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass();
|
2013-12-27 23:59:59 +01:00
|
|
|
Entity eqi;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX,
|
|
|
|
location.posY, location.posZ, itemstack );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new RuntimeException( t );
|
|
|
|
}
|
|
|
|
|
|
|
|
eqi.motionX = location.motionX;
|
|
|
|
eqi.motionY = location.motionY;
|
|
|
|
eqi.motionZ = location.motionZ;
|
|
|
|
|
|
|
|
if ( location instanceof EntityItem && eqi instanceof EntityItem )
|
|
|
|
((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
|
|
|
|
|
|
|
return eqi;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBytes(ItemStack is)
|
|
|
|
{
|
2014-01-01 10:01:38 +01:00
|
|
|
switch (getTypeByStack( is ))
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
case Cell1kPart:
|
|
|
|
return 1024;
|
|
|
|
case Cell4kPart:
|
|
|
|
return 1024 * 4;
|
|
|
|
case Cell16kPart:
|
|
|
|
return 1024 * 16;
|
|
|
|
case Cell64kPart:
|
|
|
|
return 1024 * 64;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isStorageComponent(ItemStack is)
|
|
|
|
{
|
2014-01-01 10:01:38 +01:00
|
|
|
switch (getTypeByStack( is ))
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
case Cell1kPart:
|
|
|
|
case Cell4kPart:
|
|
|
|
case Cell16kPart:
|
|
|
|
case Cell64kPart:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-01 10:01:38 +01:00
|
|
|
@Override
|
|
|
|
public Upgrades getType(ItemStack itemstack)
|
|
|
|
{
|
|
|
|
switch (getTypeByStack( itemstack ))
|
|
|
|
{
|
|
|
|
case CardCapacity:
|
|
|
|
return Upgrades.CAPACITY;
|
|
|
|
case CardFuzzy:
|
|
|
|
return Upgrades.FUZZY;
|
|
|
|
case CardRedstone:
|
|
|
|
return Upgrades.REDSTONE;
|
|
|
|
case CardSpeed:
|
|
|
|
return Upgrades.SPEED;
|
2014-01-20 17:41:37 +01:00
|
|
|
case CardInverter:
|
|
|
|
return Upgrades.INVERTER;
|
2014-01-01 10:01:38 +01:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList)
|
2014-01-01 10:01:38 +01:00
|
|
|
{
|
2014-01-03 19:30:08 +01:00
|
|
|
for (MaterialType mat : MaterialType.values())
|
|
|
|
{
|
|
|
|
if ( mat.damageValue >= 0 )
|
|
|
|
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
|
|
|
}
|
2014-01-01 10:01:38 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|