Class ImmersiveBag

java.lang.Object
com.hammy275.immersivemc.client.immersive.ImmersiveBag
All Implemented Interfaces:
Immersive<BagInfo, BagInfo.RenderState, BagStorage>, PlayerAttachmentImmersive<BagInfo, BagInfo.RenderState, BagStorage>

public class ImmersiveBag extends Object implements PlayerAttachmentImmersive<BagInfo, BagInfo.RenderState, BagStorage>
  • Field Details

  • Constructor Details

    • ImmersiveBag

      public ImmersiveBag()
  • Method Details

    • buildInfo

      public BagInfo buildInfo(net.minecraft.client.player.AbstractClientPlayer player)
      Description copied from interface: PlayerAttachmentImmersive
      Constructs a new PlayerAttachmentImmersiveInfo based on the provided owning player. It's best to calculate initial hitboxes, etc. in this method to make the Immersive is available for interaction as soon as possible.

      This method is only called if @link ImmersiveHandler#clientAuthoritative()} returns false for the PlayerAttachmentImmersiveHandler returned by PlayerAttachmentImmersive.getHandler().

      Specified by:
      buildInfo in interface PlayerAttachmentImmersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      player - The player who owns/controls this Immersive. This may not necessarily be the same player as the local player!
      Returns:
      An instance of an ImmersiveInfo implementation with the same position as provided.
    • getTrackedObjects

      public Collection<BagInfo> getTrackedObjects()
      Description copied from interface: Immersive
      Get the collection of ImmersiveInfos currently active for this Immersive. The contents of the list may be modified by ImmersiveMC with the intention of updating the actual set of active ImmersiveInfos.
      For example, if this Immersive represented a furnace, and the furnace was broken, ImmersiveMC would remove the ImmersiveInfo from the collection returned by this function to indicate that this Immersive should no longer handle the block, as it is no longer a furnace. As another example, if this Immersive represented a furnace, and a player placed a furnace, ImmersiveMC would add the result of BlockBasedImmersive.buildInfo(BlockPos, Level) to the collection returned by this function.
      In short, you should return the actual collection of ImmersiveInfos used by this Immersive instead of a copy of it.
      Specified by:
      getTrackedObjects in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Returns:
      The collection of all ImmersiveInfos tied to this Immersive.
    • handleHitboxInteract

      public int handleHitboxInteract(BagInfo info, net.minecraft.client.player.LocalPlayer player, List<Integer> hitboxIndices, net.minecraft.world.InteractionHand hand, boolean modifierPressed)
      Description copied from interface: Immersive
      The method called when a player interacts with a hitbox.
      If multiple hitboxes are being interacted with at the same time, only the first hitbox in iteration order from ImmersiveInfo.getAllHitboxes() that is being interacted with will have this function called.
      Specified by:
      handleHitboxInteract in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      info - The info containing the hitbox that was interacted with.
      player - The player that interacted with the hitbox. This player is always the player currently controlling the game window.
      hitboxIndices - The indices into ImmersiveInfo.getAllHitboxes() that were interacted with. The list is guaranteed to contain at least one element and all elements are not null.
      hand - The hand used for interaction.
      modifierPressed - Whether the modifier key (usually the button mapped to breaking blocks) was held for the interaction.
      Returns:
      A number representing the number of ticks of cooldown to apply before the player can interact with any Immersive again, or a negative number to denote no actual interaction has happened, such as obtaining items from an output slot of an Immersive when the output slot has no items.
    • tick

      public void tick(BagInfo info)
      Description copied from interface: Immersive
      This method is called once per game tick. This is where you should, for example, recalculate hitboxes if needed.
      Specified by:
      tick in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      info - The info being ticked.
    • getDragHitbox

      @Nullable public @Nullable BoundingBox getDragHitbox(BagInfo info)
      Specified by:
      getDragHitbox in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Returns:
      The hitbox that determines whether dragging between multiple slots should continue or not. Can return null here to not allow dragging. If non-null, the hitbox should contain all hitboxes where Immersive.isInputHitbox(ImmersiveInfo, int) returns true.
    • isInputHitbox

      public boolean isInputHitbox(BagInfo info, int hitboxIndex)
      Specified by:
      isInputHitbox in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      info - The info being checked with.
      hitboxIndex - The hitbox index being checked.
      Returns:
      Whether the provided hitbox index is an input, such as for inputting items.
    • shouldRender

      public boolean shouldRender(BagInfo.RenderState renderState)
      Description copied from interface: Immersive
      Whether the provided render state should render in the world. It's good to return false here if this Immersive does not have its data ready for rendering.
      Specified by:
      shouldRender in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      renderState - The render state to check.
      Returns:
      Whether the provided render state should render to the world, which includes calling Immersive.render(ImmersiveRenderState, PoseStack, ImmersiveRenderHelpers, float).
    • render

      public void render(BagInfo.RenderState renderState, com.mojang.blaze3d.vertex.PoseStack stack, ImmersiveRenderHelpers helpers, float partialTick)
      Description copied from interface: Immersive
      Render the provided render state.
      Specified by:
      render in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      renderState - The render state to render.
      stack - The pose stack being rendered with.
      helpers - Some helper functions for rendering.
      partialTick - The fraction of time between the last tick and the current tick.
    • getHandler

      Specified by:
      getHandler in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Specified by:
      getHandler in interface PlayerAttachmentImmersive<BagInfo, BagInfo.RenderState, BagStorage>
      Returns:
      The PlayerAttachmentImmersiveHandler this Immersive uses.
    • configScreenInfo

      @Nullable public @Nullable ImmersiveConfigScreenInfo configScreenInfo()
      Description copied from interface: Immersive
      The info needed to build a config screen button for this Immersive. If this method returns null, ImmersiveMC will not add a setting for this Immersive to its in-game configuration. Reasons to possibly return null from this method include, but are not limited to:
      • This Immersive cannot be controlled via a config.
      • Another mod already handles configuring this Immersive.
      Specified by:
      configScreenInfo in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Returns:
      An ImmersiveConfigScreenInfo instance used for ImmersiveMC to add this Immersive to its in-game configuration screens, or null if ImmersiveMC should not do so.
    • processStorageFromNetwork

      public void processStorageFromNetwork(BagInfo info, BagStorage storage)
      Description copied from interface: Immersive
      Process the storage from the server for this Immersive. Not called for Immersives that return true for Immersive.getHandler()'s ImmersiveHandler.clientAuthoritative().
      Specified by:
      processStorageFromNetwork in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      info - The info with storage being processed.
      storage - The storage to be processed.
    • createRenderState

      public BagInfo.RenderState createRenderState()
      Description copied from interface: Immersive
      Creates a new render state not populated with any rendering-related details.
      Specified by:
      createRenderState in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Returns:
      Created render state, as described.
    • extractRenderState

      public void extractRenderState(BagInfo info, BagInfo.RenderState renderState, float partialTicks)
      Description copied from interface: Immersive
      Extract render state from the info into the provided render state object.

      The extracted render state must be independent of the info it comes from such that mutations to the info do not affect the render state. For example, if the info contains a list of hitboxes, a modification to that list must NOT modify the list of hitboxes stored in the render state.

      Specified by:
      extractRenderState in interface Immersive<BagInfo, BagInfo.RenderState, BagStorage>
      Parameters:
      info - Info to extract render state from.
      renderState - Render state to populate from the info. Note that the API does NOT cover the state of this object when this function is called. It only defines that this should be fully populated from the provided info for rendering. As such, it's recommended to set the values for all fields in this object based on the provided info every time this method is called.
      partialTicks - The fraction of time between the last tick and the current tick.
    • getBackpackColor

      public static int getBackpackColor()
    • getBackpackModel

      public static net.minecraft.client.model.Model getBackpackModel()
    • getBackpackTexture

      public static net.minecraft.resources.Identifier getBackpackTexture()
    • canGotoNextRowFromClick

      public static boolean canGotoNextRowFromClick(BagInfo info)