2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.tile.misc;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
2014-09-25 22:30:19 +02:00
|
|
|
import appeng.api.config.Upgrades;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IComparableDefinition;
|
|
|
|
import appeng.api.definitions.ITileDefinition;
|
2015-04-05 20:16:02 +02:00
|
|
|
import appeng.api.features.IInscriberRecipe;
|
|
|
|
import appeng.api.features.InscriberProcessType;
|
2014-09-25 22:30:19 +02:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.energy.IEnergySource;
|
|
|
|
import appeng.api.networking.ticking.IGridTickable;
|
|
|
|
import appeng.api.networking.ticking.TickRateModulation;
|
|
|
|
import appeng.api.networking.ticking.TickingRequest;
|
|
|
|
import appeng.api.util.AECableType;
|
2014-09-25 22:30:19 +02:00
|
|
|
import appeng.api.util.IConfigManager;
|
2015-04-05 20:16:02 +02:00
|
|
|
import appeng.core.features.registries.entries.InscriberRecipe;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.core.settings.TickRates;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.helpers.Reflected;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.me.GridAccessException;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.parts.automation.DefinitionUpgradeInventory;
|
2014-09-25 22:30:19 +02:00
|
|
|
import appeng.parts.automation.UpgradeInventory;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.tile.TileEvent;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkPowerTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-09-25 22:30:19 +02:00
|
|
|
import appeng.util.ConfigManager;
|
|
|
|
import appeng.util.IConfigManagerHost;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.util.InventoryAdaptor;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.inv.WrapperInventoryRange;
|
|
|
|
import appeng.util.item.AEItemStack;
|
2017-04-12 16:10:13 +02:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
/**
|
|
|
|
* @author AlgorithmX2
|
|
|
|
* @author thatsIch
|
|
|
|
* @version rv2
|
|
|
|
* @since rv0
|
|
|
|
*/
|
2014-09-25 22:30:19 +02:00
|
|
|
public class TileInscriber extends AENetworkPowerTile implements IGridTickable, IUpgradeableHost, IConfigManagerHost
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final int maxProcessingTime = 100;
|
|
|
|
private final int[] top = { 0 };
|
|
|
|
private final int[] bottom = { 1 };
|
|
|
|
private final int[] sides = { 2, 3 };
|
|
|
|
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 );
|
2015-01-03 02:53:14 +01:00
|
|
|
private final IConfigManager settings;
|
|
|
|
private final UpgradeInventory upgrades;
|
2015-10-08 15:42:42 +02:00
|
|
|
private int processingTime = 0;
|
2014-09-24 02:26:27 +02:00
|
|
|
// cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine.
|
2015-10-08 15:42:42 +02:00
|
|
|
private boolean smash;
|
|
|
|
private int finalStep;
|
|
|
|
private long clientStart;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Reflected
|
|
|
|
public TileInscriber()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
this.setInternalMaxPower( 1500 );
|
|
|
|
this.getProxy().setIdlePowerUsage( 0 );
|
2015-01-03 02:53:14 +01:00
|
|
|
this.settings = new ConfigManager( this );
|
|
|
|
|
|
|
|
final ITileDefinition inscriberDefinition = AEApi.instance().definitions().blocks().inscriber();
|
|
|
|
this.upgrades = new DefinitionUpgradeInventory( inscriberDefinition, this, this.getUpgradeSlots() );
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private int getUpgradeSlots()
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
2014-09-25 22:30:19 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public AECableType getCableConnectionType( final ForgeDirection dir )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return AECableType.COVERED;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToNBT_TileInscriber( final NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.inv.writeToNBT( data, "inscriberInv" );
|
|
|
|
this.upgrades.writeToNBT( data, "upgrades" );
|
|
|
|
this.settings.writeToNBT( data );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_READ )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void readFromNBT_TileInscriber( final NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.inv.readFromNBT( data, "inscriberInv" );
|
|
|
|
this.upgrades.readFromNBT( data, "upgrades" );
|
|
|
|
this.settings.readFromNBT( data );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@TileEvent( TileEventType.NETWORK_READ )
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean readFromStream_TileInscriber( final ByteBuf data ) throws IOException
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int slot = data.readByte();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
final boolean oldSmash = this.isSmash();
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean newSmash = ( slot & 64 ) == 64;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( oldSmash != newSmash && newSmash )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setSmash( true );
|
|
|
|
this.setClientStart( System.currentTimeMillis() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( slot & ( 1 << num ) ) > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.inv.setInventorySlotContents( num, null );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@TileEvent( TileEventType.NETWORK_WRITE )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToStream_TileInscriber( final ByteBuf data ) throws IOException
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
int slot = this.isSmash() ? 64 : 0;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.inv.getStackInSlot( num ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-26 10:41:45 +01:00
|
|
|
slot |= ( 1 << num );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data.writeByte( slot );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( slot & ( 1 << num ) ) > 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEItemStack st = AEItemStack.create( this.inv.getStackInSlot( num ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
st.writeToPacket( data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void setOrientation( final ForgeDirection inForward, final ForgeDirection inUp )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
super.setOrientation( inForward, inUp );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setPowerSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void getDrops( final World w, final int x, final int y, final int z, final List<ItemStack> drops )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
super.getDrops( w, x, y, z, drops );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack is = this.upgrades.getStackInSlot( h );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
drops.add( is );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean requiresTESR()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return true;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
|
|
|
return this.inv;
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.isSmash() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i == 0 || i == 1 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEApi.instance().definitions().materials().namePress().isSameAs( itemstack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-05 20:16:02 +02:00
|
|
|
if( Platform.isSameItemPrecise( optionals, itemstack ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
return i == 2;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mc != InvOperation.markDirty )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( slot != 3 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( 0 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( !this.isSmash() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final GridAccessException e )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final int side )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.isSmash() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return slotIndex == 0 || slotIndex == 1 || slotIndex == 3;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int[] getAccessibleSlotsBySide( final ForgeDirection d )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( d == ForgeDirection.UP )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.top;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( d == ForgeDirection.DOWN )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.bottom;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
return this.sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public TickingRequest getTickingRequest( final IGridNode node )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return new TickingRequest( TickRates.Inscriber.getMin(), TickRates.Inscriber.getMax(), !this.hasWork(), false );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasWork()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.getTask() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( 0 );
|
|
|
|
return this.isSmash();
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
@Nullable
|
|
|
|
public IInscriberRecipe getTask()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack plateA = this.getStackInSlot( 0 );
|
|
|
|
final ItemStack plateB = this.getStackInSlot( 1 );
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack renamedItem = this.getStackInSlot( 2 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( plateA != null && plateA.stackSize > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( plateB != null && plateB.stackSize > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( renamedItem != null && renamedItem.stackSize > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
final IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress();
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean isNameA = namePress.isSameAs( plateA );
|
|
|
|
final boolean isNameB = namePress.isSameAs( plateB );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( isNameA || isNameB ) && ( isNameA || plateA == null ) && ( isNameB || plateB == null ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( renamedItem != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
String name = "";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( plateA != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound tag = Platform.openNbtData( plateA );
|
2014-09-24 02:26:27 +02:00
|
|
|
name += tag.getString( "InscribeName" );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( plateB != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound tag = Platform.openNbtData( plateB );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name.length() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
name += " ";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
name += tag.getString( "InscribeName" );
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack startingItem = renamedItem.copy();
|
2014-09-24 02:26:27 +02:00
|
|
|
renamedItem = renamedItem.copy();
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound tag = Platform.openNbtData( renamedItem );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound display = tag.getCompoundTag( "display" );
|
2014-09-24 02:26:27 +02:00
|
|
|
tag.setTag( "display", display );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name.length() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
display.setString( "Name", name );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
display.removeTag( "Name" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
final List<ItemStack> inputs = Lists.newArrayList( startingItem );
|
|
|
|
final InscriberProcessType type = InscriberProcessType.Inscribe;
|
|
|
|
|
|
|
|
return new InscriberRecipe( inputs, renamedItem, plateA, plateB, type );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean matchA = ( plateA == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateA, recipe.getTopOptional().orNull() ) ) && // and...
|
2017-04-12 16:10:13 +02:00
|
|
|
( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateB, recipe.getBottomOptional().orNull() ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateB, recipe.getTopOptional().orNull() ) ) && // and...
|
2017-04-12 16:10:13 +02:00
|
|
|
( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateA, recipe.getBottomOptional().orNull() ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( matchA || matchB )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ItemStack option : recipe.getInputs() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isSameItemPrecise( option, this.getStackInSlot( 2 ) ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-05 20:16:02 +02:00
|
|
|
return recipe;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.isSmash() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finalStep++;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.finalStep == 8 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-05 20:16:02 +02:00
|
|
|
final IInscriberRecipe out = this.getTask();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-05 20:16:02 +02:00
|
|
|
final ItemStack outputCopy = out.getOutput().copy();
|
2015-09-25 23:10:56 +02:00
|
|
|
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, 3, 1, true ), ForgeDirection.UNKNOWN );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
if( ad.addItems( outputCopy ) == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( 0 );
|
2015-04-05 20:16:02 +02:00
|
|
|
if( out.getProcessType() == InscriberProcessType.Press )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setInventorySlotContents( 0, null );
|
|
|
|
this.setInventorySlotContents( 1, null );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setInventorySlotContents( 2, null );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markDirty();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.finalStep == 16 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finalStep = 0;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setSmash( false );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final IEnergyGrid eg = this.getProxy().getEnergy();
|
2014-09-24 02:26:27 +02:00
|
|
|
IEnergySource src = this;
|
|
|
|
|
2014-09-25 22:30:19 +02:00
|
|
|
// Base 1, increase by 1 for each card
|
2015-09-25 23:10:56 +02:00
|
|
|
final int speedFactor = 1 + this.upgrades.getInstalledUpgrades( Upgrades.SPEED );
|
|
|
|
final int powerConsumption = 10 * speedFactor;
|
|
|
|
final double powerThreshold = powerConsumption - 0.01;
|
2014-12-29 15:13:47 +01:00
|
|
|
double powerReq = this.extractAEPower( powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( powerReq <= powerThreshold )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
src = eg;
|
2014-09-25 22:30:19 +02:00
|
|
|
powerReq = eg.extractAEPower( powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( powerReq > powerThreshold )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-09-25 22:30:19 +02:00
|
|
|
src.extractAEPower( powerConsumption, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.getProcessingTime() == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( this.getProcessingTime() + speedFactor );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( this.getProcessingTime() + ticksSinceLastCall * speedFactor );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final GridAccessException e )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.getProcessingTime() > this.getMaxProcessingTime() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setProcessingTime( this.getMaxProcessingTime() );
|
2015-09-25 23:10:56 +02:00
|
|
|
final IInscriberRecipe out = this.getTask();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack outputCopy = out.getOutput().copy();
|
|
|
|
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, 3, 1, true ), ForgeDirection.UNKNOWN );
|
2015-04-05 20:16:02 +02:00
|
|
|
if( ad.simulateAdd( outputCopy ) == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setSmash( true );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finalStep = 0;
|
|
|
|
this.markForUpdate();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2014-09-25 22:30:19 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.settings;
|
2014-09-25 22:30:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IInventory getInventoryByName( final String name )
|
2014-09-25 22:30:19 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name.equals( "inv" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.inv;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-25 22:30:19 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name.equals( "upgrades" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.upgrades;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-25 22:30:19 +02:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int getInstalledUpgrades( final Upgrades u )
|
2014-09-25 22:30:19 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.upgrades.getInstalledUpgrades( u );
|
2014-09-25 22:30:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
2014-09-25 22:30:19 +02:00
|
|
|
{
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
public long getClientStart()
|
|
|
|
{
|
|
|
|
return this.clientStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setClientStart( final long clientStart )
|
|
|
|
{
|
|
|
|
this.clientStart = clientStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSmash()
|
|
|
|
{
|
|
|
|
return this.smash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSmash( final boolean smash )
|
|
|
|
{
|
|
|
|
this.smash = smash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxProcessingTime()
|
|
|
|
{
|
|
|
|
return this.maxProcessingTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getProcessingTime()
|
|
|
|
{
|
|
|
|
return this.processingTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setProcessingTime( final int processingTime )
|
|
|
|
{
|
|
|
|
this.processingTime = processingTime;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|