Fixed an issue where Parts/Blocks would not properly identify them selves with the proper ItemStack.
This commit is contained in:
parent
7367502d75
commit
49da876b6f
|
@ -35,6 +35,7 @@ import appeng.client.texture.FlipableIcon;
|
|||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.helpers.ICustomCollision;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
|
@ -151,7 +152,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
|
|||
|
||||
protected void setTileEntiy(Class<? extends TileEntity> c)
|
||||
{
|
||||
AEBaseTile.registerTileItem( c, new ItemStack( this ) );
|
||||
AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) );
|
||||
GameRegistry.registerTileEntity( tileEntityType = c, FeatureFullname );
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ public class ContainerNetworkStatus extends AEBaseContainer
|
|||
{
|
||||
IGridBlock blk = machine.getGridBlock();
|
||||
ItemStack is = blk.getMachineRepresentation();
|
||||
if ( is != null )
|
||||
if ( is != null && is.getItem() != null )
|
||||
{
|
||||
IAEItemStack ais = AEItemStack.create( is );
|
||||
ais.setStackSize( 1 );
|
||||
|
|
|
@ -3,7 +3,6 @@ package appeng.core;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandomChestContent;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.ChestGenHooks;
|
||||
|
@ -63,6 +62,7 @@ import appeng.core.features.AEFeatureHandler;
|
|||
import appeng.core.features.ColoredItemDefinition;
|
||||
import appeng.core.features.DamagedItemDefinition;
|
||||
import appeng.core.features.IAEFeature;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.core.features.NullItemDefinition;
|
||||
import appeng.core.features.registries.P2PTunnelRegistry;
|
||||
import appeng.core.features.registries.entries.BasicCellHandler;
|
||||
|
@ -149,7 +149,7 @@ public class Registration
|
|||
try
|
||||
{
|
||||
Field f = materialClass.getField( "material" + mat.name() );
|
||||
ItemStack is = ((ItemMaterial) materialItem.item()).createMaterial( mat );
|
||||
ItemStackSrc is = ((ItemMaterial) materialItem.item()).createMaterial( mat );
|
||||
if ( is != null )
|
||||
f.set( materials, new DamagedItemDefinition( is ) );
|
||||
else
|
||||
|
@ -173,7 +173,7 @@ public class Registration
|
|||
Enum varients[] = type.getVarients();
|
||||
if ( varients == null )
|
||||
{
|
||||
ItemStack is = ((ItemPart) partItem.item()).createPart( type, null );
|
||||
ItemStackSrc is = ((ItemPart) partItem.item()).createPart( type, null );
|
||||
if ( is != null )
|
||||
f.set( parts, new DamagedItemDefinition( is ) );
|
||||
else
|
||||
|
@ -187,7 +187,7 @@ public class Registration
|
|||
|
||||
for (Enum v : varients)
|
||||
{
|
||||
ItemStack is = ((ItemPart) partItem.item()).createPart( type, v );
|
||||
ItemStackSrc is = ((ItemPart) partItem.item()).createPart( type, v );
|
||||
if ( is != null )
|
||||
def.add( (AEColor) v, is );
|
||||
}
|
||||
|
|
|
@ -10,42 +10,42 @@ import appeng.api.util.AEColoredItemDefinition;
|
|||
public class ColoredItemDefinition implements AEColoredItemDefinition
|
||||
{
|
||||
|
||||
ItemStack colors[] = new ItemStack[17];
|
||||
ItemStackSrc colors[] = new ItemStackSrc[17];
|
||||
|
||||
@Override
|
||||
public Item item(AEColor color)
|
||||
{
|
||||
ItemStack is = colors[color.ordinal()];
|
||||
ItemStackSrc is = colors[color.ordinal()];
|
||||
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
return is.getItem();
|
||||
return is.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack stack(AEColor color, int stackSize)
|
||||
{
|
||||
ItemStack is = colors[color.ordinal()];
|
||||
ItemStackSrc is = colors[color.ordinal()];
|
||||
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
return new ItemStack( is.getItem(), stackSize, is.getItemDamage() );
|
||||
return is.stack( stackSize );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameAs(AEColor color, ItemStack comparableItem)
|
||||
{
|
||||
ItemStack is = colors[color.ordinal()];
|
||||
ItemStackSrc is = colors[color.ordinal()];
|
||||
|
||||
if ( comparableItem == null )
|
||||
return false;
|
||||
|
||||
return comparableItem.getItem() == is.getItem() && comparableItem.getItemDamage() == is.getItemDamage();
|
||||
return comparableItem.getItem() == is.item && comparableItem.getItemDamage() == is.damage;
|
||||
}
|
||||
|
||||
public void add(AEColor v, ItemStack is)
|
||||
public void add(AEColor v, ItemStackSrc is)
|
||||
{
|
||||
colors[v.ordinal()] = is;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class DamagedItemDefinition implements AEItemDefinition
|
|||
final Item baseItem;
|
||||
final int damage;
|
||||
|
||||
public DamagedItemDefinition(ItemStack is) {
|
||||
public DamagedItemDefinition(ItemStackSrc is) {
|
||||
if ( is == null )
|
||||
{
|
||||
baseItem = null;
|
||||
|
@ -20,8 +20,8 @@ public class DamagedItemDefinition implements AEItemDefinition
|
|||
}
|
||||
else
|
||||
{
|
||||
baseItem = is.getItem();
|
||||
damage = is.getItemDamage();
|
||||
baseItem = is.item;
|
||||
damage = is.damage;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
33
core/features/ItemStackSrc.java
Normal file
33
core/features/ItemStackSrc.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package appeng.core.features;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemStackSrc
|
||||
{
|
||||
|
||||
public final Item item;
|
||||
public final Block block;
|
||||
public final int damage;
|
||||
|
||||
public ItemStackSrc(Item i, int dmg) {
|
||||
block = null;
|
||||
item = i;
|
||||
damage = dmg;
|
||||
}
|
||||
|
||||
public ItemStackSrc(Block b, int dmg) {
|
||||
item = null;
|
||||
block = b;
|
||||
damage = dmg;
|
||||
}
|
||||
|
||||
public ItemStack stack(int i)
|
||||
{
|
||||
if ( block != null )
|
||||
return new ItemStack( block, i, damage );
|
||||
return new ItemStack( item, i, damage );
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import appeng.api.implementations.items.IUpgradeModule;
|
|||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
@ -109,7 +110,7 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
|||
}
|
||||
}
|
||||
|
||||
public ItemStack createMaterial(MaterialType mat)
|
||||
public ItemStackSrc createMaterial(MaterialType mat)
|
||||
{
|
||||
String name = mat.name();
|
||||
|
||||
|
@ -123,13 +124,12 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
|||
{
|
||||
int newMaterialNum = AEConfig.instance.get( "materials", name, AEConfig.instance.getFreeMaterial() ).getInt();
|
||||
mat.damageValue = newMaterialNum;
|
||||
ItemStack output = new ItemStack( this, 1, newMaterialNum );
|
||||
output.setItemDamage( newMaterialNum );
|
||||
ItemStackSrc output = new ItemStackSrc( this, newMaterialNum );
|
||||
|
||||
dmgToMaterial.put( newMaterialNum, mat );
|
||||
|
||||
if ( mat.getOreName() != null )
|
||||
OreDictionary.registerOre( mat.getOreName(), output );
|
||||
OreDictionary.registerOre( mat.getOreName(), output.stack( 1 ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import appeng.api.parts.IPartItem;
|
|||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -47,10 +48,11 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
|
|||
setHasSubtypes( true );
|
||||
}
|
||||
|
||||
public ItemStack createPart(PartType mat, Enum varient)
|
||||
public ItemStackSrc createPart(PartType mat, Enum varient)
|
||||
{
|
||||
try
|
||||
{
|
||||
// I think this still works?
|
||||
ItemStack is = new ItemStack( this );
|
||||
mat.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
||||
}
|
||||
|
@ -76,8 +78,7 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
|
|||
if ( enabled )
|
||||
{
|
||||
int newPartNum = AEConfig.instance.get( "parts", name, AEConfig.instance.getFreePart() ).getInt();
|
||||
ItemStack output = new ItemStack( this );
|
||||
output.setItemDamage( newPartNum );
|
||||
ItemStackSrc output = new ItemStackSrc( this, newPartNum );
|
||||
|
||||
PartTypeIst pti = new PartTypeIst();
|
||||
pti.part = mat;
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import appeng.api.util.ICommonTile;
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.Platform;
|
||||
|
@ -32,7 +33,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile
|
|||
{
|
||||
|
||||
private final EnumMap<TileEventType, List<AETileEventHandler>> handlers = new EnumMap<TileEventType, List<AETileEventHandler>>( TileEventType.class );
|
||||
private final static HashMap<Class, ItemStack> myItem = new HashMap();
|
||||
private final static HashMap<Class, ItemStackSrc> myItem = new HashMap();
|
||||
|
||||
private ForgeDirection forward = ForgeDirection.UNKNOWN;
|
||||
private ForgeDirection up = ForgeDirection.UNKNOWN;
|
||||
|
@ -45,14 +46,17 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile
|
|||
return this;
|
||||
}
|
||||
|
||||
static public void registerTileItem(Class c, ItemStack wat)
|
||||
static public void registerTileItem(Class c, ItemStackSrc wat)
|
||||
{
|
||||
myItem.put( c, wat );
|
||||
}
|
||||
|
||||
protected ItemStack getItemFromTile(Object obj)
|
||||
{
|
||||
return myItem.get( obj.getClass() );
|
||||
ItemStackSrc src = myItem.get( obj.getClass() );
|
||||
if ( src == null )
|
||||
return null;
|
||||
return src.stack( 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue