Package org.cyclops.cyclopscore.helper
Class BlockEntityHelpers
java.lang.Object
org.cyclops.cyclopscore.helper.BlockEntityHelpers
Contains helper methods for various block entity specific things.
-
Field Summary
Modifier and TypeFieldDescriptionstatic boolean
If block entities should be retrieved in an unsafe manner from the non-main thread. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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>
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.
-
Field Details
-
UNSAFE_BLOCK_ENTITY_GETTER
public static boolean UNSAFE_BLOCK_ENTITY_GETTERIf 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
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.
-