All Implemented Interfaces:
ImmersiveHandler<ListOfItemsStorage>, MultiblockImmersiveHandler<ListOfItemsStorage>

public class ChestHandler extends ChestLikeHandler implements MultiblockImmersiveHandler<ListOfItemsStorage>
  • Constructor Details

    • ChestHandler

      public ChestHandler()
  • Method Details

    • makeInventoryContents

      public ListOfItemsStorage makeInventoryContents(net.minecraft.server.level.ServerPlayer player, net.minecraft.core.BlockPos pos)
      Description copied from interface: ImmersiveHandler
      Creates inventory contents on the server to send to clients.
      Specified by:
      makeInventoryContents in interface ImmersiveHandler<ListOfItemsStorage>
      Overrides:
      makeInventoryContents in class ChestLikeHandler
      Parameters:
      player - Player being sent to.
      pos - Position of the block being sent about.
      Returns:
      A NetworkStorage to be sent over the network.
    • swap

      public void swap(int slot, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos, net.minecraft.server.level.ServerPlayer player, ItemSwapAmount amount)
      Description copied from interface: ImmersiveHandler
      Swaps an item from a player's hand into this immersive (and/or vice-versa).
      Specified by:
      swap in interface ImmersiveHandler<ListOfItemsStorage>
      Overrides:
      swap in class ChestLikeHandler
      Parameters:
      slot - Slot being swapped with in this immersive.
      hand - Player's hand being swapped with.
      pos - Position of block being swapped with.
      player - Player who is swapping.
      amount - An object representing the amount of items to swap. Use ItemSwapAmount.getNumItemsToSwap(int), passing in the item stack size of the item in the player's hand to get the amount of items to swap.
    • isDirtyForClientSync

      public boolean isDirtyForClientSync(net.minecraft.server.level.ServerPlayer player, net.minecraft.core.BlockPos pos)
      Description copied from interface: ImmersiveHandler
      Function to determine whether the block has changed its contents to sync to the client since its last sync. Dirtiness is addressed every tick, so for every tick, you should clear ALL flags used for dirtiness.
      Specified by:
      isDirtyForClientSync in interface ImmersiveHandler<ListOfItemsStorage>
      Overrides:
      isDirtyForClientSync in class ChestLikeHandler
      Parameters:
      player - Player to potentially send new data to.
      pos - Position of block to check.
      Returns:
      Whether the given block has changed since it was last synced to the client
    • isValidBlock

      public boolean isValidBlock(net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
      Specified by:
      isValidBlock in interface ImmersiveHandler<ListOfItemsStorage>
      Overrides:
      isValidBlock in class ChestLikeHandler
      Parameters:
      pos - Position to check.
      level - The level being checked in.
      Returns:
      Whether the supplied block matches what this handler handles.
    • enabledInConfig

      public boolean enabledInConfig(net.minecraft.world.entity.player.Player player)
      Specified by:
      enabledInConfig in interface ImmersiveHandler<ListOfItemsStorage>
      Parameters:
      player - The player we're checking the config of.
      Returns:
      Whether the immersive this handler handles is enabled. If you do not have a configuration system, this should always return true.
    • getID

      public net.minecraft.resources.ResourceLocation getID()
      Specified by:
      getID in interface ImmersiveHandler<ListOfItemsStorage>
      Returns:
      A unique ID to identify this handler. The same value should always be returned by this method.
    • getHandledBlocks

      @Nullable public @Nullable Set<net.minecraft.core.BlockPos> getHandledBlocks(net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
      Description copied from interface: MultiblockImmersiveHandler
      This method should return all blocks that are part of this multiblock, given the position of one block in this multiblock. For example, if this multiblock was for a double-chest, the position provided to calls of this function may be either the left chest or the right chest, and should return a set that contains BOTH the left chest AND the right chest. Note that if the multiblock is in a correct state (no part of the multiblock has been broken), ImmersiveHandler.isValidBlock(BlockPos, Level) should return true for all blocks of the multiblock. This way, when a block in the multiblock breaks, the aforementioned function will return false, thus alerting ImmersiveMC that the multiblock is no longer valid.
      If your multiblock isn't always a multiblock (such as chests, which can sometimes simply be single-chests), you can simply return a set containing the provided block position.
      Some additional rules about this function:
      • If the block provided is unable to make a valid multiblock (such as if the multiblock is still under construction, or it was broken), you may return null. You may also simply return a set which contains at least one element that returns false for ImmersiveHandler.isValidBlock(BlockPos, Level).
      • You are not required to check if all blocks of the multiblock are valid. ImmersiveMC will check if every block in your multiblock is valid.
      • Rarely, a multiblock may change shape while never ending up in an invalid state. For example, the left chest of a double chest may become the right chest of a double chest via command blocks. Your Immersive should handle this gracefully.
      • This function should NOT return an empty set or a set containing null elements.
      Specified by:
      getHandledBlocks in interface MultiblockImmersiveHandler<ListOfItemsStorage>
      Parameters:
      pos - The position of one block in this multiblock.
      level - The level where one block of this multiblock is found.
      Returns:
      All blocks that make up this multiblock, or null if the provided position cannot make a valid multiblock. This set will not be modified by ImmersiveMC, and it should NOT contain null nor should it be an empty set.