reformatted all src files (#141)
This commit is contained in:
@@ -19,15 +19,6 @@
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
@@ -37,269 +28,215 @@ import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
||||
public class MultiCraftingTracker
|
||||
{
|
||||
public class MultiCraftingTracker {
|
||||
|
||||
private final int size;
|
||||
private final ICraftingRequester owner;
|
||||
private final int size;
|
||||
private final ICraftingRequester owner;
|
||||
|
||||
private Future<ICraftingJob>[] jobs = null;
|
||||
private ICraftingLink[] links = null;
|
||||
private Future<ICraftingJob>[] jobs = null;
|
||||
private ICraftingLink[] links = null;
|
||||
|
||||
public MultiCraftingTracker( final ICraftingRequester o, final int size )
|
||||
{
|
||||
this.owner = o;
|
||||
this.size = size;
|
||||
}
|
||||
public MultiCraftingTracker(final ICraftingRequester o, final int size) {
|
||||
this.owner = o;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void readFromNBT( final NBTTagCompound extra )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
final NBTTagCompound link = extra.getCompoundTag( "links-" + x );
|
||||
public void readFromNBT(final NBTTagCompound extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final NBTTagCompound link = extra.getCompoundTag("links-" + x);
|
||||
|
||||
if( link != null && !link.hasNoTags() )
|
||||
{
|
||||
this.setLink( x, AEApi.instance().storage().loadCraftingLink( link, this.owner ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (link != null && !link.hasNoTags()) {
|
||||
this.setLink(x, AEApi.instance().storage().loadCraftingLink(link, this.owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT( final NBTTagCompound extra )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
final ICraftingLink link = this.getLink( x );
|
||||
public void writeToNBT(final NBTTagCompound extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final ICraftingLink link = this.getLink(x);
|
||||
|
||||
if( link != null )
|
||||
{
|
||||
final NBTTagCompound ln = new NBTTagCompound();
|
||||
link.writeToNBT( ln );
|
||||
extra.setTag( "links-" + x, ln );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (link != null) {
|
||||
final NBTTagCompound ln = new NBTTagCompound();
|
||||
link.writeToNBT(ln);
|
||||
extra.setTag("links-" + x, ln);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleCrafting( final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d, final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc )
|
||||
{
|
||||
if( ais != null )
|
||||
{
|
||||
ItemStack inputStack = ais.getCachedItemStack( ais.getStackSize() );
|
||||
public boolean handleCrafting(final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d, final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc) {
|
||||
if (ais != null) {
|
||||
ItemStack inputStack = ais.getCachedItemStack(ais.getStackSize());
|
||||
|
||||
ItemStack remaining = d.simulateAdd( inputStack );
|
||||
ItemStack remaining = d.simulateAdd(inputStack);
|
||||
|
||||
if( remaining.isEmpty() )
|
||||
{
|
||||
ais.setCachedItemStack( inputStack );
|
||||
if (remaining.isEmpty()) {
|
||||
ais.setCachedItemStack(inputStack);
|
||||
|
||||
final Future<ICraftingJob> craftingJob = this.getJob( x );
|
||||
final Future<ICraftingJob> craftingJob = this.getJob(x);
|
||||
|
||||
if( this.getLink( x ) != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if( craftingJob != null )
|
||||
{
|
||||
if (this.getLink(x) != null) {
|
||||
return false;
|
||||
} else if (craftingJob != null) {
|
||||
|
||||
try
|
||||
{
|
||||
ICraftingJob job = null;
|
||||
if( craftingJob.isDone() )
|
||||
{
|
||||
job = craftingJob.get();
|
||||
}
|
||||
try {
|
||||
ICraftingJob job = null;
|
||||
if (craftingJob.isDone()) {
|
||||
job = craftingJob.get();
|
||||
}
|
||||
|
||||
if( job != null )
|
||||
{
|
||||
final ICraftingLink link = cg.submitJob( job, this.owner, null, false, mySrc );
|
||||
if (job != null) {
|
||||
final ICraftingLink link = cg.submitJob(job, this.owner, null, false, mySrc);
|
||||
|
||||
this.setJob( x, null );
|
||||
this.setJob(x, null);
|
||||
|
||||
if( link != null )
|
||||
{
|
||||
this.setLink( x, link );
|
||||
if (link != null) {
|
||||
this.setLink(x, link);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final InterruptedException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
catch( final ExecutionException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( this.getLink( x ) == null )
|
||||
{
|
||||
final IAEItemStack aisC = ais.copy();
|
||||
aisC.setStackSize( itemToCraft );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
// :P
|
||||
} catch (final ExecutionException e) {
|
||||
// :P
|
||||
}
|
||||
} else {
|
||||
if (this.getLink(x) == null) {
|
||||
final IAEItemStack aisC = ais.copy();
|
||||
aisC.setStackSize(itemToCraft);
|
||||
|
||||
this.setJob( x, cg.beginCraftingJob( w, g, mySrc, aisC, null ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ais.setCachedItemStack( remaining );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.setJob(x, cg.beginCraftingJob(w, g, mySrc, aisC, null));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ais.setCachedItemStack(remaining);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
if (this.links == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
return ImmutableSet.copyOf( new NonNullArrayIterator<>( this.links ) );
|
||||
}
|
||||
return ImmutableSet.copyOf(new NonNullArrayIterator<>(this.links));
|
||||
}
|
||||
|
||||
public void jobStateChange( final ICraftingLink link )
|
||||
{
|
||||
if( this.links != null )
|
||||
{
|
||||
for( int x = 0; x < this.links.length; x++ )
|
||||
{
|
||||
if( this.links[x] == link )
|
||||
{
|
||||
this.setLink( x, null );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
if (this.links != null) {
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
if (this.links[x] == link) {
|
||||
this.setLink(x, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getSlot( final ICraftingLink link )
|
||||
{
|
||||
if( this.links != null )
|
||||
{
|
||||
for( int x = 0; x < this.links.length; x++ )
|
||||
{
|
||||
if( this.links[x] == link )
|
||||
{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
int getSlot(final ICraftingLink link) {
|
||||
if (this.links != null) {
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
if (this.links[x] == link) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
if( this.links != null )
|
||||
{
|
||||
for( final ICraftingLink l : this.links )
|
||||
{
|
||||
if( l != null )
|
||||
{
|
||||
l.cancel();
|
||||
}
|
||||
}
|
||||
void cancel() {
|
||||
if (this.links != null) {
|
||||
for (final ICraftingLink l : this.links) {
|
||||
if (l != null) {
|
||||
l.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
this.links = null;
|
||||
}
|
||||
this.links = null;
|
||||
}
|
||||
|
||||
if( this.jobs != null )
|
||||
{
|
||||
for( final Future<ICraftingJob> l : this.jobs )
|
||||
{
|
||||
if( l != null )
|
||||
{
|
||||
l.cancel( true );
|
||||
}
|
||||
}
|
||||
if (this.jobs != null) {
|
||||
for (final Future<ICraftingJob> l : this.jobs) {
|
||||
if (l != null) {
|
||||
l.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isBusy( final int slot )
|
||||
{
|
||||
return this.getLink( slot ) != null || this.getJob( slot ) != null;
|
||||
}
|
||||
boolean isBusy(final int slot) {
|
||||
return this.getLink(slot) != null || this.getJob(slot) != null;
|
||||
}
|
||||
|
||||
private ICraftingLink getLink( final int slot )
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
private ICraftingLink getLink(final int slot) {
|
||||
if (this.links == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.links[slot];
|
||||
}
|
||||
return this.links[slot];
|
||||
}
|
||||
|
||||
private void setLink( final int slot, final ICraftingLink l )
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
this.links = new ICraftingLink[this.size];
|
||||
}
|
||||
private void setLink(final int slot, final ICraftingLink l) {
|
||||
if (this.links == null) {
|
||||
this.links = new ICraftingLink[this.size];
|
||||
}
|
||||
|
||||
this.links[slot] = l;
|
||||
this.links[slot] = l;
|
||||
|
||||
boolean hasStuff = false;
|
||||
for( int x = 0; x < this.links.length; x++ )
|
||||
{
|
||||
final ICraftingLink g = this.links[x];
|
||||
boolean hasStuff = false;
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
final ICraftingLink g = this.links[x];
|
||||
|
||||
if( g == null || g.isCanceled() || g.isDone() )
|
||||
{
|
||||
this.links[x] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
if (g == null || g.isCanceled() || g.isDone()) {
|
||||
this.links[x] = null;
|
||||
} else {
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !hasStuff )
|
||||
{
|
||||
this.links = null;
|
||||
}
|
||||
}
|
||||
if (!hasStuff) {
|
||||
this.links = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Future<ICraftingJob> getJob( final int slot )
|
||||
{
|
||||
if( this.jobs == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
private Future<ICraftingJob> getJob(final int slot) {
|
||||
if (this.jobs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.jobs[slot];
|
||||
}
|
||||
return this.jobs[slot];
|
||||
}
|
||||
|
||||
private void setJob( final int slot, final Future<ICraftingJob> l )
|
||||
{
|
||||
if( this.jobs == null )
|
||||
{
|
||||
this.jobs = new Future[this.size];
|
||||
}
|
||||
private void setJob(final int slot, final Future<ICraftingJob> l) {
|
||||
if (this.jobs == null) {
|
||||
this.jobs = new Future[this.size];
|
||||
}
|
||||
|
||||
this.jobs[slot] = l;
|
||||
this.jobs[slot] = l;
|
||||
|
||||
boolean hasStuff = false;
|
||||
boolean hasStuff = false;
|
||||
|
||||
for( final Future<ICraftingJob> job : this.jobs )
|
||||
{
|
||||
if( job != null )
|
||||
{
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
for (final Future<ICraftingJob> job : this.jobs) {
|
||||
if (job != null) {
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !hasStuff )
|
||||
{
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
if (!hasStuff) {
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user