Class Util
java.lang.Object
com.hammy275.immersivemc.common.util.Util
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final record -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<net.minecraft.core.BlockPos> allPositionsWithAABB(net.minecraft.world.phys.AABB box) static net.minecraft.world.phys.Vec3static booleanblockIsActiveImmersive(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos) static booleancanPickUpItem(net.minecraft.world.entity.item.ItemEntity item, net.minecraft.world.entity.player.Player player) static net.minecraft.world.InteractionResultdoUse(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.DirectiongetForwardFromPlayerUpAndDown(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos) static net.minecraft.core.DirectiongetForwardFromPlayerUpAndDownFilterBlockFacing(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.Vec3getLookAngle(float pitch, float yaw) Gets a look angle from pitch/yaw.static net.minecraft.world.level.block.entity.ChestBlockEntitygetOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest) protected static net.minecraft.world.level.block.entity.ChestBlockEntitygetOtherChest(net.minecraft.world.level.block.entity.ChestBlockEntity chest, boolean checkOther) static net.minecraft.world.phys.Vec3getPlayerVelocity(net.minecraft.world.phys.Vec3 lastTickPos, net.minecraft.world.phys.Vec3 currentTickPos) static net.minecraft.resources.ResourceLocationgetResourceLocation(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 voidgiveStackHandFirst(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack stack) static booleanhasItemInInventoryWithStackSpace(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack) static net.minecraft.core.DirectionhorizontalDirectionFromLook(net.minecraft.world.phys.Vec3 look) static booleanisHittingImmersive(net.minecraft.world.phys.BlockHitResult result, net.minecraft.world.level.Level level) static booleanisThrowableItem(net.minecraft.world.item.Item item) static booleanisValidBlocks(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 booleanisValidBlocks(ImmersiveHandler<?> handler, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level level) Check if Immersive has valid blocks.static Util.ItemStackMergeResultmergeStacks(net.minecraft.world.item.ItemStack mergeIntoIn, net.minecraft.world.item.ItemStack mergeFromIn, boolean useCopy) Merges two ItemStacks togetherstatic Util.ItemStackMergeResultmergeStacks(net.minecraft.world.item.ItemStack mergeIntoIn, net.minecraft.world.item.ItemStack mergeFromIn, boolean useCopy, int forcedMaxMergeIntoSize) Merges two ItemStacks togetherstatic doublemoveTowardsZero(double num, double subtract) static net.minecraft.world.InteractionHandotherHand(net.minecraft.world.InteractionHand hand) static voidplaceLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers) static voidplaceLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers, net.minecraft.world.phys.Vec3 pos) static voidputResourceLocation(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 voidsetRepeater(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, int newDelay) static booleanstacksEqualBesidesCount(net.minecraft.world.item.ItemStack a, net.minecraft.world.item.ItemStack b) static voiduseDoor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) static voiduseLever(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos) static voiduseTrapdoor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
-
Field Details
-
activeUseInfo
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
blockIsActiveImmersive
public static boolean blockIsActiveImmersive(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos) -
otherHand
public static net.minecraft.world.InteractionHand otherHand(net.minecraft.world.InteractionHand hand) -
doUse
public static net.minecraft.world.InteractionResult 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 toImmersiveHandler.isValidBlock(BlockPos, Level)for single-block Immersives, and running the former method on all blocks inMultiblockImmersiveHandler.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
-
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) -
hasItemInInventoryWithStackSpace
public static boolean hasItemInInventoryWithStackSpace(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack) -
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 intomergeFromIn- ItemStack to merge fromuseCopy- 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.
-
mergeStacks
public static Util.ItemStackMergeResult mergeStacks(net.minecraft.world.item.ItemStack mergeIntoIn, net.minecraft.world.item.ItemStack mergeFromIn, boolean useCopy, int forcedMaxMergeIntoSize) Merges two ItemStacks together- Parameters:
mergeIntoIn- ItemStack to merge intomergeFromIn- ItemStack to merge fromuseCopy- Whether or not to use copies of the ItemStacks suppliedforcedMaxMergeIntoSize- A force maximum stack size for mergeIntoIn, or -1 to not force.- 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) -
useDoor
public static void useDoor(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) -
giveStackHandFirst
public static void giveStackHandFirst(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack stack) -
placeLeftovers
public static void placeLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers) -
placeLeftovers
public static void placeLeftovers(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack leftovers, net.minecraft.world.phys.Vec3 pos) -
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.
-