Applied-Energistics-2-tiler.../src/main/java/appeng/container/implementations/ContainerCraftingStatus.java

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