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:
@@ -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 )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user