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-07-04 08:19:35 +02:00
|
|
|
package appeng.crafting;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-07-05 18:53:16 +02:00
|
|
|
import appeng.api.config.Actionable;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingCPU;
|
|
|
|
import appeng.api.networking.crafting.ICraftingLink;
|
|
|
|
import appeng.api.networking.crafting.ICraftingRequester;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
public class CraftingLink implements ICraftingLink
|
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final ICraftingRequester req;
|
|
|
|
private final ICraftingCPU cpu;
|
|
|
|
private final String CraftID;
|
|
|
|
private final boolean standalone;
|
|
|
|
private boolean canceled = false;
|
|
|
|
private boolean done = false;
|
|
|
|
private CraftingLinkNexus tie;
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public CraftingLink( final NBTTagCompound data, final ICraftingRequester req )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.CraftID = data.getString( "CraftID" );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCanceled( data.getBoolean( "canceled" ) );
|
|
|
|
this.setDone( data.getBoolean( "done" ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.standalone = data.getBoolean( "standalone" );
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !data.hasKey( "req" ) || !data.getBoolean( "req" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Invalid Crafting Link for Object" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
|
|
|
this.req = req;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.cpu = null;
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public CraftingLink( final NBTTagCompound data, final ICraftingCPU cpu )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.CraftID = data.getString( "CraftID" );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCanceled( data.getBoolean( "canceled" ) );
|
|
|
|
this.setDone( data.getBoolean( "done" ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.standalone = data.getBoolean( "standalone" );
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !data.hasKey( "req" ) || data.getBoolean( "req" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Invalid Crafting Link for Object" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
|
|
|
this.cpu = cpu;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.req = null;
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCanceled()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.canceled )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.done )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tie == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.tie.isCanceled();
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDone()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.done )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.canceled )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tie == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.tie.isDone();
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancel()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.done )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCanceled( true );
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tie != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie.cancel();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie = null;
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isStandalone()
|
|
|
|
{
|
|
|
|
return this.standalone;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToNBT( final NBTTagCompound tag )
|
2014-07-04 08:19:35 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
tag.setString( "CraftID", this.CraftID );
|
2015-10-08 15:42:42 +02:00
|
|
|
tag.setBoolean( "canceled", this.isCanceled() );
|
|
|
|
tag.setBoolean( "done", this.isDone() );
|
2014-12-29 15:13:47 +01:00
|
|
|
tag.setBoolean( "standalone", this.standalone );
|
2015-10-08 15:42:42 +02:00
|
|
|
tag.setBoolean( "req", this.getRequester() != null );
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public String getCraftingID()
|
2014-07-04 08:19:35 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.CraftID;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public void setNexus( final CraftingLinkNexus n )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( this.tie != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie.remove( this );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.isCanceled() && n != null )
|
2014-07-04 08:19:35 +02:00
|
|
|
{
|
|
|
|
n.cancel();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie = null;
|
2014-07-04 08:19:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie = n;
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
n.add( this );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode )
|
2014-07-04 08:19:35 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.tie == null || this.tie.getRequest() == null || this.tie.getRequest().getRequester() == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return input;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.tie.getRequest().getRequester().injectCraftedItems( this.tie.getRequest(), input, mode );
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void markDone()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tie != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tie.markDone();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
void setCanceled( final boolean canceled )
|
|
|
|
{
|
|
|
|
this.canceled = canceled;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICraftingRequester getRequester()
|
|
|
|
{
|
|
|
|
return this.req;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICraftingCPU getCpu()
|
|
|
|
{
|
|
|
|
return this.cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDone( final boolean done )
|
|
|
|
{
|
|
|
|
this.done = done;
|
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|