Tests parts before adding them.

Proxied IC2 Events.
This commit is contained in:
AlgorithmX2 2014-01-28 14:08:51 -06:00
parent f1aeca203d
commit 1a95fb5b0e
4 changed files with 31 additions and 15 deletions

View file

@ -177,7 +177,8 @@ public class Registration
if ( varients == null )
{
ItemStack is = ((ItemPart) partItem.item()).createPart( type, null );
f.set( parts, new DamagedItemDefinition( is ) );
if ( is != null )
f.set( parts, new DamagedItemDefinition( is ) );
}
else
{
@ -188,7 +189,8 @@ public class Registration
for (Enum v : varients)
{
ItemStack is = ((ItemPart) partItem.item()).createPart( type, v );
def.add( (AEColor) v, is );
if ( is != null )
def.add( (AEColor) v, is );
}
f.set( parts, def );

View file

@ -1,9 +1,11 @@
package appeng.integration.modules;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.recipe.RecipeInputItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import appeng.api.AEApi;
import appeng.integration.IIntegrationModule;
import appeng.integration.abstraction.IIC2;
@ -28,8 +30,7 @@ public class IC2 implements IIntegrationModule, IIC2
// certus quartz
maceratorRecipe( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) );
maceratorRecipe( AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( 1 ),
AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) );
maceratorRecipe( AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( 1 ), AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) );
// fluix
maceratorRecipe( AEApi.instance().materials().materialFluixCrystal.stack( 1 ), AEApi.instance().materials().materialFluixDust.stack( 1 ) );
@ -39,8 +40,9 @@ public class IC2 implements IIntegrationModule, IIC2
}
/*
* private void compressorRecipe(ItemStack in, ItemStack out) { ic2.api.recipe.Recipes.compressor.addRecipe( new
* RecipeInputItemStack( in, in.stackSize ), null, out ); }
* private void compressorRecipe(ItemStack in, ItemStack out) {
* ic2.api.recipe.Recipes.compressor.addRecipe( new RecipeInputItemStack(
* in, in.stackSize ), null, out ); }
*/
private void maceratorRecipe(ItemStack in, ItemStack out)
{
@ -50,15 +52,13 @@ public class IC2 implements IIntegrationModule, IIC2
@Override
public void addToEnergyNet(TileEntity appEngTile)
{
// TODO Auto-generated method stub
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) appEngTile ) );
}
@Override
public void removeFromEnergyNet(TileEntity appEngTile)
{
// TODO Auto-generated method stub
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) appEngTile ) );
}
@Override

View file

@ -48,6 +48,17 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
public ItemStack createPart(PartType mat, Enum varient)
{
try
{
ItemStack is = new ItemStack( this );
PartType t = getTypeByStack( is );
t.getPart().getConstructor( ItemStack.class ).newInstance( is );
}
catch (Throwable e)
{
return null; // part not supported..
}
String name = varient == null ? mat.name() : mat.name() + "." + varient.name();
int varID = varient == null ? 0 : varient.ordinal();

View file

@ -6,8 +6,9 @@ import java.util.EnumSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import appeng.api.config.PowerUnits;
import appeng.core.AppEng;
import appeng.integration.abstraction.IIC2;
import appeng.util.Platform;
import cpw.mods.fml.common.Optional.Interface;
@ -77,18 +78,20 @@ public abstract class IC2 extends BuildCraft implements IEnergySink
final private void addToENet()
{
if ( !isInIC2 && Platform.isServer() )
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( "IC2" );
if ( !isInIC2 && Platform.isServer() && ic2Integration != null )
{
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( this ) );
ic2Integration.addToEnergyNet( this );
isInIC2 = true;
}
}
final private void removeFromENet()
{
if ( isInIC2 && Platform.isServer() )
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( "IC2" );
if ( isInIC2 && Platform.isServer() && ic2Integration != null )
{
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( this ) );
ic2Integration.removeFromEnergyNet( this );
isInIC2 = false;
}
}