Crafting is virtually working 100%

This commit is contained in:
AlgorithmX2
2014-06-22 02:00:38 -05:00
parent 65e9e272c4
commit ff9a10b926
14 changed files with 323 additions and 68 deletions
@@ -45,7 +45,6 @@ public class ContainerCraftAmount extends AEBaseContainer implements ICraftingHo
return h.getActionableNode().getGrid(); return h.getActionableNode().getGrid();
} }
@Override
public World getWorld() public World getWorld()
{ {
return getPlayerInv().player.worldObj; return getPlayerInv().player.worldObj;
@@ -40,10 +40,13 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
try try
{ {
result = job.get(); result = job.get();
CraftingCache cc = getGrid().getCache( CraftingCache.class ); if ( !result.isSimulation() )
cc.submitJob( result, null, getActionSrc() ); {
AELog.info( "Job info is ready!" ); CraftingCache cc = getGrid().getCache( CraftingCache.class );
this.isContainerValid = false; cc.submitJob( result, null, getActionSrc() );
AELog.info( "Job info is ready!" );
this.isContainerValid = false;
}
} }
catch (Throwable e) catch (Throwable e)
{ {
@@ -87,7 +90,6 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
return h.getActionableNode().getGrid(); return h.getActionableNode().getGrid();
} }
@Override
public World getWorld() public World getWorld()
{ {
return getPlayerInv().player.worldObj; return getPlayerInv().player.worldObj;
+1 -1
View File
@@ -78,7 +78,7 @@ public class PacketCraftRequest extends AppEngPacket
try try
{ {
CraftingJob cj = new CraftingJob( cca, slotItem, Actionable.SIMULATE ); CraftingJob cj = new CraftingJob( cca.getWorld(), cca, slotItem, Actionable.SIMULATE );
ContainerOpenContext context = cca.openContext; ContainerOpenContext context = cca.openContext;
if ( context != null ) if ( context != null )
+29 -2
View File
@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingPatternDetails;
@@ -35,14 +36,16 @@ public class CraftingJob implements Runnable
public CraftingTreeNode tree; public CraftingTreeNode tree;
private BaseActionSource actionSrc; private BaseActionSource actionSrc;
World world;
public IAEItemStack getOutput() public IAEItemStack getOutput()
{ {
return output; return output;
} }
public CraftingJob(ICraftingHost host, NBTTagCompound data) { public CraftingJob(World w, ICraftingHost host, NBTTagCompound data) {
jobHost = host; jobHost = host;
world = wrapWorld( w );
storage = AEApi.instance().storage().createItemList(); storage = AEApi.instance().storage().createItemList();
prophecies = new HashSet(); prophecies = new HashSet();
original = null; original = null;
@@ -54,8 +57,9 @@ public class CraftingJob implements Runnable
return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc ); return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
} }
public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) { public CraftingJob(World w, ICraftingHost host, IAEItemStack what, Actionable mode) {
jobHost = host; jobHost = host;
world = wrapWorld( w );
output = what.copy(); output = what.copy();
storage = AEApi.instance().storage().createItemList(); storage = AEApi.instance().storage().createItemList();
prophecies = new HashSet(); prophecies = new HashSet();
@@ -68,6 +72,19 @@ public class CraftingJob implements Runnable
tree = getCraftingTree( cc, what ); tree = getCraftingTree( cc, what );
} }
private World wrapWorld(World w)
{
return w;
/*
* -- works on interfaces.. :( try {
*
* InvocationHandler handler = new CraftingWorldSync( w ); Class proxyClass = Proxy.getProxyClass(
* World.class.getClassLoader(), new Class[] { World.class } ); return (World) proxyClass.getConstructor( new
* Class[] { InvocationHandler.class } ).newInstance( new Object[] { handler } ); } catch (Throwable t) { throw
* new RuntimeException( t ); }
*/
}
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what) private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
{ {
return new CraftingTreeNode( cc, this, what, null, -1, 0 ); return new CraftingTreeNode( cc, this, what, null, -1, 0 );
@@ -191,4 +208,14 @@ public class CraftingJob implements Runnable
} }
public boolean isSimulation()
{
return simulate;
}
public World getWorld()
{
return world;
}
} }
+1 -1
View File
@@ -42,7 +42,7 @@ public class CraftingTreeNode
what = wat; what = wat;
parent = par; parent = par;
this.slot = slot; this.slot = slot;
this.world = job.jobHost.getWorld(); this.world = job.getWorld();
this.job = job; this.job = job;
sim = false; sim = false;
+58 -14
View File
@@ -4,25 +4,32 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerNull;
import appeng.me.cache.CraftingCache; import appeng.me.cache.CraftingCache;
import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
public class CraftingTreeProcess public class CraftingTreeProcess
{ {
World world;
CraftingTreeNode parent; CraftingTreeNode parent;
ICraftingPatternDetails details; ICraftingPatternDetails details;
CraftingJob job; CraftingJob job;
long crafts = 0; long crafts = 0;
boolean damageable; boolean damageable;
boolean fullsimulation;
final private int depth; final private int depth;
@@ -34,19 +41,36 @@ public class CraftingTreeProcess
this.details = details; this.details = details;
this.job = job; this.job = job;
this.depth = depth; this.depth = depth;
world = job.getWorld();
if ( details.isCraftable() ) if ( details.isCraftable() )
{ {
IAEItemStack list[] = details.getInputs(); IAEItemStack list[] = details.getInputs();
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
IAEItemStack[] is = details.getInputs();
for (int x = 0; x < ic.getSizeInventory(); x++)
ic.setInventorySlotContents( x, is[x] == null ? null : is[x].getItemStack() );
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack g = ic.getStackInSlot( x );
if ( g != null && g.stackSize > 1 )
fullsimulation = true;
}
for (int x = 0; x < list.length; x++) for (int x = 0; x < list.length; x++)
{ {
IAEItemStack part = list[x]; IAEItemStack part = list[x];
if ( part != null ) if ( part != null )
{ {
ItemStack is = part.getItemStack(); ItemStack g = part.getItemStack();
if ( is.getItem().hasContainerItem( is ) )
if ( g.getItem().hasContainerItem( g ) )
damageable = true; damageable = true;
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() ); nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
} }
} }
@@ -67,7 +91,7 @@ public class CraftingTreeProcess
long getTimes(long remaining, long stackSize) long getTimes(long remaining, long stackSize)
{ {
if ( damageable ) if ( damageable || fullsimulation )
return 1; return 1;
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0); return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
} }
@@ -92,21 +116,41 @@ public class CraftingTreeProcess
if ( Thread.interrupted() ) if ( Thread.interrupted() )
throw new InterruptedException(); throw new InterruptedException();
// request and remove inputs... if ( fullsimulation )
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
{ {
IAEItemStack item = entry.getKey().getStack( entry.getValue() ); InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
if ( damageable ) for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
{ {
ItemStack is = stack.getItemStack(); IAEItemStack item = entry.getKey().getStack( entry.getValue() );
if ( stack.getItem().hasContainerItem( is ) ) IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
{
is = stack.getItem().getContainerItem( is );
if ( is.isItemStackDamageable() && is.getItemDamage() == is.getMaxDamage() )
is = null;
ic.setInventorySlotContents( entry.getKey().slot, stack.getItemStack() );
}
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack is = ic.getStackInSlot( x );
is = Platform.getContainerItem( is );
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
if ( o != null )
inv.injectItems( o, Actionable.MODULATE, src );
}
}
else
{
// request and remove inputs...
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
{
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
if ( damageable )
{
ItemStack is = Platform.getContainerItem( stack.getItemStack() );
IAEItemStack o = AEApi.instance().storage().createItemStack( is ); IAEItemStack o = AEApi.instance().storage().createItemStack( is );
if ( o != null ) if ( o != null )
inv.injectItems( o, Actionable.MODULATE, src ); inv.injectItems( o, Actionable.MODULATE, src );
-8
View File
@@ -1,6 +1,5 @@
package appeng.crafting; package appeng.crafting;
import net.minecraft.world.World;
import appeng.api.networking.IGrid; import appeng.api.networking.IGrid;
import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.BaseActionSource;
@@ -12,13 +11,6 @@ public interface ICraftingHost
*/ */
IGrid getGrid(); IGrid getGrid();
/**
* required for crafting calculations.
*
* @return world the host is located in
*/
World getWorld();
/** /**
* get source of moving items around. * get source of moving items around.
* *
+3 -1
View File
@@ -185,6 +185,8 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
public void ignore(IAEItemStack what) public void ignore(IAEItemStack what)
{ {
IAEItemStack list = localCache.findPrecise( what );
if ( list != null )
list.setStackSize( 0 );
} }
} }
+8 -2
View File
@@ -261,13 +261,19 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
public boolean submitJob(CraftingJob job, CraftingCPUCluster target, BaseActionSource src) public boolean submitJob(CraftingJob job, CraftingCPUCluster target, BaseActionSource src)
{ {
if ( job.isSimulation() )
return false;
if ( target == null ) if ( target == null )
{ {
// TODO real stuff... // TODO real stuff...
for (CraftingCPUCluster cpu : cpuClusters) for (CraftingCPUCluster cpu : cpuClusters)
{ {
target = cpu; if ( !cpu.isBusy() )
break; {
target = cpu;
break;
}
} }
} }
@@ -9,6 +9,7 @@ import java.util.Map.Entry;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
@@ -33,7 +34,9 @@ import appeng.crafting.MECraftingInventory;
import appeng.me.cache.CraftingCache; import appeng.me.cache.CraftingCache;
import appeng.me.cluster.IAECluster; import appeng.me.cluster.IAECluster;
import appeng.tile.crafting.TileCraftingTile; import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
public class CraftingCPUCluster implements IAECluster public class CraftingCPUCluster implements IAECluster
{ {
@@ -41,6 +44,7 @@ public class CraftingCPUCluster implements IAECluster
public WorldCoord min; public WorldCoord min;
public WorldCoord max; public WorldCoord max;
public boolean isDestroyed = false; public boolean isDestroyed = false;
private boolean isComplete = true;
class TaskProgress class TaskProgress
{ {
@@ -60,6 +64,7 @@ public class CraftingCPUCluster implements IAECluster
MECraftingInventory inventory = new MECraftingInventory(); MECraftingInventory inventory = new MECraftingInventory();
IAEItemStack finalOutput; IAEItemStack finalOutput;
BaseActionSource mySrc;
boolean waiting = false; boolean waiting = false;
Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<ICraftingPatternDetails, TaskProgress>(); Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<ICraftingPatternDetails, TaskProgress>();
@@ -149,11 +154,19 @@ public class CraftingCPUCluster implements IAECluster
{ {
is.decStackSize( input.getStackSize() ); is.decStackSize( input.getStackSize() );
AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() + " remaining : " // AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() +
+ (is.getStackSize() + getRemainingTasks()) + " total left : waiting: " + (waiting ? "yes" : "no") ); // " remaining : "
// + (is.getStackSize() + getRemainingTasks()) + " total left : waiting: " + (waiting ? "yes" :
// "no") );
if ( finalOutput.equals( input ) ) if ( finalOutput.equals( input ) )
{
finalOutput.decStackSize( input.getStackSize() );
if ( finalOutput.getStackSize() <= 0 )
completeJob();
return input; // ignore it. return input; // ignore it.
}
// 2000 // 2000
return inventory.injectItems( what, type, src ); return inventory.injectItems( what, type, src );
@@ -163,13 +176,20 @@ public class CraftingCPUCluster implements IAECluster
insert.setStackSize( is.getStackSize() ); insert.setStackSize( is.getStackSize() );
what.decStackSize( is.getStackSize() ); what.decStackSize( is.getStackSize() );
AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() + " remaining : " + (is.getStackSize() + getRemainingTasks()) // AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() + " remaining : " +
+ " total left : waiting: " + (waiting ? "yes" : "no") ); // (is.getStackSize() + getRemainingTasks())
// + " total left : waiting: " + (waiting ? "yes" : "no") );
is.setStackSize( 0 ); is.setStackSize( 0 );
if ( finalOutput.equals( input ) ) if ( finalOutput.equals( input ) )
{
finalOutput.decStackSize( input.getStackSize() );
if ( finalOutput.getStackSize() <= 0 )
completeJob();
return input; // ignore it. return input; // ignore it.
}
inventory.injectItems( insert, type, src ); inventory.injectItems( insert, type, src );
@@ -180,6 +200,20 @@ public class CraftingCPUCluster implements IAECluster
return input; return input;
} }
public IGrid getGrid()
{
for (TileCraftingTile r : tiles)
return r.getActionableNode().getGrid();
throw new RuntimeException( "No tiles inside a cpu cluster." );
}
private void completeJob()
{
AELog.info( "marking job as complete" );
isComplete = true;
}
private int getRemainingTasks() private int getRemainingTasks()
{ {
int o = 0; int o = 0;
@@ -188,19 +222,72 @@ public class CraftingCPUCluster implements IAECluster
return o; return o;
} }
private boolean canCraft(IAEItemStack[] condencedInputs) private boolean canCraft(ICraftingPatternDetails details, IAEItemStack[] condencedInputs)
{ {
for (IAEItemStack is : condencedInputs) for (IAEItemStack g : condencedInputs)
{ {
IAEItemStack avail = inventory.extractItems( is, Actionable.SIMULATE, null );
if ( avail == null || avail.getStackSize() < is.getStackSize() ) if ( details.isCraftable() )
return false; {
boolean found = false;
for (IAEItemStack fuzz : inventory.getItemList().findFuzzy( g, FuzzyMode.IGNORE_ALL ))
{
fuzz = fuzz.copy();
fuzz.setStackSize( g.getStackSize() );
IAEItemStack ais = inventory.extractItems( fuzz, Actionable.SIMULATE, null );
ItemStack is = ais == null ? null : ais.getItemStack();
if ( is != null && is.stackSize == g.getStackSize() )
{
found = true;
break;
}
}
if ( !found )
return false;
}
else
{
IAEItemStack ais = inventory.extractItems( g.copy(), Actionable.SIMULATE, null );
ItemStack is = ais == null ? null : ais.getItemStack();
if ( is == null || is.stackSize < g.getStackSize() )
return false;
}
} }
return true; return true;
} }
public void updateCraftingLogic(IGrid grid, CraftingCache cc) public void updateCraftingLogic(IGrid grid, CraftingCache cc)
{ {
if ( isComplete )
{
if ( inventory.getItemList().isEmpty() )
return;
IStorageGrid sg = grid.getCache( IStorageGrid.class );
IMEInventory<IAEItemStack> ii = sg.getItemInventory();
for (IAEItemStack is : inventory.getItemList())
{
is = inventory.extractItems( is.copy(), Actionable.MODULATE, mySrc );
if ( is != null )
is = ii.injectItems( is, Actionable.MODULATE, mySrc );
if ( is != null )
inventory.injectItems( is, Actionable.MODULATE, mySrc );
}
if ( inventory.getItemList().isEmpty() )
inventory = new MECraftingInventory();
return;
}
waiting = false; waiting = false;
if ( waiting || tasks.isEmpty() ) // nothing to do here... if ( waiting || tasks.isEmpty() ) // nothing to do here...
return; return;
@@ -214,7 +301,7 @@ public class CraftingCPUCluster implements IAECluster
continue; continue;
ICraftingPatternDetails details = e.getKey(); ICraftingPatternDetails details = e.getKey();
if ( canCraft( details.getCondencedInputs() ) ) if ( canCraft( details, details.getCondencedInputs() ) )
{ {
InventoryCrafting ic = null; InventoryCrafting ic = null;
@@ -228,21 +315,22 @@ public class CraftingCPUCluster implements IAECluster
if ( ic == null ) if ( ic == null )
{ {
ic = new InventoryCrafting( new ContainerNull(), 3, 3 ); ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
boolean found = false;
IAEItemStack[] input = details.getInputs(); IAEItemStack[] input = details.getInputs();
for (int x = 0; x < input.length; x++) for (int x = 0; x < input.length; x++)
{ {
if ( input[x] != null ) if ( input[x] != null )
{ {
boolean found = true; found = false;
if ( details.isCraftable() ) if ( details.isCraftable() )
{ {
for (IAEItemStack fuzz : inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL )) for (IAEItemStack fuzz : inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ))
{ {
fuzz = fuzz.copy(); fuzz = fuzz.copy();
fuzz.setStackSize( input[x].getStackSize() ); fuzz.setStackSize( input[x].getStackSize() );
IAEItemStack ais = inventory.extractItems( fuzz, Actionable.MODULATE, null ); IAEItemStack ais = inventory.extractItems( fuzz, Actionable.MODULATE, mySrc );
ItemStack is = ais == null ? null : ais.getItemStack(); ItemStack is = ais == null ? null : ais.getItemStack();
if ( is != null && details.isValidItemForSlot( x, is, getWorld() ) ) if ( is != null && details.isValidItemForSlot( x, is, getWorld() ) )
@@ -255,7 +343,7 @@ public class CraftingCPUCluster implements IAECluster
} }
else else
{ {
IAEItemStack ais = inventory.extractItems( input[x].copy(), Actionable.MODULATE, null ); IAEItemStack ais = inventory.extractItems( input[x].copy(), Actionable.MODULATE, mySrc );
ItemStack is = ais == null ? null : ais.getItemStack(); ItemStack is = ais == null ? null : ais.getItemStack();
if ( is != null ) if ( is != null )
@@ -269,6 +357,20 @@ public class CraftingCPUCluster implements IAECluster
if ( !found ) if ( !found )
break; break;
} }
}
if ( !found )
{
// put stuff back..
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack is = ic.getStackInSlot( x );
if ( is != null )
inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, mySrc );
}
ic = null;
break;
} }
} }
@@ -280,6 +382,19 @@ public class CraftingCPUCluster implements IAECluster
for (IAEItemStack out : details.getCondencedOutputs()) for (IAEItemStack out : details.getCondencedOutputs())
waitingFor.add( out.copy() ); waitingFor.add( out.copy() );
if ( details.isCraftable() )
{
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) getWorld() ),
details.getOutput( ic, getWorld() ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) );
if ( output != null )
waitingFor.add( AEItemStack.create( output ) );
}
}
ic = null; // hand off complete! ic = null; // hand off complete!
e.getValue().value--; e.getValue().value--;
@@ -299,7 +414,7 @@ public class CraftingCPUCluster implements IAECluster
{ {
ItemStack is = ic.getStackInSlot( x ); ItemStack is = ic.getStackInSlot( x );
if ( is != null ) if ( is != null )
inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, null ); inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, mySrc );
} }
} }
} }
@@ -316,13 +431,6 @@ public class CraftingCPUCluster implements IAECluster
public boolean submitJob(IGrid g, CraftingJob job, BaseActionSource src) public boolean submitJob(IGrid g, CraftingJob job, BaseActionSource src)
{ {
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = tasks.entrySet().iterator();
while (i.hasNext())
{
if ( i.next().getValue().value <= 0 )
i.remove();
}
if ( !tasks.isEmpty() || !waitingFor.isEmpty() ) if ( !tasks.isEmpty() || !waitingFor.isEmpty() )
return false; return false;
@@ -337,6 +445,8 @@ public class CraftingCPUCluster implements IAECluster
ci.commit( src ); ci.commit( src );
finalOutput = job.getOutput(); finalOutput = job.getOutput();
waiting = false; waiting = false;
isComplete = false;
mySrc = src;
return true; return true;
} }
catch (CraftBranchFailure e) catch (CraftBranchFailure e)
@@ -363,4 +473,16 @@ public class CraftingCPUCluster implements IAECluster
i.value += crafts; i.value += crafts;
} }
public boolean isBusy()
{
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = tasks.entrySet().iterator();
while (i.hasNext())
{
if ( i.next().getValue().value <= 0 )
i.remove();
}
return !tasks.isEmpty() || !waitingFor.isEmpty();
}
} }
+11 -1
View File
@@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFirework;
import net.minecraft.item.ItemSkull; import net.minecraft.item.ItemSkull;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -385,11 +386,20 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
if ( w.getBlock( x, y, z ).isReplaceable( w, x, y, z ) ) if ( w.getBlock( x, y, z ).isReplaceable( w, x, y, z ) )
{ {
if ( i instanceof ItemBlock || i instanceof IPlantable || i instanceof ItemSkull || i instanceof IPartItem ) if ( i instanceof ItemBlock || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem )
{ {
EntityPlayer player = Platform.getPlayer( (WorldServer) w ); EntityPlayer player = Platform.getPlayer( (WorldServer) w );
Platform.configurePlayer( player, side, tile ); Platform.configurePlayer( player, side, tile );
if ( i instanceof ItemFirework )
{
Chunk c = w.getChunkFromBlockCoords( x, z );
int sum = 0;
for (List Z : c.entityLists)
sum += Z.size();
if ( sum > 32 )
return input;
}
maxStorage = is.stackSize; maxStorage = is.stackSize;
worked = true; worked = true;
if ( type == Actionable.MODULATE ) if ( type == Actionable.MODULATE )
+33 -4
View File
@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
@@ -38,6 +39,7 @@ import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost; import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor; import appeng.util.InventoryAdaptor;
import appeng.util.Platform; import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEngInventory, ISidedInventory, IUpgradeableHost, IConfigManagerHost, public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEngInventory, ISidedInventory, IUpgradeableHost, IConfigManagerHost,
IGridTickable, ICraftingMachine IGridTickable, ICraftingMachine
@@ -326,7 +328,9 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
if ( inv.getStackInSlot( 9 ) != null ) if ( inv.getStackInSlot( 9 ) != null )
{ {
pushOut( inv.getStackInSlot( 9 ) ); pushOut( inv.getStackInSlot( 9 ) );
return inv.getStackInSlot( 9 ) == null ? TickRateModulation.SLEEP : TickRateModulation.IDLE; ejectHeldItems();
isAwake = inv.getStackInSlot( 9 ) != null;
return isAwake ? TickRateModulation.SLEEP : TickRateModulation.IDLE;
} }
if ( myPlan == null ) if ( myPlan == null )
@@ -366,18 +370,43 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
ItemStack output = myPlan.getOutput( craftingInv, getWorldObj() ); ItemStack output = myPlan.getOutput( craftingInv, getWorldObj() );
if ( output != null ) if ( output != null )
{ {
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) getWorldObj() ), output, craftingInv );
for (int x = 0; x < craftingInv.getSizeInventory(); x++) for (int x = 0; x < craftingInv.getSizeInventory(); x++)
inv.setInventorySlotContents( x, null ); inv.setInventorySlotContents( x, Platform.getContainerItem( craftingInv.getStackInSlot( x ) ) );
pushOut( output.copy() ); pushOut( output.copy() );
isAwake = false;
return inv.getStackInSlot( 9 ) == null ? TickRateModulation.SLEEP : TickRateModulation.IDLE; if ( inv.getStackInSlot( 10 ) == null )
myPlan = null;
ejectHeldItems();
isAwake = inv.getStackInSlot( 9 ) != null;
return isAwake ? TickRateModulation.SLEEP : TickRateModulation.IDLE;
} }
} }
return TickRateModulation.FASTER; return TickRateModulation.FASTER;
} }
private void ejectHeldItems()
{
if ( myPlan == null && inv.getStackInSlot( 9 ) == null )
{
for (int x = 0; x < 9; x++)
{
ItemStack is = inv.getStackInSlot( x );
if ( is != null )
{
inv.setInventorySlotContents( 9, is );
inv.setInventorySlotContents( x, null );
return;
}
}
}
}
private int userPower(int i) private int userPower(int i)
{ {
try try
+26 -4
View File
@@ -1233,10 +1233,9 @@ public class Platform
Vec3 vec31 = vec3.addVector( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 ); Vec3 vec31 = vec3.addVector( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
AxisAlignedBB bb = AxisAlignedBB AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ),
.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord, vec31.zCoord ), Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ),
Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), Math.max( vec3.zCoord, vec31.zCoord ) ) Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
.expand( 16, 16, 16 );
Entity entity = null; Entity entity = null;
double Closeest = 9999999.0D; double Closeest = 9999999.0D;
@@ -1643,4 +1642,27 @@ public class Platform
return null; return null;
} }
public static ItemStack getContainerItem(ItemStack stackInSlot)
{
if ( stackInSlot == null )
return null;
Item i = stackInSlot.getItem();
if ( i == null || !i.hasContainerItem( stackInSlot ) )
{
if ( stackInSlot.stackSize > 1 )
{
stackInSlot.stackSize--;
return stackInSlot;
}
return null;
}
ItemStack ci = i.getContainerItem( stackInSlot.copy() );
if ( ci.isItemStackDamageable() && ci.getItemDamage() == ci.getMaxDamage() )
ci = null;
return ci;
}
} }
+2 -2
View File
@@ -183,14 +183,14 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
return records.isEmpty(); return !iterator().hasNext();
} }
public Collection<StackType> findFuzzyDamage(AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta) public Collection<StackType> findFuzzyDamage(AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta)
{ {
StackType low = (StackType) filter.getLow( fuzzy, ignoreMeta ); StackType low = (StackType) filter.getLow( fuzzy, ignoreMeta );
StackType high = (StackType) filter.getHigh( fuzzy, ignoreMeta ); StackType high = (StackType) filter.getHigh( fuzzy, ignoreMeta );
return records.subMap( low, true, high, true ).values(); return records.subMap( low, true, high, true ).descendingMap().values();
} }
@Override @Override