Compare commits
3 Commits
v0.56.3
...
ctree-tweak
| Author | SHA1 | Date | |
|---|---|---|---|
| e3b3c8cc10 | |||
| eea5bc7c6b | |||
| d414c458ae |
@@ -58,6 +58,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemList<IAEItemStack> usedWhileBuilding = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemList<IAEItemStack> uniques = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||
private final Object monitor = new Object();
|
||||
@@ -110,9 +111,9 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
return usedWhileBuilding;
|
||||
}
|
||||
|
||||
public IAEItemStack getOriginal( IAEItemStack request )
|
||||
public IItemList<IAEItemStack> getUniques()
|
||||
{
|
||||
return original.getItemList().findPrecise( request );
|
||||
return uniques;
|
||||
}
|
||||
|
||||
IAEItemStack checkUse( final IAEItemStack available )
|
||||
|
||||
@@ -81,7 +81,7 @@ public class CraftingTreeNode
|
||||
for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
|
||||
// order.
|
||||
{
|
||||
if( this.parent == null || this.parent.notRecursive( details ) )
|
||||
if( this.parent == null || this.parent.notRecursive() )
|
||||
{
|
||||
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class CraftingTreeNode
|
||||
for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
|
||||
// order.
|
||||
{
|
||||
if( this.parent == null || this.parent.notRecursive( details ) )
|
||||
if( this.parent == null || this.parent.notRecursive() )
|
||||
{
|
||||
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class CraftingTreeNode
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.parent.notRecursive( details );
|
||||
return this.parent.notRecursive();
|
||||
}
|
||||
|
||||
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
@@ -345,6 +345,11 @@ public class CraftingTreeNode
|
||||
throw new CraftBranchFailure( this.what, l );
|
||||
}
|
||||
|
||||
boolean notRecursive()
|
||||
{
|
||||
return job.getUniques().findPrecise( this.what ) == null || this.parent == null;
|
||||
}
|
||||
|
||||
void dive( final CraftingJob job )
|
||||
{
|
||||
if( this.missing > 0 )
|
||||
|
||||
@@ -19,17 +19,13 @@
|
||||
package appeng.crafting;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -39,26 +35,21 @@ import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.util.Platform;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
||||
public class CraftingTreeProcess
|
||||
{
|
||||
|
||||
private final CraftingTreeNode parent;
|
||||
final ICraftingPatternDetails details;
|
||||
private final CraftingJob job;
|
||||
private final Object2LongArrayMap<CraftingTreeNode> nodes = new Object2LongArrayMap<>();
|
||||
private final int depth;
|
||||
boolean possible = true;
|
||||
private World world;
|
||||
private long crafts = 0;
|
||||
private boolean containerItems;
|
||||
private IItemList<IAEItemStack> containerItems;
|
||||
private boolean limitQty;
|
||||
private boolean fullSimulation;
|
||||
private long bytes = 0;
|
||||
|
||||
public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth )
|
||||
@@ -69,143 +60,84 @@ public class CraftingTreeProcess
|
||||
this.depth = depth;
|
||||
final World world = job.getWorld();
|
||||
|
||||
if( details.isCraftable() )
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
final IAEItemStack[] list = details.getInputs();
|
||||
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
||||
{
|
||||
boolean isAnInput = false;
|
||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||
if( containerItems == null )
|
||||
{
|
||||
if( a != null && a.equals( part ) )
|
||||
{
|
||||
isAnInput = true;
|
||||
break;
|
||||
containerItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
}
|
||||
containerItems.add( part );
|
||||
this.limitQty = true;
|
||||
}
|
||||
}
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for( IAEItemStack part : details.getCondensedInputs() ) {
|
||||
if (part == null) {
|
||||
continue;
|
||||
}
|
||||
for (int x = 0; x < list.length; x++) {
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if (part.equals(comparePart)) {
|
||||
if (isContainerItem(part)) {
|
||||
part = list[x];
|
||||
}
|
||||
this.nodes.put(new CraftingTreeNode(cc, job, part.copy(), this, x, depth + 1), part.getStackSize());
|
||||
if (details.canSubstitute()) {
|
||||
for ()
|
||||
}
|
||||
}
|
||||
|
||||
if( isAnInput )
|
||||
{
|
||||
this.limitQty = true;
|
||||
}
|
||||
|
||||
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
||||
{
|
||||
this.limitQty = this.containerItems = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.containerItems )
|
||||
{
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
final IAEItemStack part = list[x];
|
||||
if( part != null )
|
||||
{
|
||||
job.getUsedWhileBuilding().addStorage( part );
|
||||
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
for( int x = 0; x < list.length; x++ )
|
||||
{
|
||||
final IAEItemStack comparePart = list[x];
|
||||
if( part != null && part.equals( comparePart ) )
|
||||
{
|
||||
job.getUsedWhileBuilding().addStorage( part );
|
||||
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// use the first slot...
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
boolean isAnInput = false;
|
||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||
{
|
||||
if( a != null && a.equals( part ) )
|
||||
{
|
||||
isAnInput = true;
|
||||
|
||||
if(!this.limitQty) {
|
||||
for (final IAEItemStack part : details.getCondensedOutputs()) {
|
||||
for (final IAEItemStack o : details.getCondensedInputs()) {
|
||||
if (part.equals(o)) {
|
||||
this.limitQty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( isAnInput )
|
||||
{
|
||||
this.limitQty = true;
|
||||
}
|
||||
}
|
||||
|
||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||
{
|
||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, -1, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean notRecursive( final ICraftingPatternDetails details )
|
||||
boolean isContainerItem(IAEItemStack iaeItemStack) {
|
||||
return (containerItems != null && !containerItems.findFuzzy(iaeItemStack, FuzzyMode.IGNORE_ALL).isEmpty());
|
||||
}
|
||||
|
||||
boolean notRecursive()
|
||||
{
|
||||
return this.parent == null || this.parent.notRecursive( details );
|
||||
return this.parent == null || this.parent.notRecursive();
|
||||
}
|
||||
|
||||
long getTimes( final long remaining, final long stackSize )
|
||||
{
|
||||
if( this.limitQty || this.fullSimulation )
|
||||
if( this.limitQty )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return ( remaining / stackSize ) + ( remaining % stackSize != 0 ? 1 : 0 );
|
||||
}
|
||||
|
||||
void request( final MECraftingInventory inv, final long i, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
void request( final MECraftingInventory inv, final long amountOfTimes, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
this.job.handlePausing();
|
||||
if( this.fullSimulation )
|
||||
|
||||
// request and remove inputs...
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
final IAEItemStack craftableStack = entry.getKey().getStack( entry.getValue() );
|
||||
final IAEItemStack stack = entry.getKey().request( inv, craftableStack.getStackSize() * amountOfTimes, src );
|
||||
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
if( containerItems != null && !this.containerItems.findFuzzy( stack, FuzzyMode.IGNORE_ALL ).isEmpty() )
|
||||
{
|
||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
|
||||
|
||||
ic.setInventorySlotContents( entry.getKey().getSlot(), stack.createItemStack() );
|
||||
}
|
||||
|
||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = ic.getStackInSlot( x );
|
||||
is = Platform.getContainerItem( is );
|
||||
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
|
||||
final ItemStack is = Platform.getContainerItem( stack.createItemStack() );
|
||||
final IAEItemStack o = AEItemStack.fromItemStack( is );
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
@@ -213,26 +145,6 @@ public class CraftingTreeProcess
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// request and remove inputs...
|
||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||
{
|
||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||
|
||||
if( this.containerItems )
|
||||
{
|
||||
final ItemStack is = Platform.getContainerItem( stack.createItemStack() );
|
||||
final IAEItemStack o = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
|
||||
if( o != null )
|
||||
{
|
||||
this.bytes++;
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assume its possible.
|
||||
|
||||
@@ -240,10 +152,10 @@ public class CraftingTreeProcess
|
||||
for( final IAEItemStack out : this.details.getCondensedOutputs() )
|
||||
{
|
||||
final IAEItemStack o = out.copy();
|
||||
o.setStackSize( o.getStackSize() * i );
|
||||
o.setStackSize( o.getStackSize() * amountOfTimes );
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
this.crafts += i;
|
||||
this.crafts += amountOfTimes;
|
||||
}
|
||||
|
||||
void dive( final CraftingJob job )
|
||||
|
||||
@@ -464,14 +464,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
try
|
||||
{
|
||||
if( removed )
|
||||
{
|
||||
this.gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, this.gridProxy.getNode() ) );
|
||||
}
|
||||
else if( newPattern )
|
||||
{
|
||||
this.provideCrafting( (ICraftingProviderHelper) this.gridProxy.getCrafting() );
|
||||
}
|
||||
this.gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, this.gridProxy.getNode() ) );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
|
||||
@@ -411,27 +411,6 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
{
|
||||
details.add( medium );
|
||||
}
|
||||
|
||||
if( !updatePatterns )
|
||||
{
|
||||
List<IAEItemStack> newCraftables = new ArrayList<>();
|
||||
|
||||
ObjectSet<ICraftingPatternDetails> b = new ObjectRBTreeSet<>( COMPARATOR );
|
||||
ImmutableList<ICraftingPatternDetails> a = this.craftableItems.get( api.getCondensedOutputs()[0] );
|
||||
if( a != null )
|
||||
{
|
||||
b.addAll( this.craftableItems.get( api.getOutputs()[0] ) );
|
||||
}
|
||||
b.add( api );
|
||||
|
||||
for( IAEItemStack stack : api.getCondensedOutputs() )
|
||||
{
|
||||
IAEItemStack i = stack.copy().reset().setCraftable( true );
|
||||
this.craftableItems.put( i, ImmutableList.copyOf( b ) );
|
||||
newCraftables.add( i );
|
||||
}
|
||||
this.storageGrid.postCraftablesChanges( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), newCraftables, new BaseActionSource() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user