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-02-23 02:28:52 +01:00
|
|
|
package appeng.items.misc;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-02-23 07:55:46 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2015-01-03 02:53:14 +01:00
|
|
|
import javax.annotation.Nullable;
|
2014-02-23 07:55:46 +01:00
|
|
|
|
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-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.registry.EntityRegistry;
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IMaterials;
|
2014-02-23 02:28:52 +01:00
|
|
|
import appeng.api.implementations.items.IGrowableCrystal;
|
2014-07-29 04:52:17 +02:00
|
|
|
import appeng.api.recipes.ResolverResult;
|
2014-02-23 07:55:46 +01:00
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.core.features.AEFeature;
|
2014-08-10 06:42:40 +02:00
|
|
|
import appeng.core.localization.ButtonToolTips;
|
2014-02-23 07:55:46 +01:00
|
|
|
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 02:28:52 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
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-09-29 09:54:34 +02:00
|
|
|
final IIcon[] certus = new IIcon[3];
|
|
|
|
final IIcon[] fluix = new IIcon[3];
|
|
|
|
final IIcon[] nether = new IIcon[3];
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public ItemCrystalSeed()
|
|
|
|
{
|
|
|
|
this.setHasSubtypes( true );
|
|
|
|
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
|
|
|
|
|
|
|
EntityRegistry.registerModEntity( EntityGrowingCrystal.class, EntityGrowingCrystal.class.getSimpleName(), EntityIds.get( EntityGrowingCrystal.class ), AppEng.instance, 16, 4, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public static ResolverResult getResolver( int certus2 )
|
|
|
|
{
|
|
|
|
ResolverResult resolver = null;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack crystalSeedStack : AEApi.instance().definitions().items().crystalSeed().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
crystalSeedStack.setItemDamage( certus2 );
|
|
|
|
crystalSeedStack = newStyle( crystalSeedStack );
|
|
|
|
resolver = new ResolverResult( "ItemCrystalSeed", crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ItemStack newStyle( ItemStack itemStack )
|
|
|
|
{
|
|
|
|
( (ItemCrystalSeed) itemStack.getItem() ).getProgress( itemStack );
|
|
|
|
return itemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getProgress( ItemStack is )
|
2014-06-11 07:21:03 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is.hasTagCompound() )
|
2014-06-11 07:21:03 +02:00
|
|
|
{
|
|
|
|
return is.getTagCompound().getInteger( "progress" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int progress;
|
|
|
|
NBTTagCompound comp = Platform.openNbtData( is );
|
|
|
|
comp.setInteger( "progress", progress = is.getItemDamage() );
|
2015-01-03 02:53:14 +01:00
|
|
|
is.setItemDamage( ( is.getItemDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
|
2014-06-11 07:21:03 +02:00
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public ItemStack triggerGrowth( ItemStack is )
|
|
|
|
{
|
|
|
|
int newDamage = this.getProgress( is ) + 1;
|
|
|
|
final IMaterials materials = AEApi.instance().definitions().materials();
|
|
|
|
final int size = is.stackSize;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( newDamage == Certus + SINGLE_OFFSET )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack quartzStack : materials.purifiedCertusQuartzCrystal().maybeStack( size ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return quartzStack;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( newDamage == Nether + SINGLE_OFFSET )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack quartzStack : materials.purifiedNetherQuartzCrystal().maybeStack( size ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return quartzStack;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( newDamage == Fluix + SINGLE_OFFSET )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack quartzStack : materials.purifiedFluixCrystal().maybeStack( size ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return quartzStack;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( newDamage > END )
|
2015-01-03 02:53:14 +01:00
|
|
|
return null;
|
|
|
|
|
|
|
|
this.setProgress( is, newDamage );
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setProgress( ItemStack is, int newDamage )
|
2014-06-11 07:21:03 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound comp = Platform.openNbtData( is );
|
|
|
|
comp.setInteger( "progress", newDamage );
|
2014-09-28 20:56:16 +02:00
|
|
|
is.setItemDamage( is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET );
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|
|
|
|
|
2014-07-31 01:01:41 +02:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public float getMultiplier( Block blk, Material mat )
|
2014-07-31 01:01:41 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return 0.5f;
|
2014-07-31 01:01:41 +02:00
|
|
|
}
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
@Override
|
2015-04-03 23:59:40 +02:00
|
|
|
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayMoreInfo )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
lines.add( ButtonToolTips.DoesntDespawn.getLocal() );
|
|
|
|
int progress = this.getProgress( stack ) % SINGLE_OFFSET;
|
|
|
|
lines.add( Math.floor( (float) progress / (float) ( SINGLE_OFFSET / 100 ) ) + "%" );
|
|
|
|
|
2015-04-03 23:59:40 +02:00
|
|
|
super.addCheckedInformation( stack, player, lines, displayMoreInfo );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEntityLifespan( ItemStack itemStack, World world )
|
|
|
|
{
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public String getUnlocalizedName( ItemStack is )
|
2014-02-23 02:28:52 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int damage = this.getProgress( is );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( damage < Certus + SINGLE_OFFSET )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getUnlocalizedName() + ".Certus";
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( damage < Nether + SINGLE_OFFSET )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getUnlocalizedName() + ".Nether";
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( damage < Fluix + SINGLE_OFFSET )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getUnlocalizedName() + ".Fluix";
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getUnlocalizedName();
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|
|
|
|
|
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
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean isDamaged( ItemStack stack )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
2014-03-29 09:55:02 +01:00
|
|
|
return false;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public int getMaxDamage( ItemStack stack )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
2014-06-11 07:21:03 +02:00
|
|
|
return END;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
2014-07-13 22:19:25 +02:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public IIcon getIcon( ItemStack stack, int pass )
|
2014-07-13 22:19:25 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getIconIndex( stack );
|
2014-07-13 22:19:25 +02:00
|
|
|
}
|
|
|
|
|
2014-02-23 02:28:52 +01:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public IIcon getIconIndex( ItemStack stack )
|
2014-02-23 02:28:52 +01:00
|
|
|
{
|
2015-01-01 21:15:03 +01:00
|
|
|
IIcon[] list = null;
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
int damage = this.getProgress( stack );
|
2014-06-11 07:21:03 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( damage < Certus + SINGLE_OFFSET )
|
2014-12-29 15:13:47 +01:00
|
|
|
list = this.certus;
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02: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-12-29 15:13:47 +01:00
|
|
|
list = this.nether;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02: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-12-29 15:13:47 +01:00
|
|
|
list = this.fluix;
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( list == null )
|
2014-02-23 02:28:52 +01:00
|
|
|
return Items.diamond.getIconFromDamage( 0 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( damage < LEVEL_OFFSET )
|
2014-02-23 02:28:52 +01:00
|
|
|
return list[0];
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( damage < LEVEL_OFFSET * 2 )
|
2014-02-23 02:28:52 +01:00
|
|
|
return list[1];
|
|
|
|
else
|
|
|
|
return list[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void registerIcons( IIconRegister ir )
|
2014-02-23 02:28:52 +01:00
|
|
|
{
|
2014-03-12 03:26:03 +01:00
|
|
|
String preFix = "appliedenergistics2:ItemCrystalSeed.";
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.certus[0] = ir.registerIcon( preFix + "Certus" );
|
|
|
|
this.certus[1] = ir.registerIcon( preFix + "Certus2" );
|
|
|
|
this.certus[2] = ir.registerIcon( preFix + "Certus3" );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.nether[0] = ir.registerIcon( preFix + "Nether" );
|
|
|
|
this.nether[1] = ir.registerIcon( preFix + "Nether2" );
|
|
|
|
this.nether[2] = ir.registerIcon( preFix + "Nether3" );
|
2014-02-23 02:28:52 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fluix[0] = ir.registerIcon( preFix + "Fluix" );
|
|
|
|
this.fluix[1] = ir.registerIcon( preFix + "Fluix2" );
|
|
|
|
this.fluix[2] = ir.registerIcon( preFix + "Fluix3" );
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean hasCustomEntity( ItemStack stack )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public Entity createEntity( World world, Entity location, ItemStack itemstack )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
|
|
|
EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
|
|
|
|
|
|
|
|
egc.motionX = location.motionX;
|
|
|
|
egc.motionY = location.motionY;
|
|
|
|
egc.motionZ = location.motionZ;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( location instanceof EntityItem )
|
2015-01-03 02:53:14 +01:00
|
|
|
egc.delayBeforeCanPickup = ( (EntityItem) location ).delayBeforeCanPickup;
|
2014-02-23 07:55:46 +01:00
|
|
|
|
|
|
|
return egc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void getSubItems( Item i, CreativeTabs t, List l )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
|
|
|
// 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 ) ) );
|
|
|
|
}
|
2014-02-23 02:28:52 +01:00
|
|
|
}
|