Class BlockEntityHelpers

java.lang.Object
org.cyclops.cyclopscore.helper.BlockEntityHelpers

public final class BlockEntityHelpers extends Object
Contains helper methods for various block entity specific things.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    If block entities should be retrieved in an unsafe manner from the non-main thread.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Optional<T>
    get(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, Class<T> targetClazz)
    Safely cast a block entity.
    static <T> Optional<T>
    get(DimPos dimPos, Class<T> targetClazz)
    Safely cast a block entity.
    static <T, C> Optional<T>
    getCapability(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, C context, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
    Safely get a capability from a block entity.
    static <T, C> Optional<T>
    getCapability(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
    Safely get a capability from a block entity.
    static <T, C> Optional<T>
    getCapability(DimPos dimPos, C context, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
    Safely get a capability from a block entity.
    static <T, C> Optional<T>
    getCapability(DimPos dimPos, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
    Safely get a capability from a block entity.

    Methods inherited from class java.lang.Object

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

    • UNSAFE_BLOCK_ENTITY_GETTER

      public static boolean UNSAFE_BLOCK_ENTITY_GETTER
      If block entities should be retrieved in an unsafe manner from the non-main thread. USE WITH CAUTION!!!
  • Constructor Details

    • BlockEntityHelpers

      public BlockEntityHelpers()
  • Method Details

    • get

      public static <T> Optional<T> get(DimPos dimPos, Class<T> targetClazz)
      Safely cast a block entity.
      Type Parameters:
      T - The type of block entity to cast at.
      Parameters:
      dimPos - The dimensional position of the block providing the block entity.
      targetClazz - The class to cast to.
      Returns:
      The optional block entity.
    • get

      public static <T> Optional<T> get(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, Class<T> targetClazz)
      Safely cast a block entity.
      Type Parameters:
      T - The type of block entity to cast at.
      Parameters:
      level - The level.
      pos - The position of the block providing the block entity.
      targetClazz - The class to cast to.
      Returns:
      The optional block entity.
    • getCapability

      public static <T, C> Optional<T> getCapability(DimPos dimPos, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
      Safely get a capability from a block entity.
      Type Parameters:
      T - The capability instance.
      C - The capability context.
      Parameters:
      dimPos - The dimensional position of the block providing the block entity.
      capability - The capability.
      Returns:
      The lazy optional capability.
    • getCapability

      public static <T, C> Optional<T> getCapability(DimPos dimPos, C context, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
      Safely get a capability from a block entity.
      Type Parameters:
      T - The capability instance.
      C - The capability context.
      Parameters:
      dimPos - The dimensional position of the block providing the block entity.
      context - The context to get the capability from.
      capability - The capability.
      Returns:
      The lazy optional capability.
    • getCapability

      public static <T, C> Optional<T> getCapability(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
      Safely get a capability from a block entity.
      Type Parameters:
      T - The capability instance.
      C - The capability context.
      Parameters:
      level - The level.
      pos - The position of the block of the block entity providing the capability.
      capability - The capability.
      Returns:
      The lazy optional capability.
    • getCapability

      public static <T, C> Optional<T> getCapability(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, C context, net.neoforged.neoforge.capabilities.BlockCapability<T,C> capability)
      Safely get a capability from a block entity.
      Type Parameters:
      T - The capability instance.
      C - The capability context.
      Parameters:
      level - The level.
      pos - The position of the block of the block entity providing the capability.
      context - The context to get the capability from.
      capability - The capability.
      Returns:
      The lazy optional capability.