Class ModularSlot

java.lang.Object
net.minecraft.world.inventory.Slot
net.neoforged.neoforge.items.SlotItemHandler
codechicken.lib.inventory.container.modular.ModularSlot

public class ModularSlot extends net.neoforged.neoforge.items.SlotItemHandler
A fully configurable inventory slot. If there is anything this slot can not do... Let me know.

Created by brandon3055 on 10/09/2023

  • Field Summary

    Fields inherited from class net.neoforged.neoforge.items.SlotItemHandler

    index

    Fields inherited from class net.minecraft.world.inventory.Slot

    container, x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    ModularSlot(net.minecraft.world.Container container, int index)
     
    ModularSlot(net.minecraft.world.Container container, int index, int xPos, int yPos)
     
    ModularSlot(net.neoforged.neoforge.items.IItemHandler itemHandler, int index)
     
    ModularSlot(net.neoforged.neoforge.items.IItemHandler itemHandler, int index, int xPos, int yPos)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    getMaxStackSize(net.minecraft.world.item.ItemStack itemStack)
     
    boolean
     
    boolean
    mayPickup(net.minecraft.world.entity.player.Player player)
     
    boolean
    mayPlace(net.minecraft.world.item.ItemStack itemStack)
     
    Do not use the containers canPlaceItem when checking if an item can be placed.
    onSet(BiConsumer<net.minecraft.world.item.ItemStack,net.minecraft.world.item.ItemStack> onSet)
    Allows you to get a callback when the slot contents are set.
    Configure this slot as an output only slot.
    void
    set(net.minecraft.world.item.ItemStack itemStack)
     
    setCanRemove(BiPredicate<net.minecraft.world.entity.player.Player,net.minecraft.world.item.ItemStack> canRemove)
    Allows you to attach a "can remove" predicate that can block removal of a stack from the slot by the player.
    setEnabled(boolean enabled)
     
     
    setStackLimit(Function<net.minecraft.world.item.ItemStack,Integer> stackLimit)
    Allows you to apply a stack size limit that (if smaller) will override the container and the item stack limits.
    setValidator(Predicate<net.minecraft.world.item.ItemStack> validator)
    Allows you to attach a validator to control what items are allowed in this slot.

    Methods inherited from class net.neoforged.neoforge.items.SlotItemHandler

    getItem, getItemHandler, getMaxStackSize, initialize, onQuickCraft, remove

    Methods inherited from class net.minecraft.world.inventory.Slot

    allowModification, checkTakeAchievements, getContainerSlot, getNoItemIcon, getSlotIndex, hasItem, isFake, isHighlightable, isSameInventory, onQuickCraft, onSwapCraft, onTake, safeInsert, safeInsert, safeTake, setBackground, setByPlayer, setByPlayer, setChanged, tryRemove

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ModularSlot

      public ModularSlot(net.minecraft.world.Container container, int index)
    • ModularSlot

      public ModularSlot(net.neoforged.neoforge.items.IItemHandler itemHandler, int index)
    • ModularSlot

      public ModularSlot(net.minecraft.world.Container container, int index, int xPos, int yPos)
    • ModularSlot

      public ModularSlot(net.neoforged.neoforge.items.IItemHandler itemHandler, int index, int xPos, int yPos)
  • Method Details

    • output

      public ModularSlot output()
      Configure this slot as an output only slot. Items can not be placed in this slot by the player.
    • noCheck

      public ModularSlot noCheck()
      Do not use the containers canPlaceItem when checking if an item can be placed.
    • setValidator

      public ModularSlot setValidator(Predicate<net.minecraft.world.item.ItemStack> validator)
      Allows you to attach a validator to control what items are allowed in this slot. You can also limit a slots allowed contents via the Container.canPlaceItem(int, ItemStack) method of the container.
      Parameters:
      validator - The validator predicate, If the predicate returns false for a stack, the stack will not be placed.
    • onSet

      public ModularSlot onSet(BiConsumer<net.minecraft.world.item.ItemStack,net.minecraft.world.item.ItemStack> onSet)
      Allows you to get a callback when the slot contents are set. Parameters given are Old stack then New stack.
    • setStackLimit

      public ModularSlot setStackLimit(Function<net.minecraft.world.item.ItemStack,Integer> stackLimit)
      Allows you to apply a stack size limit that (if smaller) will override the container and the item stack limits.
    • setCanRemove

      public ModularSlot setCanRemove(BiPredicate<net.minecraft.world.entity.player.Player,net.minecraft.world.item.ItemStack> canRemove)
      Allows you to attach a "can remove" predicate that can block removal of a stack from the slot by the player.
    • setEnabled

      public ModularSlot setEnabled(Supplier<Boolean> enabled)
    • setEnabled

      public ModularSlot setEnabled(boolean enabled)
    • mayPlace

      public boolean mayPlace(net.minecraft.world.item.ItemStack itemStack)
      Overrides:
      mayPlace in class net.neoforged.neoforge.items.SlotItemHandler
    • mayPickup

      public boolean mayPickup(net.minecraft.world.entity.player.Player player)
      Overrides:
      mayPickup in class net.neoforged.neoforge.items.SlotItemHandler
    • set

      public void set(net.minecraft.world.item.ItemStack itemStack)
      Overrides:
      set in class net.neoforged.neoforge.items.SlotItemHandler
    • isActive

      public boolean isActive()
      Overrides:
      isActive in class net.minecraft.world.inventory.Slot
    • getMaxStackSize

      public int getMaxStackSize(net.minecraft.world.item.ItemStack itemStack)
      Overrides:
      getMaxStackSize in class net.neoforged.neoforge.items.SlotItemHandler