From e7471eb7e4b232cce88e065a9f86d828e3114f86 Mon Sep 17 00:00:00 2001
From: Technici4n <13494793+Technici4n@users.noreply.github.com>
Date: Thu, 23 Feb 2023 11:12:57 +0100
Subject: [PATCH] Transfer API v3: Allow null directions, remove deprecated
 exactView override (#2909)

---
 .../fabric/api/transfer/v1/fluid/FluidStorage.java  |  4 ++--
 .../fabric/api/transfer/v1/item/ItemStorage.java    |  5 +++--
 .../fabric/api/transfer/v1/storage/Storage.java     |  9 ---------
 .../transfer/v1/storage/base/FilteringStorage.java  | 13 -------------
 .../fabric/impl/transfer/item/ComposterWrapper.java |  7 ++-----
 5 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/fluid/FluidStorage.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/fluid/FluidStorage.java
index d6ac5e77b..084ef4010 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/fluid/FluidStorage.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/fluid/FluidStorage.java
@@ -55,7 +55,7 @@ public final class FluidStorage {
 	/**
 	 * Sided block access to fluid variant storages.
 	 * Fluid amounts are always expressed in {@linkplain FluidConstants droplets}.
-	 * The {@code Direction} parameter may never be null.
+	 * The {@code Direction} parameter may be null, meaning that the full inventory (ignoring side restrictions) should be queried.
 	 * Refer to {@link BlockApiLookup} for documentation on how to use this field.
 	 *
 	 * <p>A simple way to expose fluid variant storages for a block entity hierarchy is to extend {@link SidedStorageBlockEntity}.
@@ -68,7 +68,7 @@ public final class FluidStorage {
 	 * On the server thread (i.e. with a server world), all transfer functionality is always supported.
 	 * On the client thread (i.e. with a client world), contents of queried Storages are unreliable and should not be modified.
 	 */
-	public static final BlockApiLookup<Storage<FluidVariant>, Direction> SIDED =
+	public static final BlockApiLookup<Storage<FluidVariant>, @Nullable Direction> SIDED =
 			BlockApiLookup.get(new Identifier("fabric:sided_fluid_storage"), Storage.asClass(), Direction.class);
 
 	/**
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/ItemStorage.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/ItemStorage.java
index dd25c51d0..2b0c812c8 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/ItemStorage.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/ItemStorage.java
@@ -19,6 +19,7 @@ package net.fabricmc.fabric.api.transfer.v1.item;
 import java.util.List;
 
 import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
 
 import net.minecraft.block.Blocks;
 import net.minecraft.block.ChestBlock;
@@ -48,7 +49,7 @@ import net.fabricmc.fabric.mixin.transfer.DoubleInventoryAccessor;
 public final class ItemStorage {
 	/**
 	 * Sided block access to item variant storages.
-	 * The {@code Direction} parameter may never be null.
+	 * The {@code Direction} parameter may be null, meaning that the full inventory (ignoring side restrictions) should be queried.
 	 * Refer to {@link BlockApiLookup} for documentation on how to use this field.
 	 *
 	 * <p>When the operations supported by a storage change,
@@ -79,7 +80,7 @@ public final class ItemStorage {
 	 * On the server thread (i.e. with a server world), all transfer functionality is always supported.
 	 * On the client thread (i.e. with a client world), contents of queried Storages are unreliable and should not be modified.
 	 */
-	public static final BlockApiLookup<Storage<ItemVariant>, Direction> SIDED =
+	public static final BlockApiLookup<Storage<ItemVariant>, @Nullable Direction> SIDED =
 			BlockApiLookup.get(new Identifier("fabric:sided_item_storage"), Storage.asClass(), Direction.class);
 
 	private ItemStorage() {
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/Storage.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/Storage.java
index 012c89a69..85e9b7493 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/Storage.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/Storage.java
@@ -167,15 +167,6 @@ public interface Storage<T> extends Iterable<StorageView<T>> {
 		return null;
 	}
 
-	/**
-	 * @deprecated Use and implement the overload without the transaction parameter.
-	 */
-	@Deprecated(forRemoval = true)
-	@Nullable
-	default StorageView<T> exactView(TransactionContext transaction, T resource) {
-		return exactView(resource);
-	}
-
 	/**
 	 * Return an integer representing the current version of this storage instance to allow for fast change detection:
 	 * if the version hasn't changed since the last time, <b>and the storage instance is the same</b>, the storage has the same contents.
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java
index 506388047..b55f1db78 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java
@@ -177,19 +177,6 @@ public abstract class FilteringStorage<T> implements Storage<T> {
 		}
 	}
 
-	@Deprecated(forRemoval = true)
-	@Override
-	@Nullable
-	public StorageView<T> exactView(TransactionContext transaction, T resource) {
-		StorageView<T> exact = backingStorage.get().exactView(transaction, resource);
-
-		if (exact != null) {
-			return new FilteringStorageView(exact);
-		} else {
-			return null;
-		}
-	}
-
 	@Override
 	public long getVersion() {
 		return backingStorage.get().getVersion();
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/ComposterWrapper.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/ComposterWrapper.java
index 6fe8fa0fa..5f81ad065 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/ComposterWrapper.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/ComposterWrapper.java
@@ -19,7 +19,6 @@ package net.fabricmc.fabric.impl.transfer.item;
 import static net.minecraft.util.math.Direction.UP;
 
 import java.util.Map;
-import java.util.Objects;
 
 import com.google.common.collect.MapMaker;
 import org.jetbrains.annotations.Nullable;
@@ -63,10 +62,8 @@ public class ComposterWrapper extends SnapshotParticipant<Float> {
 	private static final Map<WorldLocation, ComposterWrapper> COMPOSTERS = new MapMaker().concurrencyLevel(1).weakValues().makeMap();
 
 	@Nullable
-	public static Storage<ItemVariant> get(World world, BlockPos pos, Direction direction) {
-		Objects.requireNonNull(direction);
-
-		if (direction.getAxis().isVertical()) {
+	public static Storage<ItemVariant> get(World world, BlockPos pos, @Nullable Direction direction) {
+		if (direction != null && direction.getAxis().isVertical()) {
 			WorldLocation location = new WorldLocation(world, pos.toImmutable());
 			ComposterWrapper composterWrapper = COMPOSTERS.computeIfAbsent(location, ComposterWrapper::new);
 			return direction == UP ? composterWrapper.upStorage : composterWrapper.downStorage;