Fixes #675 No disabled feature should log spam or crash anymore.
Deprecates the old usage of the AEItemDefinitions via the direct method access of * blocks() * parts() * items() * materials() and thus use the new re-direct via definitions(). All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
@@ -18,8 +18,10 @@
|
||||
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -38,6 +40,7 @@ import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IGrowableCrystal;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.core.AppEng;
|
||||
@@ -48,6 +51,7 @@ import appeng.entity.EntityIds;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
{
|
||||
|
||||
@@ -63,7 +67,36 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
final IIcon[] fluix = new IIcon[3];
|
||||
final IIcon[] nether = new IIcon[3];
|
||||
|
||||
private int getProgress(ItemStack is)
|
||||
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;
|
||||
|
||||
for ( ItemStack crystalSeedStack : AEApi.instance().definitions().items().crystalSeed().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( is.hasTagCompound() )
|
||||
{
|
||||
@@ -74,35 +107,74 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
int progress;
|
||||
NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", progress = is.getItemDamage() );
|
||||
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
|
||||
is.setItemDamage( ( is.getItemDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
private void setProgress(ItemStack is, int newDamage)
|
||||
@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;
|
||||
|
||||
if ( newDamage == Certus + SINGLE_OFFSET )
|
||||
{
|
||||
for ( ItemStack quartzStack : materials.purifiedCertusQuartzCrystal().maybeStack( size ).asSet() )
|
||||
{
|
||||
return quartzStack;
|
||||
}
|
||||
}
|
||||
if ( newDamage == Nether + SINGLE_OFFSET )
|
||||
{
|
||||
for ( ItemStack quartzStack : materials.purifiedNetherQuartzCrystal().maybeStack( size ).asSet() )
|
||||
{
|
||||
return quartzStack;
|
||||
}
|
||||
}
|
||||
if ( newDamage == Fluix + SINGLE_OFFSET )
|
||||
{
|
||||
for ( ItemStack quartzStack : materials.purifiedFluixCrystal().maybeStack( size ).asSet() )
|
||||
{
|
||||
return quartzStack;
|
||||
}
|
||||
}
|
||||
if ( newDamage > END )
|
||||
return null;
|
||||
|
||||
this.setProgress( is, newDamage );
|
||||
return is;
|
||||
}
|
||||
|
||||
private void setProgress( ItemStack is, int newDamage )
|
||||
{
|
||||
NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", newDamage );
|
||||
is.setItemDamage( is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET );
|
||||
}
|
||||
|
||||
public ItemCrystalSeed() {
|
||||
super( ItemCrystalSeed.class );
|
||||
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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntityLifespan(ItemStack itemStack, World world)
|
||||
} @Override
|
||||
public int getEntityLifespan( ItemStack itemStack, World world )
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
public float getMultiplier( Block blk, Material mat )
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
{
|
||||
lines.add( ButtonToolTips.DoesntDespawn.getLocal() );
|
||||
int progress = this.getProgress( stack ) % SINGLE_OFFSET;
|
||||
lines.add( Math.floor( (float) progress / (float) ( SINGLE_OFFSET / 100 ) ) + "%" );
|
||||
|
||||
super.addCheckedInformation( stack, player, lines, displayAdditionalInformation );
|
||||
} @Override
|
||||
public String getUnlocalizedName( ItemStack is )
|
||||
{
|
||||
int damage = this.getProgress( is );
|
||||
|
||||
@@ -118,23 +190,7 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
return this.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack triggerGrowth(ItemStack is)
|
||||
{
|
||||
int newDamage = this.getProgress( is ) + 1;
|
||||
|
||||
if ( newDamage == Certus + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedCertusQuartzCrystal.stack( is.stackSize );
|
||||
if ( newDamage == Nether + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedNetherQuartzCrystal.stack( is.stackSize );
|
||||
if ( newDamage == Fluix + SINGLE_OFFSET )
|
||||
return AEApi.instance().materials().materialPurifiedFluixCrystal.stack( is.stackSize );
|
||||
if ( newDamage > END )
|
||||
return null;
|
||||
|
||||
this.setProgress( is, newDamage );
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
@@ -143,35 +199,25 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
{
|
||||
lines.add( ButtonToolTips.DoesntDespawn.getLocal() );
|
||||
int progress = this.getProgress( stack ) % SINGLE_OFFSET;
|
||||
lines.add( Math.floor( (float) progress / (float) (SINGLE_OFFSET / 100) ) + "%" );
|
||||
|
||||
super.addCheckedInformation( stack, player, lines, displayAdditionalInformation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack)
|
||||
public boolean isDamaged( ItemStack stack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack)
|
||||
public int getMaxDamage( ItemStack stack )
|
||||
{
|
||||
return END;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int pass)
|
||||
public IIcon getIcon( ItemStack stack, int pass )
|
||||
{
|
||||
return this.getIconIndex( stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack stack)
|
||||
public IIcon getIconIndex( ItemStack stack )
|
||||
{
|
||||
IIcon[] list = null;
|
||||
|
||||
@@ -204,13 +250,7 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMultiplier(Block blk, Material mat)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister ir)
|
||||
public void registerIcons( IIconRegister ir )
|
||||
{
|
||||
String preFix = "appliedenergistics2:ItemCrystalSeed.";
|
||||
|
||||
@@ -228,13 +268,13 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEntity(ItemStack stack)
|
||||
public boolean hasCustomEntity( ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(World world, Entity location, ItemStack itemstack)
|
||||
public Entity createEntity( World world, Entity location, ItemStack itemstack )
|
||||
{
|
||||
EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
|
||||
|
||||
@@ -243,13 +283,13 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
egc.motionZ = location.motionZ;
|
||||
|
||||
if ( location instanceof EntityItem )
|
||||
egc.delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
||||
egc.delayBeforeCanPickup = ( (EntityItem) location ).delayBeforeCanPickup;
|
||||
|
||||
return egc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item i, CreativeTabs t, List l)
|
||||
public void getSubItems( Item i, CreativeTabs t, List l )
|
||||
{
|
||||
// lvl 0
|
||||
l.add( newStyle( new ItemStack( this, 1, Certus ) ) );
|
||||
@@ -267,18 +307,5 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Fluix ) ) );
|
||||
}
|
||||
|
||||
private static ItemStack newStyle(ItemStack itemStack)
|
||||
{
|
||||
((ItemCrystalSeed) itemStack.getItem()).getProgress( itemStack );
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ResolverResult getResolver(int certus2)
|
||||
{
|
||||
ItemStack is = AEApi.instance().items().itemCrystalSeed.stack( 1 );
|
||||
is.setItemDamage( certus2 );
|
||||
is = newStyle( is );
|
||||
return new ResolverResult( "ItemCrystalSeed", is.getItemDamage(), is.getTagCompound() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package appeng.items.misc;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -42,18 +43,35 @@ import appeng.helpers.PatternHelper;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
|
||||
{
|
||||
// rather simple client side caching.
|
||||
private static final Map<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<ItemStack, ItemStack>();
|
||||
|
||||
public ItemEncodedPattern() {
|
||||
super( ItemEncodedPattern.class );
|
||||
public ItemEncodedPattern()
|
||||
{
|
||||
this.setFeature( EnumSet.of( AEFeature.Patterns ) );
|
||||
this.setMaxStackSize( 1 );
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new ItemEncodedPatternRenderer() );
|
||||
}
|
||||
|
||||
private boolean clearPattern(ItemStack stack, EntityPlayer player)
|
||||
@Override
|
||||
public ItemStack onItemRightClick( ItemStack stack, World w, EntityPlayer player )
|
||||
{
|
||||
this.clearPattern( stack, player );
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
return this.clearPattern( stack, player );
|
||||
}
|
||||
|
||||
private boolean clearPattern( ItemStack stack, EntityPlayer player )
|
||||
{
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
@@ -62,11 +80,15 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
|
||||
InventoryPlayer inv = player.inventory;
|
||||
|
||||
for (int s = 0; s < player.inventory.getSizeInventory(); s++)
|
||||
for ( int s = 0; s < player.inventory.getSizeInventory(); s++ )
|
||||
{
|
||||
if ( inv.getStackInSlot( s ) == stack )
|
||||
{
|
||||
inv.setInventorySlotContents( s, AEApi.instance().materials().materialBlankPattern.stack( stack.stackSize ) );
|
||||
for ( ItemStack blankPattern : AEApi.instance().definitions().materials().blankPattern().maybeStack( stack.stackSize ).asSet() )
|
||||
{
|
||||
inv.setInventorySlotContents( s, blankPattern );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -76,20 +98,7 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return this.clearPattern( stack, player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer player)
|
||||
{
|
||||
this.clearPattern( stack, player );
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
{
|
||||
ICraftingPatternDetails details = this.getPatternForItem( stack, player.worldObj );
|
||||
|
||||
@@ -104,39 +113,49 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
IAEItemStack[] in = details.getCondensedInputs();
|
||||
IAEItemStack[] out = details.getCondensedOutputs();
|
||||
|
||||
String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
|
||||
String label = ( isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal() ) + ": ";
|
||||
String and = ' ' + GuiText.And.getLocal() + ' ';
|
||||
String with = GuiText.With.getLocal() + ": ";
|
||||
|
||||
boolean first = true;
|
||||
for (IAEItemStack anOut : out)
|
||||
for ( IAEItemStack anOut : out )
|
||||
{
|
||||
if ( anOut == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lines.add( (first ? label : and) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName( anOut ) );
|
||||
lines.add( ( first ? label : and ) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName( anOut ) );
|
||||
first = false;
|
||||
}
|
||||
|
||||
first = true;
|
||||
for (IAEItemStack anIn : in)
|
||||
for ( IAEItemStack anIn : in )
|
||||
{
|
||||
if ( anIn == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lines.add( (first ? with : and) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName( anIn ) );
|
||||
lines.add( ( first ? with : and ) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName( anIn ) );
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
// rather simple client side caching.
|
||||
static final WeakHashMap<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<ItemStack, ItemStack>();
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem( ItemStack is, World w )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PatternHelper( is, w );
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getOutput(ItemStack item)
|
||||
public ItemStack getOutput( ItemStack item )
|
||||
{
|
||||
ItemStack out = SIMPLE_CACHE.get( item );
|
||||
if ( out != null )
|
||||
@@ -154,18 +173,4 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
SIMPLE_CACHE.put( item, out = details.getCondensedOutputs()[0].getItemStack() );
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PatternHelper( is, w );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,33 +34,37 @@ import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ItemPaintBall extends AEBaseItem
|
||||
{
|
||||
|
||||
public ItemPaintBall() {
|
||||
super( ItemPaintBall.class );
|
||||
public static final int DAMAGE_THRESHOLD = 20;
|
||||
|
||||
public ItemPaintBall()
|
||||
{
|
||||
this.setFeature( EnumSet.of( AEFeature.PaintBalls ) );
|
||||
this.hasSubtypes = true;
|
||||
this.setHasSubtypes( true );
|
||||
|
||||
if ( Platform.isClient() )
|
||||
MinecraftForgeClient.registerItemRenderer( this, new PaintBallRender() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
public String getItemStackDisplayName( ItemStack is )
|
||||
{
|
||||
return super.getItemStackDisplayName( is ) + " - " + this.getExtraName( is );
|
||||
}
|
||||
|
||||
public String getExtraName(ItemStack is)
|
||||
public String getExtraName( ItemStack is )
|
||||
{
|
||||
return (is.getItemDamage() >= 20 ? GuiText.Lumen.getLocal() + ' ' : "") + this.getColor( is );
|
||||
return ( is.getItemDamage() >= DAMAGE_THRESHOLD ? GuiText.Lumen.getLocal() + ' ' : "" ) + this.getColor( is );
|
||||
}
|
||||
|
||||
public AEColor getColor(ItemStack is)
|
||||
public AEColor getColor( ItemStack is )
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
if ( dmg >= 20 )
|
||||
dmg -= 20;
|
||||
if ( dmg >= DAMAGE_THRESHOLD )
|
||||
dmg -= DAMAGE_THRESHOLD;
|
||||
|
||||
if ( dmg >= AEColor.values().length )
|
||||
return AEColor.Transparent;
|
||||
@@ -69,21 +73,20 @@ public class ItemPaintBall extends AEBaseItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item i, CreativeTabs ct, List l)
|
||||
public void getSubItems( Item i, CreativeTabs ct, List l )
|
||||
{
|
||||
for (AEColor c : AEColor.values())
|
||||
for ( AEColor c : AEColor.values() )
|
||||
if ( c != AEColor.Transparent )
|
||||
l.add( new ItemStack( this, 1, c.ordinal() ) );
|
||||
|
||||
for (AEColor c : AEColor.values())
|
||||
for ( AEColor c : AEColor.values() )
|
||||
if ( c != AEColor.Transparent )
|
||||
l.add( new ItemStack( this, 1, 20 + c.ordinal() ) );
|
||||
l.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) );
|
||||
}
|
||||
|
||||
public boolean isLumen(ItemStack is)
|
||||
public boolean isLumen( ItemStack is )
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
return dmg >= 20;
|
||||
return dmg >= DAMAGE_THRESHOLD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user