Class ExtendedInventory

java.lang.Object
net.minecraft.world.entity.player.Inventory
com.petrolpark.core.extendedinventory.ExtendedInventory
All Implemented Interfaces:
net.minecraft.world.Clearable, net.minecraft.world.Container, net.minecraft.world.Nameable

@Experimental public class ExtendedInventory extends net.minecraft.world.entity.player.Inventory
  • Nested Class Summary

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

    Fields
    Modifier and Type
    Field
    Description
    net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>
    The ItemStacks additional to those in the Vanilla Inventory, including all those on the Hotbar.

    Fields inherited from class net.minecraft.world.entity.player.Inventory

    ALL_ARMOR_SLOTS, armor, HELMET_SLOT_ONLY, INVENTORY_SIZE, items, NOT_FOUND_INDEX, offhand, player, POP_TIME_DURATION, selected, SLOT_OFFHAND

    Fields inherited from interface net.minecraft.world.Container

    DEFAULT_DISTANCE_BUFFER
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExtendedInventory(net.minecraft.world.entity.player.Player player)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(int slot, net.minecraft.world.item.ItemStack stack)
    Copied from Minecraft source code.
    void
    addExtraInventorySlotsToMenu(Consumer<net.minecraft.world.inventory.Slot> slotAdder, ExtendedInventory.SlotFactory slotFactory, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
     
    void
    addExtraInventorySlotsToMenu(net.minecraft.world.inventory.AbstractContainerMenu menu, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
     
    void
     
    boolean
    contains(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag)
     
    boolean
    contains(net.minecraft.world.item.ItemStack stack)
     
    void
     
    static final boolean
    Whether the Extended Inventory experiment is enabled in this world.
    static final boolean
    enabled(net.minecraft.world.flag.FeatureFlagSet flagSet)
    Whether the Extended Inventory experiment is enabled in this world.
    void
    fillStackedContents(net.minecraft.world.entity.player.StackedContents stackedContents)
     
    int
    findSlot(Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
    Search for a Slot in the Vanilla and extended Inventories (i.e.
    int
    findSlotMatchingItem(net.minecraft.world.item.ItemStack stack)
     
    int
    findSlotMatchingUnusedItem(net.minecraft.world.item.ItemStack stack)
     
    void
    forEach(Consumer<? super net.minecraft.world.item.ItemStack> action)
     
    get(net.minecraft.world.entity.player.Player player)
    Attempt to access the Player's Extended Inventory (cast as such).
    int
     
    float
    getDestroySpeed(net.minecraft.world.level.block.state.BlockState state)
     
    int
    The number of additional Hotbar Slots beyond the usual 9.
    int
     
    int
     
    int
    The total Hotbar size, Vanilla + extra Slots
    net.minecraft.world.item.ItemStack
    getItem(int slotIndex)
     
    net.minecraft.world.item.ItemStack
     
    int
    The Slot index of the currently selected Slot
    protected int
    getSlotIndex(int hotbarIndex)
    Get the Slot index of the given index in the displayed Hotbar - how far right the selected Slot is, considering the sides on which the extra Slots are
    int
    getSlotWithRemainingSpace(net.minecraft.world.item.ItemStack stack)
     
    int
     
    boolean
     
    boolean
    isFullHotbarSlot(int index)
    Whether the given Slot index is part of the extended Hotbar
    static boolean
    Whether the given Slot index corresponds to a Vanilla Hotbar Slot.
    void
    load(net.minecraft.nbt.ListTag listTag)
     
    static void
    onOpenContainer(net.neoforged.neoforge.event.entity.player.PlayerContainerEvent.Open event)
     
    static void
    onPlayerJoinsWorld(net.neoforged.neoforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent event)
     
    void
    pickSlot(int index)
    Stick an Item from the Inventory in the Hotbar
    static void
    refreshPlayerInventoryMenu(net.minecraft.world.entity.player.Player player, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
    Re-create the Player's Inventory Menu with the right number of extra Slots, in the right places.
    static void
    refreshPlayerInventoryMenuServer(net.minecraft.world.entity.player.Player player)
    Re-create the Player's Inventory Menu on the logical server.
    net.minecraft.world.item.ItemStack
    removeItem(int slotIndex, int count)
     
    void
    removeItem(net.minecraft.world.item.ItemStack stack)
     
    net.minecraft.world.item.ItemStack
    removeItemNoUpdate(int slotIndex)
     
    void
    replaceWith(net.minecraft.world.entity.player.Inventory playerInventory)
     
    net.minecraft.nbt.ListTag
    save(net.minecraft.nbt.ListTag listTag)
     
    void
    setExtraHotbarSlots(int extraSlots)
     
    void
     
    void
    setItem(int slotIndex, net.minecraft.world.item.ItemStack stack)
     
    void
    setPickedItem(net.minecraft.world.item.ItemStack stack)
    Pick an Item in Creative mode
    Stream<net.minecraft.world.item.ItemStack>
     
    static boolean
    supportsExtraInventory(net.minecraft.world.inventory.AbstractContainerMenu menu)
     
    void
    swapPaint(double scroll)
     
    void
     
    void
     
    void
    updateSize(boolean forceSync)
    Update the size of the Extended Inventory and Hotbar based on the corresponding PetrolparkAttributes.

    Methods inherited from class net.minecraft.world.entity.player.Inventory

    add, addResource, addResource, clearOrCountMatchingItems, contains, getArmor, getName, getSelectionSize, getTimesChanged, hasRemainingSpaceForItem, isHotbarSlot, placeItemBackInInventory, placeItemBackInInventory, removeFromSelected, setChanged, stillValid

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface net.minecraft.world.Container

    canPlaceItem, canTakeItem, countItem, getMaxStackSize, getMaxStackSize, hasAnyMatching, hasAnyOf, startOpen, stopOpen

    Methods inherited from interface net.minecraft.world.Nameable

    getCustomName, getDisplayName, hasCustomName
  • Field Details

    • extraItems

      public net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> extraItems
      The ItemStacks additional to those in the Vanilla Inventory, including all those on the Hotbar. Controlled by PetrolparkAttributes.EXTRA_INVENTORY_SIZE.
  • Constructor Details

    • ExtendedInventory

      public ExtendedInventory(net.minecraft.world.entity.player.Player player)
  • Method Details

    • enabled

      public static final boolean enabled()
      Whether the Extended Inventory experiment is enabled in this world.
      Returns:
      false if it is not enabled, or if it is too early to say
      See Also:
    • enabled

      public static final boolean enabled(net.minecraft.world.flag.FeatureFlagSet flagSet)
      Whether the Extended Inventory experiment is enabled in this world.
      Parameters:
      flagSet -
      See Also:
    • get

      public static Optional<ExtendedInventory> get(net.minecraft.world.entity.player.Player player)
      Attempt to access the Player's Extended Inventory (cast as such).
      Parameters:
      player -
      Returns:
      The Player's Extended Inventory, if they are enabled in this world and one can be found
    • updateSize

      public void updateSize()
      See Also:
    • updateSize

      public void updateSize(boolean forceSync)
      Update the size of the Extended Inventory and Hotbar based on the corresponding PetrolparkAttributes.
      Parameters:
      forceSync - Whether to sync the size of the Extended Inventory to the client
      See Also:
    • refreshPlayerInventoryMenu

      public static void refreshPlayerInventoryMenu(net.minecraft.world.entity.player.Player player, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
      Re-create the Player's Inventory Menu with the right number of extra Slots, in the right places. This is the riskiest part of the whole Extended Inventory API as we are reassigning what was originally a final field.
      Parameters:
      player -
      columns - How many columns in the (non-Hotbar) Inventory set of Slots
      invX - Left side of the (non-Hotbar) Inventory set of Slots
      invY - Top side of the (non-Hotbar) Inventory set of Slots
      leftHotbarSlots - How many Hotbar Slots to put on the left of the Vanilla Hotbar
      leftHotbarX - Left side of the extra Hotbar Slots to the left of the Vanilla Hotbar
      leftHotbarY - Top side of the extra Hotbar Slots to the left of the Vanilla Hotbar
      rightHotbarX - Left side of the extra Hotbar Slots to the right of the Vanilla Hotbar
      rightHotbarY - Right side of the extra Hotbar Slots to the right of the Vanilla Hotbar
      See Also:
    • refreshPlayerInventoryMenuServer

      public static void refreshPlayerInventoryMenuServer(net.minecraft.world.entity.player.Player player)
      Re-create the Player's Inventory Menu on the logical server. All Slots are added at (0,0) (or some arbitrary location) because their location does not matter on the server side.
      Parameters:
      player -
      See Also:
    • isVanillaHotbarSlot

      public static boolean isVanillaHotbarSlot(int index)
      Whether the given Slot index corresponds to a Vanilla Hotbar Slot.
      Parameters:
      index -
      Returns:
      false if the Slot is not in the Vanilla Hotbar, even if there are additional Hotbar Slots
    • setExtraInventorySize

      public void setExtraInventorySize(int size)
      Parameters:
      size - The additional Slots beyond what the Player would usually have
    • setExtraHotbarSlots

      public void setExtraHotbarSlots(int extraSlots)
      Parameters:
      extraSlots - The additional Slots beyond what the Player would usually have
    • getExtraHotbarSlots

      public int getExtraHotbarSlots()
      The number of additional Hotbar Slots beyond the usual 9.
    • getExtraInventoryStartSlotIndex

      public int getExtraInventoryStartSlotIndex()
    • isFullHotbarSlot

      public boolean isFullHotbarSlot(int index)
      Whether the given Slot index is part of the extended Hotbar
      Parameters:
      index -
      Returns:
      true if it's a Vanilla or extended index
    • getHotbarSize

      public int getHotbarSize()
      The total Hotbar size, Vanilla + extra Slots
      See Also:
    • getSlotIndex

      protected int getSlotIndex(int hotbarIndex)
      Get the Slot index of the given index in the displayed Hotbar - how far right the selected Slot is, considering the sides on which the extra Slots are
      Parameters:
      hotbarIndex - A number from 0 to 8 + getExtraHotbarSlots()
    • getSelectedHotbarIndex

      public int getSelectedHotbarIndex()
      The Slot index of the currently selected Slot
      Returns:
    • onPlayerJoinsWorld

      public static void onPlayerJoinsWorld(net.neoforged.neoforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent event)
    • onOpenContainer

      public static void onOpenContainer(net.neoforged.neoforge.event.entity.player.PlayerContainerEvent.Open event)
    • supportsExtraInventory

      public static boolean supportsExtraInventory(net.minecraft.world.inventory.AbstractContainerMenu menu)
    • addExtraInventorySlotsToMenu

      public void addExtraInventorySlotsToMenu(net.minecraft.world.inventory.AbstractContainerMenu menu, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
    • addExtraInventorySlotsToMenu

      public void addExtraInventorySlotsToMenu(Consumer<net.minecraft.world.inventory.Slot> slotAdder, ExtendedInventory.SlotFactory slotFactory, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY)
    • forEach

      public void forEach(Consumer<? super net.minecraft.world.item.ItemStack> action)
    • stream

      public Stream<net.minecraft.world.item.ItemStack> stream()
    • getSelected

      public net.minecraft.world.item.ItemStack getSelected()
      Overrides:
      getSelected in class net.minecraft.world.entity.player.Inventory
    • getFreeSlot

      public int getFreeSlot()
      Overrides:
      getFreeSlot in class net.minecraft.world.entity.player.Inventory
    • setPickedItem

      public void setPickedItem(@Nonnull net.minecraft.world.item.ItemStack stack)
      Pick an Item in Creative mode
      Overrides:
      setPickedItem in class net.minecraft.world.entity.player.Inventory
    • pickSlot

      public void pickSlot(int index)
      Stick an Item from the Inventory in the Hotbar
      Overrides:
      pickSlot in class net.minecraft.world.entity.player.Inventory
    • findSlotMatchingItem

      public int findSlotMatchingItem(@Nonnull net.minecraft.world.item.ItemStack stack)
      Overrides:
      findSlotMatchingItem in class net.minecraft.world.entity.player.Inventory
    • findSlotMatchingUnusedItem

      public int findSlotMatchingUnusedItem(@Nonnull net.minecraft.world.item.ItemStack stack)
      Overrides:
      findSlotMatchingUnusedItem in class net.minecraft.world.entity.player.Inventory
    • findSlot

      public int findSlot(Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
      Search for a Slot in the Vanilla and extended Inventories (i.e. not armor or offhand).
      Parameters:
      stackPredicate -
    • getSuitableHotbarSlot

      public int getSuitableHotbarSlot()
      Overrides:
      getSuitableHotbarSlot in class net.minecraft.world.entity.player.Inventory
    • swapPaint

      public void swapPaint(double scroll)
      Overrides:
      swapPaint in class net.minecraft.world.entity.player.Inventory
    • getSlotWithRemainingSpace

      public int getSlotWithRemainingSpace(@Nonnull net.minecraft.world.item.ItemStack stack)
      Overrides:
      getSlotWithRemainingSpace in class net.minecraft.world.entity.player.Inventory
    • tick

      public void tick()
      Overrides:
      tick in class net.minecraft.world.entity.player.Inventory
    • add

      public boolean add(int slot, @Nonnull net.minecraft.world.item.ItemStack stack)
      Copied from Minecraft source code. Place an ItemStack in the specified Slot, and shrink the ItemStack appropriately.
      Overrides:
      add in class net.minecraft.world.entity.player.Inventory
      Returns:
      true if any of the ItemStack could be placed in the Slot
    • removeItem

      public net.minecraft.world.item.ItemStack removeItem(int slotIndex, int count)
      Specified by:
      removeItem in interface net.minecraft.world.Container
      Overrides:
      removeItem in class net.minecraft.world.entity.player.Inventory
    • removeItem

      public void removeItem(@Nonnull net.minecraft.world.item.ItemStack stack)
      Overrides:
      removeItem in class net.minecraft.world.entity.player.Inventory
    • removeItemNoUpdate

      public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slotIndex)
      Specified by:
      removeItemNoUpdate in interface net.minecraft.world.Container
      Overrides:
      removeItemNoUpdate in class net.minecraft.world.entity.player.Inventory
    • setItem

      public void setItem(int slotIndex, @Nonnull net.minecraft.world.item.ItemStack stack)
      Specified by:
      setItem in interface net.minecraft.world.Container
      Overrides:
      setItem in class net.minecraft.world.entity.player.Inventory
    • getDestroySpeed

      public float getDestroySpeed(@Nonnull net.minecraft.world.level.block.state.BlockState state)
      Overrides:
      getDestroySpeed in class net.minecraft.world.entity.player.Inventory
    • save

      public net.minecraft.nbt.ListTag save(@Nonnull net.minecraft.nbt.ListTag listTag)
      Overrides:
      save in class net.minecraft.world.entity.player.Inventory
    • load

      public void load(@Nonnull net.minecraft.nbt.ListTag listTag)
      Overrides:
      load in class net.minecraft.world.entity.player.Inventory
    • getContainerSize

      public int getContainerSize()
      Specified by:
      getContainerSize in interface net.minecraft.world.Container
      Overrides:
      getContainerSize in class net.minecraft.world.entity.player.Inventory
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface net.minecraft.world.Container
      Overrides:
      isEmpty in class net.minecraft.world.entity.player.Inventory
    • getItem

      public net.minecraft.world.item.ItemStack getItem(int slotIndex)
      Specified by:
      getItem in interface net.minecraft.world.Container
      Overrides:
      getItem in class net.minecraft.world.entity.player.Inventory
    • dropAll

      public void dropAll()
      Overrides:
      dropAll in class net.minecraft.world.entity.player.Inventory
    • contains

      public boolean contains(@Nonnull net.minecraft.world.item.ItemStack stack)
      Overrides:
      contains in class net.minecraft.world.entity.player.Inventory
    • contains

      public boolean contains(@Nonnull net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag)
      Overrides:
      contains in class net.minecraft.world.entity.player.Inventory
    • replaceWith

      public void replaceWith(@Nonnull net.minecraft.world.entity.player.Inventory playerInventory)
      Overrides:
      replaceWith in class net.minecraft.world.entity.player.Inventory
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface net.minecraft.world.Clearable
      Overrides:
      clearContent in class net.minecraft.world.entity.player.Inventory
    • fillStackedContents

      public void fillStackedContents(@Nonnull net.minecraft.world.entity.player.StackedContents stackedContents)
      Overrides:
      fillStackedContents in class net.minecraft.world.entity.player.Inventory