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-06-04 06:37:47 +02:00
|
|
|
package appeng.crafting;
|
|
|
|
|
2015-03-26 10:23:59 +01:00
|
|
|
|
2014-06-17 05:36:35 +02:00
|
|
|
import java.util.HashMap;
|
2014-06-16 07:48:43 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2014-06-04 06:37:47 +02:00
|
|
|
|
2015-12-24 02:07:03 +01:00
|
|
|
import com.google.common.base.Stopwatch;
|
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-06-04 06:37:47 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-06-22 09:00:38 +02:00
|
|
|
import net.minecraft.world.World;
|
2015-12-24 02:07:03 +01:00
|
|
|
|
2014-06-05 05:54:01 +02:00
|
|
|
import appeng.api.AEApi;
|
2014-06-05 02:47:13 +02:00
|
|
|
import appeng.api.config.Actionable;
|
2014-07-03 06:48:18 +02:00
|
|
|
import appeng.api.networking.IGrid;
|
2015-11-22 15:54:29 +01:00
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
2014-07-03 06:48:18 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingCallback;
|
|
|
|
import appeng.api.networking.crafting.ICraftingGrid;
|
|
|
|
import appeng.api.networking.crafting.ICraftingJob;
|
2014-06-06 06:26:01 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
2014-06-18 08:23:37 +02:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2015-11-22 15:54:29 +01:00
|
|
|
import appeng.api.networking.security.IActionHost;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
|
|
|
import appeng.api.networking.security.PlayerSource;
|
2014-06-05 05:54:01 +02:00
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
2014-06-04 06:37:47 +02:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2015-11-22 15:54:29 +01:00
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-06-16 07:48:43 +02:00
|
|
|
import appeng.core.AELog;
|
2014-06-23 06:50:56 +02:00
|
|
|
import appeng.hooks.TickHandler;
|
2014-06-04 06:37:47 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
public class CraftingJob implements Runnable, ICraftingJob
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
private static final String LOG_CRAFTING_JOB = "CraftingJob (%s) issued by %s requesting [%s] using %s bytes took %s ms";
|
|
|
|
private static final String LOG_MACHINE_SOURCE_DETAILS = "Machine[object=%s, %s]";
|
2014-06-04 06:37:47 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final MECraftingInventory original;
|
|
|
|
private final World world;
|
|
|
|
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().createItemList();
|
|
|
|
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
|
|
|
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<String, TwoIntegers>();
|
2015-04-03 08:54:31 +02:00
|
|
|
private final Object monitor = new Object();
|
|
|
|
private final Stopwatch watch = Stopwatch.createUnstarted();
|
2015-10-08 15:42:42 +02:00
|
|
|
private CraftingTreeNode tree;
|
|
|
|
private final IAEItemStack output;
|
|
|
|
private boolean simulate = false;
|
|
|
|
private MECraftingInventory availableCheck;
|
|
|
|
private long bytes = 0;
|
|
|
|
private final BaseActionSource actionSrc;
|
|
|
|
private final ICraftingCallback callback;
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean running = false;
|
|
|
|
private boolean done = false;
|
|
|
|
private int time = 5;
|
|
|
|
private int incTime = Integer.MAX_VALUE;
|
2014-07-03 06:48:18 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private World wrapWorld( final World w )
|
2014-06-20 09:12:39 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return w;
|
2014-06-05 02:47:13 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public CraftingJob( final World w, final IGrid grid, final BaseActionSource actionSrc, final IAEItemStack what, final ICraftingCallback callback )
|
2014-09-19 03:31:11 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.world = this.wrapWorld( w );
|
|
|
|
this.output = what.copy();
|
2014-07-03 06:48:18 +02:00
|
|
|
this.actionSrc = actionSrc;
|
2014-06-05 05:54:01 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
this.callback = callback;
|
2015-09-30 14:24:40 +02:00
|
|
|
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
|
|
|
|
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.original = new MECraftingInventory( sg.getItemInventory(), actionSrc, false, false, false );
|
2014-09-19 03:31:11 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setTree( this.getCraftingTree( cc, what ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.availableCheck = null;
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private CraftingTreeNode getCraftingTree( final ICraftingGrid cc, final IAEItemStack what )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
2014-06-22 09:00:38 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void refund( final IAEItemStack o )
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
IAEItemStack checkUse( final IAEItemStack available )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public void writeToNBT( final NBTTagCompound out )
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
|
|
|
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void addTask( IAEItemStack what, final long crafts, final ICraftingPatternDetails details, final int depth )
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( crafts > 0 )
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2014-06-18 08:23:37 +02:00
|
|
|
what = what.copy();
|
|
|
|
what.setStackSize( what.getStackSize() * crafts );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.crafting.add( what );
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void addMissing( IAEItemStack what )
|
2014-06-04 06:37:47 +02:00
|
|
|
{
|
2014-06-18 08:23:37 +02:00
|
|
|
what = what.copy();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.missing.add( what );
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 08:23:37 +02:00
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.handlePausing();
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final Stopwatch timer = Stopwatch.createStarted();
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
2014-12-29 15:13:47 +01:00
|
|
|
craftingInventory.ignore( this.output );
|
2014-06-18 08:23:37 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
|
|
|
this.getTree().dive( this );
|
2014-06-18 08:23:37 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final String s : this.opsAndMultiplier.keySet() )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
this.logCraftingJob( "real", timer );
|
2014-06-23 06:50:56 +02:00
|
|
|
// if ( mode == Actionable.MODULATE )
|
2014-09-28 11:47:17 +02:00
|
|
|
// craftingInventory.moveItemsToStorage( storage );
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final CraftBranchFailure e )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.simulate = true;
|
2014-06-23 06:50:56 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final Stopwatch timer = Stopwatch.createStarted();
|
|
|
|
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
2014-12-29 15:13:47 +01:00
|
|
|
craftingInventory.ignore( this.output );
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
2014-07-17 03:31:23 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getTree().setSimulate();
|
|
|
|
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
|
|
|
this.getTree().dive( this );
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final String s : this.opsAndMultiplier.keySet() )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
this.logCraftingJob( "simulate", timer );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final CraftBranchFailure e1 )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( e1 );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final CraftingCalculationFailure f )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( f );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final InterruptedException e1 )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2014-07-05 00:43:53 +02:00
|
|
|
AELog.crafting( "Crafting calculation canceled." );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finish();
|
2014-06-23 06:50:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final CraftingCalculationFailure f )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( f );
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final InterruptedException e1 )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2014-07-05 00:43:53 +02:00
|
|
|
AELog.crafting( "Crafting calculation canceled." );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finish();
|
2014-06-18 08:23:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.craftingDebug( "crafting job now done" );
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Throwable t )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finish();
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( t );
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.finish();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void handlePausing() throws InterruptedException
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( this.incTime > 100 )
|
|
|
|
{
|
|
|
|
this.incTime = 0;
|
|
|
|
|
|
|
|
synchronized( this.monitor )
|
|
|
|
{
|
|
|
|
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
|
|
|
{
|
|
|
|
this.running = false;
|
|
|
|
this.watch.stop();
|
|
|
|
this.monitor.notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !this.running )
|
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.craftingDebug( "crafting job will now sleep" );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
while( !this.running )
|
|
|
|
{
|
|
|
|
this.monitor.wait();
|
|
|
|
}
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.craftingDebug( "crafting job now active" );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Thread.interrupted() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
throw new InterruptedException();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
this.incTime++;
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private void finish()
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.callback != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.callback.calculationComplete( this );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-03 06:48:18 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.availableCheck = null;
|
2014-07-17 03:31:23 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
synchronized( this.monitor )
|
2014-06-18 08:23:37 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.running = false;
|
|
|
|
this.done = true;
|
|
|
|
this.monitor.notify();
|
2014-06-18 08:23:37 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-19 08:28:45 +02:00
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-06-22 09:00:38 +02:00
|
|
|
public boolean isSimulation()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.simulate;
|
2014-06-22 09:00:38 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public long getByteTotal()
|
|
|
|
{
|
|
|
|
return this.bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-30 14:24:40 +02:00
|
|
|
public void populatePlan( final IItemList<IAEItemStack> plan )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.getTree() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getTree().getPlan( plan );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack getOutput()
|
|
|
|
{
|
|
|
|
return this.output;
|
|
|
|
}
|
|
|
|
|
2014-06-23 06:50:56 +02:00
|
|
|
public boolean isDone()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.done;
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
World getWorld()
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.world;
|
2014-06-22 09:00:38 +02:00
|
|
|
}
|
|
|
|
|
2014-06-23 06:50:56 +02:00
|
|
|
/**
|
|
|
|
* returns true if this needs more simulation.
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-09-27 23:17:47 +02:00
|
|
|
* @param milli milliseconds of simulation
|
2015-04-03 08:54:31 +02:00
|
|
|
*
|
2014-09-27 23:17:47 +02:00
|
|
|
* @return true if this needs more simulation
|
2014-06-23 06:50:56 +02:00
|
|
|
*/
|
2015-09-30 14:24:40 +02:00
|
|
|
public boolean simulateFor( final int milli )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.time = milli;
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
synchronized( this.monitor )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.done )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-06-23 06:50:56 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.watch.reset();
|
|
|
|
this.watch.start();
|
|
|
|
this.running = true;
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.craftingDebug( "main thread is now going to sleep" );
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.monitor.notify();
|
2014-06-23 06:50:56 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
while( this.running )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.monitor.wait();
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final InterruptedException ignored )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.craftingDebug( "main thread is now active" );
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void addBytes( final long crafts )
|
2014-06-23 06:50:56 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.bytes += crafts;
|
2014-06-23 06:50:56 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
public CraftingTreeNode getTree()
|
|
|
|
{
|
|
|
|
return this.tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setTree( final CraftingTreeNode tree )
|
|
|
|
{
|
|
|
|
this.tree = tree;
|
|
|
|
}
|
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
private void logCraftingJob( String type, Stopwatch timer )
|
2014-07-03 06:48:18 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
if( AELog.isCraftingLogEnabled() )
|
|
|
|
{
|
|
|
|
final String itemToOutput = this.output.toString();
|
|
|
|
final long elapsedTime = timer.elapsed( TimeUnit.MILLISECONDS );
|
|
|
|
final String actionSource;
|
|
|
|
|
|
|
|
if( this.actionSrc instanceof MachineSource )
|
|
|
|
{
|
|
|
|
final IActionHost machineSource = ( (MachineSource) this.actionSrc ).via;
|
|
|
|
final IGridNode actionableNode = machineSource.getActionableNode();
|
|
|
|
final IGridHost machine = actionableNode.getMachine();
|
|
|
|
final DimensionalCoord location = actionableNode.getGridBlock().getLocation();
|
|
|
|
|
|
|
|
actionSource = String.format( LOG_MACHINE_SOURCE_DETAILS, machine, location );
|
|
|
|
}
|
|
|
|
else if( this.actionSrc instanceof PlayerSource )
|
|
|
|
{
|
|
|
|
final PlayerSource source = (PlayerSource) this.actionSrc;
|
|
|
|
final EntityPlayer player = source.player;
|
2014-07-03 06:48:18 +02:00
|
|
|
|
2015-11-22 15:54:29 +01:00
|
|
|
actionSource = player.toString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
actionSource = "[unknown source]";
|
|
|
|
}
|
|
|
|
|
|
|
|
AELog.crafting( LOG_CRAFTING_JOB, type, actionSource, itemToOutput, this.bytes, elapsedTime );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class TwoIntegers
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
private final long perOp = 0;
|
|
|
|
private final long times = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-06-04 06:37:47 +02:00
|
|
|
}
|