Skip to content

Commit

Permalink
[1.20.3] Make Transfer API stable & remove previously deprecated API. (
Browse files Browse the repository at this point in the history
…#3364)

* Remove deprecated transfer APIs.

* Make Transfer API stable.
  • Loading branch information
modmuss50 authored Oct 8, 2023
1 parent 10292b9 commit 0e870a0
Show file tree
Hide file tree
Showing 40 changed files with 5 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.item.TooltipContext;
Expand All @@ -34,11 +33,7 @@
/**
* Defines how {@linkplain FluidVariant fluid variants} of a given Fluid should be displayed to clients.
* Register with {@link FluidVariantRendering#register}.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public interface FluidVariantRenderHandler {
/**
* Append additional tooltips to the passed list if additional information is contained in the fluid variant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Objects;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.MinecraftClient;
Expand All @@ -39,11 +38,7 @@

/**
* Client-side display of fluid variants.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FluidVariantRendering {
private static final ApiProviderMap<Fluid, FluidVariantRenderHandler> HANDLERS = ApiProviderMap.create();
private static final FluidVariantRenderHandler DEFAULT_HANDLER = new FluidVariantRenderHandler() { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;

Expand All @@ -39,7 +38,6 @@
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.fabricmc.fabric.impl.transfer.context.ConstantContainerItemContext;
import net.fabricmc.fabric.impl.transfer.context.CreativeInteractionContainerItemContext;
import net.fabricmc.fabric.impl.transfer.context.InitialContentsContainerItemContext;
import net.fabricmc.fabric.impl.transfer.context.PlayerContainerItemContext;
import net.fabricmc.fabric.impl.transfer.context.SingleSlotContainerItemContext;

Expand Down Expand Up @@ -85,11 +83,7 @@
* <li>Exchange some of the current variant with another variant through {@link #exchange}.
* In the water bucket example, this function can be used to combine steps 1, 2 and 3.</li>
* </ul>
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public interface ContainerItemContext {
/**
* Returns a context for interaction with a player's hand. This is recommended for item use interactions.
Expand Down Expand Up @@ -168,33 +162,6 @@ static ContainerItemContext withConstant(ItemVariant constantVariant, long const
return new ConstantContainerItemContext(constantVariant, constantAmount);
}

/**
* Return a context that can accept anything, and will accept (and destroy) any overflow items, with some initial content.
* This can typically be used to check if a stack provides an API, or simulate operations on the returned API,
* for example to simulate how much fluid could be extracted from the stack.
*
* <p>Note that the stack can never be mutated by this function: its contents are copied directly.
*
* @deprecated Use {@link #withConstant(ItemStack)} instead.
*/
@Deprecated(forRemoval = true)
static ContainerItemContext withInitial(ItemStack initialContent) {
return withInitial(ItemVariant.of(initialContent), initialContent.getCount());
}

/**
* Return a context that can accept anything, and will accept (and destroy) any overflow items, with some initial variant and amount.
* This can typically be used to check if a variant provides an API, or simulate operations on the returned API,
* for example to simulate how much fluid could be extracted from the variant and amount.
*
* @deprecated Use {@link #withConstant(ItemVariant, long)} instead.
*/
@Deprecated(forRemoval = true)
static ContainerItemContext withInitial(ItemVariant initialVariant, long initialAmount) {
StoragePreconditions.notNegative(initialAmount);
return new InitialContentsContainerItemContext(initialVariant, initialAmount);
}

/**
* Try to find an API instance for the passed lookup and return it, or {@code null} if there is none.
* The API is queried for the current variant, if it's not blank.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.Collection;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -47,11 +46,7 @@
* </li>
* <li>{@code amountPerLevel} defines how much fluid (in droplets) there is in one level of the cauldron.</li>
* </ul>
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class CauldronFluidContent {
/**
* Block of the cauldron.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@

package net.fabricmc.fabric.api.transfer.v1.fluid;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.fluid.FlowableFluid;

/**
* Constants for fluid transfer. In general, 1 bucket = 81000 droplets = 1 block.
*
* <p>If you don't know how many droplets you should pick for a specific resource that has a block form,
* the convention is to use 81000 droplets for what is worth one block of that resource.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FluidConstants {
///////////////////////////
// ==== FLUID UNITS ==== //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

package net.fabricmc.fabric.api.transfer.v1.fluid;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.util.Identifier;
Expand All @@ -33,24 +32,20 @@
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup;
import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.base.EmptyItemFluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.base.FullItemFluidStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.impl.transfer.fluid.EmptyBucketStorage;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity;
import net.fabricmc.fabric.impl.transfer.fluid.CombinedProvidersImpl;
import net.fabricmc.fabric.impl.transfer.fluid.EmptyBucketStorage;
import net.fabricmc.fabric.impl.transfer.fluid.WaterPotionStorage;
import net.fabricmc.fabric.mixin.transfer.BucketItemAccessor;

/**
* Access to {@link Storage Storage&lt;FluidVariant&gt;} instances.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FluidStorage {
/**
* Sided block access to fluid variant storages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.Objects;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
Expand All @@ -39,11 +37,7 @@

/**
* Helper functions to work with fluid storages.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FluidStorageUtil {
/**
* Try to make the item in a player hand "interact" with a fluid storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@
*
* <p><b>Fluid variants must always be compared with {@code equals}, never by reference!</b>
* {@code hashCode} is guaranteed to be correct and constant time independently of the size of the NBT.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface FluidVariant extends TransferVariant<Fluid> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.Optional;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Block;
Expand All @@ -35,11 +34,7 @@
/**
* Defines the common attributes of {@linkplain FluidVariant fluid variants} of a given Fluid.
* Register with {@link FluidVariantAttributes#register}.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public interface FluidVariantAttributeHandler {
/**
* Return the name that should be used for the passed fluid variant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.Optional;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Blocks;
Expand All @@ -37,11 +36,7 @@

/**
* Common fluid variant attributes, accessible both client-side and server-side.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FluidVariantAttributes {
private static final ApiProviderMap<Fluid, FluidVariantAttributeHandler> HANDLERS = ApiProviderMap.create();
private static final FluidVariantAttributeHandler DEFAULT_HANDLER = new FluidVariantAttributeHandler() { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.List;
import java.util.function.Function;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;

Expand Down Expand Up @@ -55,11 +53,7 @@
* (This is just for illustration purposes! In practice, Fabric API already registers storages for most buckets,
* and it is inefficient to have one storage registered per fluid
* so Fabric API has a storage that accepts any fluid with a corresponding full bucket).
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class EmptyItemFluidStorage implements InsertionOnlyStorage<FluidVariant> {
private final ContainerItemContext context;
private final Item emptyItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.function.Function;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.item.Item;

import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
Expand All @@ -37,11 +35,7 @@
* however there is a second constructor that allows customizing the mapping.
*
* <p>This is used similarly to {@link EmptyItemFluidStorage}.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class FullItemFluidStorage implements ExtractionOnlyStorage<FluidVariant>, SingleSlotStorage<FluidVariant> {
private final ContainerItemContext context;
private final Item fullItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.Objects;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.nbt.NbtCompound;

import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
Expand All @@ -34,11 +32,7 @@
*
* <p>This is a convenient specialization of {@link SingleVariantStorage} for fluids that additionally offers methods
* to read the contents of the storage from NBT.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public abstract class SingleFluidStorage extends SingleVariantStorage<FluidVariant> {
/**
* Create a fluid storage with a fixed capacity and a change handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
*
* <p><b>Important note:</b> This wrapper assumes that the inventory owns its slots.
* If the inventory does not own its slots, for example because it delegates to another inventory, this wrapper should not be used!
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface InventoryStorage extends SlottedStorage<ItemVariant> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Blocks;
Expand All @@ -43,11 +42,7 @@

/**
* Access to {@link Storage Storage&lt;ItemVariant&gt;} instances.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public final class ItemStorage {
/**
* Sided block access to item variant storages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
* An immutable count-less ItemStack, i.e. an immutable association of an item and an optional NBT compound tag.
*
* <p>Do not implement, use the static {@code of(...)} functions instead.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface ItemVariant extends TransferVariant<Item> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@
* However, {@link #insert} is overridden to behave like {@link #offer}.
* For simple insertions, {@link #offer} or {@link #offerOrDrop} is recommended.
* {@link #getSlots} can also be used and combined with {@link CombinedStorage} to retrieve a wrapper around a specific range of slots.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
// TODO: Consider explicitly syncing stacks by sending a ScreenHandlerSlotUpdateS2CPacket if that proves to be necessary.
// TODO: Vanilla doesn't seem to be doing it reliably, so we ignore it for now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package net.fabricmc.fabric.api.transfer.v1.item.base;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.nbt.NbtCompound;

import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
Expand All @@ -31,11 +29,7 @@
*
* <p>This is a convenient specialization of {@link SingleVariantStorage} for items that additionally offers methods
* to read the contents of the storage from NBT.
*
* <p><b>Experimental feature</b>, we reserve the right to remove or change it without further notice.
* The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
*/
@ApiStatus.Experimental
public abstract class SingleItemStorage extends SingleVariantStorage<ItemVariant> {
@Override
protected final ItemVariant getBlankVariant() {
Expand Down
Loading

0 comments on commit 0e870a0

Please sign in to comment.