Parts/Materials both now have better registration, and both use DamageValues.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package appeng.items.materials;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
@@ -22,8 +23,7 @@ import appeng.items.AEBaseItem;
|
||||
public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
{
|
||||
|
||||
private int currentMaterial = 0;
|
||||
private final MaterialType material[] = new MaterialType[MaterialType.values().length];
|
||||
HashMap<Integer, MaterialType> dmgToMaterial = new HashMap();
|
||||
|
||||
public ItemMaterial() {
|
||||
super( ItemMaterial.class );
|
||||
@@ -32,6 +32,8 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
||||
|
||||
public ItemStack createMaterial(MaterialType mat)
|
||||
{
|
||||
String name = mat.name();
|
||||
|
||||
if ( mat.damageValue == -1 )
|
||||
{
|
||||
boolean enabled = true;
|
||||
@@ -40,14 +42,15 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
||||
|
||||
if ( enabled )
|
||||
{
|
||||
material[currentMaterial] = mat;
|
||||
mat.damageValue = currentMaterial;
|
||||
ItemStack output = new ItemStack( this );
|
||||
output.setItemDamage( currentMaterial );
|
||||
currentMaterial++;
|
||||
int newMaterialNum = Configuration.instance.get( "materials", name, Configuration.instance.getFreeMaterial() ).getInt();
|
||||
mat.damageValue = newMaterialNum;
|
||||
ItemStack output = new ItemStack( this, 1, newMaterialNum );
|
||||
output.setItemDamage( newMaterialNum );
|
||||
|
||||
dmgToMaterial.put( newMaterialNum, mat );
|
||||
|
||||
if ( mat.getOreName() != null )
|
||||
OreDictionary.registerOre( mat.getOreName(), this );
|
||||
OreDictionary.registerOre( mat.getOreName(), output );
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -60,13 +63,13 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
||||
|
||||
public MaterialType getTypeByStack(ItemStack is)
|
||||
{
|
||||
return material[is.getItemDamage()];
|
||||
return dmgToMaterial.get( is.getItemDamage() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIconFromDamage(int dmg)
|
||||
{
|
||||
return material[dmg].icon;
|
||||
return dmgToMaterial.get( dmg ).icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,10 +81,13 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
||||
@Override
|
||||
public void registerIcons(IconRegister par1IconRegister)
|
||||
{
|
||||
for (int x = 0; x < currentMaterial; x++)
|
||||
for (MaterialType mat : MaterialType.values())
|
||||
{
|
||||
String tex = "appliedenergistics2:" + getUnlocalizedName( new ItemStack( this, 1, x ) );
|
||||
material[x].icon = par1IconRegister.registerIcon( tex );
|
||||
if ( mat.damageValue != -1 )
|
||||
{
|
||||
String tex = "appliedenergistics2:" + getUnlocalizedName( new ItemStack( this, 1, mat.damageValue ) );
|
||||
mat.icon = par1IconRegister.registerIcon( tex );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +177,10 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List cList)
|
||||
{
|
||||
for (int x = 0; x < currentMaterial; x++)
|
||||
cList.add( new ItemStack( this, 1, x ) );
|
||||
for (MaterialType mat : MaterialType.values())
|
||||
{
|
||||
if ( mat.damageValue >= 0 )
|
||||
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+96
-21
@@ -1,14 +1,22 @@
|
||||
package appeng.items.parts;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.core.Configuration;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.items.AEBaseItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -16,17 +24,62 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class ItemPart extends AEBaseItem implements IPartItem
|
||||
{
|
||||
|
||||
final PartType part;
|
||||
class PartTypeIst
|
||||
{
|
||||
|
||||
public ItemPart(PartType type) {
|
||||
super( ItemPart.class, type.name() );
|
||||
setfeature( type.getFeature() );
|
||||
PartType part;
|
||||
int varient;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
Icon ico;
|
||||
|
||||
};
|
||||
|
||||
HashMap<Integer, PartTypeIst> dmgToPart = new HashMap();
|
||||
|
||||
public ItemPart() {
|
||||
super( ItemPart.class );
|
||||
setfeature( EnumSet.of( AEFeature.Core ) );
|
||||
AEApi.instance().partHelper().setItemBusRenderer( this );
|
||||
part = type;
|
||||
if ( type == PartType.CableSmart || type == PartType.CableCovered || type == PartType.CableGlass )
|
||||
setHasSubtypes( true );
|
||||
}
|
||||
|
||||
public ItemStack createPart(PartType mat, Enum varient)
|
||||
{
|
||||
String name = varient == null ? mat.name() : mat.name() + "." + varient.name();
|
||||
int varID = varient == null ? 0 : varient.ordinal();
|
||||
|
||||
// verify
|
||||
for (PartTypeIst p : dmgToPart.values())
|
||||
{
|
||||
setHasSubtypes( true );
|
||||
if ( p.part == mat && p.varient == varID )
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
}
|
||||
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
enabled = enabled && Configuration.instance.isFeatureEnabled( f );
|
||||
|
||||
if ( enabled )
|
||||
{
|
||||
int newPartNum = Configuration.instance.get( "parts", name, Configuration.instance.getFreePart() ).getInt();
|
||||
ItemStack output = new ItemStack( this );
|
||||
output.setItemDamage( newPartNum );
|
||||
|
||||
PartTypeIst pti = new PartTypeIst();
|
||||
pti.part = mat;
|
||||
pti.varient = varID;
|
||||
|
||||
dmgToPart.put( newPartNum, pti );
|
||||
return output;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PartType getTypeByStack(ItemStack is)
|
||||
{
|
||||
return dmgToPart.get( is.getItemDamage() ).part;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,8 +90,30 @@ public class ItemPart extends AEBaseItem implements IPartItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY,
|
||||
float hitZ)
|
||||
public Icon getIconFromDamage(int dmg)
|
||||
{
|
||||
Icon ico = dmgToPart.get( dmg ).ico;
|
||||
return ico;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
{
|
||||
return AEFeatureHandler.getName( ItemPart.class, getTypeByStack( is ).name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IconRegister par1IconRegister)
|
||||
{
|
||||
for (Entry<Integer, PartTypeIst> part : dmgToPart.entrySet())
|
||||
{
|
||||
String tex = "appliedenergistics2:" + getUnlocalizedName( new ItemStack( this, 1, part.getKey() ) );
|
||||
part.getValue().ico = par1IconRegister.registerIcon( tex );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
|
||||
}
|
||||
@@ -48,26 +123,26 @@ public class ItemPart extends AEBaseItem implements IPartItem
|
||||
{
|
||||
try
|
||||
{
|
||||
return part.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
||||
PartType t = getTypeByStack( is );
|
||||
return t.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + part.getPart().getName()
|
||||
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName()
|
||||
+ " ; Possibly didn't have correct constructor( ItemStack )", e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int number, CreativeTabs tab, List list)
|
||||
public void getSubItems(int number, CreativeTabs tab, List cList)
|
||||
{
|
||||
if ( part == PartType.CableSmart || part == PartType.CableCovered || part == PartType.CableGlass )
|
||||
{
|
||||
list.add( new ItemStack( this, 1, 16 ) );
|
||||
for (int x = 0; x < 16; x++)
|
||||
list.add( new ItemStack( this, 1, x ) );
|
||||
return;
|
||||
}
|
||||
super.getSubItems( number, tab, list );
|
||||
for (Entry<Integer, PartTypeIst> part : dmgToPart.entrySet())
|
||||
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
|
||||
public int varientOf(int itemDamage)
|
||||
{
|
||||
return dmgToPart.get( itemDamage ).varient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package appeng.items.parts;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.parts.automation.PartAnnihilationPlane;
|
||||
import appeng.parts.automation.PartExportBus;
|
||||
@@ -10,6 +11,7 @@ import appeng.parts.automation.PartFormationPlane;
|
||||
import appeng.parts.automation.PartImportBus;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
import appeng.parts.misc.PartCableAnchor;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.parts.misc.PartInvertedToggleBus;
|
||||
import appeng.parts.misc.PartP2PTunnel;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
@@ -70,7 +72,9 @@ public enum PartType
|
||||
|
||||
StorageMonitor(AEFeature.StorageMonitor, PartStorageMonitor.class),
|
||||
|
||||
ConversionMonitor(AEFeature.PartConversionMonitor, PartConversionMonitor.class);
|
||||
ConversionMonitor(AEFeature.PartConversionMonitor, PartConversionMonitor.class),
|
||||
|
||||
Interface(AEFeature.Core, PartInterface.class);
|
||||
|
||||
private EnumSet<AEFeature> features;
|
||||
private Class<? extends IPart> myPart;
|
||||
@@ -80,6 +84,11 @@ public enum PartType
|
||||
myPart = c;
|
||||
}
|
||||
|
||||
public Enum[] getVarients()
|
||||
{
|
||||
return (this == CableSmart || this == CableCovered || this == CableGlass) ? AEColor.values() : null;
|
||||
}
|
||||
|
||||
public EnumSet<AEFeature> getFeature()
|
||||
{
|
||||
return features;
|
||||
|
||||
Reference in New Issue
Block a user