Class BlockHelpers

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

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

    Fields
    Modifier and Type
    Field
    Description
    static net.minecraft.core.HolderGetter<net.minecraft.world.level.block.Block>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addCollisionBoxToList(net.minecraft.core.BlockPos pos, net.minecraft.world.phys.AABB collidingBox, List<net.minecraft.world.phys.AABB> collisions, net.minecraft.world.phys.AABB addingBox)
    Add a collision box to the given list if it intersects with a box.
    static net.minecraft.world.level.block.state.BlockState
    deserializeBlockState(net.minecraft.core.HolderGetter<net.minecraft.world.level.block.Block> holderGetter, net.minecraft.nbt.CompoundTag serializedBlockState)
    Convert the given serialized NBT blockstate to a blockstate instance.
    static boolean
    doesBlockHaveSolidTopSurface(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos blockPos)
    If the given block has a solid top surface.
    static net.minecraft.world.level.block.state.BlockState
    getBlockStateFromItemStack(net.minecraft.world.item.ItemStack itemStack)
    Get the blockstate from the given itemstack
    static net.minecraft.world.item.ItemStack
    getItemStackFromBlockState(net.minecraft.world.level.block.state.BlockState blockState)
    Get the itemstack from the given blockstate
    static <T extends Comparable<T>>
    T
    getSafeBlockStateProperty(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.properties.Property<T> property, T fallback)
    Safely get a block state property for a nullable state and value that may not have been set yet.
    static void
    markForUpdate(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Trigger a block update.
    static net.minecraft.nbt.CompoundTag
    serializeBlockState(net.minecraft.world.level.block.state.BlockState blockState)
    Convert the given blockstate to NBT.

    Methods inherited from class java.lang.Object

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

    • HOLDER_GETTER_FORGE

      public static net.minecraft.core.HolderGetter<net.minecraft.world.level.block.Block> HOLDER_GETTER_FORGE
  • Constructor Details

    • BlockHelpers

      public BlockHelpers()
  • Method Details

    • getSafeBlockStateProperty

      public static <T extends Comparable<T>> T getSafeBlockStateProperty(@Nullable net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.properties.Property<T> property, T fallback)
      Safely get a block state property for a nullable state and value that may not have been set yet.
      Type Parameters:
      T - The type of value to fetch.
      Parameters:
      state - The block state.
      property - The property to get the value for.
      fallback - The fallback value when something has failed.
      Returns:
      The value.
    • serializeBlockState

      public static net.minecraft.nbt.CompoundTag serializeBlockState(net.minecraft.world.level.block.state.BlockState blockState)
      Convert the given blockstate to NBT.
      Parameters:
      blockState - The blockstate to serialize.
      Returns:
      The blockstate as NBT.
    • deserializeBlockState

      public static net.minecraft.world.level.block.state.BlockState deserializeBlockState(net.minecraft.core.HolderGetter<net.minecraft.world.level.block.Block> holderGetter, net.minecraft.nbt.CompoundTag serializedBlockState)
      Convert the given serialized NBT blockstate to a blockstate instance.
      Parameters:
      holderGetter - The block getter.
      serializedBlockState - The blockstate as NBT.
      Returns:
      The resulting blockstate.
    • getBlockStateFromItemStack

      public static net.minecraft.world.level.block.state.BlockState getBlockStateFromItemStack(net.minecraft.world.item.ItemStack itemStack)
      Get the blockstate from the given itemstack
      Parameters:
      itemStack - The itemstack
      Returns:
      The blockstate
    • getItemStackFromBlockState

      public static net.minecraft.world.item.ItemStack getItemStackFromBlockState(net.minecraft.world.level.block.state.BlockState blockState)
      Get the itemstack from the given blockstate
      Parameters:
      blockState - The blockstate
      Returns:
      The itemstack
    • markForUpdate

      public static void markForUpdate(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Trigger a block update.
      Parameters:
      world - The world.
      pos - The pos.
    • addCollisionBoxToList

      public static void addCollisionBoxToList(net.minecraft.core.BlockPos pos, net.minecraft.world.phys.AABB collidingBox, List<net.minecraft.world.phys.AABB> collisions, net.minecraft.world.phys.AABB addingBox)
      Add a collision box to the given list if it intersects with a box.
      Parameters:
      pos - The block position the collision is happening in.
      collidingBox - The box that is colliding with the block, absolute coordinates.
      collisions - The list fo add the box to.
      addingBox - The box to add to the lost, relative coordinates.
    • doesBlockHaveSolidTopSurface

      public static boolean doesBlockHaveSolidTopSurface(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos blockPos)
      If the given block has a solid top surface.
      Parameters:
      world - The world`.
      blockPos - The block to check the top of.
      Returns:
      If it has a solid top surface.