java.lang.Object
com.hammy275.immersivemc.common.immersive.storage.dual.impl.ItemStorage
All Implemented Interfaces:
NetworkStorage, WorldStorage
Direct Known Subclasses:
AnvilStorage, BeaconStorage, CraftingTableStorage, ETableWorldStorage, SmithingTableStorage

public abstract class ItemStorage extends Object implements WorldStorage, NetworkStorage
Functions both as WorldStorage for saving server side and as a NetworkStorage for sending items to the client. Note that only the items array is sent to the client, no other fields are!
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Item counts from each player for each slot.
    protected net.minecraft.world.item.ItemStack[]
    A list of items.
    final int
    The index of the last item in the items array that is an input item.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemStorage(int numItems, int maxInputIndex)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addSlotsToEnd(int slotsToAdd)
    Add slotsToAdd number of slots.
    void
     
    void
    decode(net.minecraft.network.FriendlyByteBuf buffer)
    Decode the buffer into this object.
    void
    encode(net.minecraft.network.FriendlyByteBuf buffer)
    Encode this storage into a buffer.
    net.minecraft.world.item.ItemStack
    getItem(int slot)
     
    net.minecraft.world.item.ItemStack[]
    Get item array directly.
    int
     
    boolean
     
    void
    load(net.minecraft.nbt.CompoundTag nbt, int lastVanillaDataVersion)
    Load from the NBT tag into this object.
    void
    moveSlot(int oldSlot, int newSlot)
    Moves the slot at position oldSlot to position newSlot.
    void
    placeItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int amountToPlace, int slot)
    Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.
    void
    returnItems(net.minecraft.world.entity.player.Player player)
    Return items to player when leaving radius
    net.minecraft.nbt.CompoundTag
    save(net.minecraft.nbt.CompoundTag nbt)
    Save this object into the NBT tag.
    void
    setDirty(net.minecraft.server.level.ServerLevel level)
     
    void
    setItem(int slot, net.minecraft.world.item.ItemStack stack)
    Directly set stack into slot.
    void
     
    void
    shrinkCountsOnly(int slot, int amount)
    Shrink a slot, but only for the itemCounts, not the actual stored items!
    void
    shrinkSlot(int slot, int amount)
    Shrink slot, adjusting the leftovers along the way.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.hammy275.immersivemc.api.server.WorldStorage

    getHandler
  • Field Details

    • items

      protected net.minecraft.world.item.ItemStack[] items
      A list of items. Usually contains inputs and outputs.
    • itemCounts

      protected List<ItemStorage.PlayerItemCounts>[] itemCounts
      Item counts from each player for each slot. Used for item returns.
    • maxInputIndex

      public final int maxInputIndex
      The index of the last item in the items array that is an input item.
  • Constructor Details

    • ItemStorage

      public ItemStorage(int numItems, int maxInputIndex)
  • Method Details

    • isDirtyForClientSync

      public boolean isDirtyForClientSync()
    • setDirty

      public void setDirty(net.minecraft.server.level.ServerLevel level)
    • setNoLongerDirtyForClientSync

      public void setNoLongerDirtyForClientSync()
    • setItem

      public void setItem(int slot, net.minecraft.world.item.ItemStack stack)
      Directly set stack into slot.
      Parameters:
      slot - Slot to place into
      stack - Stack to place
    • shrinkSlot

      public void shrinkSlot(int slot, int amount)
      Shrink slot, adjusting the leftovers along the way.
      Parameters:
      slot - Slot to shrink from
      amount - Amount to shrink by
    • shrinkCountsOnly

      public void shrinkCountsOnly(int slot, int amount)
      Shrink a slot, but only for the itemCounts, not the actual stored items!
      Parameters:
      slot - Slot to shrink from
      amount - Amount to shrink by
    • placeItem

      public void placeItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int amountToPlace, int slot)
      Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.
      Parameters:
      player - Player to get items from
      hand - Hand to get item from
      slot - Slot to merge into
    • getItem

      public net.minecraft.world.item.ItemStack getItem(int slot)
    • getNumItems

      public int getNumItems()
    • getItemsRaw

      public net.minecraft.world.item.ItemStack[] getItemsRaw()
      Get item array directly. Only use for immersives that don't utilize the queue.
      Returns:
      Items array.
    • copyFromOld

      public void copyFromOld(ItemStorage oldStorage)
    • returnItems

      public void returnItems(net.minecraft.world.entity.player.Player player)
      Return items to player when leaving radius
      Parameters:
      player - Player to return items to
    • load

      public void load(net.minecraft.nbt.CompoundTag nbt, int lastVanillaDataVersion)
      Description copied from interface: WorldStorage
      Load from the NBT tag into this object.
      Specified by:
      load in interface WorldStorage
      Parameters:
      nbt - NBT tag to load from.
      lastVanillaDataVersion - The last vanilla data version this storage was loaded in.
    • save

      public net.minecraft.nbt.CompoundTag save(net.minecraft.nbt.CompoundTag nbt)
      Description copied from interface: WorldStorage
      Save this object into the NBT tag.
      Specified by:
      save in interface WorldStorage
      Parameters:
      nbt - NBT tag to save to.
      Returns:
      The same NBT tag as provided to this method.
    • moveSlot

      public void moveSlot(int oldSlot, int newSlot)
      Moves the slot at position oldSlot to position newSlot. Only be used for version conversion, such as the addition of smithing templates in 1.20. The old slot will be made into air and have its item counts wiped.
      Parameters:
      oldSlot - Old slot number
      newSlot - New slot number
    • addSlotsToEnd

      public void addSlotsToEnd(int slotsToAdd)
      Add slotsToAdd number of slots. Really should only be used for version conversion.
      Parameters:
      slotsToAdd - Number of slots to add. Will be added at the end of arrays.
    • encode

      public void encode(net.minecraft.network.FriendlyByteBuf buffer)
      Description copied from interface: NetworkStorage
      Encode this storage into a buffer.
      Specified by:
      encode in interface NetworkStorage
      Parameters:
      buffer - Buffer to encode storage into.
    • decode

      public void decode(net.minecraft.network.FriendlyByteBuf buffer)
      Description copied from interface: NetworkStorage
      Decode the buffer into this object.
      Specified by:
      decode in interface NetworkStorage
      Parameters:
      buffer - Buffer to decode from.