Interface ImmersiveBuilder<E,S extends NetworkStorage>

Type Parameters:
E - The type of "extra data" to add to BuiltImmersiveInfo instances. This way, data other than what ImmersiveMC keeps track of can be used. This type MUST have a public constructor that takes 0 arguments.
S - The type of storage to use for sending Immersive data over the network.
All Known Implementing Classes:
ImmersiveBuilderImpl

public interface ImmersiveBuilder<E,S extends NetworkStorage>
An alternative to Immersive to make (block-based) Immersives with much less effort, while still getting a significant amount of flexibility. Note that the underlying defaults if a given builder method isn't called are not part of the API, and may change in the future.
  • Method Details

    • create

      static <NS extends NetworkStorage> ImmersiveBuilder<?,NS> create(ImmersiveHandler<NS> handler) throws IllegalArgumentException
      Create an ImmersiveBuilder to start making an Immersive. You cannot use ImmersiveBuilders with MultiblockImmersiveHandlers; write an Immersive implementation instead to use those.
      Parameters:
      handler - The handler for the Immersive.
      Returns:
      A builder object.
      Throws:
      IllegalArgumentException - If provided a MultiblockImmersiveHandler, as it is unsupported with ImmersiveBuilders.
    • create

      static <E, NS extends NetworkStorage> ImmersiveBuilder<E,NS> create(ImmersiveHandler<NS> handler, Class<E> extraInfoDataClass) throws IllegalArgumentException
      Create an ImmersiveBuilder to start making an Immersive. You cannot use ImmersiveBuilders with MultiblockImmersiveHandlers; write an Immersive implementation instead to use those.
      Parameters:
      handler - The handler for the Immersive.
      extraInfoDataClass - A class with an empty constructor that holds extra data for each info instance.
      Returns:
      A builder object.
      Throws:
      IllegalArgumentException - If provided a MultiblockImmersiveHandler, as it is unsupported with ImmersiveBuilders.
    • setRenderSize

      ImmersiveBuilder<E,S> setRenderSize(float size)
      Sets the size for items rendered by this immersive.
      Parameters:
      size - The size of the item when rendering.
      Returns:
      Builder object.
    • addHitbox

      ImmersiveBuilder<E,S> addHitbox(RelativeHitboxInfo relativeHitboxInfo)
      Adds a hitbox. Note that item hitboxes MUST be added in slot-order. Aka, the underlying block's slot 0 should be added before its slot 1, etc.
      Parameters:
      relativeHitboxInfo - HitboxInfo to add. Can use HitboxInfoBuilder to make it easier to create.
      Returns:
      Builder object.
    • add3x3Grid

      ImmersiveBuilder<E,S> add3x3Grid(RelativeHitboxInfo relativeHitboxInfo, double distBetweenBoxes)
      Adds a 3x3 grid of hitboxes, such as for the crafting table. Adds the top row from left to right, then the middle row from left to right, then the bottom row from left to right.
      Parameters:
      relativeHitboxInfo - HitboxInfo for center box. Can use HitboxInfoBuilder to make it easier to create.
      distBetweenBoxes - Distance between boxes.
      Returns:
      Builder object.
    • setPositioningMode

      ImmersiveBuilder<E,S> setPositioningMode(HitboxPositioningMode newMode)
      Sets the way hitboxes are positioned on the block.
      Parameters:
      newMode - New mode for positioning.
      Returns:
      Builder object.
    • setConfigChecker

      ImmersiveBuilder<E,S> setConfigChecker(Supplier<Boolean> checker)
      Sets a function used to retrieve the config value for whether this immerisve is enabled.
      Parameters:
      checker - Checker to retrieve config value. Something such as () -> ActiveConfig.active().myConfigValue works here.
      Returns:
      Builder object.
    • setHitboxInteractHandler

      ImmersiveBuilder<E,S> setHitboxInteractHandler(HitboxInteractHandler<E> handler)
      Sets what should happen when a hitbox is interacted with.
      Parameters:
      handler - Function that takes an info instance, a player doing the interaction, the slot being interacted with, and the hand being interacted with. This function should return a number denoting the cooldown until the user can interact with Immersives again, or a negative number to denote that no interaction took place. The returned cooldown is increased for VR users, unless the Immersive is VR-only.
      Returns:
      Builder object.
    • setVROnly

      ImmersiveBuilder<E,S> setVROnly(boolean vrOnly)
      Sets whether this immersive is only for VR users.
      Parameters:
      vrOnly - Whether this immersive should now be VR only.
      Returns:
      Builder object.
    • setExtraStorageConsumer

      ImmersiveBuilder<E,S> setExtraStorageConsumer(BiConsumer<S,BuiltImmersiveInfo<E>> storageConsumer)
      Sets a consumer that acts after an incoming NetworkStorage is parsed. For example, this is used for the anvil to retrieve the level amount and store it in extra data.
      Parameters:
      storageConsumer - New storage consumer.
      Returns:
      Builder object.
    • setSlotActiveFunction

      ImmersiveBuilder<E,S> setSlotActiveFunction(BiFunction<BuiltImmersiveInfo<E>,Integer,Boolean> slotActive)
      Sets a function that determines whether a given slot should be active (rendered, reacts to interactions, etc.).
      Parameters:
      slotActive - Function that takes an info instance and a slot number and returns whether the slot is active.
      Returns:
      Builder object.
    • setOnRemove

      ImmersiveBuilder<E,S> setOnRemove(Consumer<BuiltImmersiveInfo<E>> onRemove)
      Set function to run on an info before it's removed.
      Parameters:
      onRemove - Function to run on info just before removal.
      Returns:
      Builder object.
    • shouldDisableRightClicksWhenInteractionsDisabled

      ImmersiveBuilder<E,S> shouldDisableRightClicksWhenInteractionsDisabled(boolean doDisable)
      Set whether to disable right-click interactions on this immersive when the option to disable said interactions is enabled.
      Parameters:
      doDisable - Whether to disable as described above.
      Returns:
      Builder object.
    • setShouldRenderItemGuideFunction

      ImmersiveBuilder<E,S> setShouldRenderItemGuideFunction(BiFunction<BuiltImmersiveInfo<E>,Integer,Boolean> itemGuideActive)
      Set whether the item guide for this slot should be active. This result is AND'd with the built-in checker, which is simply if the slot holds items but currently isn't holding one.
      Parameters:
      itemGuideActive - Function that returns whether the given slot is active given the info.
      Returns:
      Builder object.
    • setConfigScreenInfo

      ImmersiveBuilder<E,S> setConfigScreenInfo(ImmersiveConfigScreenInfo info)
      Set the config screen info associated with this Immersive.
      Parameters:
      info - The config screen info to associate with this Immersive.
      Returns:
      Builder object.
    • overwriteHitbox

      ImmersiveBuilder<E,S> overwriteHitbox(int index, RelativeHitboxInfo relativeHitboxInfo)
      Overwrites hitbox at index with a new hitbox. Useful when cloning.
      Parameters:
      index - Index to overwrite.
      relativeHitboxInfo - New hitbox information.
      Returns:
      Builder object.
    • modifyHitbox

      Modify a hitbox.
      Parameters:
      index - Index of hitbox to modify.
      modifier - A function that takes the old hitbox as a builder and returns new hitbox info.
      Returns:
      Builder object.
    • modifyHitboxes

      ImmersiveBuilder<E,S> modifyHitboxes(int startIndex, int endIndex, Function<RelativeHitboxInfoBuilder,RelativeHitboxInfo> modifier)
      Modify a range of hitboxes, inclusive for both ends.
      Parameters:
      startIndex - Starting index of range of hitboxes to modify inclusive.
      endIndex - Ending index of range of hitboxes to modify inclusive.
      modifier - A function that takes the old hitbox as a builder and returns new hitbox info.
      Returns:
      Builder object.
    • copy

      <T extends NetworkStorage> ImmersiveBuilder<E,T> copy(ImmersiveHandler<T> newHandler)
      Create a copy of this ImmersiveBuilder, setting the extra storage consumer and the Immersive config info to null on the copy.
      Returns:
      A best-effort copy of this ImmersiveBuilder.
    • copy

      <F, T extends NetworkStorage> ImmersiveBuilder<F,T> copy(ImmersiveHandler<T> newHandler, Class<F> newExtraInfoDataClass)
      Create a copy of this ImmersiveBuilder, setting the extra storage consumer, the extra render ready, the slot active function, the on remove function, the slot renders item guide function, the right click handler, and the Immersive config info to null/no-op on the copy.
      Returns:
      A best-effort copy of this ImmersiveBuilder.
    • build

      BuiltImmersive<E,S> build()
      Builds this Immersive.
      Returns:
      The built Immersive from this builder.