Class ExtendedContainerBlockEntity

java.lang.Object
net.minecraft.world.level.block.entity.BlockEntity
net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity
net.ixdarklord.coolcatcore.api.block.ExtendedContainerBlockEntity
All Implemented Interfaces:
HandlerProvider, net.minecraft.world.Clearable, net.minecraft.world.Container, net.minecraft.world.WorldlyContainer

public abstract class ExtendedContainerBlockEntity extends ExtendedBlockEntity implements net.minecraft.world.WorldlyContainer
A ExtendedBlockEntity with an inventory. The inventory is a container attachment, so it saves and syncs like the rest of the data; the block entity itself is a WorldlyContainer, so hoppers, comparators, menus, and other mods' pipes (on both loaders) use it through the layout's faces and roles.

 public static final Attachment<SlotContainer> INVENTORY = MyMod.ATTACHMENTS.container("crusher_inventory", CRUSHER_LAYOUT).build();

 public CrusherBlockEntity(BlockPos pos, BlockState state) {
     super(MyBlockEntities.CRUSHER.get(), pos, state, INVENTORY);
 }
 
The contents spill when the block is broken, unless the layout keeps them; on 1.20.1 the block does that from its onRemove, with onBlockRemoved(net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.Level, net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState). Add .sync(SyncPolicy.ALL) to the attachment when clients need the contents without a menu open (to render them).
  • Field Summary

    Fields inherited from class net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity

    handlers

    Fields inherited from class net.minecraft.world.level.block.entity.BlockEntity

    level, remove, worldPosition

    Fields inherited from interface net.minecraft.world.Container

    DEFAULT_DISTANCE_LIMIT, LARGE_MAX_STACK_SIZE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ExtendedContainerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, Attachment<SlotContainer> containerAttachment)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack)
     
    boolean
    canPlaceItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side)
     
    boolean
    canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack)
     
    boolean
    canTakeItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side)
     
    void
     
    int
    The comparator signal of the contents, for the block's getAnalogOutputSignal.
     
     
    int
     
    <T> T
    getHandler(HandlerType<T> type, @Nullable net.minecraft.core.Direction side)
     
    net.minecraft.world.item.ItemStack
    getItem(int slot)
     
     
    int
     
    int
    getMaxStackSize(net.minecraft.world.item.ItemStack stack)
    The most of the item a slot holds, before per-slot limits.
    int[]
    getSlotsForFace(net.minecraft.core.Direction side)
     
    boolean
     
    void
    load(net.minecraft.nbt.CompoundTag tag)
     
    static void
    onBlockRemoved(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState newState)
    For the block's onRemove, before calling super.onRemove: when the block is replaced by another, spills the contents of its ExtendedContainerBlockEntity (unless the layout keeps them) and updates comparators.
    net.minecraft.world.item.ItemStack
    removeItem(int slot, int count)
     
    net.minecraft.world.item.ItemStack
     
    protected void
    saveAdditional(net.minecraft.nbt.CompoundTag tag)
     
    void
     
    void
    setItem(int slot, net.minecraft.world.item.ItemStack stack)
     
    boolean
    stillValid(net.minecraft.world.entity.player.Player player)
     

    Methods inherited from class net.ixdarklord.coolcatcore.api.block.ExtendedBlockEntity

    attachments, clientTick, get, invalidateHandlers, modify, serverTick, set, ticker, update

    Methods inherited from class net.minecraft.world.level.block.entity.BlockEntity

    addEntityType, clearRemoved, fillCrashReportCategory, getBlockPos, getBlockState, getLevel, getPosFromTag, getType, getUpdatePacket, getUpdateTag, hasLevel, isRemoved, loadStatic, onlyOpCanSetNbt, saveToItem, saveWithFullMetadata, saveWithId, saveWithoutMetadata, setBlockState, setChanged, setLevel, setRemoved, triggerEvent

    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

    countItem, hasAnyMatching, hasAnyOf, startOpen, stopOpen
  • Constructor Details

    • ExtendedContainerBlockEntity

      protected ExtendedContainerBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, Attachment<SlotContainer> containerAttachment)
  • Method Details

    • getContainer

      public SlotContainer getContainer()
    • getContainerAttachment

      public Attachment<SlotContainer> getContainerAttachment()
    • getLayout

      public ContainerLayout getLayout()
    • getComparatorSignal

      public int getComparatorSignal()
      The comparator signal of the contents, for the block's getAnalogOutputSignal.
    • getHandler

      @Nullable public <T> T getHandler(HandlerType<T> type, @Nullable @Nullable net.minecraft.core.Direction side)
      Specified by:
      getHandler in interface HandlerProvider
      Overrides:
      getHandler in class ExtendedBlockEntity
      side - the face asked through, or null for the holder as a whole (always null for most entity lookups)
      Returns:
      the handler, or null if this holder has none of that type on that side
    • setChanged

      public void setChanged()
      Specified by:
      setChanged in interface net.minecraft.world.Container
      Overrides:
      setChanged in class net.minecraft.world.level.block.entity.BlockEntity
    • onBlockRemoved

      public static void onBlockRemoved(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState newState)
      For the block's onRemove, before calling super.onRemove: when the block is replaced by another, spills the contents of its ExtendedContainerBlockEntity (unless the layout keeps them) and updates comparators.
      
       public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
           ExtendedContainerBlockEntity.onBlockRemoved(state, level, pos, newState);
           super.onRemove(state, level, pos, newState, movedByPiston);
       }
       
    • saveAdditional

      protected void saveAdditional(net.minecraft.nbt.CompoundTag tag)
      Overrides:
      saveAdditional in class net.minecraft.world.level.block.entity.BlockEntity
    • load

      public void load(net.minecraft.nbt.CompoundTag tag)
      Overrides:
      load in class net.minecraft.world.level.block.entity.BlockEntity
    • getSlotsForFace

      public int[] getSlotsForFace(net.minecraft.core.Direction side)
      Specified by:
      getSlotsForFace in interface net.minecraft.world.WorldlyContainer
    • canPlaceItemThroughFace

      public boolean canPlaceItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction side)
      Specified by:
      canPlaceItemThroughFace in interface net.minecraft.world.WorldlyContainer
    • canTakeItemThroughFace

      public boolean canTakeItemThroughFace(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side)
      Specified by:
      canTakeItemThroughFace in interface net.minecraft.world.WorldlyContainer
    • getContainerSize

      public int getContainerSize()
      Specified by:
      getContainerSize in interface net.minecraft.world.Container
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface net.minecraft.world.Container
    • getItem

      public net.minecraft.world.item.ItemStack getItem(int slot)
      Specified by:
      getItem in interface net.minecraft.world.Container
    • removeItem

      public net.minecraft.world.item.ItemStack removeItem(int slot, int count)
      Specified by:
      removeItem in interface net.minecraft.world.Container
    • removeItemNoUpdate

      public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot)
      Specified by:
      removeItemNoUpdate in interface net.minecraft.world.Container
    • setItem

      public void setItem(int slot, net.minecraft.world.item.ItemStack stack)
      Specified by:
      setItem in interface net.minecraft.world.Container
    • getMaxStackSize

      public int getMaxStackSize()
      Specified by:
      getMaxStackSize in interface net.minecraft.world.Container
    • getMaxStackSize

      public int getMaxStackSize(net.minecraft.world.item.ItemStack stack)
      The most of the item a slot holds, before per-slot limits.
    • stillValid

      public boolean stillValid(net.minecraft.world.entity.player.Player player)
      Specified by:
      stillValid in interface net.minecraft.world.Container
    • canPlaceItem

      public boolean canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack)
      Specified by:
      canPlaceItem in interface net.minecraft.world.Container
    • canTakeItem

      public boolean canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack)
      Specified by:
      canTakeItem in interface net.minecraft.world.Container
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface net.minecraft.world.Clearable