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
@@ -34,6 +34,8 @@ import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.PowerUnits;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.implementations.tiles.ICrankable;
import appeng.api.storage.data.IAEItemStack;
@@ -124,6 +126,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
if ( myItem == null )
return;
final IMaterials materials = AEApi.instance().definitions().materials();
if ( this.internalCurrentPower > 149 && Platform.isChargeable( myItem ) )
{
IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
@@ -138,12 +142,16 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
this.tickTickTimer = 20; // keep ticking...
}
}
else if ( this.internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
else if ( this.internalCurrentPower > 1499 && materials.certusQuartzCrystal().isSameAs( myItem ) )
{
if ( Platform.getRandomFloat() > 0.8f ) // simulate wait
{
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
this.setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
for ( ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
{
this.setInventorySlotContents( 0, charged );
}
}
}
}
@@ -175,10 +183,19 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
this.injectExternalPower( PowerUnits.AE, 150 );
ItemStack myItem = this.getStackInSlot( 0 );
if ( this.internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
if ( this.internalCurrentPower > 1499 )
{
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
this.setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
final IMaterials materials = AEApi.instance().definitions().materials();
if ( materials.certusQuartzCrystal().isSameAs( myItem ) )
{
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
for ( ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
{
this.setInventorySlotContents( 0, charged );
}
}
}
}
@@ -215,7 +232,9 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return Platform.isChargeable( itemstack ) || AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( itemstack );
final IItemDefinition cert = AEApi.instance().definitions().materials().certusQuartzCrystal();
return Platform.isChargeable( itemstack ) || cert.isSameAs( itemstack );
}
@Override
@@ -228,7 +247,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
return true;
}
return AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( extractedItem );
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( extractedItem );
}
public void activate(EntityPlayer player)
@@ -240,7 +259,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
if ( myItem == null )
{
ItemStack held = player.inventory.getCurrentItem();
if ( AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( held ) || Platform.isChargeable( held ) )
if ( AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs( held ) || Platform.isChargeable( held ) )
{
held = player.inventory.decrStackSize( player.inventory.currentItem, 1 );
this.setInventorySlotContents( 0, held );
@@ -30,6 +30,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import appeng.api.AEApi;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IStorageComponent;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
@@ -102,7 +103,6 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
else
break;
}
}
private boolean canAddOutput(ItemStack output)
@@ -130,14 +130,24 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
private ItemStack getOutput()
{
final IMaterials materials = AEApi.instance().definitions().materials();
switch ((CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ))
{
case MATTER_BALLS:
return AEApi.instance().materials().materialMatterBall.stack( 1 );
case SINGULARITY:
return AEApi.instance().materials().materialSingularity.stack( 1 );
case TRASH:
default:
case MATTER_BALLS:
for ( ItemStack matterBallStack : materials.matterBall().maybeStack( 1 ).asSet() )
{
return matterBallStack;
}
case SINGULARITY:
for ( ItemStack singularityStack : materials.singularity().maybeStack( 1 ).asSet() )
{
return singularityStack;
}
case TRASH:
default:
}
return null;
}
+126 -128
View File
@@ -18,6 +18,7 @@
package appeng.tile.misc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
@@ -34,6 +35,8 @@ import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IComparableDefinition;
import appeng.api.definitions.ITileDefinition;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
@@ -44,7 +47,9 @@ import appeng.api.networking.ticking.TickingRequest;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.core.settings.TickRates;
import appeng.helpers.Reflected;
import appeng.me.GridAccessException;
import appeng.parts.automation.DefinitionUpgradeInventory;
import appeng.parts.automation.UpgradeInventory;
import appeng.recipes.handlers.Inscribe;
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
@@ -60,57 +65,69 @@ import appeng.util.Platform;
import appeng.util.inv.WrapperInventoryRange;
import appeng.util.item.AEItemStack;
public class TileInscriber extends AENetworkPowerTile implements IGridTickable, IUpgradeableHost, IConfigManagerHost
{
public final int maxProcessingTime = 100;
final int[] top = new int[] { 0 };
final int[] bottom = new int[] { 1 };
final int[] sides = new int[] { 2, 3 };
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 );
public final int maxProcessingTime = 100;
private final IConfigManager settings;
private final UpgradeInventory upgrades;
public int processingTime = 0;
// cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine.
public boolean smash;
public int finalStep;
public long clientStart;
static final ItemStack STACK_INSCRIBER = AEApi.instance().blocks().blockInscriber.stack( 1 );
private final IConfigManager settings = new ConfigManager( this );
private final UpgradeInventory upgrades = new UpgradeInventory( STACK_INSCRIBER, this, this.getUpgradeSlots() );
@Reflected
public TileInscriber()
{
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
this.internalMaxPower = 1500;
this.gridProxy.setIdlePowerUsage( 0 );
this.settings = new ConfigManager( this );
final ITileDefinition inscriberDefinition = AEApi.instance().definitions().blocks().inscriber();
this.upgrades = new DefinitionUpgradeInventory( inscriberDefinition, this, this.getUpgradeSlots() );
}
protected int getUpgradeSlots()
{
return 3;
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir)
public AECableType getCableConnectionType( ForgeDirection dir )
{
return AECableType.COVERED;
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void writeToNBT_TileInscriber(NBTTagCompound data)
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_TileInscriber( NBTTagCompound data )
{
this.inv.writeToNBT( data, "inscriberInv" );
this.upgrades.writeToNBT( data, "upgrades" );
this.settings.writeToNBT( data );
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBT_TileInscriber(NBTTagCompound data)
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_TileInscriber( NBTTagCompound data )
{
this.inv.readFromNBT( data, "inscriberInv" );
this.upgrades.readFromNBT( data, "upgrades" );
this.settings.readFromNBT( data );
}
@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream_TileInscriber(ByteBuf data) throws IOException
@TileEvent( TileEventType.NETWORK_READ )
public boolean readFromStream_TileInscriber( ByteBuf data ) throws IOException
{
int slot = data.readByte();
boolean oldSmash = this.smash;
boolean newSmash = (slot & 64) == 64;
boolean newSmash = ( slot & 64 ) == 64;
if ( oldSmash != newSmash && newSmash )
{
@@ -118,9 +135,9 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.clientStart = System.currentTimeMillis();
}
for (int num = 0; num < this.inv.getSizeInventory(); num++)
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
{
if ( (slot & (1 << num)) > 0 )
if ( ( slot & ( 1 << num ) ) > 0 )
this.inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
else
this.inv.setInventorySlotContents( num, null );
@@ -129,21 +146,21 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
return false;
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileInscriber(ByteBuf data) throws IOException
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileInscriber( ByteBuf data ) throws IOException
{
int slot = this.smash ? 64 : 0;
for (int num = 0; num < this.inv.getSizeInventory(); num++)
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
{
if ( this.inv.getStackInSlot( num ) != null )
slot |= ( 1 << num );
}
data.writeByte( slot );
for (int num = 0; num < this.inv.getSizeInventory(); num++)
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
{
if ( (slot & (1 << num)) > 0 )
if ( ( slot & ( 1 << num ) ) > 0 )
{
AEItemStack st = AEItemStack.create( this.inv.getStackInSlot( num ) );
st.writeToPacket( data );
@@ -151,45 +168,33 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
}
@Override
public void setOrientation( ForgeDirection inForward, ForgeDirection inUp )
{
super.setOrientation( inForward, inUp );
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
this.setPowerSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
}
@Override
public void getDrops( World w, int x, int y, int z, ArrayList<ItemStack> drops )
{
super.getDrops( w, x, y, z, drops );
for ( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
{
ItemStack is = this.upgrades.getStackInSlot( h );
if ( is != null )
drops.add( is );
}
}
@Override
public boolean requiresTESR()
{
return true;
}
public TileInscriber()
{
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
this.internalMaxPower = 1500;
this.gridProxy.setIdlePowerUsage( 0 );
}
@Override
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
{
super.setOrientation( inForward, inUp );
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
this.setPowerSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
}
@Override
public IInventory getInternalInventory()
{
return this.inv;
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection d)
{
if ( d == ForgeDirection.UP )
return this.top;
if ( d == ForgeDirection.DOWN )
return this.bottom;
return this.sides;
}
@Override
public int getInventoryStackLimit()
{
@@ -197,30 +202,24 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
if ( this.smash )
return false;
if ( i == 0 || i == 1 )
{
if ( AEApi.instance().materials().materialNamePress.sameAsStack( itemstack ) )
if ( AEApi.instance().definitions().materials().namePress().isSameAs( itemstack ) )
{
return true;
}
for (ItemStack s : Inscribe.PLATES )
for ( ItemStack s : Inscribe.PLATES )
if ( Platform.isSameItemPrecise( s, itemstack ) )
return true;
}
if ( i == 2 )
{
return true;
// for (ItemStack s : Inscribe.inputs)
// if ( Platform.isSameItemPrecise( s, itemstack ) )
// return true;
}
return false;
return i == 2;
}
@Override
@@ -233,7 +232,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
public IInventory getInternalInventory()
{
return this.inv;
}
@Override
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
{
try
{
@@ -248,45 +253,73 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
}
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
}
@Override
public int[] getAccessibleSlotsBySide( ForgeDirection d )
{
if ( d == ForgeDirection.UP )
return this.top;
if ( d == ForgeDirection.DOWN )
return this.bottom;
return this.sides;
}
@Override
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !this.hasWork(), false );
}
private boolean hasWork()
{
if ( this.getTask() != null )
return true;
this.processingTime = 0;
return this.smash;
}
public InscriberRecipe getTask()
{
ItemStack PlateA = this.getStackInSlot( 0 );
ItemStack PlateB = this.getStackInSlot( 1 );
ItemStack plateA = this.getStackInSlot( 0 );
ItemStack plateB = this.getStackInSlot( 1 );
ItemStack renamedItem = this.getStackInSlot( 2 );
if ( PlateA != null && PlateA.stackSize > 1 )
if ( plateA != null && plateA.stackSize > 1 )
return null;
if ( PlateB != null && PlateB.stackSize > 1 )
if ( plateB != null && plateB.stackSize > 1 )
return null;
if ( renamedItem != null && renamedItem.stackSize > 1 )
return null;
boolean isNameA = AEApi.instance().materials().materialNamePress.sameAsStack( PlateA );
boolean isNameB = AEApi.instance().materials().materialNamePress.sameAsStack( PlateB );
final IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress();
boolean isNameA = namePress.isSameAs( plateA );
boolean isNameB = namePress.isSameAs( plateB );
if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) )
if ( ( isNameA || isNameB ) && ( isNameA || plateA == null ) && ( isNameB || plateB == null ) )
{
if ( renamedItem != null )
{
String name = "";
if ( PlateA != null )
if ( plateA != null )
{
NBTTagCompound tag = Platform.openNbtData( PlateA );
NBTTagCompound tag = Platform.openNbtData( plateA );
name += tag.getString( "InscribeName" );
}
if ( PlateB != null )
if ( plateB != null )
{
NBTTagCompound tag = Platform.openNbtData( PlateB );
NBTTagCompound tag = Platform.openNbtData( plateB );
if ( name.length() > 0 )
name += " ";
name += tag.getString( "InscribeName" );
@@ -304,49 +337,33 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
else
display.removeTag( "Name" );
return new InscriberRecipe( new ItemStack[] { startingItem }, PlateA, PlateB, renamedItem, false );
return new InscriberRecipe( new ItemStack[] { startingItem }, plateA, plateB, renamedItem, false );
}
}
for (InscriberRecipe i : Inscribe.RECIPES )
for ( InscriberRecipe i : Inscribe.RECIPES )
{
boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and...
(PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB ));
boolean matchA = ( plateA == null && i.plateA == null ) || ( Platform.isSameItemPrecise( plateA, i.plateA ) ) && // and...
( plateB == null && i.plateB == null ) | ( Platform.isSameItemPrecise( plateB, i.plateB ) );
boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and...
(PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB ));
boolean matchB = ( plateB == null && i.plateA == null ) || ( Platform.isSameItemPrecise( plateB, i.plateA ) ) && // and...
( plateA == null && i.plateB == null ) | ( Platform.isSameItemPrecise( plateA, i.plateB ) );
if ( matchA || matchB )
{
for (ItemStack option : i.imprintable)
for ( ItemStack option : i.imprintable )
{
if ( Platform.isSameItemPrecise( option, this.getStackInSlot( 2 ) ) )
return i;
}
}
}
return null;
}
private boolean hasWork()
{
if ( this.getTask() != null )
return true;
this.processingTime = 0;
return this.smash;
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !this.hasWork(), false );
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
{
if ( this.smash )
{
@@ -374,7 +391,6 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
this.markDirty();
}
else if ( this.finalStep == 16 )
{
@@ -413,7 +429,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.processingTime += TicksSinceLastCall * speedFactor;
}
}
catch (GridAccessException e)
catch ( GridAccessException e )
{
// :P
}
@@ -446,7 +462,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public IInventory getInventoryByName(String name)
public IInventory getInventoryByName( String name )
{
if ( name.equals( "inv" ) )
return this.inv;
@@ -458,31 +474,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public int getInstalledUpgrades(Upgrades u)
public int getInstalledUpgrades( Upgrades u )
{
return this.upgrades.getInstalledUpgrades( u );
}
protected int getUpgradeSlots()
{
return 3;
}
@Override
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
{
super.getDrops( w, x, y, z, drops );
for (int h = 0; h < this.upgrades.getSizeInventory(); h++)
{
ItemStack is = this.upgrades.getStackInSlot( h );
if ( is != null )
drops.add( is );
}
}
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
}
}