mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-29 00:08:50 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a9e1e86b2 |
No files matched your search
@@ -10,6 +10,7 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -20,6 +21,7 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
@@ -1134,6 +1136,11 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
return pullBookmarkItems(this.grid.createRecipeChainMath(groupId), shift);
|
||||
}
|
||||
|
||||
private static long fluidPerContainer(ItemStack stack) {
|
||||
final FluidStack fluid = StackInfo.isFluidContainer(stack) ? StackInfo.getFluid(stack) : null;
|
||||
return fluid != null ? fluid.amount : 0;
|
||||
}
|
||||
|
||||
public boolean pullBookmarkItems(RecipeChainMath math, boolean shift) {
|
||||
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
|
||||
final IBookmarkContainerHandler containerHandler = BookmarkContainerInfo
|
||||
@@ -1181,7 +1188,11 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
math.initialItems.add(BookmarkItem.of(-1, stack));
|
||||
}
|
||||
|
||||
for (ItemStack stack : containerStorage.values()) {
|
||||
// The chain takes storage items in this order, so partly filled fluid containers are used up first
|
||||
final List<ItemStack> storageStacks = containerStorage.values();
|
||||
storageStacks.sort(Comparator.comparingLong(BookmarkPanel::fluidPerContainer));
|
||||
|
||||
for (ItemStack stack : storageStacks) {
|
||||
math.initialItems.add(BookmarkItem.of(-2, stack));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.api.IBookmarkContainerHandler;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandler {
|
||||
|
||||
@@ -19,7 +20,7 @@ public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandle
|
||||
for (ItemStack bookmarkItem : bookmarkItems) {
|
||||
for (int i = 0; i < slots.size() - 4 * 9; i++) {
|
||||
final Slot slot = slots.get(i);
|
||||
if (slot.getHasStack() && bookmarkItem.isItemEqual(slot.getStack())) {
|
||||
if (slot.getHasStack() && matches(bookmarkItem, slot.getStack())) {
|
||||
final int transferAmount = Math.min(bookmarkItem.stackSize, slot.getStack().stackSize);
|
||||
manager.transferItems(guiContainer, i, transferAmount);
|
||||
bookmarkItem.stackSize -= transferAmount;
|
||||
@@ -27,4 +28,15 @@ public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If either stack holds a fluid, both need the same NBT, so a filled fluid cell is not taken for an empty one.
|
||||
* Other items match as in crafting, so an item that got its NBT later is still pulled.
|
||||
*/
|
||||
private static boolean matches(ItemStack bookmarkItem, ItemStack stack) {
|
||||
if (StackInfo.getFluid(bookmarkItem) != null || StackInfo.getFluid(stack) != null) {
|
||||
return bookmarkItem.isItemEqual(stack) && StackInfo.equalItemAndNBT(bookmarkItem, stack, true);
|
||||
}
|
||||
return NEIServerUtils.areStacksSameTypeCraftingWithNBT(bookmarkItem, stack);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user