diff --git a/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java b/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java index 14dd9c8..db606cc 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java @@ -2,20 +2,23 @@ package de.ellpeck.prettypipes.misc; import net.minecraft.item.ItemStack; +import java.util.Arrays; import java.util.Objects; public class EquatableItemStack { public final ItemStack stack; + public final ItemEqualityType[] equalityTypes; - public EquatableItemStack(ItemStack stack) { + public EquatableItemStack(ItemStack stack, ItemEqualityType... equalityTypes) { this.stack = stack; + this.equalityTypes = equalityTypes; } public boolean equals(Object o) { if (o instanceof EquatableItemStack) { - ItemStack other = ((EquatableItemStack) o).stack; - return ItemEqualityType.compareItems(this.stack, other, ItemEqualityType.NBT); + EquatableItemStack other = (EquatableItemStack) o; + return Arrays.equals(this.equalityTypes, other.equalityTypes) && ItemEqualityType.compareItems(this.stack, other.stack, this.equalityTypes); } return false; } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index a323c42..76a7a37 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -251,7 +251,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return tile; } - public List> getCurrentlyCrafting(BlockPos node) { + public List> getCurrentlyCrafting(BlockPos node, ItemEqualityType... equalityTypes) { this.startProfile("get_currently_crafting"); List> items = new ArrayList<>(); Iterator craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator(); @@ -262,7 +262,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL ItemStack stack = request.getRight(); // add up all the items that should go to the same location Optional> existing = items.stream() - .filter(s -> s.getLeft().equals(dest) && ItemEqualityType.compareItems(s.getRight(), stack, ItemEqualityType.NBT)) + .filter(s -> s.getLeft().equals(dest) && ItemEqualityType.compareItems(s.getRight(), stack, equalityTypes)) .findFirst(); if (existing.isPresent()) { existing.get().getRight().grow(stack.getCount()); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java index b203c91..61a2ab2 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java @@ -77,7 +77,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { for (ItemStack stack : items) { int amount = 0; // check existing items - NetworkItem network = this.networkItems.get(new EquatableItemStack(stack)); + NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT)); if (network != null) { amount = network.getLocations().stream() .mapToInt(l -> l.getItemAmount(this.world, stack, ItemEqualityType.NBT)) @@ -204,7 +204,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { ItemStack requested = inputFunction.apply(i); if (requested.isEmpty()) continue; - MutableInt amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested), s -> new MutableInt()); + MutableInt amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested, equalityTypes), s -> new MutableInt()); amount.add(requested.getCount()); // if no items fit into the crafting input, we still want to pretend they do for requesting int fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java index 58ec91f..11a5354 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java @@ -5,8 +5,10 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.misc.EquatableItemStack; import de.ellpeck.prettypipes.misc.ItemEqualityType; -import de.ellpeck.prettypipes.misc.ItemOrder; -import de.ellpeck.prettypipes.network.*; +import de.ellpeck.prettypipes.network.NetworkItem; +import de.ellpeck.prettypipes.network.NetworkLocation; +import de.ellpeck.prettypipes.network.NetworkLock; +import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketNetworkItems; import de.ellpeck.prettypipes.pipe.ConnectionType; @@ -16,7 +18,6 @@ import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; @@ -31,23 +32,17 @@ import net.minecraft.util.text.Style; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; -import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.lang3.tuple.Triple; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; import java.util.function.Consumer; -import java.util.function.Function; import java.util.stream.Collectors; public class ItemTerminalTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable { @@ -131,7 +126,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine PipeTileEntity pipe = this.getConnectedPipe(); if (pipe == null) return; - this.networkItems = this.collectItems(); + this.networkItems = this.collectItems(ItemEqualityType.NBT); if (playersToSync.length > 0) { List clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList()); List clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList()); @@ -161,7 +156,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine } public int requestItemImpl(ItemStack stack, Consumer unavailableConsumer) { - NetworkItem item = this.networkItems.get(new EquatableItemStack(stack)); + NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT)); Collection locations = item == null ? Collections.emptyList() : item.getLocations(); Pair, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, ItemEqualityType.NBT); this.existingRequests.addAll(ret.getLeft()); @@ -175,14 +170,14 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine .toArray(PlayerEntity[]::new); } - private Map collectItems() { + private Map collectItems(ItemEqualityType... equalityTypes) { PipeNetwork network = PipeNetwork.get(this.world); network.startProfile("terminal_collect_items"); PipeTileEntity pipe = this.getConnectedPipe(); Map items = new HashMap<>(); for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) { for (ItemStack stack : location.getItems(this.world).values()) { - EquatableItemStack equatable = new EquatableItemStack(stack); + EquatableItemStack equatable = new EquatableItemStack(stack, equalityTypes); NetworkItem item = items.computeIfAbsent(equatable, NetworkItem::new); item.add(location, stack); } @@ -277,10 +272,10 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine PipeNetwork network = PipeNetwork.get(world); // check for existing items for (NetworkLocation location : locations) { - int amount = location.getItemAmount(world, stack, ItemEqualityType.NBT); + int amount = location.getItemAmount(world, stack, equalityTypes); if (amount <= 0) continue; - amount -= network.getLockedAmount(location.getPos(), stack, null, ItemEqualityType.NBT); + amount -= network.getLockedAmount(location.getPos(), stack, null, equalityTypes); if (amount > 0) { if (remain.getCount() < amount) amount = remain.getCount();