diff --git a/src/main/java/appeng/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java index 2c9c8185e..44cb81ddd 100644 --- a/src/main/java/appeng/crafting/CraftingTreeNode.java +++ b/src/main/java/appeng/crafting/CraftingTreeNode.java @@ -32,9 +32,10 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInformPlayer; import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.util.Platform; +import appeng.util.item.AEItemStack; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import net.minecraftforge.fml.common.Optional; import java.io.IOException; import java.util.ArrayList; @@ -137,13 +138,23 @@ public class CraftingTreeNode { } for (IAEItemStack fuzz : itemList) { - if (this.parent.details.isValidItemForSlot(this.getSlot(), fuzz.copy().getCachedItemStack(1), this.world)) { + if (this.parent.details.isValidItemForSlot(this.getSlot(), fuzz.getDefinition(), this.world)) { fuzz = fuzz.copy(); fuzz.setStackSize(l); final IAEItemStack available = inv.extractItems(fuzz, Actionable.MODULATE, src); if (available != null) { + + if (available.getItem().hasContainerItem(available.getDefinition())) { + final ItemStack is2 = Platform.getContainerItem(available.createItemStack()); + final IAEItemStack o = AEItemStack.fromItemStack(is2); + + if (o != null) { + this.parent.addContainers(o); + } + } + if (!this.exhausted) { final IAEItemStack is = this.job.checkUse(available); @@ -197,6 +208,16 @@ public class CraftingTreeNode { final IAEItemStack available = inv.extractItems(madeWhat, Actionable.MODULATE, src); if (available != null) { + + if (parent != null && available.getItem().hasContainerItem(available.getDefinition())) { + final ItemStack is2 = Platform.getContainerItem(available.createItemStack()); + final IAEItemStack o = AEItemStack.fromItemStack(is2); + + if (o != null) { + this.parent.addContainers(o); + } + } + this.bytes += available.getStackSize(); l -= available.getStackSize(); @@ -238,6 +259,17 @@ public class CraftingTreeNode { } } + if (this.parent != null) { + if (what.getItem().hasContainerItem(what.createItemStack())) { + final ItemStack is2 = Platform.getContainerItem(what.copy().setStackSize(1).createItemStack()); + final IAEItemStack o = AEItemStack.fromItemStack(is2); + + if (o != null) { + this.parent.addContainers(o); + } + } + } + if (job.isSimulation()) { this.bytes += l; this.missing += l; diff --git a/src/main/java/appeng/crafting/CraftingTreeProcess.java b/src/main/java/appeng/crafting/CraftingTreeProcess.java index 30d496efc..1d0d3e414 100644 --- a/src/main/java/appeng/crafting/CraftingTreeProcess.java +++ b/src/main/java/appeng/crafting/CraftingTreeProcess.java @@ -27,15 +27,11 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.core.AEConfig; import appeng.me.cluster.implementations.CraftingCPUCluster; -import appeng.util.Platform; -import appeng.util.item.AEItemStack; import com.google.common.collect.ImmutableCollection; import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; -import net.minecraft.item.ItemStack; import net.minecraft.world.World; import java.util.ArrayList; -import java.util.List; import java.util.Map.Entry; @@ -50,6 +46,7 @@ public class CraftingTreeProcess { boolean possible = true; private long crafts = 0; private long bytes = 0; + private ArrayList containers; public CraftingTreeProcess(final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth) { this.parent = craftingTreeNode; @@ -198,40 +195,18 @@ public class CraftingTreeProcess { void request(final MECraftingInventory inv, final long amountOfTimes, final IActionSource src) throws CraftBranchFailure, InterruptedException { addProcess(); this.job.handlePausing(); - List containerItems = null; // request and remove inputs... for (final Entry entry : this.nodes.object2LongEntrySet()) { final IAEItemStack stack = entry.getKey().request(inv, entry.getValue() * amountOfTimes, src); - - if (this.details.isCraftable() && stack.getItem().hasContainerItem(stack.getDefinition())) { - final ItemStack is = Platform.getContainerItem(stack.createItemStack()); - final IAEItemStack o = AEItemStack.fromItemStack(is); - - //if the container item is a identical copy or a damageable one, return it immediately. - //if it is not it will need to be recrafted - if (stack.equals(is) || is.getItem().isDamageable() || Platform.isGTDamageableItem(is.getItem())){ - inv.injectItems(o, Actionable.MODULATE, src); - this.bytes++; - continue; - } - if (o != null) { - if (containerItems == null) { - containerItems = new ArrayList<>(); - } - this.bytes++; - o.setCachedItemStack(is); - containerItems.add(o); - } - } } - if (containerItems != null) { - for (IAEItemStack i : containerItems) { - inv.injectItems(i, Actionable.MODULATE, src); + if (this.containers != null) { + for (IAEItemStack iae : containers) { + inv.injectItems(iae, Actionable.MODULATE, src); } + containers = null; } - // assume its possible. // add crafting results.. @@ -243,6 +218,13 @@ public class CraftingTreeProcess { this.crafts += amountOfTimes; } + public void addContainers(IAEItemStack container) { + if (this.containers == null) { + this.containers = new ArrayList<>(); + } + this.containers.add(container); + } + void dive(final CraftingJob job) { job.addTask(this.getAmountCrafted(this.parent.getStack(1)), this.crafts, this.details, this.depth); for (final Entry entry : this.nodes.object2LongEntrySet()) {