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-08-05 05:33:26 +02:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
|
2015-05-09 13:06:09 +02:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingCPU;
|
|
|
|
import appeng.api.networking.crafting.ICraftingGrid;
|
|
|
|
import appeng.api.storage.ITerminalHost;
|
|
|
|
import appeng.container.guisync.GuiSync;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
public class ContainerCraftingStatus extends ContainerCraftingCPU
|
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
|
|
|
@GuiSync( 5 )
|
2014-08-05 05:33:26 +02:00
|
|
|
public int selectedCpu = -1;
|
2015-04-03 08:54:31 +02:00
|
|
|
@GuiSync( 6 )
|
2014-08-05 05:33:26 +02:00
|
|
|
public boolean noCPU = true;
|
2015-04-03 08:54:31 +02:00
|
|
|
@GuiSync( 7 )
|
2014-08-05 05:33:26 +02:00
|
|
|
public String myName = "";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public ContainerCraftingStatus( InventoryPlayer ip, ITerminalHost te )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
super( ip, te );
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ICraftingGrid cc = this.network.getCache( ICraftingGrid.class );
|
2014-08-05 05:33:26 +02:00
|
|
|
ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
|
|
|
|
|
|
|
|
int matches = 0;
|
|
|
|
boolean changed = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ICraftingCPU c : cpuSet )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
|
|
|
boolean found = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( CraftingCPURecord ccr : this.cpus )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ccr.cpu == c )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-05 05:33:26 +02:00
|
|
|
found = true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
boolean matched = this.cpuMatches( c );
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( matched )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-05 05:33:26 +02:00
|
|
|
matches++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( found == !matched )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-05 05:33:26 +02:00
|
|
|
changed = true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( changed || this.cpus.size() != matches )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.cpus.clear();
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ICraftingCPU c : cpuSet )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.cpuMatches( c ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.sendCPUs();
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:18:27 +02:00
|
|
|
this.noCPU = this.cpus.isEmpty();
|
2014-08-05 05:33:26 +02:00
|
|
|
|
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean cpuMatches( ICraftingCPU c )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
|
|
|
return c.isBusy();
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void sendCPUs()
|
|
|
|
{
|
|
|
|
Collections.sort( this.cpus );
|
|
|
|
|
|
|
|
if( this.selectedCpu >= this.cpus.size() )
|
|
|
|
{
|
|
|
|
this.selectedCpu = -1;
|
|
|
|
this.myName = "";
|
|
|
|
}
|
|
|
|
else if( this.selectedCpu != -1 )
|
|
|
|
{
|
|
|
|
this.myName = this.cpus.get( this.selectedCpu ).myName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( this.selectedCpu == -1 && this.cpus.size() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.selectedCpu = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( this.selectedCpu != -1 )
|
|
|
|
{
|
|
|
|
if( this.cpus.get( this.selectedCpu ).cpu != this.monitor )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.setCPU( this.cpus.get( this.selectedCpu ).cpu );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.setCPU( null );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public void cycleCpu( boolean next )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( next )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.selectedCpu++;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.selectedCpu--;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.selectedCpu < -1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.selectedCpu = this.cpus.size() - 1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.selectedCpu >= this.cpus.size() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.selectedCpu = -1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.selectedCpu == -1 && this.cpus.size() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.selectedCpu = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.selectedCpu == -1 )
|
2014-08-05 05:33:26 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myName = "";
|
|
|
|
this.setCPU( null );
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myName = this.cpus.get( this.selectedCpu ).myName;
|
|
|
|
this.setCPU( this.cpus.get( this.selectedCpu ).cpu );
|
2014-08-05 05:33:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|