Class PneumaticCraftUtils
java.lang.Object
me.desht.pneumaticcraft.common.util.PneumaticCraftUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<? extends net.minecraft.network.chat.Component>static booleancanPlayerReach(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos) static voidcollectNonEmptyItems(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 booleanconsumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.Item item) Convenience method, ported from 1.8.static booleanconsumeInventoryItem(net.minecraft.world.entity.player.Inventory inv, net.minecraft.world.item.ItemStack stack) Convenience method, ported from 1.8.static StringconvertAmountToString(int amount) Takes in any integer, and converts it into a string with a additional postfix if needed.static StringconvertTicksToMinutesAndSeconds(long ticks, boolean fraction) Takes in the amount of ticks, and converts it into a time notation.static voidcopyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest) static voidcopyItemHandler(net.minecraftforge.items.IItemHandler source, net.minecraftforge.items.ItemStackHandler dest, int maxSlots) static net.minecraft.nbt.CompoundTagcopyNBTWithout(net.minecraft.nbt.CompoundTag nbt, String skip) static net.minecraft.world.entity.MobcreateDummyEntity(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 doubledistBetween(double x1, double y1, double x2, double y2) static doubledistBetween(double x1, double y1, double z1, double x2, double y2, double z2) static doubledistBetween(net.minecraft.core.Vec3i pos, double x, double y, double z) static doubledistBetween(net.minecraft.core.Vec3i pos1, net.minecraft.core.Vec3i pos2) static doubledistBetweenSq(double x1, double y1, double x2, double y2) static doubledistBetweenSq(double x1, double y1, double z1, double x2, double y2, double z2) static doubledistBetweenSq(net.minecraft.core.BlockPos pos1, net.minecraft.core.BlockPos pos2) static doubledistBetweenSq(net.minecraft.core.Vec3i pos, double x, double y, double z) static booleandoesItemMatchFilter(net.minecraft.world.item.ItemStack filterStack, net.minecraft.world.item.ItemStack stack, boolean checkDurability, boolean checkNBT, boolean checkModSimilarity) static voiddropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z) static voiddropItemOnGround(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) static voiddropItemOnGroundPrecisely(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level world, double x, double y, double z) static net.minecraft.network.chat.ComponentdyeColorDesc(int c) static booleanepsilonEquals(double d1, double d2) static booleanepsilonEquals(double d1, double d2, double maxDifference) static booleanepsilonEquals(float f1, float f2) Compare two floats which are tested for having (almost) the same value.static booleanepsilonEquals(float f1, float f2, float maxDifference) static booleanfillTankWithOrb(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.ComponentgetBlockNameAt(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Get the name of the block at the given positionstatic intgetDyeColorAsRGB(net.minecraft.world.item.DyeColor dyeColor) Convert a DyeColor to packed RGB integer (top 8 bits - alpha - are 0)static StringRetrieve a web page from the given URL.static net.minecraft.server.level.ServerPlayergetPlayerFromId(UUID uuid) static net.minecraft.server.level.ServerPlayergetPlayerFromName(String name) static doublegetPlayerReachDistance(net.minecraft.world.entity.player.Player player) 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.BlockPosstatic booleanisBlockLiquid(net.minecraft.world.level.block.Block block) static booleanCheck if a given string encodes a valid integer (negative included).static booleanCheck if a given string encodes a valid number (negative & decimal point included).static booleanisPlayerOp(net.minecraft.world.entity.player.Player player) static booleanisValidPos(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.ResourceLocationmodDefaultedRL(String str) Get a resource location from the given string, defaulting to "pneumaticcraft:" namespacestatic StringmodDefaultedString(net.minecraft.resources.ResourceLocation rl) Stringify a resource location, omitting the namespace if it's "pneumaticcraft:"static StringposToString(net.minecraft.core.BlockPos pos) static StringroundNumberTo(double value, int decimals) Rounds numbers (round-nearest) to the given number of decimal places.static doubleroundNumberToDouble(double value, int decimals) Rounds numbers to the given number of decimal places.splitString(String text) splitString(String text, int maxCharPerLine) static List<? extends net.minecraft.network.chat.Component>splitStringComponent(String text) 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, 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, net.minecraft.world.item.ItemStack[] originalStacks, String prefix) Sort the given array of itemstacks alphabetically by display name, then combine them (so e.g.static booleantryPlaceBlock(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.TranslatableComponentGet a translation string for the given key.
-
Constructor Details
-
PneumaticCraftUtils
public PneumaticCraftUtils()
-
-
Method Details
-
splitStringComponent
-
splitStringComponent
-
splitString
-
splitString
-
asStringComponent
-
convertTicksToMinutesAndSeconds
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 ticksfraction- When true, 30 ticks will show as '1.5s' instead of '1s'.- Returns:
- a formatted time
-
convertAmountToString
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
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 quantitydecimals- 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 quantitydecimals- 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, 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 theIInventoryIteminterface.- Parameters:
textList- string list to add information tooriginalStacks- array of item stacks to sort & combine
-
summariseItemStacks
public static List<net.minecraft.network.chat.Component> summariseItemStacks(List<net.minecraft.network.chat.Component> textList, net.minecraft.world.item.ItemStack[] originalStacks, String 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 theIInventoryIteminterface.- Parameters:
textList- text component list to add information tooriginalStacks- array of item stacks to sort & combineprefix- prefix string to prepend to each line of output
-
getPage
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
-
getPlayerFromName
-
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 worldpos- the position in the worldplayer- the player who is placing the blockface- the face against which the block is placednewState- 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 inventoryitem- 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 handleritems- 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 inventorystack- item to consume- Returns:
- true if an item was consumed
-
xlate
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.Component 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
-
isValidPos
public static boolean isValidPos(@Nullable net.minecraft.core.BlockPos pos) -
invalidPos
public static net.minecraft.core.BlockPos invalidPos() -
getTileEntityAt
-
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 handlerorb- the XP orbaction- whether or not 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
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
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
Get a resource location from the given string, defaulting to "pneumaticcraft:" namespace- Parameters:
str- a string- Returns:
- a resource location
-
modDefaultedString
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 levelpos- 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)
-