Fixes #1474: Prevents crafting of disabled recipes and deletes invalid parts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -83,14 +84,26 @@ public abstract class AEBaseItem extends Item implements IAEFeature
|
||||
this.addCheckedInformation( stack, player, lines, displayMoreInfo );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public final void getSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks )
|
||||
{
|
||||
this.getCheckedSubItems( sameItem, creativeTab, itemStacks );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayMoreInfo )
|
||||
protected void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayMoreInfo )
|
||||
{
|
||||
super.addInformation( stack, player, lines, displayMoreInfo );
|
||||
}
|
||||
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
super.getSubItems( sameItem, creativeTab, itemStacks );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -291,7 +291,7 @@ public final class ItemMultiMaterial extends AEBaseItem implements IStorageCompo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item par1, CreativeTabs par2CreativeTabs, List cList )
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
List<MaterialType> types = Arrays.asList( MaterialType.values() );
|
||||
Collections.sort( types, new Comparator<MaterialType>()
|
||||
@@ -308,7 +308,7 @@ public final class ItemMultiMaterial extends AEBaseItem implements IStorageCompo
|
||||
{
|
||||
if( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this )
|
||||
{
|
||||
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
itemStacks.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,21 +310,21 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item i, CreativeTabs t, List l )
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
// lvl 0
|
||||
l.add( newStyle( new ItemStack( this, 1, CERTUS ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, NETHER ) ) );
|
||||
l.add( newStyle( new ItemStack( this, 1, FLUIX ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, FLUIX ) ) );
|
||||
|
||||
// lvl 1
|
||||
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 ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + FLUIX ) ) );
|
||||
|
||||
// lvl 2
|
||||
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 ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -79,13 +79,13 @@ public class ItemPaintBall extends AEBaseItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item i, CreativeTabs ct, List l )
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
for( AEColor c : AEColor.values() )
|
||||
{
|
||||
if( c != AEColor.Transparent )
|
||||
{
|
||||
l.add( new ItemStack( this, 1, c.ordinal() ) );
|
||||
itemStacks.add( new ItemStack( this, 1, c.ordinal() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ItemPaintBall extends AEBaseItem
|
||||
{
|
||||
if( c != AEColor.Transparent )
|
||||
{
|
||||
l.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) );
|
||||
itemStacks.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -103,17 +103,17 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item number, CreativeTabs tab, List list )
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
this.calculateSubTypes();
|
||||
list.addAll( this.subTypes );
|
||||
itemStacks.addAll( this.subTypes );
|
||||
}
|
||||
|
||||
private void calculateSubTypes()
|
||||
{
|
||||
if( this.subTypes == null )
|
||||
{
|
||||
this.subTypes = new ArrayList<ItemStack>();
|
||||
this.subTypes = new ArrayList<ItemStack>( 1000 );
|
||||
for( Object blk : Block.blockRegistry )
|
||||
{
|
||||
Block b = (Block) blk;
|
||||
@@ -121,7 +121,7 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
||||
{
|
||||
Item item = Item.getItemFromBlock( b );
|
||||
|
||||
List<ItemStack> tmpList = new ArrayList<ItemStack>();
|
||||
List<ItemStack> tmpList = new ArrayList<ItemStack>( 100 );
|
||||
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
|
||||
for( ItemStack l : tmpList )
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -21,6 +21,7 @@ package appeng.items.parts;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
@@ -29,7 +30,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -47,6 +47,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.MissingDefinition;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHelper;
|
||||
@@ -54,6 +55,7 @@ import appeng.api.parts.IPartItem;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.core.features.NameResolver;
|
||||
import appeng.core.localization.GuiText;
|
||||
@@ -64,19 +66,18 @@ import appeng.items.AEBaseItem;
|
||||
|
||||
public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
{
|
||||
private static final int INITIAL_REGISTERED_CAPACITY = PartType.values().length;
|
||||
private static final Comparator<Entry<Integer, PartTypeWithVariant>> REGISTERED_COMPARATOR = new RegisteredComparator();
|
||||
|
||||
|
||||
public static ItemMultiPart instance;
|
||||
private final NameResolver nameResolver;
|
||||
private final Map<Integer, PartTypeWithVariant> registered;
|
||||
private final Map<Integer, PartTypeWithVariant> unregistered;
|
||||
|
||||
public ItemMultiPart( IPartHelper partHelper )
|
||||
{
|
||||
Preconditions.checkNotNull( partHelper );
|
||||
|
||||
this.registered = new HashMap<Integer, PartTypeWithVariant>();
|
||||
this.unregistered = new HashMap<Integer, PartTypeWithVariant>();
|
||||
this.registered = new HashMap<Integer, PartTypeWithVariant>( INITIAL_REGISTERED_CAPACITY );
|
||||
|
||||
this.nameResolver = new NameResolver( this.getClass() );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
@@ -132,7 +133,8 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
}
|
||||
|
||||
final int partDamage = mat.baseDamage + varID;
|
||||
final ItemStackSrc output = new ItemStackSrc( this, partDamage );
|
||||
final ActivityState state = ActivityState.from( enabled );
|
||||
final ItemStackSrc output = new ItemStackSrc( this, partDamage, state );
|
||||
|
||||
final PartTypeWithVariant pti = new PartTypeWithVariant( mat, varID );
|
||||
|
||||
@@ -147,13 +149,13 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
assert mat != null;
|
||||
assert pti != null;
|
||||
|
||||
final Map<Integer, PartTypeWithVariant> reference = ( enabled ) ? this.registered : this.unregistered;
|
||||
if( reference.containsKey( partDamage ) )
|
||||
final PartTypeWithVariant registeredPartType = this.registered.get( partDamage );
|
||||
if( registeredPartType != null )
|
||||
{
|
||||
throw new IllegalStateException( "Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + reference.get( partDamage ) + " there already." );
|
||||
throw new IllegalStateException( "Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + registeredPartType + " there already." );
|
||||
}
|
||||
|
||||
reference.put( partDamage, pti );
|
||||
this.registered.put( partDamage, pti );
|
||||
}
|
||||
|
||||
public int getDamageByType( PartType t )
|
||||
@@ -180,7 +182,14 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
@Override
|
||||
public IIcon getIconFromDamage( int dmg )
|
||||
{
|
||||
return this.registered.get( dmg ).ico;
|
||||
final PartTypeWithVariant registeredType = this.registered.get( dmg );
|
||||
if( registeredType != null )
|
||||
{
|
||||
return registeredType.ico;
|
||||
}
|
||||
|
||||
final String formattedRegistered = Arrays.toString( this.registered.keySet().toArray() );
|
||||
throw new MissingDefinition( "Tried to get the icon from a non-existent part with damage value " + dmg + ". There were registered: " + formattedRegistered + '.' );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +213,12 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
{
|
||||
final AEColor[] variants = AEColor.values();
|
||||
|
||||
return super.getItemStackDisplayName( is ) + " - " + variants[this.registered.get( is.getItemDamage() ).variant].toString();
|
||||
final int itemDamage = is.getItemDamage();
|
||||
final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage );
|
||||
if( registeredPartType != null )
|
||||
{
|
||||
return super.getItemStackDisplayName( is ) + " - " + variants[registeredPartType.variant].toString();
|
||||
}
|
||||
}
|
||||
|
||||
if( pt.getExtraName() != null )
|
||||
@@ -216,24 +230,24 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item number, CreativeTabs tab, List cList )
|
||||
public void registerIcons( IIconRegister iconRegister )
|
||||
{
|
||||
for( Entry<Integer, PartTypeWithVariant> part : this.registered.entrySet() )
|
||||
{
|
||||
String tex = "appliedenergistics2:" + this.getName( new ItemStack( this, 1, part.getKey() ) );
|
||||
part.getValue().ico = iconRegister.registerIcon( tex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
List<Entry<Integer, PartTypeWithVariant>> types = new ArrayList<Entry<Integer, PartTypeWithVariant>>( this.registered.entrySet() );
|
||||
Collections.sort( types, REGISTERED_COMPARATOR );
|
||||
|
||||
for( Entry<Integer, PartTypeWithVariant> part : types )
|
||||
{
|
||||
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons( IIconRegister par1IconRegister )
|
||||
{
|
||||
for( Entry<Integer, PartTypeWithVariant> part : this.registered.entrySet() )
|
||||
{
|
||||
String tex = "appliedenergistics2:" + this.getName( new ItemStack( this, 1, part.getKey() ) );
|
||||
part.getValue().ico = par1IconRegister.registerIcon( tex );
|
||||
itemStacks.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,21 +271,20 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
{
|
||||
return pt.part;
|
||||
}
|
||||
final PartTypeWithVariant unregisteredPartType = this.unregistered.get( is.getItemDamage() );
|
||||
if( unregisteredPartType != null )
|
||||
{
|
||||
return unregisteredPartType.part;
|
||||
}
|
||||
|
||||
throw new IllegalStateException( "ItemStack " + is + " has to be either registered or unregistered, but was not found in either." );
|
||||
return PartType.InvalidType;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
@Override
|
||||
public IPart createPartFromItemStack( ItemStack is )
|
||||
{
|
||||
final PartType type = this.getTypeByStack( is );
|
||||
final Class<? extends IPart> part = type.getPart();
|
||||
if( part == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -302,10 +315,12 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
|
||||
public int variantOf( int itemDamage )
|
||||
{
|
||||
if( this.registered.containsKey( itemDamage ) )
|
||||
final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage );
|
||||
if( registeredPartType != null )
|
||||
{
|
||||
return this.registered.get( itemDamage ).variant;
|
||||
return registeredPartType.variant;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -369,8 +384,19 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
this.part = part;
|
||||
this.variant = variant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "PartTypeWithVariant{" +
|
||||
"part=" + this.part +
|
||||
", variant=" + this.variant +
|
||||
", ico=" + this.ico +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final class RegisteredComparator implements Comparator<Entry<Integer, PartTypeWithVariant>>
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -77,15 +77,16 @@ public abstract class AERootPoweredItem extends AEBaseItem implements IAEItemPow
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems( Item id, CreativeTabs tab, List list )
|
||||
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
|
||||
{
|
||||
super.getSubItems( id, tab, list );
|
||||
super.getCheckedSubItems( sameItem, creativeTab, itemStacks );
|
||||
|
||||
ItemStack charged = new ItemStack( this, 1 );
|
||||
NBTTagCompound tag = Platform.openNbtData( charged );
|
||||
final ItemStack charged = new ItemStack( this, 1 );
|
||||
final NBTTagCompound tag = Platform.openNbtData( charged );
|
||||
tag.setDouble( "internalCurrentPower", this.getAEMaxPower( charged ) );
|
||||
tag.setDouble( "internalMaxPower", this.getAEMaxPower( charged ) );
|
||||
list.add( charged );
|
||||
|
||||
itemStacks.add( charged );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user