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