Class PneumaticCraftUtils

java.lang.Object
me.desht.pneumaticcraft.common.util.PneumaticCraftUtils

public class PneumaticCraftUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<? extends net.minecraft.network.chat.Component>
     
    static double
    average(long[] pValues)
     
    static boolean
    canPlayerReach(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
     
    static void
    collectNonEmptyItems(net.minecraftforge.items.IItemHandler handler, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> items)
    Add all of the non-empty items in the given item handler to the given list.
    static net.minecraft.network.chat.Component
    combineComponents(List<net.minecraft.network.chat.Component> components)
     
    static boolean
    consumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.Item item)
    Convenience method, ported from 1.8.
    static boolean
    consumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.ItemStack stack)
    Convenience method, ported from 1.8.
    static String
    Takes in any integer, and converts it into a string with a additional postfix if needed.
    static String
    convertTicksToMinutesAndSeconds(long ticks, boolean fraction)
    Takes in the amount of ticks, and converts it into a time notation.
    static void
    copyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest)
     
    static void
    copyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest, int maxSlots)
     
    static net.minecraft.nbt.CompoundTag
    copyNBTWithout(net.minecraft.nbt.CompoundTag nbt, String skip)
     
    static net.minecraft.world.entity.Mob
    createDummyEntity(net.minecraft.world.entity.player.Player player)
    A little hack needed here; in 1.8 players were a subclass of EntityLiving and could be used as entities for pathfinding purposes.
    static double
    distBetween(double x1, double y1, double x2, double y2)
     
    static double
    distBetween(double x1, double y1, double z1, double x2, double y2, double z2)
     
    static double
    distBetween(net.minecraft.core.Vec3i pos, double x, double y, double z)
     
    static double
    distBetween(net.minecraft.core.Vec3i pos1, net.minecraft.core.Vec3i pos2)
     
    static double
    distBetweenSq(double x1, double y1, double x2, double y2)
     
    static double
    distBetweenSq(double x1, double y1, double z1, double x2, double y2, double z2)
     
    static double
    distBetweenSq(net.minecraft.core.BlockPos pos1, net.minecraft.core.BlockPos pos2)
     
    static double
    distBetweenSq(net.minecraft.core.Vec3i pos, double x, double y, double z)
     
    static boolean
    doesItemMatchFilter(net.minecraft.world.item.ItemStack filterStack, net.minecraft.world.item.ItemStack stack, boolean checkDurability, boolean checkNBT, boolean checkModSimilarity)
     
    static void
    dropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z)
     
    static void
    dropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
     
    static void
    dropItemOnGroundPrecisely(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z)
     
    static net.minecraft.network.chat.MutableComponent
    dyeColorDesc(int c)
     
    static boolean
    epsilonEquals(double d1, double d2)
     
    static boolean
    epsilonEquals(double d1, double d2, double maxDifference)
     
    static boolean
    epsilonEquals(float f1, float f2)
    Compare two floats which are tested for having (almost) the same value.
    static boolean
    epsilonEquals(float f1, float f2, float maxDifference)
     
    static boolean
    fillTankWithOrb(net.minecraftforge.fluids.capability.IFluidHandler handler, net.minecraft.world.entity.ExperienceOrb orb, net.minecraftforge.fluids.capability.IFluidHandler.FluidAction action)
    Try to transfer the XP from the given XP orb entity into the given fluid handler.
    static net.minecraft.network.chat.Component
    getBlockNameAt(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Get the name of the block at the given position
    static int
    getDyeColorAsRGB(net.minecraft.world.item.DyeColor dyeColor)
    Convert a DyeColor to packed RGB integer (top 8 bits - alpha - are 0)
    static String
    getPage(String urlString)
    Retrieve a web page from the given URL.
    static net.minecraft.server.level.ServerPlayer
     
    static net.minecraft.server.level.ServerPlayer
     
    static double
    getPlayerReachDistance(net.minecraft.world.entity.player.Player player)
     
    static Optional<net.minecraft.resources.ResourceLocation>
    getRegistryName(net.minecraft.world.entity.Entity entity)
     
    static Optional<net.minecraft.resources.ResourceLocation>
    getRegistryName(net.minecraft.world.item.Item item)
     
    static Optional<net.minecraft.resources.ResourceLocation>
    getRegistryName(net.minecraft.world.level.block.Block block)
     
    static Optional<net.minecraft.resources.ResourceLocation>
    getRegistryName(net.minecraft.world.level.material.Fluid fluid)
     
    static <T> Optional<net.minecraft.resources.ResourceLocation>
    getRegistryName(net.minecraftforge.registries.IForgeRegistry<T> registry, T object)
     
    static <T extends net.minecraft.world.level.block.entity.BlockEntity>
    Optional<T>
    getTileEntityAt(net.minecraft.world.level.BlockGetter w, net.minecraft.core.BlockPos pos, Class<T> cls)
     
    static net.minecraft.core.BlockPos
     
    static boolean
    isBlockLiquid(net.minecraft.world.level.block.Block block)
     
    static boolean
    isChunkLoaded(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos pos)
     
    static boolean
    Check if a given string encodes a valid integer (negative included).
    static boolean
    Check if a given string encodes a valid number (negative & decimal point included).
    static boolean
    isPlayerOp(net.minecraft.world.entity.player.Player player)
     
    static boolean
    isValidPos(net.minecraft.core.BlockPos pos)
     
    static Set<net.minecraft.tags.TagKey<net.minecraft.world.item.Item>>
    itemTags(net.minecraft.world.item.Item item)
     
    static net.minecraft.resources.ResourceLocation
    Get a resource location from the given string, defaulting to "pneumaticcraft:" namespace
    static String
    modDefaultedString(net.minecraft.resources.ResourceLocation rl)
    Stringify a resource location, omitting the namespace if it's "pneumaticcraft:"
    static String
    posToString(net.minecraft.core.BlockPos pos)
     
    static String
    roundNumberTo(double value, int decimals)
    Rounds numbers (round-nearest) to the given number of decimal places.
    static double
    roundNumberToDouble(double value, int decimals)
    Rounds numbers to the given number of decimal places.
    static List<String>
     
    static List<String>
    splitString(String text, int maxCharPerLine)
     
    static List<? extends net.minecraft.network.chat.Component>
     
    static List<? extends net.minecraft.network.chat.Component>
    splitStringComponent(String text, int maxCharPerLine)
     
    static List<net.minecraft.network.chat.Component>
    summariseItemStacks(List<net.minecraft.network.chat.Component> textList, List<net.minecraft.world.item.ItemStack> originalStacks)
    Sorts the stacks given alphabetically, combines them (so 2x64 will become 1x128), and adds the strings into the given string list.
    static List<net.minecraft.network.chat.Component>
    summariseItemStacks(List<net.minecraft.network.chat.Component> textList, List<net.minecraft.world.item.ItemStack> originalStacks, net.minecraft.network.chat.MutableComponent prefix)
    Sort the given array of itemstacks alphabetically by display name, then combine them (so e.g.
    static boolean
    tryPlaceBlock(net.minecraft.world.level.Level w, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player, net.minecraft.core.Direction face, net.minecraft.world.level.block.state.BlockState newState)
    Attempt to place a block in the world, respecting BlockEvent.PlaceEvent results.
    static net.minecraft.network.chat.MutableComponent
    xlate(String s, Object... args)
    Get a translation string for the given key.

    Methods inherited from class java.lang.Object

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

    • PneumaticCraftUtils

      public PneumaticCraftUtils()
  • Method Details

    • splitStringComponent

      public static List<? extends net.minecraft.network.chat.Component> splitStringComponent(String text)
    • splitStringComponent

      public static List<? extends net.minecraft.network.chat.Component> splitStringComponent(String text, int maxCharPerLine)
    • splitString

      public static List<String> splitString(String text, int maxCharPerLine)
    • splitString

      public static List<String> splitString(String text)
    • asStringComponent

      public static List<? extends net.minecraft.network.chat.Component> asStringComponent(List<String> l)
    • convertTicksToMinutesAndSeconds

      public static String convertTicksToMinutesAndSeconds(long ticks, boolean fraction)
      Takes in the amount of ticks, and converts it into a time notation. 40 ticks will become "2s", while 2400 will result in "2m".
      Parameters:
      ticks - number of ticks
      fraction - When true, 30 ticks will show as '1.5s' instead of '1s'.
      Returns:
      a formatted time
    • convertAmountToString

      public static String convertAmountToString(int amount)
      Takes in any integer, and converts it into a string with a additional postfix if needed. 23000 will convert into 23k for instance.
      Parameters:
      amount - an integer quantity
      Returns:
      a formatted string representation
    • roundNumberTo

      public static String roundNumberTo(double value, int decimals)
      Rounds numbers (round-nearest) to the given number of decimal places. E.g. 1.234 with decimal 1 will result in a string holding "1.2" but 1.26 with decimal 1 will result in "1.3"
      Parameters:
      value - a double-precision quantity
      decimals - number of digits to the right of the decimal point
      Returns:
      a formatted string representation
    • roundNumberToDouble

      public static double roundNumberToDouble(double value, int decimals)
      Rounds numbers to the given number of decimal places. E.g. 1.234 with decimal 1 will result in a string holding "1.2"
      Parameters:
      value - a double-precision quantity
      decimals - number of digits to the right of the decimal point
      Returns:
      the rounded value as a double-precision quantity
    • epsilonEquals

      public static boolean epsilonEquals(float f1, float f2)
      Compare two floats which are tested for having (almost) the same value. There are methods in MathHelper to do this but at least one of them is client-only.
    • epsilonEquals

      public static boolean epsilonEquals(float f1, float f2, float maxDifference)
    • epsilonEquals

      public static boolean epsilonEquals(double d1, double d2)
    • epsilonEquals

      public static boolean epsilonEquals(double d1, double d2, double maxDifference)
    • summariseItemStacks

      public static List<net.minecraft.network.chat.Component> summariseItemStacks(List<net.minecraft.network.chat.Component> textList, List<net.minecraft.world.item.ItemStack> originalStacks)
      Sorts the stacks given alphabetically, combines them (so 2x64 will become 1x128), and adds the strings into the given string list. This method is aware of inventory items implementing the IInventoryItem interface.
      Parameters:
      textList - string list to add information to
      originalStacks - array of item stacks to sort & combine
    • summariseItemStacks

      public static List<net.minecraft.network.chat.Component> summariseItemStacks(List<net.minecraft.network.chat.Component> textList, List<net.minecraft.world.item.ItemStack> originalStacks, net.minecraft.network.chat.MutableComponent prefix)
      Sort the given array of itemstacks alphabetically by display name, then combine them (so e.g. 2x64 becomes 1x128), and add the display name to the given text component list. This method is aware of inventory items implementing the IInventoryItem interface.
      Parameters:
      textList - text component list to add information to
      originalStacks - array of item stacks to sort & combine
      prefix - prefix string to prepend to each line of output
    • getPage

      public static String getPage(String urlString) throws IOException
      Retrieve a web page from the given URL.
      Parameters:
      urlString - the URL
      Returns:
      the web page
      Throws:
      IOException - if there are any problems
    • distBetween

      public static double distBetween(double x1, double y1, double z1, double x2, double y2, double z2)
    • distBetweenSq

      public static double distBetweenSq(double x1, double y1, double z1, double x2, double y2, double z2)
    • distBetweenSq

      public static double distBetweenSq(net.minecraft.core.Vec3i pos, double x, double y, double z)
    • distBetweenSq

      public static double distBetweenSq(net.minecraft.core.BlockPos pos1, net.minecraft.core.BlockPos pos2)
    • distBetween

      public static double distBetween(double x1, double y1, double x2, double y2)
    • distBetweenSq

      public static double distBetweenSq(double x1, double y1, double x2, double y2)
    • distBetween

      public static double distBetween(net.minecraft.core.Vec3i pos, double x, double y, double z)
    • distBetween

      public static double distBetween(net.minecraft.core.Vec3i pos1, net.minecraft.core.Vec3i pos2)
    • doesItemMatchFilter

      public static boolean doesItemMatchFilter(@Nonnull net.minecraft.world.item.ItemStack filterStack, @Nonnull net.minecraft.world.item.ItemStack stack, boolean checkDurability, boolean checkNBT, boolean checkModSimilarity)
    • isBlockLiquid

      public static boolean isBlockLiquid(net.minecraft.world.level.block.Block block)
    • dropItemOnGround

      public static void dropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    • dropItemOnGround

      public static void dropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z)
    • dropItemOnGroundPrecisely

      public static void dropItemOnGroundPrecisely(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z)
    • getPlayerFromId

      public static net.minecraft.server.level.ServerPlayer getPlayerFromId(UUID uuid)
    • getPlayerFromName

      public static net.minecraft.server.level.ServerPlayer getPlayerFromName(String name)
    • isPlayerOp

      public static boolean isPlayerOp(net.minecraft.world.entity.player.Player player)
    • tryPlaceBlock

      public static boolean tryPlaceBlock(net.minecraft.world.level.Level w, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player, net.minecraft.core.Direction face, net.minecraft.world.level.block.state.BlockState newState)
      Attempt to place a block in the world, respecting BlockEvent.PlaceEvent results.
      Parameters:
      w - the world
      pos - the position in the world
      player - the player who is placing the block
      face - the face against which the block is placed
      newState - the blockstate to change the position to
      Returns:
      true if the block could be placed, false otherwise
    • createDummyEntity

      public static net.minecraft.world.entity.Mob createDummyEntity(net.minecraft.world.entity.player.Player player)
      A little hack needed here; in 1.8 players were a subclass of EntityLiving and could be used as entities for pathfinding purposes. But now they extend EntityLivingBase, and pathfinder methods only work for subclasses of EntityLiving. So create a temporary living entity at the player's location and pathfind from that.
      Parameters:
      player - the player to mimic
      Returns:
      a dummy player-sized living entity
    • consumeInventoryItem

      public static boolean consumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.Item item)
      Convenience method, ported from 1.8. Consume one item from the player's inventory.
      Parameters:
      inv - player's inventory
      item - item to consume
      Returns:
      true if an item was consumed
    • collectNonEmptyItems

      public static void collectNonEmptyItems(net.minecraftforge.items.IItemHandler handler, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> items)
      Add all of the non-empty items in the given item handler to the given list.
      Parameters:
      handler - the item handler
      items - the list
    • consumeInventoryItem

      public static boolean consumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.ItemStack stack)
      Convenience method, ported from 1.8. Try to consume one item from the player's inventory.
      Parameters:
      inv - player's inventory
      stack - item to consume
      Returns:
      true if an item was consumed
    • xlate

      public static net.minecraft.network.chat.MutableComponent xlate(String s, Object... args)
      Get a translation string for the given key. This has support for The One Probe which runs server-side.
      Parameters:
      s - the translation key
      Returns:
      the translated string (if called server-side, a string which The One Probe will handle client-side)
    • dyeColorDesc

      public static net.minecraft.network.chat.MutableComponent dyeColorDesc(int c)
    • copyItemHandler

      public static void copyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest, int maxSlots)
    • copyItemHandler

      public static void copyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest)
    • posToString

      public static String posToString(@Nullable net.minecraft.core.BlockPos pos)
    • isValidPos

      public static boolean isValidPos(@Nullable net.minecraft.core.BlockPos pos)
    • invalidPos

      public static net.minecraft.core.BlockPos invalidPos()
    • getTileEntityAt

      public static <T extends net.minecraft.world.level.block.entity.BlockEntity> Optional<T> getTileEntityAt(net.minecraft.world.level.BlockGetter w, net.minecraft.core.BlockPos pos, Class<T> cls)
    • fillTankWithOrb

      public static boolean fillTankWithOrb(net.minecraftforge.fluids.capability.IFluidHandler handler, net.minecraft.world.entity.ExperienceOrb orb, net.minecraftforge.fluids.capability.IFluidHandler.FluidAction action)
      Try to transfer the XP from the given XP orb entity into the given fluid handler. If the handler has enough room to store only part of the orb's XP, it will reduce the orb's XP by the amount taken (assuming the action is execute). Does not remove the entity; the caller should do that iff this returns true.
      Parameters:
      handler - the fluid handler
      orb - the XP orb
      action - whether to simulate the action
      Returns:
      true if the XP orb was (or could be) fully absorbed into the fluid handler
    • getPlayerReachDistance

      public static double getPlayerReachDistance(net.minecraft.world.entity.player.Player player)
    • canPlayerReach

      public static boolean canPlayerReach(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos)
    • isInteger

      public static boolean isInteger(String str)
      Check if a given string encodes a valid integer (negative included). Also intended to work for partial strings, so useful for textfield validation.
      Parameters:
      str - the string to test
      Returns:
      true if the string encodes an integer (i.e. Integer.parseInt(str) won't throw an exception)
    • isNumber

      public static boolean isNumber(String str)
      Check if a given string encodes a valid number (negative & decimal point included). Also intended to work for partial strings, so useful for textfield validation.
      Parameters:
      str - the string to test
      Returns:
      true if the string encodes a number (i.e. NumberUtils.createNumber(str) won't throw an exception)
    • modDefaultedRL

      public static net.minecraft.resources.ResourceLocation modDefaultedRL(String str)
      Get a resource location from the given string, defaulting to "pneumaticcraft:" namespace
      Parameters:
      str - a string
      Returns:
      a resource location
    • modDefaultedString

      public static String modDefaultedString(net.minecraft.resources.ResourceLocation rl)
      Stringify a resource location, omitting the namespace if it's "pneumaticcraft:"
      Parameters:
      rl - a resource location
      Returns:
      stringified resource location
    • getDyeColorAsRGB

      public static int getDyeColorAsRGB(net.minecraft.world.item.DyeColor dyeColor)
      Convert a DyeColor to packed RGB integer (top 8 bits - alpha - are 0)
      Parameters:
      dyeColor - the dye color
      Returns:
      packed RGB integer
    • getBlockNameAt

      public static net.minecraft.network.chat.Component getBlockNameAt(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Get the name of the block at the given position
      Parameters:
      level - the level
      pos - the blockpos
      Returns:
      the block name, empty if the given position isn't currently loaded
    • copyNBTWithout

      public static net.minecraft.nbt.CompoundTag copyNBTWithout(@Nonnull net.minecraft.nbt.CompoundTag nbt, @Nonnull String skip)
    • itemTags

      public static Set<net.minecraft.tags.TagKey<net.minecraft.world.item.Item>> itemTags(net.minecraft.world.item.Item item)
    • getRegistryName

      public static Optional<net.minecraft.resources.ResourceLocation> getRegistryName(net.minecraft.world.item.Item item)
    • getRegistryName

      public static Optional<net.minecraft.resources.ResourceLocation> getRegistryName(net.minecraft.world.level.block.Block block)
    • getRegistryName

      public static Optional<net.minecraft.resources.ResourceLocation> getRegistryName(net.minecraft.world.level.material.Fluid fluid)
    • getRegistryName

      public static Optional<net.minecraft.resources.ResourceLocation> getRegistryName(net.minecraft.world.entity.Entity entity)
    • getRegistryName

      public static <T> Optional<net.minecraft.resources.ResourceLocation> getRegistryName(net.minecraftforge.registries.IForgeRegistry<T> registry, T object)
    • isChunkLoaded

      public static boolean isChunkLoaded(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos pos)
    • average

      public static double average(long[] pValues)
    • combineComponents

      public static net.minecraft.network.chat.Component combineComponents(List<net.minecraft.network.chat.Component> components)