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

165 lines
3 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 appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.me.cache.CraftingGridCache;
public class CraftingLinkNexus
{
public final String CraftID;
boolean canceled = false;
boolean done = false;
int tickOfDeath = 0;
CraftingLink req;
CraftingLink cpu;
public CraftingLinkNexus( final String craftID )
{
this.CraftID = craftID;
}
public boolean isDead( final IGrid g, final CraftingGridCache craftingGridCache )
{
if( this.canceled || this.done )
2015-04-29 02:30:53 +02:00
{
return true;
2015-04-29 02:30:53 +02:00
}
if( this.req == null || this.cpu == null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.tickOfDeath++;
2015-04-29 02:30:53 +02:00
}
else
{
final boolean hasCpu = craftingGridCache.hasCpu( this.cpu.cpu );
final boolean hasMachine = this.req.req.getActionableNode().getGrid() == g;
if( hasCpu && hasMachine )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.tickOfDeath = 0;
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.tickOfDeath += 60;
2015-04-29 02:30:53 +02:00
}
}
if( this.tickOfDeath > 60 )
{
2014-12-29 15:13:47 +01:00
this.cancel();
return true;
}
return false;
}
public void cancel()
{
this.canceled = true;
if( this.req != null )
{
this.req.canceled = true;
if( this.req.req != null )
2015-04-29 02:30:53 +02:00
{
this.req.req.jobStateChange( this.req );
2015-04-29 02:30:53 +02:00
}
}
if( this.cpu != null )
2015-04-29 02:30:53 +02:00
{
this.cpu.canceled = true;
2015-04-29 02:30:53 +02:00
}
}
public void remove( final CraftingLink craftingLink )
{
if( this.req == craftingLink )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.req = null;
2015-04-29 02:30:53 +02:00
}
else if( this.cpu == craftingLink )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.cpu = null;
2015-04-29 02:30:53 +02:00
}
}
public void add( final CraftingLink craftingLink )
{
if( craftingLink.cpu != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.cpu = craftingLink;
2015-04-29 02:30:53 +02:00
}
else if( craftingLink.req != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.req = craftingLink;
2015-04-29 02:30:53 +02:00
}
}
public boolean isCanceled()
{
2014-12-29 15:13:47 +01:00
return this.canceled;
}
public boolean isDone()
{
2014-12-29 15:13:47 +01:00
return this.done;
}
public void markDone()
{
2014-12-29 15:13:47 +01:00
this.done = true;
if( this.req != null )
{
2014-12-29 15:13:47 +01:00
this.req.done = true;
if( this.req.req != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.req.req.jobStateChange( this.req );
2015-04-29 02:30:53 +02:00
}
}
if( this.cpu != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.cpu.done = true;
2015-04-29 02:30:53 +02:00
}
}
public boolean isMachine( final IGridHost machine )
{
2014-12-29 15:13:47 +01:00
return this.req == machine;
}
public void removeNode()
{
if( this.req != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.req.setNexus( null );
2015-04-29 02:30:53 +02:00
}
2014-12-29 15:13:47 +01:00
this.req = null;
this.tickOfDeath = 0;
}
}