Package com.ldtteam.structurize.api
Class ItemStackUtils
java.lang.Object
com.ldtteam.structurize.api.ItemStackUtils
Utility methods for the inventories.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.ldtteam.common.fakelevel.SingleBlockFakeLevel.SidedSingleBlockFakeLevel -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2) Method to compare to stacks, ignoring their stacksize.static booleancompareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2, boolean matchDamage, boolean matchNBT) Method to compare to stacks, ignoring their stacksize.static booleancompareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2, boolean matchDamage, boolean matchNBT, boolean min) Method to compare to stacks, ignoring their stacksize.static voiddeepExtractItemHandler(@Nullable net.neoforged.neoforge.items.IItemHandler handler, Consumer<net.minecraft.world.item.ItemStack> sink) static net.minecraft.world.item.ItemStackdeserializeFromBuffer(net.minecraft.network.RegistryFriendlyByteBuf buf) Item deserializer helper, including air.static @Nullable net.minecraft.world.item.ItemStackgetEntitySpawningItem(net.minecraft.world.entity.Entity entity) static Set<net.neoforged.neoforge.items.IItemHandler> getItemHandlersFromProvider(@Nullable net.minecraft.world.level.block.entity.BlockEntity provider, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) Method to get sensible item handlers from blockEntity.static List<net.minecraft.world.item.ItemStack> getItemStacksOfEntity(net.minecraft.world.entity.Entity entity) Get the list of required resources for entities.static List<net.minecraft.world.item.ItemStack> getItemStacksOfTileEntity(net.minecraft.nbt.CompoundTag compound, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level) Get itemStack of tileEntityData.static List<net.minecraft.world.item.ItemStack> getListOfStackForEntity(net.minecraft.world.entity.Entity entity) Get the list of required resources for entities + entity spawning item.static List<net.minecraft.world.item.ItemStack> getListOfStackForEntity(net.minecraft.world.entity.Entity entity, net.minecraft.core.BlockPos pos) Deprecated, for removal: This API element is subject to removal in a future version.static intgetSize(net.minecraft.world.item.ItemStack stack) get the size of the stack.static booleanisEmpty(@Nullable net.minecraft.world.item.ItemStack stack) Wrapper method to check if a stack is empty.static voidserializeToBuffer(net.minecraft.world.item.ItemStack stack, net.minecraft.network.RegistryFriendlyByteBuf buf) Item serializer helper, including air
-
Field Details
-
ITEM_HANDLER_FAKE_LEVEL
public static final com.ldtteam.common.fakelevel.SingleBlockFakeLevel.SidedSingleBlockFakeLevel ITEM_HANDLER_FAKE_LEVEL
-
-
Method Details
-
getItemStacksOfTileEntity
public static List<net.minecraft.world.item.ItemStack> getItemStacksOfTileEntity(net.minecraft.nbt.CompoundTag compound, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level) Get itemStack of tileEntityData. Retrieve the data from the tileEntity. Including recursive content, eg. shulkers- Parameters:
compound- the tileEntity stored in a compound.state- the block.level- real vanilla instance for fakeLevel- Returns:
- the list of itemstacks.
- See Also:
-
deepExtractItemHandler
public static void deepExtractItemHandler(@Nullable @Nullable net.neoforged.neoforge.items.IItemHandler handler, Consumer<net.minecraft.world.item.ItemStack> sink) - Parameters:
handler- root itemHandler to extractsink- where to put content of all found itemStacks, incl. recursive contents
-
getItemHandlersFromProvider
public static Set<net.neoforged.neoforge.items.IItemHandler> getItemHandlersFromProvider(@Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity provider, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) Method to get sensible item handlers from blockEntity. Tries to provide whole deduplicated content. However this assumption is weak. There still might be content (in returned set) that is not present at all or duplicated.- Parameters:
provider- The provider to get the IItemHandlers from.- Returns:
- A list with all the unique IItemHandlers a provider has.
-
isEmpty
public static boolean isEmpty(@Nullable @Nullable net.minecraft.world.item.ItemStack stack) Wrapper method to check if a stack is empty. Used for easy updating to 1.11.- Parameters:
stack- The stack to check.- Returns:
- True when the stack is empty, false when not.
-
getSize
public static int getSize(net.minecraft.world.item.ItemStack stack) get the size of the stack. This is for compatibility between 1.10 and 1.11- Parameters:
stack- to get the size from- Returns:
- the size of the stack
-
getListOfStackForEntity
@Deprecated(forRemoval=true, since="1.21.1") public static List<net.minecraft.world.item.ItemStack> getListOfStackForEntity(net.minecraft.world.entity.Entity entity, net.minecraft.core.BlockPos pos) Deprecated, for removal: This API element is subject to removal in a future version. -
getListOfStackForEntity
public static List<net.minecraft.world.item.ItemStack> getListOfStackForEntity(net.minecraft.world.entity.Entity entity) Get the list of required resources for entities + entity spawning item. Same implementation as blockEntity logic. Including recursive content, eg. shulkers- Parameters:
entity- the entity object.- Returns:
- a list of stacks.
- See Also:
-
getItemStacksOfEntity
public static List<net.minecraft.world.item.ItemStack> getItemStacksOfEntity(net.minecraft.world.entity.Entity entity) Get the list of required resources for entities. Same implementation as blockEntity logic. Including recursive content, eg. shulkers- Parameters:
entity- the entity object.- Returns:
- a list of stacks.
- See Also:
-
getEntitySpawningItem
@Nullable public static @Nullable net.minecraft.world.item.ItemStack getEntitySpawningItem(net.minecraft.world.entity.Entity entity) - Returns:
- item that should spawn given entity
-
compareItemStacksIgnoreStackSize
public static boolean compareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2) Method to compare to stacks, ignoring their stacksize.- Parameters:
itemStack1- The left stack to compare.itemStack2- The right stack to compare.- Returns:
- True when they are equal except the stacksize, false when not.
-
compareItemStacksIgnoreStackSize
public static boolean compareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2, boolean matchDamage, boolean matchNBT) Method to compare to stacks, ignoring their stacksize.- Parameters:
itemStack1- The left stack to compare.itemStack2- The right stack to compare.matchDamage- Set to true to match damage data.matchNBT- Set to true to match nbt- Returns:
- True when they are equal except the stacksize, false when not.
-
compareItemStacksIgnoreStackSize
public static boolean compareItemStacksIgnoreStackSize(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2, boolean matchDamage, boolean matchNBT, boolean min) Method to compare to stacks, ignoring their stacksize.- Parameters:
itemStack1- The left stack to compare.itemStack2- The right stack to compare.matchDamage- Set to true to match damage data.matchNBT- Set to true to match nbtmin- if the count of stack2 has to be at least the same as stack1.- Returns:
- True when they are equal except the stacksize, false when not.
-
serializeToBuffer
public static void serializeToBuffer(net.minecraft.world.item.ItemStack stack, net.minecraft.network.RegistryFriendlyByteBuf buf) Item serializer helper, including air- Parameters:
stack-buf-
-
deserializeFromBuffer
public static net.minecraft.world.item.ItemStack deserializeFromBuffer(net.minecraft.network.RegistryFriendlyByteBuf buf) Item deserializer helper, including air. Must be serialized with the above util- Parameters:
buf-
-
getListOfStackForEntity(Entity)