java.lang.Object
com.hammy275.immersivemc.common.util.Util

public class Util extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static final record 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addStackToInventory(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack item)
     
    static List<net.minecraft.core.BlockPos>
    allPositionsWithAABB(net.minecraft.world.phys.AABB box)
     
    static net.minecraft.world.phys.Vec3
    average(Set<net.minecraft.core.BlockPos> positions)
     
    static boolean
    canPickUpItem(net.minecraft.world.entity.item.ItemEntity item, net.minecraft.world.entity.player.Player player)
     
    static net.minecraft.world.InteractionResultHolder<net.minecraft.world.item.ItemStack>
    doUse(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos)
     
    static net.minecraft.world.phys.Vec3[]
    get3x3HorizontalGrid(net.minecraft.core.BlockPos blockPos, double spacing, net.minecraft.core.Direction blockForward, boolean use3DCompat)
     
    getClosestIntersect(net.minecraft.world.phys.Vec3 pos, List<BoundingBox> targets)
     
    getFirstIntersect(net.minecraft.world.phys.Vec3 pos, BoundingBox... targets)
     
    getFirstIntersect(net.minecraft.world.phys.Vec3 pos, Iterable<BoundingBox> targets)
     
    getFirstIntersect(net.minecraft.world.phys.Vec3 pos, Collection<? extends HitboxInfo> targets)
     
    static net.minecraft.core.Direction
    getForwardFromPlayerUpAndDown(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
     
    static net.minecraft.core.Direction
    getForwardFromPlayerUpAndDownFilterBlockFacing(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, boolean filterOnBlockFacing)
    Same as getForwardFromPlayer, but can return the block facing up or down, alongside any of the four directions of N/E/S/W.
    static net.minecraft.world.phys.Vec3
    getLookAngle(float pitch, float yaw)
    Gets a look angle from pitch/yaw.
    static net.minecraft.world.level.block.entity.ChestBlockEntity
    getOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest)
     
    protected static net.minecraft.world.level.block.entity.ChestBlockEntity
    getOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest, boolean checkOther)
     
    static net.minecraft.world.phys.Vec3
    getPlayerVelocity(net.minecraft.world.phys.Vec3 lastTickPos, net.minecraft.world.phys.Vec3 currentTickPos)
     
    static net.minecraft.resources.ResourceLocation
    getResourceLocation(net.minecraft.nbt.CompoundTag nbt, String key)
     
    static Set<net.minecraft.core.BlockPos>
    getValidBlocks(ImmersiveHandler<?> handler, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
    Get all blocks part of the Immersive at the specified position for the given handler.
    static net.minecraft.core.Direction
    horizontalDirectionFromLook(net.minecraft.world.phys.Vec3 look)
     
    static boolean
    isHittingImmersive(net.minecraft.world.phys.BlockHitResult result, net.minecraft.world.level.Level level)
     
    static boolean
    isThrowableItem(net.minecraft.world.item.Item item)
     
    static boolean
    isValidBlocks(ImmersiveHandler<?> handler, Set<net.minecraft.core.BlockPos> pos, net.minecraft.world.level.Level level)
    Checks if Immersive exactly matches the supplied set of blocks.
    static boolean
    isValidBlocks(ImmersiveHandler<?> handler, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
    Check if Immersive has valid blocks.
    mergeStacks(net.minecraft.world.item.ItemStack mergeIntoIn, net.minecraft.world.item.ItemStack mergeFromIn, boolean useCopy)
    Merges two ItemStacks together
    static double
    moveTowardsZero(double num, double subtract)
     
    static void
    placeLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers)
     
    static void
    putResourceLocation(net.minecraft.nbt.CompoundTag nbt, String key, net.minecraft.resources.ResourceLocation loc)
     
    rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, BoundingBox... targets)
    Find the closest BoundingBox that is ray traced through the ray.
    rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, Iterable<BoundingBox> targets)
     
    rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, Collection<? extends HitboxInfo> targets)
     
    static void
    setRepeater(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, int newDelay)
     
    static boolean
    stacksEqualBesidesCount(net.minecraft.world.item.ItemStack a, net.minecraft.world.item.ItemStack b)
     
    static void
    useLever(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
     
    static void
    useTrapdoor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
     

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • Util

      public Util()
  • Method Details

    • doUse

      public static net.minecraft.world.InteractionResultHolder<net.minecraft.world.item.ItemStack> doUse(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos)
    • getLookAngle

      public static net.minecraft.world.phys.Vec3 getLookAngle(float pitch, float yaw)
      Gets a look angle from pitch/yaw.
      Parameters:
      pitch - The pitch in radians.
      yaw - The yaw in radians.
      Returns:
      The look angle represented by the pitch and yaw.
    • isValidBlocks

      public static boolean isValidBlocks(ImmersiveHandler<?> handler, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
      Check if Immersive has valid blocks. This is equivalent to ImmersiveHandler.isValidBlock(BlockPos, Level) for single-block Immersives, and running the former method on all blocks in MultiblockImmersiveHandler.getHandledBlocks(BlockPos, Level) for multiblock Immersives.
      Parameters:
      handler - Handler to run on.
      pos - Position to check, or a position to check if part of a multiblock.
      level - Level to check in.
      Returns:
      Whether all blocks are valid or not.
    • isValidBlocks

      public static boolean isValidBlocks(ImmersiveHandler<?> handler, Set<net.minecraft.core.BlockPos> pos, net.minecraft.world.level.Level level)
      Checks if Immersive exactly matches the supplied set of blocks.
      Parameters:
      handler - Handler.
      pos - Set of all positions in the Immersive.
      level - Level.
      Returns:
      Whether the provided set of positions match the Immersive as it exists in-world.
    • getValidBlocks

      public static Set<net.minecraft.core.BlockPos> getValidBlocks(ImmersiveHandler<?> handler, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level)
      Get all blocks part of the Immersive at the specified position for the given handler.
      Parameters:
      handler - Handler to get valid positions of.
      pos - A BlockPos that's part of the Immersive.
      level - The level to get in.
      Returns:
      A set of valid positions for the Immersive, or an empty set if not valid.
    • average

      public static net.minecraft.world.phys.Vec3 average(Set<net.minecraft.core.BlockPos> positions)
    • isThrowableItem

      public static boolean isThrowableItem(net.minecraft.world.item.Item item)
    • horizontalDirectionFromLook

      public static net.minecraft.core.Direction horizontalDirectionFromLook(net.minecraft.world.phys.Vec3 look)
    • isHittingImmersive

      public static boolean isHittingImmersive(net.minecraft.world.phys.BlockHitResult result, net.minecraft.world.level.Level level)
    • addStackToInventory

      public static void addStackToInventory(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack item)
    • canPickUpItem

      public static boolean canPickUpItem(net.minecraft.world.entity.item.ItemEntity item, net.minecraft.world.entity.player.Player player)
    • rayTraceClosest

      public static Optional<Integer> rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, BoundingBox... targets)
      Find the closest BoundingBox that is ray traced through the ray.
      Parameters:
      rayStart - Start of the ray.
      rayEnd - End of the ray.
      targets - List of targets.
      Returns:
      Target in targets that intersects the ray and is closer to rayStart than all other intersecting targets.
    • rayTraceClosest

      public static Optional<Integer> rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, Collection<? extends HitboxInfo> targets)
    • rayTraceClosest

      public static Optional<Integer> rayTraceClosest(net.minecraft.world.phys.Vec3 rayStart, net.minecraft.world.phys.Vec3 rayEnd, Iterable<BoundingBox> targets)
    • getFirstIntersect

      public static Optional<Integer> getFirstIntersect(net.minecraft.world.phys.Vec3 pos, BoundingBox... targets)
    • getFirstIntersect

      public static Optional<Integer> getFirstIntersect(net.minecraft.world.phys.Vec3 pos, Collection<? extends HitboxInfo> targets)
    • getFirstIntersect

      public static Optional<Integer> getFirstIntersect(net.minecraft.world.phys.Vec3 pos, Iterable<BoundingBox> targets)
    • getClosestIntersect

      public static Optional<Integer> getClosestIntersect(net.minecraft.world.phys.Vec3 pos, List<BoundingBox> targets)
    • getOtherChest

      public static net.minecraft.world.level.block.entity.ChestBlockEntity getOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest)
    • getOtherChest

      protected static net.minecraft.world.level.block.entity.ChestBlockEntity getOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest, boolean checkOther)
    • stacksEqualBesidesCount

      public static boolean stacksEqualBesidesCount(net.minecraft.world.item.ItemStack a, net.minecraft.world.item.ItemStack b)
    • mergeStacks

      public static Util.ItemStackMergeResult mergeStacks(net.minecraft.world.item.ItemStack mergeIntoIn, net.minecraft.world.item.ItemStack mergeFromIn, boolean useCopy)
      Merges two ItemStacks together
      Parameters:
      mergeIntoIn - ItemStack to merge into
      mergeFromIn - ItemStack to merge from
      useCopy - Whether or not to use copies of the ItemStacks supplied
      Returns:
      An ItemStackMergeResult containing the results post-merge. If no merge takes place, the returned result just contains the inputted ItemStacks.
    • setRepeater

      public static void setRepeater(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, int newDelay)
    • useLever

      public static void useLever(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
    • useTrapdoor

      public static void useTrapdoor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    • getPlayerVelocity

      public static net.minecraft.world.phys.Vec3 getPlayerVelocity(net.minecraft.world.phys.Vec3 lastTickPos, net.minecraft.world.phys.Vec3 currentTickPos)
    • moveTowardsZero

      public static double moveTowardsZero(double num, double subtract)
    • placeLeftovers

      public static void placeLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers)
    • putResourceLocation

      public static void putResourceLocation(net.minecraft.nbt.CompoundTag nbt, String key, net.minecraft.resources.ResourceLocation loc)
    • getResourceLocation

      public static net.minecraft.resources.ResourceLocation getResourceLocation(net.minecraft.nbt.CompoundTag nbt, String key)
    • allPositionsWithAABB

      public static List<net.minecraft.core.BlockPos> allPositionsWithAABB(net.minecraft.world.phys.AABB box)
    • get3x3HorizontalGrid

      public static net.minecraft.world.phys.Vec3[] get3x3HorizontalGrid(net.minecraft.core.BlockPos blockPos, double spacing, net.minecraft.core.Direction blockForward, boolean use3DCompat)
    • getForwardFromPlayerUpAndDown

      public static net.minecraft.core.Direction getForwardFromPlayerUpAndDown(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
    • getForwardFromPlayerUpAndDownFilterBlockFacing

      public static net.minecraft.core.Direction getForwardFromPlayerUpAndDownFilterBlockFacing(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, boolean filterOnBlockFacing)
      Same as getForwardFromPlayer, but can return the block facing up or down, alongside any of the four directions of N/E/S/W.
      Parameters:
      player - Player.
      pos - Position of block.
      filterOnBlockFacing - If true, the axis of the block's DirectionalBlock.FACING will not be returned from this function. The block should have this property if this is true, of course!
      Returns:
      Any Direction, representing what direction the block should be facing based on the player's position.