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

140 lines
2.8 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 CraftingLinkNexus(String craftID) {
this.CraftID = craftID;
}
public final String CraftID;
boolean canceled = false;
boolean done = false;
int tickOfDeath = 0;
CraftingLink req;
CraftingLink cpu;
public boolean isDead(IGrid g, CraftingGridCache craftingGridCache)
{
if ( this.canceled || this.done )
return true;
2014-12-29 15:13:47 +01:00
if ( this.req == null || this.cpu == null )
this.tickOfDeath++;
else
{
2014-12-29 15:13:47 +01:00
boolean hasCpu = craftingGridCache.hasCpu( this.cpu.cpu );
boolean hasMachine = this.req.req.getActionableNode().getGrid() == g;
if ( hasCpu && hasMachine )
2014-12-29 15:13:47 +01:00
this.tickOfDeath = 0;
else
2014-12-29 15:13:47 +01:00
this.tickOfDeath += 60;
}
2014-12-29 15:13:47 +01:00
if ( this.tickOfDeath > 60 )
{
2014-12-29 15:13:47 +01:00
this.cancel();
return true;
}
return false;
}
public void remove(CraftingLink craftingLink)
{
2014-12-29 15:13:47 +01:00
if ( this.req == craftingLink )
this.req = null;
else if ( this.cpu == craftingLink )
this.cpu = null;
}
public void add(CraftingLink craftingLink)
{
if ( craftingLink.cpu != null )
2014-12-29 15:13:47 +01:00
this.cpu = craftingLink;
else if ( craftingLink.req != null )
2014-12-29 15:13:47 +01:00
this.req = craftingLink;
}
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;
2014-12-29 15:13:47 +01:00
if ( this.req != null )
{
2014-12-29 15:13:47 +01:00
this.req.done = true;
if ( this.req.req != null )
this.req.req.jobStateChange( this.req );
}
2014-12-29 15:13:47 +01:00
if ( this.cpu != null )
this.cpu.done = true;
}
public void cancel()
{
2014-12-29 15:13:47 +01:00
this.canceled = true;
2014-12-29 15:13:47 +01:00
if ( this.req != null )
{
2014-12-29 15:13:47 +01:00
this.req.canceled = true;
if ( this.req.req != null )
this.req.req.jobStateChange( this.req );
}
2014-12-29 15:13:47 +01:00
if ( this.cpu != null )
this.cpu.canceled = true;
}
public boolean isMachine(IGridHost machine)
{
2014-12-29 15:13:47 +01:00
return this.req == machine;
}
public void removeNode()
{
2014-12-29 15:13:47 +01:00
if ( this.req != null )
this.req.setNexus( null );
2014-12-29 15:13:47 +01:00
this.req = null;
this.tickOfDeath = 0;
}
}