Interface TransferVariant<O>
- Type Parameters:
O
- The type of the immutable object instance, for exampleItem
orFluid
. Experimental feature, 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.
- All Known Subinterfaces:
FluidVariant
,ItemVariant
Item
or Fluid
) and an optional NBT tag.
This is exposed for convenience for code that needs to be generic across multiple transfer variants,
but note that a Storage
is not necessarily bound to TransferVariant
. Its generic parameter can be any immutable object.
Transfer variants must always be compared with equals
, never by reference!
hashCode
is guaranteed to be correct and constant time independently of the size of the NBT.
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable NbtCompound
copyNbt()
Return a copy of the tag of this variant, ornull
if this variant doesn't have a tag.default NbtCompound
Return a copy of the tag of this variant, or a new compound if this variant doesn't have a tag.getNbt()
Return the underlying tag.Return the immutable object instance of this variant.default boolean
hasNbt()
Return true if this variant has a tag, false otherwise.boolean
isBlank()
Return true if this variant is blank, and false otherwise.default boolean
Returntrue
if the object of this variant matches the passed fluid.default boolean
nbtMatches
(@Nullable NbtCompound other) Return true if the tag of this variant matches the passed tag, and false otherwise.toNbt()
Save this variant into an NBT compound tag.void
toPacket
(PacketByteBuf buf) Write this variant into a packet byte buffer.
-
Method Details
-
isBlank
boolean isBlank()Return true if this variant is blank, and false otherwise. -
getObject
O getObject()Return the immutable object instance of this variant. -
getNbt
Return the underlying tag.NEVER MUTATE THIS NBT TAG, if you need to mutate it you can use
copyNbt()
to retrieve a copy instead. -
hasNbt
default boolean hasNbt()Return true if this variant has a tag, false otherwise. -
nbtMatches
Return true if the tag of this variant matches the passed tag, and false otherwise.Note: True is returned if both tags are
null
. -
isOf
Returntrue
if the object of this variant matches the passed fluid. -
copyNbt
Return a copy of the tag of this variant, ornull
if this variant doesn't have a tag.Note: Use
nbtMatches(net.minecraft.nbt.NbtCompound)
if you only need to check for custom tag equality, orgetNbt()
if you don't need to mutate the tag. -
copyOrCreateNbt
Return a copy of the tag of this variant, or a new compound if this variant doesn't have a tag. -
toNbt
NbtCompound toNbt()Save this variant into an NBT compound tag. Subinterfaces should have a matching staticfromNbt
.Note: This is safe to use for persisting data as objects are saved using their full Identifier.
-
toPacket
Write this variant into a packet byte buffer. Subinterfaces should have a matching staticfromPacket
.Implementation note: Objects are saved using their raw registry integer id.
-