2014-02-23 02:28:52 +01:00
|
|
|
package appeng.items.misc;
|
|
|
|
|
2014-02-23 07:55:46 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2014-02-23 07:55:46 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-03-29 09:55:02 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-23 02:28:52 +01:00
|
|
|
import net.minecraft.init.Items;
|
2014-02-23 07:55:46 +01:00
|
|
|
import net.minecraft.item.Item;
|
2014-02-23 02:28:52 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-06-11 07:21:03 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-23 02:28:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
2014-02-23 07:55:46 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-02-23 02:28:52 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.implementations.items.IGrowableCrystal;
|
2014-02-23 07:55:46 +01:00
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.entity.EntityGrowingCrystal;
|
|
|
|
import appeng.entity.EntityIds;
|
2014-02-23 02:28:52 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
2014-06-11 07:21:03 +02:00
|
|
|
import appeng.util.Platform;
|
2014-02-23 07:55:46 +01:00
|
|
|
import cpw.mods.fml.common.registry.EntityRegistry;
|
2014-02-23 02:28:52 +01:00
|
|
|
|
|
|
|
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
|
|
|
{
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
public static final int LEVEL_OFFSET = 200;
|
|
|
|
public static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
|
|
|
|
|
|
|
public static final int Certus = 0;
|
|
|
|
public static final int Nether = SINGLE_OFFSET;
|
|
|
|
public static final int Fluix = SINGLE_OFFSET * 2;
|
|
|
|
public static final int END = SINGLE_OFFSET * 3;
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
IIcon certus[] = new IIcon[3];
|
|
|
|
IIcon fluix[] = new IIcon[3];
|
|
|
|
IIcon nether[] = new IIcon[3];
|
|
|
|
|
2014-06-11 07:21:03 +02:00
|
|
|
private int getProgress(ItemStack is)
|
|
|
|
{
|
|
|
|
if ( is.hasTagCompound() )
|
|
|
|
{
|
|
|
|
return is.getTagCompound().getInteger( "progress" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int progress;
|
|
|
|
NBTTagCompound comp = Platform.openNbtData( is );
|
|
|
|
comp.setInteger( "progress", progress = is.getItemDamage() );
|
|
|
|
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setProgress(ItemStack is, int newDamage)
|
|
|
|
{
|
|
|
|
NBTTagCompound comp = Platform.openNbtData( is );
|
|
|
|
comp.setInteger( "progress", newDamage );
|
|
|
|
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
|
|
|
|
}
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
public ItemCrystalSeed() {
|
|
|
|
super( ItemCrystalSeed.class );
|
2014-02-23 07:55:46 +01:00
|
|
|
setHasSubtypes( true );
|
|
|
|
setMaxStackSize( 8 );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Core ) );
|
|
|
|
|
|
|
|
EntityRegistry.registerModEntity( EntityGrowingCrystal.class, EntityGrowingCrystal.class.getSimpleName(), EntityIds.get( EntityGrowingCrystal.class ),
|
|
|
|
AppEng.instance, 16, 4, true );
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack is)
|
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
int damage = getProgress( is );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( damage < Certus + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return getUnlocalizedName() + ".Certus";
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( damage < Nether + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return getUnlocalizedName() + ".Nether";
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( damage < Fluix + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return getUnlocalizedName() + ".Fluix";
|
|
|
|
|
|
|
|
return getUnlocalizedName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack triggerGrowth(ItemStack is)
|
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
int newDamage = getProgress( is ) + 1;
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( newDamage == Certus + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return AEApi.instance().materials().materialPureifiedCertusQuartzCrystal.stack( is.stackSize );
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( newDamage == Nether + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return AEApi.instance().materials().materialPureifiedNetherQuartzCrystal.stack( is.stackSize );
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( newDamage == Fluix + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return AEApi.instance().materials().materialPureifiedFluixCrystal.stack( is.stackSize );
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( newDamage > END )
|
2014-02-23 07:55:46 +01:00
|
|
|
return null;
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-06-11 07:21:03 +02:00
|
|
|
setProgress( is, newDamage );
|
2014-02-23 02:28:52 +01:00
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
2014-02-23 07:55:46 +01:00
|
|
|
@Override
|
|
|
|
public boolean isDamageable()
|
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
return false;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
2014-03-29 09:55:02 +01:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer p, List l, boolean b)
|
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
int progress = getProgress( stack ) % SINGLE_OFFSET;
|
|
|
|
l.add( Math.floor( (float) progress / (float) (SINGLE_OFFSET / 100) ) + "%" );
|
2014-03-29 09:55:02 +01:00
|
|
|
super.addInformation( stack, p, l, b );
|
|
|
|
}
|
|
|
|
|
2014-02-23 07:55:46 +01:00
|
|
|
@Override
|
|
|
|
public boolean isDamaged(ItemStack stack)
|
|
|
|
{
|
2014-03-29 09:55:02 +01:00
|
|
|
return false;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxDamage(ItemStack stack)
|
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
return END;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
@Override
|
2014-06-11 07:21:03 +02:00
|
|
|
public IIcon getIconIndex(ItemStack stack)
|
2014-02-23 02:28:52 +01:00
|
|
|
{
|
|
|
|
IIcon list[] = null;
|
|
|
|
|
2014-06-11 07:21:03 +02:00
|
|
|
int damage = getProgress( stack );
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( damage < Certus + SINGLE_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
list = certus;
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
else if ( damage < Nether + SINGLE_OFFSET )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
2014-02-25 06:33:31 +01:00
|
|
|
damage -= Nether;
|
2014-02-23 02:28:52 +01:00
|
|
|
list = nether;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
else if ( damage < Fluix + SINGLE_OFFSET )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
2014-02-25 06:33:31 +01:00
|
|
|
damage -= Fluix;
|
2014-02-23 02:28:52 +01:00
|
|
|
list = fluix;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
2014-02-23 02:28:52 +01:00
|
|
|
|
|
|
|
if ( list == null )
|
|
|
|
return Items.diamond.getIconFromDamage( 0 );
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
if ( damage < LEVEL_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return list[0];
|
2014-02-25 06:33:31 +01:00
|
|
|
else if ( damage < LEVEL_OFFSET * 2 )
|
2014-02-23 02:28:52 +01:00
|
|
|
return list[1];
|
|
|
|
else
|
|
|
|
return list[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getMultiplier(Block blk, Material mat)
|
|
|
|
{
|
2014-02-23 07:55:46 +01:00
|
|
|
return 0.5f;
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerIcons(IIconRegister ir)
|
|
|
|
{
|
2014-03-12 03:26:03 +01:00
|
|
|
String preFix = "appliedenergistics2:ItemCrystalSeed.";
|
2014-02-23 02:28:52 +01:00
|
|
|
|
|
|
|
certus[0] = ir.registerIcon( preFix + "Certus" );
|
2014-02-23 07:55:46 +01:00
|
|
|
certus[1] = ir.registerIcon( preFix + "Certus2" );
|
|
|
|
certus[2] = ir.registerIcon( preFix + "Certus3" );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
|
|
|
nether[0] = ir.registerIcon( preFix + "Nether" );
|
2014-02-23 07:55:46 +01:00
|
|
|
nether[1] = ir.registerIcon( preFix + "Nether2" );
|
|
|
|
nether[2] = ir.registerIcon( preFix + "Nether3" );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
|
|
|
fluix[0] = ir.registerIcon( preFix + "Fluix" );
|
2014-02-23 07:55:46 +01:00
|
|
|
fluix[1] = ir.registerIcon( preFix + "Fluix2" );
|
|
|
|
fluix[2] = ir.registerIcon( preFix + "Fluix3" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomEntity(ItemStack stack)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Entity createEntity(World world, Entity location, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
|
|
|
|
|
|
|
|
egc.motionX = location.motionX;
|
|
|
|
egc.motionY = location.motionY;
|
|
|
|
egc.motionZ = location.motionZ;
|
|
|
|
|
|
|
|
if ( location instanceof EntityItem && egc instanceof EntityItem )
|
|
|
|
((EntityItem) egc).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
|
|
|
|
|
|
|
return egc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getSubItems(Item i, CreativeTabs t, List l)
|
|
|
|
{
|
|
|
|
// lvl 0
|
2014-06-11 07:21:03 +02:00
|
|
|
l.add( newStyle( new ItemStack( this, 1, Certus ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, Nether ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, Fluix ) ) );
|
2014-02-23 07:55:46 +01:00
|
|
|
|
|
|
|
// lvl 1
|
2014-06-11 07:21:03 +02:00
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Certus ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Nether ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Fluix ) ) );
|
2014-02-23 07:55:46 +01:00
|
|
|
|
|
|
|
// lvl 2
|
2014-06-11 07:21:03 +02:00
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Certus ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Nether ) ) );
|
|
|
|
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Fluix ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
private ItemStack newStyle(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
getProgress( itemStack );
|
|
|
|
return itemStack;
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|