Parts/Materials both now have better registration, and both use DamageValues.
This commit is contained in:
parent
3220a2e07c
commit
35a21d472f
5 changed files with 168 additions and 41 deletions
|
@ -3,6 +3,7 @@ package appeng.core;
|
|||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.Property;
|
||||
import appeng.api.config.CondenserOuput;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.Settings;
|
||||
|
@ -155,6 +156,22 @@ public class Configuration extends net.minecraftforge.common.Configuration imple
|
|||
super.save();
|
||||
}
|
||||
|
||||
public int getFreeMaterial()
|
||||
{
|
||||
int min = 0;
|
||||
for (Property p : getCategory( "materials" ).getValues().values())
|
||||
min = Math.max( min, p.getInt() + 1 );
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getFreePart()
|
||||
{
|
||||
int min = 0;
|
||||
for (Property p : getCategory( "parts" ).getValues().values())
|
||||
min = Math.max( min, p.getInt() + 1 );
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ import appeng.api.definitions.Blocks;
|
|||
import appeng.api.definitions.Items;
|
||||
import appeng.api.definitions.Materials;
|
||||
import appeng.api.definitions.Parts;
|
||||
import appeng.api.implementations.ITileStorageMonitorable;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.pathing.IPathingGrid;
|
||||
import appeng.api.networking.spatial.ISpatialCache;
|
||||
|
@ -159,17 +160,32 @@ public class Registration
|
|||
}
|
||||
}
|
||||
|
||||
AEItemDefinition partItem = (AEFeatureHandler) addFeature( ItemPart.class );
|
||||
|
||||
Class partClass = parts.getClass();
|
||||
for (PartType part : PartType.values())
|
||||
for (PartType type : PartType.values())
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = partClass.getField( "part" + part.name() );
|
||||
f.set( parts, addFeature( ItemPart.class, part ) );
|
||||
Field f = partClass.getField( "part" + type.name() );
|
||||
Enum varients[] = type.getVarients();
|
||||
if ( varients == null )
|
||||
{
|
||||
ItemStack is = ((ItemPart) partItem.item()).createPart( type, null );
|
||||
f.set( parts, new DamagedItemDefinition( is ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Enum v : varients)
|
||||
{
|
||||
ItemStack is = ((ItemPart) partItem.item()).createPart( type, v );
|
||||
f.set( parts, new DamagedItemDefinition( is ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
AELog.severe( "Error creating part: " + part.name() );
|
||||
AELog.severe( "Error creating part: " + type.name() );
|
||||
throw new RuntimeException( err );
|
||||
}
|
||||
}
|
||||
|
@ -358,6 +374,7 @@ public class Registration
|
|||
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIPowerEmitter", IPowerEmitter.class );
|
||||
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIPowerReceptor", IPowerReceptor.class );
|
||||
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIFluidHandler", IFluidHandler.class );
|
||||
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerITileStorageMonitorable", ITileStorageMonitorable.class );
|
||||
|
||||
TickRegistry.registerTickHandler( TickHandler.instance, Side.SERVER );
|
||||
TickRegistry.registerTickHandler( TickHandler.instance, Side.CLIENT );
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue