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 ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionnet.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_OFFHANDFields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_BUFFER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int slot, net.minecraft.world.item.ItemStack stack) Copied fromMinecraft source code.voidaddExtraInventorySlotsToMenu(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) voidaddExtraInventorySlotsToMenu(net.minecraft.world.inventory.AbstractContainerMenu menu, int columns, int invX, int invY, int leftHotbarSlots, int leftHotbarX, int leftHotbarY, int rightHotbarX, int rightHotbarY) voidbooleancontains(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag) booleancontains(net.minecraft.world.item.ItemStack stack) voiddropAll()static final booleanenabled()Whether theExtended Inventory experimentis enabled in this world.static final booleanenabled(net.minecraft.world.flag.FeatureFlagSet flagSet) Whether theExtended Inventory experimentis enabled in this world.voidfillStackedContents(net.minecraft.world.entity.player.StackedContents stackedContents) intSearch for a Slot in the Vanilla and extended Inventories (i.e.intfindSlotMatchingItem(net.minecraft.world.item.ItemStack stack) intfindSlotMatchingUnusedItem(net.minecraft.world.item.ItemStack stack) voidstatic Optional<ExtendedInventory> get(net.minecraft.world.entity.player.Player player) Attempt to access the Player's Extended Inventory (cast as such).intfloatgetDestroySpeed(net.minecraft.world.level.block.state.BlockState state) intThe number of additional Hotbar Slots beyond the usual 9.intintintThe total Hotbar size, Vanilla + extra Slotsnet.minecraft.world.item.ItemStackgetItem(int slotIndex) net.minecraft.world.item.ItemStackintThe Slot index of the currently selected Slotprotected intgetSlotIndex(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 areintgetSlotWithRemainingSpace(net.minecraft.world.item.ItemStack stack) intbooleanisEmpty()booleanisFullHotbarSlot(int index) Whether the given Slot index is part of the extended Hotbarstatic booleanisVanillaHotbarSlot(int index) Whether the given Slot index corresponds to a Vanilla Hotbar Slot.voidload(net.minecraft.nbt.ListTag listTag) static voidonOpenContainer(net.neoforged.neoforge.event.entity.player.PlayerContainerEvent.Open event) static voidonPlayerJoinsWorld(net.neoforged.neoforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent event) voidpickSlot(int index) Stick an Item from the Inventory in the Hotbarstatic voidrefreshPlayerInventoryMenu(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'sInventory Menuwith the right number of extra Slots, in the right places.static voidrefreshPlayerInventoryMenuServer(net.minecraft.world.entity.player.Player player) Re-create the Player'sInventory Menuon the logical server.net.minecraft.world.item.ItemStackremoveItem(int slotIndex, int count) voidremoveItem(net.minecraft.world.item.ItemStack stack) net.minecraft.world.item.ItemStackremoveItemNoUpdate(int slotIndex) voidreplaceWith(net.minecraft.world.entity.player.Inventory playerInventory) net.minecraft.nbt.ListTagsave(net.minecraft.nbt.ListTag listTag) voidsetExtraHotbarSlots(int extraSlots) voidsetExtraInventorySize(int size) voidsetItem(int slotIndex, net.minecraft.world.item.ItemStack stack) voidsetPickedItem(net.minecraft.world.item.ItemStack stack) Pick an Item in Creative modeStream<net.minecraft.world.item.ItemStack> stream()static booleansupportsExtraInventory(net.minecraft.world.inventory.AbstractContainerMenu menu) voidswapPaint(double scroll) voidtick()voidvoidupdateSize(boolean forceSync) Update the size of the Extended Inventory and Hotbar based on the correspondingPetrolparkAttributes.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, stillValidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.world.Container
canPlaceItem, canTakeItem, countItem, getMaxStackSize, getMaxStackSize, hasAnyMatching, hasAnyOf, startOpen, stopOpenMethods inherited from interface net.minecraft.world.Nameable
getCustomName, getDisplayName, hasCustomName
-
Field Details
-
extraItems
public net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> extraItemsThe ItemStacks additional to those in the Vanilla Inventory, including all those on the Hotbar. Controlled byPetrolparkAttributes.EXTRA_INVENTORY_SIZE.
-
-
Constructor Details
-
ExtendedInventory
public ExtendedInventory(net.minecraft.world.entity.player.Player player)
-
-
Method Details
-
enabled
public static final boolean enabled()Whether theExtended Inventory experimentis enabled in this world.- Returns:
falseif 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 theExtended Inventory experimentis enabled in this world.- Parameters:
flagSet-- See Also:
-
get
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 correspondingPetrolparkAttributes.- 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'sInventory Menuwith 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 afinalfield.- Parameters:
player-columns- How many columns in the (non-Hotbar) Inventory set of SlotsinvX- Left side of the (non-Hotbar) Inventory set of SlotsinvY- Top side of the (non-Hotbar) Inventory set of SlotsleftHotbarSlots- How many Hotbar Slots to put on the left of the Vanilla HotbarleftHotbarX- Left side of the extra Hotbar Slots to the left of the Vanilla HotbarleftHotbarY- Top side of the extra Hotbar Slots to the left of the Vanilla HotbarrightHotbarX- Left side of the extra Hotbar Slots to the right of the Vanilla HotbarrightHotbarY- 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'sInventory Menuon 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:
falseif 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:
trueif 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 from0to8 + 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
-
stream
-
getSelected
public net.minecraft.world.item.ItemStack getSelected()- Overrides:
getSelectedin classnet.minecraft.world.entity.player.Inventory
-
getFreeSlot
public int getFreeSlot()- Overrides:
getFreeSlotin classnet.minecraft.world.entity.player.Inventory
-
setPickedItem
public void setPickedItem(@Nonnull net.minecraft.world.item.ItemStack stack) Pick an Item in Creative mode- Overrides:
setPickedItemin classnet.minecraft.world.entity.player.Inventory
-
pickSlot
public void pickSlot(int index) Stick an Item from the Inventory in the Hotbar- Overrides:
pickSlotin classnet.minecraft.world.entity.player.Inventory
-
findSlotMatchingItem
public int findSlotMatchingItem(@Nonnull net.minecraft.world.item.ItemStack stack) - Overrides:
findSlotMatchingItemin classnet.minecraft.world.entity.player.Inventory
-
findSlotMatchingUnusedItem
public int findSlotMatchingUnusedItem(@Nonnull net.minecraft.world.item.ItemStack stack) - Overrides:
findSlotMatchingUnusedItemin classnet.minecraft.world.entity.player.Inventory
-
findSlot
Search for a Slot in the Vanilla and extended Inventories (i.e. not armor or offhand).- Parameters:
stackPredicate-
-
getSuitableHotbarSlot
public int getSuitableHotbarSlot()- Overrides:
getSuitableHotbarSlotin classnet.minecraft.world.entity.player.Inventory
-
swapPaint
public void swapPaint(double scroll) - Overrides:
swapPaintin classnet.minecraft.world.entity.player.Inventory
-
getSlotWithRemainingSpace
public int getSlotWithRemainingSpace(@Nonnull net.minecraft.world.item.ItemStack stack) - Overrides:
getSlotWithRemainingSpacein classnet.minecraft.world.entity.player.Inventory
-
tick
public void tick()- Overrides:
tickin classnet.minecraft.world.entity.player.Inventory
-
add
public boolean add(int slot, @Nonnull net.minecraft.world.item.ItemStack stack) Copied fromMinecraft source code. Place an ItemStack in the specified Slot, and shrink the ItemStack appropriately.- Overrides:
addin classnet.minecraft.world.entity.player.Inventory- Returns:
trueif any of the ItemStack could be placed in the Slot
-
removeItem
public net.minecraft.world.item.ItemStack removeItem(int slotIndex, int count) - Specified by:
removeItemin interfacenet.minecraft.world.Container- Overrides:
removeItemin classnet.minecraft.world.entity.player.Inventory
-
removeItem
public void removeItem(@Nonnull net.minecraft.world.item.ItemStack stack) - Overrides:
removeItemin classnet.minecraft.world.entity.player.Inventory
-
removeItemNoUpdate
public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slotIndex) - Specified by:
removeItemNoUpdatein interfacenet.minecraft.world.Container- Overrides:
removeItemNoUpdatein classnet.minecraft.world.entity.player.Inventory
-
setItem
public void setItem(int slotIndex, @Nonnull net.minecraft.world.item.ItemStack stack) - Specified by:
setItemin interfacenet.minecraft.world.Container- Overrides:
setItemin classnet.minecraft.world.entity.player.Inventory
-
getDestroySpeed
public float getDestroySpeed(@Nonnull net.minecraft.world.level.block.state.BlockState state) - Overrides:
getDestroySpeedin classnet.minecraft.world.entity.player.Inventory
-
save
public net.minecraft.nbt.ListTag save(@Nonnull net.minecraft.nbt.ListTag listTag) - Overrides:
savein classnet.minecraft.world.entity.player.Inventory
-
load
public void load(@Nonnull net.minecraft.nbt.ListTag listTag) - Overrides:
loadin classnet.minecraft.world.entity.player.Inventory
-
getContainerSize
public int getContainerSize()- Specified by:
getContainerSizein interfacenet.minecraft.world.Container- Overrides:
getContainerSizein classnet.minecraft.world.entity.player.Inventory
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfacenet.minecraft.world.Container- Overrides:
isEmptyin classnet.minecraft.world.entity.player.Inventory
-
getItem
public net.minecraft.world.item.ItemStack getItem(int slotIndex) - Specified by:
getItemin interfacenet.minecraft.world.Container- Overrides:
getItemin classnet.minecraft.world.entity.player.Inventory
-
dropAll
public void dropAll()- Overrides:
dropAllin classnet.minecraft.world.entity.player.Inventory
-
contains
public boolean contains(@Nonnull net.minecraft.world.item.ItemStack stack) - Overrides:
containsin classnet.minecraft.world.entity.player.Inventory
-
contains
public boolean contains(@Nonnull net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag) - Overrides:
containsin classnet.minecraft.world.entity.player.Inventory
-
replaceWith
public void replaceWith(@Nonnull net.minecraft.world.entity.player.Inventory playerInventory) - Overrides:
replaceWithin classnet.minecraft.world.entity.player.Inventory
-
clearContent
public void clearContent()- Specified by:
clearContentin interfacenet.minecraft.world.Clearable- Overrides:
clearContentin classnet.minecraft.world.entity.player.Inventory
-
fillStackedContents
public void fillStackedContents(@Nonnull net.minecraft.world.entity.player.StackedContents stackedContents) - Overrides:
fillStackedContentsin classnet.minecraft.world.entity.player.Inventory
-