Fixes #675 No disabled feature should log spam or crash anymore.

Deprecates the old usage of the AEItemDefinitions via the direct method access of

* blocks()
* parts()
* items()
* materials()

and thus use the new re-direct via definitions().

All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
thatsIch
2015-01-03 02:53:14 +01:00
parent 3dd81433ac
commit 9986ffc458
385 changed files with 12477 additions and 8292 deletions
+210 -178
View File
@@ -18,11 +18,14 @@
package appeng.parts.p2p;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
@@ -32,11 +35,14 @@ import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import com.google.common.base.Optional;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.PowerUnits;
import appeng.api.config.TunnelType;
import appeng.api.definitions.IParts;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.parts.IPart;
@@ -52,17 +58,158 @@ import appeng.me.cache.helpers.TunnelCollection;
import appeng.parts.PartBasicState;
import appeng.util.Platform;
public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
private final TunnelCollection type = new TunnelCollection<T>( null, this.getClass() );
public boolean output;
public long freq;
final TunnelCollection type = new TunnelCollection<T>( null, this.getClass() );
public PartP2PTunnel(ItemStack is) {
super( PartP2PTunnel.class, is );
if ( this.getClass() == PartP2PTunnel.class )
throw new RuntimeException( "Don't construct the root tunnel!" );
public PartP2PTunnel( ItemStack is )
{
super( is );
}
public TunnelCollection<T> getCollection( Collection<PartP2PTunnel> collection, Class<? extends PartP2PTunnel> c )
{
if ( this.type.matches( c ) )
{
this.type.setSource( collection );
return this.type;
}
return null;
}
public T getInput()
{
if ( this.freq == 0 )
return null;
PartP2PTunnel tunnel;
try
{
tunnel = this.proxy.getP2P().getInput( this.freq );
if ( this.getClass().isInstance( tunnel ) )
return (T) tunnel;
}
catch ( GridAccessException e )
{
// :P
}
return null;
}
public TunnelCollection<T> getOutputs() throws GridAccessException
{
if ( this.proxy.isActive() )
return (TunnelCollection<T>) this.proxy.getP2P().getOutputs( this.freq, this.getClass() );
return new TunnelCollection( new ArrayList(), this.getClass() );
}
@Override
@SideOnly( Side.CLIENT )
public void renderInventory( IPartRenderHelper rh, RenderBlocks renderer )
{
rh.setTexture( this.getTypeTexture() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderInventoryBox( renderer );
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(), this.is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderInventoryBox( renderer );
}
/**
* @return If enabled it returns the icon of an AE quatz block, else vanilla quartz block icon
*/
protected IIcon getTypeTexture()
{
final Optional<Block> maybeBlock = AEApi.instance().definitions().blocks().quartz().maybeBlock();
if ( maybeBlock.isPresent() )
{
return maybeBlock.get().getIcon( 0, 0 );
}
else
{
return Blocks.quartz_block.getIcon( 0, 0 );
}
}
@Override
@SideOnly( Side.CLIENT )
public void renderStatic( int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer )
{
this.renderCache = rh.useSimplifiedRendering( x, y, z, this, this.renderCache );
rh.setTexture( this.getTypeTexture() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderBlock( x, y, z, renderer );
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(), this.is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderBlock( x, y, z, renderer );
rh.setBounds( 3, 3, 13, 13, 13, 14 );
rh.renderBlock( x, y, z, renderer );
rh.setTexture( CableBusTextures.BlockP2PTunnel3.getIcon() );
rh.setBounds( 6, 5, 12, 10, 11, 13 );
rh.renderBlock( x, y, z, renderer );
rh.setBounds( 5, 6, 12, 11, 10, 13 );
rh.renderBlock( x, y, z, renderer );
this.renderLights( x, y, z, rh, renderer );
}
@Override
public ItemStack getItemStack( PartItemStack type )
{
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
return super.getItemStack( type );
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack( 1 );
if ( maybeMEStack.isPresent() )
{
return maybeMEStack.get();
}
return super.getItemStack( type );
}
@Override
public void readFromNBT( NBTTagCompound data )
{
super.readFromNBT( data );
this.output = data.getBoolean( "output" );
this.freq = data.getLong( "freq" );
}
@Override
public void writeToNBT( NBTTagCompound data )
{
super.writeToNBT( data );
data.setBoolean( "output", this.output );
data.setLong( "freq", this.freq );
}
@Override
public void getBoxes( IPartCollisionHelper bch )
{
bch.addBox( 5, 5, 12, 11, 11, 13 );
bch.addBox( 3, 3, 13, 13, 13, 14 );
bch.addBox( 2, 2, 14, 14, 14, 16 );
}
@Override
public int cableConnectionRenderTo()
{
return 1;
}
@Override
@@ -72,23 +219,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
}
@Override
public void writeToNBT(NBTTagCompound data)
{
super.writeToNBT( data );
data.setBoolean( "output", this.output );
data.setLong( "freq", this.freq );
}
@Override
public void readFromNBT(NBTTagCompound data)
{
super.readFromNBT( data );
this.output = data.getBoolean( "output" );
this.freq = data.getLong( "freq" );
}
@Override
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate( EntityPlayer player, Vec3 pos )
{
ItemStack is = player.inventory.getCurrentItem();
@@ -108,7 +239,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
if ( newType.getItem() instanceof IPartItem )
{
IPart testPart = ((IPartItem) newType.getItem()).createPartFromItemStack( newType );
IPart testPart = ( (IPartItem) newType.getItem() ).createPartFromItemStack( newType );
if ( testPart instanceof PartP2PTunnel )
{
this.getHost().removePart( this.side, true );
@@ -125,7 +256,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
P2PCache p2p = newTunnel.proxy.getP2P();
p2p.updateFreq( newTunnel, freq );
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
@@ -144,43 +275,61 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
ItemStack newType = null;
switch (tt)
final IParts parts = AEApi.instance().definitions().parts();
switch ( tt )
{
case LIGHT:
newType = AEApi.instance().parts().partP2PTunnelLight.stack( 1 );
break;
case LIGHT:
for ( ItemStack stack : parts.p2PTunnelLight().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case RF_POWER:
newType = AEApi.instance().parts().partP2PTunnelRF.stack( 1 );
break;
case RF_POWER:
for ( ItemStack stack : parts.p2PTunnelRF().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case BC_POWER:
newType = AEApi.instance().parts().partP2PTunnelMJ.stack( 1 );
break;
case FLUID:
for ( ItemStack stack : parts.p2PTunnelLiquids().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case FLUID:
newType = AEApi.instance().parts().partP2PTunnelLiquids.stack( 1 );
break;
case IC2_POWER:
for ( ItemStack stack : parts.p2PTunnelEU().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case IC2_POWER:
newType = AEApi.instance().parts().partP2PTunnelEU.stack( 1 );
break;
case ITEM:
for ( ItemStack stack : parts.p2PTunnelItems().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case ITEM:
newType = AEApi.instance().parts().partP2PTunnelItems.stack( 1 );
break;
case ME:
for ( ItemStack stack : parts.p2PTunnelME().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case ME:
newType = AEApi.instance().parts().partP2PTunnelME.stack( 1 );
break;
case REDSTONE:
newType = AEApi.instance().parts().partP2PTunnelRedstone.stack( 1 );
break;
default:
break;
case REDSTONE:
for ( ItemStack stack : parts.p2PTunnelRedstone().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
default:
break;
}
if ( newType != null && !Platform.isSameItem( newType, this.is ) )
@@ -203,7 +352,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
P2PCache p2p = newTunnel.proxy.getP2P();
p2p.updateFreq( newTunnel, myFreq );
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
@@ -217,13 +366,8 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
return false;
}
public TunnelType getTunnelType()
{
return null;
}
@Override
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
public boolean onPartShiftActivate( EntityPlayer player, Vec3 pos )
{
ItemStack is = player.inventory.getCurrentItem();
if ( is != null && is.getItem() instanceof IMemoryCard )
@@ -242,7 +386,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
this.proxy.getP2P().updateFreq( this, newFreq );
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
@@ -266,116 +410,19 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
}
@Override
public ItemStack getItemStack(PartItemStack type)
{
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
return super.getItemStack( type );
return AEApi.instance().parts().partP2PTunnelME.stack( 1 );
}
public TunnelCollection<T> getCollection(Collection<PartP2PTunnel> collection, Class<? extends PartP2PTunnel> c)
{
if ( this.type.matches( c ) )
{
this.type.setSource( collection );
return this.type;
}
return null;
}
public T getInput()
{
if ( this.freq == 0 )
return null;
PartP2PTunnel tunnel;
try
{
tunnel = this.proxy.getP2P().getInput( this.freq );
if ( this.getClass().isInstance( tunnel ) )
return (T) tunnel;
}
catch (GridAccessException e)
{
// :P
}
return null;
}
public TunnelCollection<T> getOutputs() throws GridAccessException
{
if ( this.proxy.isActive() )
return (TunnelCollection<T>) this.proxy.getP2P().getOutputs( this.freq, this.getClass() );
return new TunnelCollection( new ArrayList(), this.getClass() );
}
public void onTunnelNetworkChange()
{
}
@Override
@SideOnly(Side.CLIENT)
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
{
rh.setTexture( this.getTypeTexture() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderInventoryBox( renderer );
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
this.is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderInventoryBox( renderer );
}
protected IIcon getTypeTexture()
{
return AEApi.instance().blocks().blockQuartz.block().getIcon( 0, 0 );
}
@Override
@SideOnly(Side.CLIENT)
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
{
this.renderCache = rh.useSimplifiedRendering( x, y, z, this, this.renderCache );
rh.setTexture( this.getTypeTexture() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderBlock( x, y, z, renderer );
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
this.is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
rh.setBounds( 2, 2, 14, 14, 14, 16 );
rh.renderBlock( x, y, z, renderer );
rh.setBounds( 3, 3, 13, 13, 13, 14 );
rh.renderBlock( x, y, z, renderer );
rh.setTexture( CableBusTextures.BlockP2PTunnel3.getIcon() );
rh.setBounds( 6, 5, 12, 10, 11, 13 );
rh.renderBlock( x, y, z, renderer );
rh.setBounds( 5, 6, 12, 11, 10, 13 );
rh.renderBlock( x, y, z, renderer );
this.renderLights( x, y, z, rh, renderer );
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly( Side.CLIENT )
public IIcon getBreakingTexture()
{
return CableBusTextures.BlockP2PTunnel2.getIcon();
}
protected void QueueTunnelDrain(PowerUnits unit, double f)
protected void QueueTunnelDrain( PowerUnits unit, double f )
{
double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS );
@@ -383,24 +430,9 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
this.proxy.getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
}
@Override
public void getBoxes(IPartCollisionHelper bch)
{
bch.addBox( 5, 5, 12, 11, 11, 13 );
bch.addBox( 3, 3, 13, 13, 13, 14 );
bch.addBox( 2, 2, 14, 14, 14, 16 );
}
@Override
public int cableConnectionRenderTo()
{
return 1;
}
}