Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.items.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -27,7 +28,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -50,29 +50,20 @@ import appeng.api.util.AEColor;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.NameResolver;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.core.features.NameResolver;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
|
||||
|
||||
public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
{
|
||||
public static ItemMultiPart instance;
|
||||
private final NameResolver nameResolver;
|
||||
|
||||
private static class PartTypeIst
|
||||
{
|
||||
private PartType part;
|
||||
private int variant;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon ico;
|
||||
}
|
||||
|
||||
private final Map<Integer, PartTypeIst> dmgToPart = new HashMap<Integer, PartTypeIst>();
|
||||
|
||||
public static ItemMultiPart instance;
|
||||
|
||||
public ItemMultiPart( IPartHelper partHelper ) {
|
||||
public ItemMultiPart( IPartHelper partHelper )
|
||||
{
|
||||
this.nameResolver = new NameResolver( this.getClass() );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
partHelper.setItemBusRenderer( this );
|
||||
@@ -85,26 +76,26 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
int varID = 0;
|
||||
|
||||
// verify
|
||||
for (PartTypeIst p : this.dmgToPart.values())
|
||||
for( PartTypeIst p : this.dmgToPart.values() )
|
||||
{
|
||||
if ( p.part == mat && p.variant == varID )
|
||||
if( p.part == mat && p.variant == varID )
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
}
|
||||
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
for( AEFeature f : mat.getFeature() )
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
|
||||
int newPartNum = mat.baseDamage + varID;
|
||||
ItemStackSrc output = new ItemStackSrc( this, newPartNum );
|
||||
|
||||
if ( enabled )
|
||||
if( enabled )
|
||||
{
|
||||
PartTypeIst pti = new PartTypeIst();
|
||||
pti.part = mat;
|
||||
pti.variant = varID;
|
||||
|
||||
if ( this.dmgToPart.get( newPartNum ) == null )
|
||||
if( this.dmgToPart.get( newPartNum ) == null )
|
||||
{
|
||||
this.dmgToPart.put( newPartNum, pti );
|
||||
return output;
|
||||
@@ -118,7 +109,7 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
return output;
|
||||
}
|
||||
|
||||
public ItemStackSrc createPart(PartType mat, Enum variant)
|
||||
public ItemStackSrc createPart( PartType mat, Enum variant )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -126,7 +117,7 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
ItemStack is = new ItemStack( this );
|
||||
mat.getPart().getConstructor( ItemStack.class ).newInstance( is );
|
||||
}
|
||||
catch (Throwable e)
|
||||
catch( Throwable e )
|
||||
{
|
||||
AELog.integration( e );
|
||||
e.printStackTrace();
|
||||
@@ -136,17 +127,17 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
int varID = variant == null ? 0 : variant.ordinal();
|
||||
|
||||
// verify
|
||||
for (PartTypeIst p : this.dmgToPart.values())
|
||||
for( PartTypeIst p : this.dmgToPart.values() )
|
||||
{
|
||||
if ( p.part == mat && p.variant == varID )
|
||||
if( p.part == mat && p.variant == varID )
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
}
|
||||
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
for( AEFeature f : mat.getFeature() )
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
|
||||
if ( enabled )
|
||||
if( enabled )
|
||||
{
|
||||
int newPartNum = mat.baseDamage + varID;
|
||||
ItemStackSrc output = new ItemStackSrc( this, newPartNum );
|
||||
@@ -155,7 +146,7 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
pti.part = mat;
|
||||
pti.variant = varID;
|
||||
|
||||
if ( this.dmgToPart.get( newPartNum ) == null )
|
||||
if( this.dmgToPart.get( newPartNum ) == null )
|
||||
{
|
||||
this.dmgToPart.put( newPartNum, pti );
|
||||
return output;
|
||||
@@ -167,77 +158,101 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getDamageByType(PartType t)
|
||||
public int getDamageByType( PartType t )
|
||||
{
|
||||
for (Entry<Integer, PartTypeIst> pt : this.dmgToPart.entrySet())
|
||||
for( Entry<Integer, PartTypeIst> pt : this.dmgToPart.entrySet() )
|
||||
{
|
||||
if ( pt.getValue().part == t )
|
||||
if( pt.getValue().part == t )
|
||||
return pt.getKey();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PartType getTypeByStack(ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
return null;
|
||||
|
||||
PartTypeIst pt = this.dmgToPart.get( is.getItemDamage() );
|
||||
if ( pt != null )
|
||||
return pt.part;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
public int getSpriteNumber()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int dmg)
|
||||
public IIcon getIconFromDamage( int dmg )
|
||||
{
|
||||
return this.dmgToPart.get( dmg ).ico;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName( ItemStack is )
|
||||
{
|
||||
return "item.appliedenergistics2." + this.getName( is );
|
||||
}
|
||||
|
||||
public String getName(ItemStack is)
|
||||
public String getName( ItemStack is )
|
||||
{
|
||||
return this.nameResolver.getName( this.getTypeByStack( is ).name() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PartType getTypeByStack( ItemStack is )
|
||||
{
|
||||
if( is == null )
|
||||
return null;
|
||||
|
||||
PartTypeIst pt = this.dmgToPart.get( is.getItemDamage() );
|
||||
if( pt != null )
|
||||
return pt.part;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
public String getItemStackDisplayName( ItemStack is )
|
||||
{
|
||||
PartType pt = this.getTypeByStack( is );
|
||||
if ( pt == null )
|
||||
if( pt == null )
|
||||
return "Unnamed";
|
||||
|
||||
if ( pt.isCable() )
|
||||
if( pt.isCable() )
|
||||
{
|
||||
final AEColor[] variants = AEColor.values();
|
||||
|
||||
return super.getItemStackDisplayName( is ) + " - " + variants[this.dmgToPart.get( is.getItemDamage() ).variant].toString();
|
||||
}
|
||||
|
||||
if ( pt.getExtraName() != null )
|
||||
if( pt.getExtraName() != null )
|
||||
return super.getItemStackDisplayName( is ) + " - " + pt.getExtraName().getLocal();
|
||||
|
||||
return super.getItemStackDisplayName( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister par1IconRegister)
|
||||
public void getSubItems( Item number, CreativeTabs tab, List cList )
|
||||
{
|
||||
for (Entry<Integer, PartTypeIst> part : this.dmgToPart.entrySet())
|
||||
List<Entry<Integer, PartTypeIst>> types = new ArrayList<Entry<Integer, PartTypeIst>>( this.dmgToPart.entrySet() );
|
||||
Collections.sort( types, new Comparator<Entry<Integer, PartTypeIst>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare( Entry<Integer, PartTypeIst> o1, Entry<Integer, PartTypeIst> o2 )
|
||||
{
|
||||
return o1.getValue().part.name().compareTo( o2.getValue().part.name() );
|
||||
}
|
||||
} );
|
||||
|
||||
for( Entry<Integer, PartTypeIst> part : types )
|
||||
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons( IIconRegister par1IconRegister )
|
||||
{
|
||||
for( Entry<Integer, PartTypeIst> part : this.dmgToPart.entrySet() )
|
||||
{
|
||||
String tex = "appliedenergistics2:" + this.getName( new ItemStack( this, 1, part.getKey() ) );
|
||||
part.getValue().ico = par1IconRegister.registerIcon( tex );
|
||||
@@ -245,60 +260,35 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPart createPartFromItemStack(ItemStack is)
|
||||
public IPart createPartFromItemStack( ItemStack is )
|
||||
{
|
||||
try
|
||||
{
|
||||
PartType t = this.getTypeByStack( is );
|
||||
if ( t != null )
|
||||
if( t != null )
|
||||
{
|
||||
if ( t.constructor == null )
|
||||
if( t.constructor == null )
|
||||
t.constructor = t.getPart().getConstructor( ItemStack.class );
|
||||
|
||||
return t.constructor.newInstance( is );
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
catch( Throwable e )
|
||||
{
|
||||
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + this.getTypeByStack( is ).getPart().getName()
|
||||
+ " ; Possibly didn't have correct constructor( ItemStack )", e );
|
||||
throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + this.getTypeByStack( is ).getPart().getName() + " ; Possibly didn't have correct constructor( ItemStack )", e );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item number, CreativeTabs tab, List cList)
|
||||
public int variantOf( int itemDamage )
|
||||
{
|
||||
List<Entry<Integer, PartTypeIst>> types = new ArrayList<Entry<Integer, PartTypeIst>>( this.dmgToPart.entrySet() );
|
||||
Collections.sort( types, new Comparator<Entry<Integer, PartTypeIst>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Entry<Integer, PartTypeIst> o1, Entry<Integer, PartTypeIst> o2)
|
||||
{
|
||||
return o1.getValue().part.name().compareTo( o2.getValue().part.name() );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
for (Entry<Integer, PartTypeIst> part : types)
|
||||
cList.add( new ItemStack( this, 1, part.getKey() ) );
|
||||
}
|
||||
|
||||
public int variantOf(int itemDamage)
|
||||
{
|
||||
if ( this.dmgToPart.containsKey( itemDamage ) )
|
||||
if( this.dmgToPart.containsKey( itemDamage ) )
|
||||
return this.dmgToPart.get( itemDamage ).variant;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is)
|
||||
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
|
||||
{
|
||||
boolean importBus = false;
|
||||
boolean exportBus = false;
|
||||
@@ -306,36 +296,45 @@ public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
|
||||
PartType u = this.getTypeByStack( is );
|
||||
|
||||
for (ItemStack stack : others)
|
||||
for( ItemStack stack : others )
|
||||
{
|
||||
if ( stack.getItem() == this )
|
||||
if( stack.getItem() == this )
|
||||
{
|
||||
PartType pt = this.getTypeByStack( stack );
|
||||
switch (pt)
|
||||
switch( pt )
|
||||
{
|
||||
case ImportBus:
|
||||
importBus = true;
|
||||
if ( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
case ExportBus:
|
||||
exportBus = true;
|
||||
if ( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
default:
|
||||
case ImportBus:
|
||||
importBus = true;
|
||||
if( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
case ExportBus:
|
||||
exportBus = true;
|
||||
if( u == pt )
|
||||
group = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( group && importBus && exportBus )
|
||||
if( group && importBus && exportBus )
|
||||
return GuiText.IOBuses.getUnlocalized();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getStackFromTypeAndVariant(PartType mt, int variant)
|
||||
public ItemStack getStackFromTypeAndVariant( PartType mt, int variant )
|
||||
{
|
||||
return new ItemStack( this, 1, mt.baseDamage + variant );
|
||||
}
|
||||
|
||||
private static class PartTypeIst
|
||||
{
|
||||
private PartType part;
|
||||
private int variant;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private IIcon ico;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user