Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,13 +18,12 @@
|
||||
|
||||
package appeng.container.implementations;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -33,6 +32,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
@@ -62,78 +63,51 @@ import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.parts.reporting.PartTerminal;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ContainerCraftConfirm extends AEBaseContainer
|
||||
{
|
||||
|
||||
public final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
||||
final ITerminalHost priHost;
|
||||
public Future<ICraftingJob> job;
|
||||
public ICraftingJob result;
|
||||
|
||||
@GuiSync(0)
|
||||
@GuiSync( 0 )
|
||||
public long bytesUsed;
|
||||
|
||||
@GuiSync(1)
|
||||
@GuiSync( 1 )
|
||||
public long cpuBytesAvail;
|
||||
|
||||
@GuiSync(2)
|
||||
@GuiSync( 2 )
|
||||
public int cpuCoProcessors;
|
||||
|
||||
@GuiSync(3)
|
||||
@GuiSync( 3 )
|
||||
public boolean autoStart = false;
|
||||
|
||||
@GuiSync(4)
|
||||
@GuiSync( 4 )
|
||||
public boolean simulation = true;
|
||||
|
||||
@GuiSync(5)
|
||||
@GuiSync( 5 )
|
||||
public int selectedCpu = -1;
|
||||
|
||||
@GuiSync(6)
|
||||
@GuiSync( 6 )
|
||||
public boolean noCPU = true;
|
||||
|
||||
@GuiSync(7)
|
||||
@GuiSync( 7 )
|
||||
public String myName = "";
|
||||
|
||||
protected long cpuIdx = Long.MIN_VALUE;
|
||||
|
||||
public final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
||||
|
||||
public ContainerCraftConfirm(InventoryPlayer ip, ITerminalHost te) {
|
||||
public ContainerCraftConfirm( InventoryPlayer ip, ITerminalHost te )
|
||||
{
|
||||
super( ip, te );
|
||||
this.priHost = te;
|
||||
}
|
||||
|
||||
private void sendCPUs()
|
||||
public void cycleCpu( boolean next )
|
||||
{
|
||||
Collections.sort( this.cpus );
|
||||
|
||||
if ( this.selectedCpu >= this.cpus.size() )
|
||||
{
|
||||
this.selectedCpu = -1;
|
||||
this.cpuBytesAvail = 0;
|
||||
this.cpuCoProcessors = 0;
|
||||
this.myName = "";
|
||||
}
|
||||
else if ( this.selectedCpu != -1 )
|
||||
{
|
||||
this.myName = this.cpus.get( this.selectedCpu ).myName;
|
||||
this.cpuBytesAvail = this.cpus.get( this.selectedCpu ).size;
|
||||
this.cpuCoProcessors = this.cpus.get( this.selectedCpu ).processors;
|
||||
}
|
||||
}
|
||||
|
||||
public void cycleCpu(boolean next)
|
||||
{
|
||||
if ( next )
|
||||
if( next )
|
||||
this.selectedCpu++;
|
||||
else
|
||||
this.selectedCpu--;
|
||||
|
||||
if ( this.selectedCpu < -1 )
|
||||
if( this.selectedCpu < -1 )
|
||||
this.selectedCpu = this.cpus.size() - 1;
|
||||
else if ( this.selectedCpu >= this.cpus.size() )
|
||||
else if( this.selectedCpu >= this.cpus.size() )
|
||||
this.selectedCpu = -1;
|
||||
|
||||
if ( this.selectedCpu == -1 )
|
||||
if( this.selectedCpu == -1 )
|
||||
{
|
||||
this.cpuBytesAvail = 0;
|
||||
this.cpuCoProcessors = 0;
|
||||
@@ -150,7 +124,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
if( Platform.isClient() )
|
||||
return;
|
||||
|
||||
ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
|
||||
@@ -158,28 +132,28 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
|
||||
int matches = 0;
|
||||
boolean changed = false;
|
||||
for (ICraftingCPU c : cpuSet)
|
||||
for( ICraftingCPU c : cpuSet )
|
||||
{
|
||||
boolean found = false;
|
||||
for (CraftingCPURecord ccr : this.cpus)
|
||||
if ( ccr.cpu == c )
|
||||
for( CraftingCPURecord ccr : this.cpus )
|
||||
if( ccr.cpu == c )
|
||||
found = true;
|
||||
|
||||
boolean matched = this.cpuMatches( c );
|
||||
|
||||
if ( matched )
|
||||
if( matched )
|
||||
matches++;
|
||||
|
||||
if ( found == !matched )
|
||||
if( found == !matched )
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if ( changed || this.cpus.size() != matches )
|
||||
if( changed || this.cpus.size() != matches )
|
||||
{
|
||||
this.cpus.clear();
|
||||
for (ICraftingCPU c : cpuSet)
|
||||
for( ICraftingCPU c : cpuSet )
|
||||
{
|
||||
if ( this.cpuMatches( c ) )
|
||||
if( this.cpuMatches( c ) )
|
||||
this.cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
|
||||
}
|
||||
|
||||
@@ -190,16 +164,16 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if ( this.job != null && this.job.isDone() )
|
||||
if( this.job != null && this.job.isDone() )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.result = this.job.get();
|
||||
|
||||
if ( !this.result.isSimulation() )
|
||||
if( !this.result.isSimulation() )
|
||||
{
|
||||
this.simulation = false;
|
||||
if ( this.autoStart )
|
||||
if( this.autoStart )
|
||||
{
|
||||
this.startJob();
|
||||
return;
|
||||
@@ -219,7 +193,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
|
||||
this.bytesUsed = this.result.getByteTotal();
|
||||
|
||||
for (IAEItemStack out : plan)
|
||||
for( IAEItemStack out : plan )
|
||||
{
|
||||
IAEItemStack m = null;
|
||||
|
||||
@@ -234,12 +208,12 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
IStorageGrid sg = this.getGrid().getCache( IStorageGrid.class );
|
||||
IMEInventory<IAEItemStack> items = sg.getItemInventory();
|
||||
|
||||
if ( c != null && this.result.isSimulation() )
|
||||
if( c != null && this.result.isSimulation() )
|
||||
{
|
||||
m = o.copy();
|
||||
o = items.extractItems( o, Actionable.SIMULATE, this.mySrc );
|
||||
|
||||
if ( o == null )
|
||||
if( o == null )
|
||||
{
|
||||
o = m.copy();
|
||||
o.setStackSize( 0 );
|
||||
@@ -248,33 +222,33 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
m.setStackSize( m.getStackSize() - o.getStackSize() );
|
||||
}
|
||||
|
||||
if ( o.getStackSize() > 0 )
|
||||
if( o.getStackSize() > 0 )
|
||||
a.appendItem( o );
|
||||
|
||||
if ( p.getStackSize() > 0 )
|
||||
if( p.getStackSize() > 0 )
|
||||
b.appendItem( p );
|
||||
|
||||
if ( c != null && m != null && m.getStackSize() > 0 )
|
||||
if( c != null && m != null && m.getStackSize() > 0 )
|
||||
c.appendItem( m );
|
||||
}
|
||||
|
||||
for (Object g : this.crafters)
|
||||
for( Object g : this.crafters )
|
||||
{
|
||||
if ( g instanceof EntityPlayer )
|
||||
if( g instanceof EntityPlayer )
|
||||
{
|
||||
NetworkHandler.instance.sendTo( a, (EntityPlayerMP) g );
|
||||
NetworkHandler.instance.sendTo( b, (EntityPlayerMP) g );
|
||||
if ( c != null )
|
||||
if( c != null )
|
||||
NetworkHandler.instance.sendTo( c, (EntityPlayerMP) g );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
catch( IOException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
catch( Throwable e )
|
||||
{
|
||||
this.getPlayerInv().player.addChatMessage( new ChatComponentText( "Error: " + e.toString() ) );
|
||||
AELog.error( e );
|
||||
@@ -287,34 +261,59 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
this.verifyPermissions( SecurityPermissions.CRAFT, false );
|
||||
}
|
||||
|
||||
private boolean cpuMatches(ICraftingCPU c)
|
||||
public IGrid getGrid()
|
||||
{
|
||||
IActionHost h = ( (IActionHost) this.getTarget() );
|
||||
return h.getActionableNode().getGrid();
|
||||
}
|
||||
|
||||
private boolean cpuMatches( ICraftingCPU c )
|
||||
{
|
||||
return c.getAvailableStorage() >= this.bytesUsed && !c.isBusy();
|
||||
}
|
||||
|
||||
private void sendCPUs()
|
||||
{
|
||||
Collections.sort( this.cpus );
|
||||
|
||||
if( this.selectedCpu >= this.cpus.size() )
|
||||
{
|
||||
this.selectedCpu = -1;
|
||||
this.cpuBytesAvail = 0;
|
||||
this.cpuCoProcessors = 0;
|
||||
this.myName = "";
|
||||
}
|
||||
else if( this.selectedCpu != -1 )
|
||||
{
|
||||
this.myName = this.cpus.get( this.selectedCpu ).myName;
|
||||
this.cpuBytesAvail = this.cpus.get( this.selectedCpu ).size;
|
||||
this.cpuCoProcessors = this.cpus.get( this.selectedCpu ).processors;
|
||||
}
|
||||
}
|
||||
|
||||
public void startJob()
|
||||
{
|
||||
GuiBridge OriginalGui = null;
|
||||
|
||||
IActionHost ah = this.getActionHost();
|
||||
if ( ah instanceof WirelessTerminalGuiObject )
|
||||
if( ah instanceof WirelessTerminalGuiObject )
|
||||
OriginalGui = GuiBridge.GUI_WIRELESS_TERM;
|
||||
|
||||
if ( ah instanceof PartTerminal )
|
||||
if( ah instanceof PartTerminal )
|
||||
OriginalGui = GuiBridge.GUI_ME;
|
||||
|
||||
if ( ah instanceof PartCraftingTerminal )
|
||||
if( ah instanceof PartCraftingTerminal )
|
||||
OriginalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
|
||||
if ( ah instanceof PartPatternTerminal )
|
||||
if( ah instanceof PartPatternTerminal )
|
||||
OriginalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
|
||||
if ( this.result != null && !this.simulation )
|
||||
if( this.result != null && !this.simulation )
|
||||
{
|
||||
ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
|
||||
ICraftingLink g = cc.submitJob( this.result, null, this.selectedCpu == -1 ? null : this.cpus.get( this.selectedCpu ).cpu, true, this.getActionSrc() );
|
||||
this.autoStart = false;
|
||||
if ( g != null && OriginalGui != null && this.openContext != null )
|
||||
if( g != null && OriginalGui != null && this.openContext != null )
|
||||
{
|
||||
NetworkHandler.instance.sendTo( new PacketSwitchGuis( OriginalGui ), (EntityPlayerMP) this.invPlayer.player );
|
||||
|
||||
@@ -324,41 +323,35 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer par1EntityPlayer)
|
||||
public BaseActionSource getActionSrc()
|
||||
{
|
||||
super.onContainerClosed( par1EntityPlayer );
|
||||
if ( this.job != null )
|
||||
{
|
||||
this.job.cancel( true );
|
||||
this.job = null;
|
||||
}
|
||||
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingFromCrafters(ICrafting c)
|
||||
public void removeCraftingFromCrafters( ICrafting c )
|
||||
{
|
||||
super.removeCraftingFromCrafters( c );
|
||||
if ( this.job != null )
|
||||
if( this.job != null )
|
||||
{
|
||||
this.job.cancel( true );
|
||||
this.job = null;
|
||||
}
|
||||
}
|
||||
|
||||
public IGrid getGrid()
|
||||
@Override
|
||||
public void onContainerClosed( EntityPlayer par1EntityPlayer )
|
||||
{
|
||||
IActionHost h = ((IActionHost) this.getTarget());
|
||||
return h.getActionableNode().getGrid();
|
||||
super.onContainerClosed( par1EntityPlayer );
|
||||
if( this.job != null )
|
||||
{
|
||||
this.job.cancel( true );
|
||||
this.job = null;
|
||||
}
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return this.getPlayerInv().player.worldObj;
|
||||
}
|
||||
|
||||
public BaseActionSource getActionSrc()
|
||||
{
|
||||
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user