Fix container item crafting (again)

avoid making some copies
fix crash without JEI
This commit is contained in:
PrototypeTrousers
2022-03-15 23:42:56 -03:00
parent ccc8486571
commit 706e577dab
12 changed files with 130 additions and 191 deletions
+2 -13
View File
@@ -58,7 +58,6 @@ public class CraftingJob implements Runnable, ICraftingJob
private final World world;
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 HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
private final Object monitor = new Object();
@@ -92,7 +91,7 @@ public class CraftingJob implements Runnable, ICraftingJob
this.cc = grid.getCache( ICraftingGrid.class );
final GridStorageCache sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg.getExtractableList( actionSrc ) );
this.original = sg.getExtractableList( actionSrc );
this.setTree( this.getCraftingTree( cc, what ) );
this.availableCheck = null;
@@ -108,11 +107,6 @@ public class CraftingJob implements Runnable, ICraftingJob
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
}
public IItemList<IAEItemStack> getUsedWhileBuilding()
{
return usedWhileBuilding;
}
IAEItemStack checkUse( final IAEItemStack available )
{
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
@@ -120,12 +114,7 @@ public class CraftingJob implements Runnable, ICraftingJob
IAEItemStack checkAvailable( final IAEItemStack available )
{
return this.original.extractItems( available.copy().setStackSize( Long.MAX_VALUE ), Actionable.SIMULATE, this.actionSrc );
}
public void writeToNBT( final NBTTagCompound out )
{
return this.availableCheck.extractItems( available, Actionable.SIMULATE, this.actionSrc );
}
void addTask( IAEItemStack what, final long crafts, final ICraftingPatternDetails details, final int depth )
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.List;
import appeng.api.config.FuzzyMode;
import appeng.util.Platform;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
@@ -36,8 +37,10 @@ import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import net.minecraftforge.fml.common.Optional;
@Optional.Interface( iface = "gregtech.api.items.IToolItem", modid = "gregtech" )
public class CraftingTreeNode
{
@@ -119,7 +122,7 @@ public class CraftingTreeNode
{
Collection<IAEItemStack> itemList = new ArrayList<>();
if( this.what.getItem().hasContainerItem( this.what.getDefinition() ) || this.what.getItem().isDamageable() )
if( this.what.getItem().isDamageable() || Platform.isGTDamageableItem( this.what.getItem() ) )
{
itemList.addAll( inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) );
@@ -51,7 +51,6 @@ public class CraftingTreeProcess
private final World world;
boolean possible = true;
private long crafts = 0;
private boolean limitQty;
private long bytes = 0;
public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth )
@@ -70,19 +69,8 @@ public class CraftingTreeProcess
{
return;
}
final IAEItemStack[] list = details.getInputs();
for( final IAEItemStack part : details.getCondensedOutputs() )
{
for( final IAEItemStack o : details.getCondensedInputs() )
{
if( part.equals( o ) )
{
this.limitQty = true;
break;
}
}
}
final IAEItemStack[] list = details.getInputs();
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
for( IAEItemStack part : details.getCondensedInputs() )
@@ -100,13 +88,11 @@ public class CraftingTreeProcess
if( part.getItem().hasContainerItem( part.getDefinition() ) )
{
part = list[x];
this.limitQty = true;
isPartContainer = true;
}
long wantedSize = part.getStackSize();
IAEItemStack found;
IAEItemStack used;
long remaining = 0;
long requestAmount = 0;
@@ -120,19 +106,7 @@ public class CraftingTreeProcess
if( found != null )
{
used = job.getUsedWhileBuilding().findPrecise( subs );
remaining = found.getStackSize();
if( used != null )
{
if( used.getStackSize() >= found.getStackSize() )
{
remaining = 0;
}
else
{
remaining -= used.getStackSize();
}
}
}
if( remaining > 0 )
@@ -149,7 +123,6 @@ public class CraftingTreeProcess
wantedSize -= remaining;
}
subs = subs.copy().setStackSize( requestAmount );
job.getUsedWhileBuilding().addStorage( subs );
this.nodes.put( new CraftingTreeNode( cc, job, subs, this, x, depth + 1 ), requestAmount );
if( wantedSize == 0 )
{
@@ -164,19 +137,7 @@ public class CraftingTreeProcess
if( found != null )
{
used = job.getUsedWhileBuilding().findPrecise( part );
remaining = found.getStackSize();
if( used != null )
{
if( used.getStackSize() >= found.getStackSize() )
{
remaining = 0;
}
else
{
remaining -= used.getStackSize();
}
}
}
if( remaining > 0 )
@@ -193,7 +154,6 @@ public class CraftingTreeProcess
wantedSize -= remaining;
}
part = part.copy().setStackSize( requestAmount );
job.getUsedWhileBuilding().addStorage( part );
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), requestAmount );
}
}
@@ -272,9 +232,15 @@ public class CraftingTreeProcess
long getTimes( final long remaining, final long stackSize )
{
if( this.limitQty )
for( final IAEItemStack part : details.getCondensedOutputs() )
{
return 1;
for( final IAEItemStack o : details.getCondensedInputs() )
{
if( part.equals( o ) || o.getItem().hasContainerItem( part.getDefinition() ) )
{
return 1;
}
}
}
return ( remaining / stackSize ) + ( remaining % stackSize != 0 ? 1 : 0 );
}