mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-26 05:28:33 +01:00
fixed some equality type inconsistencies
This commit is contained in:
parent
c041b2320b
commit
78deb87993
4 changed files with 20 additions and 22 deletions
|
@ -2,20 +2,23 @@ package de.ellpeck.prettypipes.misc;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class EquatableItemStack {
|
public class EquatableItemStack {
|
||||||
|
|
||||||
public final ItemStack stack;
|
public final ItemStack stack;
|
||||||
|
public final ItemEqualityType[] equalityTypes;
|
||||||
|
|
||||||
public EquatableItemStack(ItemStack stack) {
|
public EquatableItemStack(ItemStack stack, ItemEqualityType... equalityTypes) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
this.equalityTypes = equalityTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof EquatableItemStack) {
|
if (o instanceof EquatableItemStack) {
|
||||||
ItemStack other = ((EquatableItemStack) o).stack;
|
EquatableItemStack other = (EquatableItemStack) o;
|
||||||
return ItemEqualityType.compareItems(this.stack, other, ItemEqualityType.NBT);
|
return Arrays.equals(this.equalityTypes, other.equalityTypes) && ItemEqualityType.compareItems(this.stack, other.stack, this.equalityTypes);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pair<BlockPos, ItemStack>> getCurrentlyCrafting(BlockPos node) {
|
public List<Pair<BlockPos, ItemStack>> getCurrentlyCrafting(BlockPos node, ItemEqualityType... equalityTypes) {
|
||||||
this.startProfile("get_currently_crafting");
|
this.startProfile("get_currently_crafting");
|
||||||
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
||||||
Iterator<PipeTileEntity> craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator();
|
Iterator<PipeTileEntity> craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator();
|
||||||
|
@ -262,7 +262,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
||||||
ItemStack stack = request.getRight();
|
ItemStack stack = request.getRight();
|
||||||
// add up all the items that should go to the same location
|
// add up all the items that should go to the same location
|
||||||
Optional<Pair<BlockPos, ItemStack>> existing = items.stream()
|
Optional<Pair<BlockPos, ItemStack>> 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();
|
.findFirst();
|
||||||
if (existing.isPresent()) {
|
if (existing.isPresent()) {
|
||||||
existing.get().getRight().grow(stack.getCount());
|
existing.get().getRight().grow(stack.getCount());
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
for (ItemStack stack : items) {
|
for (ItemStack stack : items) {
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
// check existing items
|
// check existing items
|
||||||
NetworkItem network = this.networkItems.get(new EquatableItemStack(stack));
|
NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT));
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
amount = network.getLocations().stream()
|
amount = network.getLocations().stream()
|
||||||
.mapToInt(l -> l.getItemAmount(this.world, stack, ItemEqualityType.NBT))
|
.mapToInt(l -> l.getItemAmount(this.world, stack, ItemEqualityType.NBT))
|
||||||
|
@ -204,7 +204,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
ItemStack requested = inputFunction.apply(i);
|
ItemStack requested = inputFunction.apply(i);
|
||||||
if (requested.isEmpty())
|
if (requested.isEmpty())
|
||||||
continue;
|
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());
|
amount.add(requested.getCount());
|
||||||
// if no items fit into the crafting input, we still want to pretend they do for requesting
|
// 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);
|
int fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1);
|
||||||
|
|
|
@ -5,8 +5,10 @@ import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.misc.EquatableItemStack;
|
import de.ellpeck.prettypipes.misc.EquatableItemStack;
|
||||||
import de.ellpeck.prettypipes.misc.ItemEqualityType;
|
import de.ellpeck.prettypipes.misc.ItemEqualityType;
|
||||||
import de.ellpeck.prettypipes.misc.ItemOrder;
|
import de.ellpeck.prettypipes.network.NetworkItem;
|
||||||
import de.ellpeck.prettypipes.network.*;
|
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.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
|
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
|
||||||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
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.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
import net.minecraft.inventory.container.Container;
|
||||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||||
import net.minecraft.item.ItemStack;
|
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.TextFormatting;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.Constants;
|
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
import net.minecraftforge.common.util.Constants.NBT;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
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.Pair;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ItemTerminalTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
|
public class ItemTerminalTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
|
||||||
|
@ -131,7 +126,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
PipeTileEntity pipe = this.getConnectedPipe();
|
PipeTileEntity pipe = this.getConnectedPipe();
|
||||||
if (pipe == null)
|
if (pipe == null)
|
||||||
return;
|
return;
|
||||||
this.networkItems = this.collectItems();
|
this.networkItems = this.collectItems(ItemEqualityType.NBT);
|
||||||
if (playersToSync.length > 0) {
|
if (playersToSync.length > 0) {
|
||||||
List<ItemStack> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
List<ItemStack> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||||
List<ItemStack> clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
List<ItemStack> 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<ItemStack> unavailableConsumer) {
|
public int requestItemImpl(ItemStack stack, Consumer<ItemStack> unavailableConsumer) {
|
||||||
NetworkItem item = this.networkItems.get(new EquatableItemStack(stack));
|
NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT));
|
||||||
Collection<NetworkLocation> locations = item == null ? Collections.emptyList() : item.getLocations();
|
Collection<NetworkLocation> locations = item == null ? Collections.emptyList() : item.getLocations();
|
||||||
Pair<List<NetworkLock>, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, ItemEqualityType.NBT);
|
Pair<List<NetworkLock>, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, ItemEqualityType.NBT);
|
||||||
this.existingRequests.addAll(ret.getLeft());
|
this.existingRequests.addAll(ret.getLeft());
|
||||||
|
@ -175,14 +170,14 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
.toArray(PlayerEntity[]::new);
|
.toArray(PlayerEntity[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<EquatableItemStack, NetworkItem> collectItems() {
|
private Map<EquatableItemStack, NetworkItem> collectItems(ItemEqualityType... equalityTypes) {
|
||||||
PipeNetwork network = PipeNetwork.get(this.world);
|
PipeNetwork network = PipeNetwork.get(this.world);
|
||||||
network.startProfile("terminal_collect_items");
|
network.startProfile("terminal_collect_items");
|
||||||
PipeTileEntity pipe = this.getConnectedPipe();
|
PipeTileEntity pipe = this.getConnectedPipe();
|
||||||
Map<EquatableItemStack, NetworkItem> items = new HashMap<>();
|
Map<EquatableItemStack, NetworkItem> items = new HashMap<>();
|
||||||
for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) {
|
for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) {
|
||||||
for (ItemStack stack : location.getItems(this.world).values()) {
|
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);
|
NetworkItem item = items.computeIfAbsent(equatable, NetworkItem::new);
|
||||||
item.add(location, stack);
|
item.add(location, stack);
|
||||||
}
|
}
|
||||||
|
@ -277,10 +272,10 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
PipeNetwork network = PipeNetwork.get(world);
|
PipeNetwork network = PipeNetwork.get(world);
|
||||||
// check for existing items
|
// check for existing items
|
||||||
for (NetworkLocation location : locations) {
|
for (NetworkLocation location : locations) {
|
||||||
int amount = location.getItemAmount(world, stack, ItemEqualityType.NBT);
|
int amount = location.getItemAmount(world, stack, equalityTypes);
|
||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
continue;
|
continue;
|
||||||
amount -= network.getLockedAmount(location.getPos(), stack, null, ItemEqualityType.NBT);
|
amount -= network.getLockedAmount(location.getPos(), stack, null, equalityTypes);
|
||||||
if (amount > 0) {
|
if (amount > 0) {
|
||||||
if (remain.getCount() < amount)
|
if (remain.getCount() < amount)
|
||||||
amount = remain.getCount();
|
amount = remain.getCount();
|
||||||
|
|
Loading…
Reference in a new issue