Reduces visibility of internal fields/methods
Reduces the visibility of all fields to private and create setters/getters when necessary. Exceptions are fields with GuiSync as these need to be public. Reduces the visibility of internal methods to private/protected/default when possible.
This commit is contained in:
@@ -24,6 +24,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -31,6 +35,7 @@ import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
@@ -60,16 +65,13 @@ import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.parts.reporting.PartTerminal;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
|
||||
public class ContainerCraftConfirm extends AEBaseContainer
|
||||
{
|
||||
|
||||
public final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
||||
final ITerminalHost priHost;
|
||||
public Future<ICraftingJob> job;
|
||||
public ICraftingJob result;
|
||||
private final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
||||
private Future<ICraftingJob> job;
|
||||
private ICraftingJob result;
|
||||
@GuiSync( 0 )
|
||||
public long bytesUsed;
|
||||
@GuiSync( 1 )
|
||||
@@ -86,45 +88,43 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
public boolean noCPU = true;
|
||||
@GuiSync( 7 )
|
||||
public String myName = "";
|
||||
protected long cpuIdx = Long.MIN_VALUE;
|
||||
|
||||
public ContainerCraftConfirm( final InventoryPlayer ip, final ITerminalHost te )
|
||||
{
|
||||
super( ip, te );
|
||||
this.priHost = te;
|
||||
}
|
||||
|
||||
public void cycleCpu( final boolean next )
|
||||
{
|
||||
if( next )
|
||||
{
|
||||
this.selectedCpu++;
|
||||
this.setSelectedCpu( this.getSelectedCpu() + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.selectedCpu--;
|
||||
this.setSelectedCpu( this.getSelectedCpu() - 1 );
|
||||
}
|
||||
|
||||
if( this.selectedCpu < -1 )
|
||||
if( this.getSelectedCpu() < -1 )
|
||||
{
|
||||
this.selectedCpu = this.cpus.size() - 1;
|
||||
this.setSelectedCpu( this.cpus.size() - 1 );
|
||||
}
|
||||
else if( this.selectedCpu >= this.cpus.size() )
|
||||
else if( this.getSelectedCpu() >= this.cpus.size() )
|
||||
{
|
||||
this.selectedCpu = -1;
|
||||
this.setSelectedCpu( -1 );
|
||||
}
|
||||
|
||||
if( this.selectedCpu == -1 )
|
||||
if( this.getSelectedCpu() == -1 )
|
||||
{
|
||||
this.cpuBytesAvail = 0;
|
||||
this.cpuCoProcessors = 0;
|
||||
this.myName = "";
|
||||
this.setCpuAvailableBytes( 0 );
|
||||
this.setCpuCoProcessors( 0 );
|
||||
this.setName( "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myName = this.cpus.get( this.selectedCpu ).myName;
|
||||
this.cpuBytesAvail = this.cpus.get( this.selectedCpu ).size;
|
||||
this.cpuCoProcessors = this.cpus.get( this.selectedCpu ).processors;
|
||||
this.setName( this.cpus.get( this.getSelectedCpu() ).getName() );
|
||||
this.setCpuAvailableBytes( this.cpus.get( this.getSelectedCpu() ).getSize() );
|
||||
this.setCpuCoProcessors( this.cpus.get( this.getSelectedCpu() ).getProcessors() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
boolean found = false;
|
||||
for( final CraftingCPURecord ccr : this.cpus )
|
||||
{
|
||||
if( ccr.cpu == c )
|
||||
if( ccr.getCpu() == c )
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
@@ -179,20 +179,20 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
this.sendCPUs();
|
||||
}
|
||||
|
||||
this.noCPU = this.cpus.isEmpty();
|
||||
this.setNoCPU( this.cpus.isEmpty() );
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if( this.job != null && this.job.isDone() )
|
||||
if( this.getJob() != null && this.getJob().isDone() )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.result = this.job.get();
|
||||
this.result = this.getJob().get();
|
||||
|
||||
if( !this.result.isSimulation() )
|
||||
{
|
||||
this.simulation = false;
|
||||
if( this.autoStart )
|
||||
this.setSimulation( false );
|
||||
if( this.isAutoStart() )
|
||||
{
|
||||
this.startJob();
|
||||
return;
|
||||
@@ -200,7 +200,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
}
|
||||
else
|
||||
{
|
||||
this.simulation = true;
|
||||
this.setSimulation( true );
|
||||
}
|
||||
|
||||
try
|
||||
@@ -212,7 +212,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
final IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
|
||||
this.result.populatePlan( plan );
|
||||
|
||||
this.bytesUsed = this.result.getByteTotal();
|
||||
this.setUsedBytes( this.result.getByteTotal() );
|
||||
|
||||
for( final IAEItemStack out : plan )
|
||||
{
|
||||
@@ -232,7 +232,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
if( c != null && this.result.isSimulation() )
|
||||
{
|
||||
m = o.copy();
|
||||
o = items.extractItems( o, Actionable.SIMULATE, this.mySrc );
|
||||
o = items.extractItems( o, Actionable.SIMULATE, this.getActionSource() );
|
||||
|
||||
if( o == null )
|
||||
{
|
||||
@@ -281,16 +281,16 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
{
|
||||
this.getPlayerInv().player.addChatMessage( new ChatComponentText( "Error: " + e.toString() ) );
|
||||
AELog.error( e );
|
||||
this.isContainerValid = false;
|
||||
this.setValidContainer( false );
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
this.job = null;
|
||||
this.setJob( null );
|
||||
}
|
||||
this.verifyPermissions( SecurityPermissions.CRAFT, false );
|
||||
}
|
||||
|
||||
public IGrid getGrid()
|
||||
private IGrid getGrid()
|
||||
{
|
||||
final IActionHost h = ( (IActionHost) this.getTarget() );
|
||||
return h.getActionableNode().getGrid();
|
||||
@@ -298,25 +298,25 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
|
||||
private boolean cpuMatches( final ICraftingCPU c )
|
||||
{
|
||||
return c.getAvailableStorage() >= this.bytesUsed && !c.isBusy();
|
||||
return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy();
|
||||
}
|
||||
|
||||
private void sendCPUs()
|
||||
{
|
||||
Collections.sort( this.cpus );
|
||||
|
||||
if( this.selectedCpu >= this.cpus.size() )
|
||||
if( this.getSelectedCpu() >= this.cpus.size() )
|
||||
{
|
||||
this.selectedCpu = -1;
|
||||
this.cpuBytesAvail = 0;
|
||||
this.cpuCoProcessors = 0;
|
||||
this.myName = "";
|
||||
this.setSelectedCpu( -1 );
|
||||
this.setCpuAvailableBytes( 0 );
|
||||
this.setCpuCoProcessors( 0 );
|
||||
this.setName( "" );
|
||||
}
|
||||
else if( this.selectedCpu != -1 )
|
||||
else if( this.getSelectedCpu() != -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;
|
||||
this.setName( this.cpus.get( this.getSelectedCpu() ).getName() );
|
||||
this.setCpuAvailableBytes( this.cpus.get( this.getSelectedCpu() ).getSize() );
|
||||
this.setCpuCoProcessors( this.cpus.get( this.getSelectedCpu() ).getProcessors() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,22 +345,22 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
|
||||
if( this.result != null && !this.simulation )
|
||||
if( this.result != null && !this.isSimulation() )
|
||||
{
|
||||
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
|
||||
final 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 )
|
||||
final ICraftingLink g = cc.submitJob( this.result, null, this.getSelectedCpu() == -1 ? null : this.cpus.get( this.getSelectedCpu() ).getCpu(), true, this.getActionSrc() );
|
||||
this.setAutoStart( false );
|
||||
if( g != null && originalGui != null && this.getOpenContext() != null )
|
||||
{
|
||||
NetworkHandler.instance.sendTo( new PacketSwitchGuis( originalGui ), (EntityPlayerMP) this.invPlayer.player );
|
||||
NetworkHandler.instance.sendTo( new PacketSwitchGuis( originalGui ), (EntityPlayerMP) this.getInventoryPlayer().player );
|
||||
|
||||
final TileEntity te = this.openContext.getTile();
|
||||
Platform.openGUI( this.invPlayer.player, te, this.openContext.side, originalGui );
|
||||
final TileEntity te = this.getOpenContext().getTile();
|
||||
Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseActionSource getActionSrc()
|
||||
private BaseActionSource getActionSrc()
|
||||
{
|
||||
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
|
||||
}
|
||||
@@ -369,10 +369,10 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
public void removeCraftingFromCrafters( final ICrafting c )
|
||||
{
|
||||
super.removeCraftingFromCrafters( c );
|
||||
if( this.job != null )
|
||||
if( this.getJob() != null )
|
||||
{
|
||||
this.job.cancel( true );
|
||||
this.job = null;
|
||||
this.getJob().cancel( true );
|
||||
this.setJob( null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,10 +380,10 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
public void onContainerClosed( final EntityPlayer par1EntityPlayer )
|
||||
{
|
||||
super.onContainerClosed( par1EntityPlayer );
|
||||
if( this.job != null )
|
||||
if( this.getJob() != null )
|
||||
{
|
||||
this.job.cancel( true );
|
||||
this.job = null;
|
||||
this.getJob().cancel( true );
|
||||
this.setJob( null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,4 +391,94 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
{
|
||||
return this.getPlayerInv().player.worldObj;
|
||||
}
|
||||
|
||||
public boolean isAutoStart()
|
||||
{
|
||||
return this.autoStart;
|
||||
}
|
||||
|
||||
public void setAutoStart( final boolean autoStart )
|
||||
{
|
||||
this.autoStart = autoStart;
|
||||
}
|
||||
|
||||
public long getUsedBytes()
|
||||
{
|
||||
return this.bytesUsed;
|
||||
}
|
||||
|
||||
private void setUsedBytes( final long bytesUsed )
|
||||
{
|
||||
this.bytesUsed = bytesUsed;
|
||||
}
|
||||
|
||||
public long getCpuAvailableBytes()
|
||||
{
|
||||
return this.cpuBytesAvail;
|
||||
}
|
||||
|
||||
private void setCpuAvailableBytes( final long cpuBytesAvail )
|
||||
{
|
||||
this.cpuBytesAvail = cpuBytesAvail;
|
||||
}
|
||||
|
||||
public int getCpuCoProcessors()
|
||||
{
|
||||
return this.cpuCoProcessors;
|
||||
}
|
||||
|
||||
private void setCpuCoProcessors( final int cpuCoProcessors )
|
||||
{
|
||||
this.cpuCoProcessors = cpuCoProcessors;
|
||||
}
|
||||
|
||||
public int getSelectedCpu()
|
||||
{
|
||||
return this.selectedCpu;
|
||||
}
|
||||
|
||||
private void setSelectedCpu( final int selectedCpu )
|
||||
{
|
||||
this.selectedCpu = selectedCpu;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.myName;
|
||||
}
|
||||
|
||||
private void setName( @Nonnull final String myName )
|
||||
{
|
||||
this.myName = myName;
|
||||
}
|
||||
|
||||
public boolean hasNoCPU()
|
||||
{
|
||||
return this.noCPU;
|
||||
}
|
||||
|
||||
private void setNoCPU( final boolean noCPU )
|
||||
{
|
||||
this.noCPU = noCPU;
|
||||
}
|
||||
|
||||
public boolean isSimulation()
|
||||
{
|
||||
return this.simulation;
|
||||
}
|
||||
|
||||
private void setSimulation( final boolean simulation )
|
||||
{
|
||||
this.simulation = simulation;
|
||||
}
|
||||
|
||||
private Future<ICraftingJob> getJob()
|
||||
{
|
||||
return this.job;
|
||||
}
|
||||
|
||||
public void setJob( final Future<ICraftingJob> job )
|
||||
{
|
||||
this.job = job;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user