Applied-Energistics-2-tiler.../src/main/java/appeng/crafting/CraftingLink.java

168 lines
3.7 KiB
Java
Raw Normal View History

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>.
*/
package appeng.crafting;
import net.minecraft.nbt.NBTTagCompound;
2014-12-29 21:59:05 +01:00
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.storage.data.IAEItemStack;
public class CraftingLink implements ICraftingLink
{
final ICraftingRequester req;
final ICraftingCPU cpu;
final String CraftID;
final boolean standalone;
boolean canceled = false;
boolean done = false;
CraftingLinkNexus tie;
public CraftingLink( NBTTagCompound data, ICraftingRequester req )
{
2014-12-29 15:13:47 +01:00
this.CraftID = data.getString( "CraftID" );
this.canceled = data.getBoolean( "canceled" );
this.done = data.getBoolean( "done" );
this.standalone = data.getBoolean( "standalone" );
if( !data.hasKey( "req" ) || !data.getBoolean( "req" ) )
throw new IllegalStateException( "Invalid Crafting Link for Object" );
this.req = req;
2014-12-29 15:13:47 +01:00
this.cpu = null;
}
public CraftingLink( NBTTagCompound data, ICraftingCPU cpu )
{
2014-12-29 15:13:47 +01:00
this.CraftID = data.getString( "CraftID" );
this.canceled = data.getBoolean( "canceled" );
this.done = data.getBoolean( "done" );
this.standalone = data.getBoolean( "standalone" );
if( !data.hasKey( "req" ) || data.getBoolean( "req" ) )
throw new IllegalStateException( "Invalid Crafting Link for Object" );
this.cpu = cpu;
2014-12-29 15:13:47 +01:00
this.req = null;
}
@Override
public boolean isCanceled()
{
if( this.canceled )
return true;
if( this.done )
return false;
if( this.tie == null )
return false;
2014-12-29 15:13:47 +01:00
return this.tie.isCanceled();
}
@Override
public boolean isDone()
{
if( this.done )
return true;
if( this.canceled )
return false;
if( this.tie == null )
return false;
2014-12-29 15:13:47 +01:00
return this.tie.isDone();
}
@Override
public void cancel()
{
if( this.done )
return;
2014-12-29 15:13:47 +01:00
this.canceled = true;
if( this.tie != null )
2014-12-29 15:13:47 +01:00
this.tie.cancel();
2014-12-29 15:13:47 +01:00
this.tie = null;
}
@Override
public boolean isStandalone()
{
return this.standalone;
}
@Override
public void writeToNBT( NBTTagCompound tag )
{
2014-12-29 15:13:47 +01:00
tag.setString( "CraftID", this.CraftID );
tag.setBoolean( "canceled", this.canceled );
tag.setBoolean( "done", this.done );
tag.setBoolean( "standalone", this.standalone );
tag.setBoolean( "req", this.req != null );
}
@Override
public String getCraftingID()
{
return this.CraftID;
}
public void setNexus( CraftingLinkNexus n )
{
if( this.tie != null )
2014-12-29 15:13:47 +01:00
this.tie.remove( this );
if( this.canceled && n != null )
{
n.cancel();
2014-12-29 15:13:47 +01:00
this.tie = null;
return;
}
2014-12-29 15:13:47 +01:00
this.tie = n;
if( n != null )
n.add( this );
}
public IAEItemStack injectItems( IAEItemStack input, Actionable mode )
{
if( this.tie == null || this.tie.req == null || this.tie.req.req == null )
return input;
2014-12-29 15:13:47 +01:00
return this.tie.req.req.injectCraftedItems( this.tie.req, input, mode );
}
public void markDone()
{
if( this.tie != null )
2014-12-29 15:13:47 +01:00
this.tie.markDone();
}
}