public final class Util
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static com.google.gson.Gson |
GSON
A global instance of google gson' gson that can be used to serialize and
deserialize json objects.
|
static com.google.gson.JsonParser |
JSON_PARSER
A global instance of google gson's json parser that can be used to parse
jsons into easily modifyable and queryable json objects.
|
static java.util.Random |
RANDOM
A global random with a randomized seed that can be used for operations
that are not based on the world seed.
|
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static int |
ceil(double value)
This is a faster implementation of
Math.ceil(double), in that it
simply typecasts the given value and then adjusts it accordingly. |
static double |
clamp(double num,
double min,
double max)
Clamps a value between a minimum and a maximum value.
|
static int |
clamp(int num,
int min,
int max)
Clamps a value between a minimum and a maximum value.
|
static boolean |
createAndOpen(java.io.File file)
Creates a file if it doesn't exist and then opens it with the operating
system's default file opening software.
|
static Entity |
createEntity(ResourceName name,
IWorld world)
Creates an entity from its entity registry name and with the given
world.
|
static void |
deleteFolder(java.io.File file)
A helper method to recursively delete a folder and all of its contents.
|
static double |
distance(double x1,
double y1,
double x2,
double y2)
Returns the absolute distance between two points using the Pythagorean
theorem.
|
static double |
distanceSq(double x1,
double y1,
double x2,
double y2)
Returns the squared distance between two points using the Pythagorean
theorem.
|
static int |
floor(double value)
This is a faster implementation of
Math.floor(double), in that it
simply typecasts the given value and then adjusts it accordingly. |
static long |
getTimeMillis()
Gets the system time in milliseconds.
|
static boolean |
isResourceName(java.lang.String s)
Utility method to figure out if a string is a resource name, meaning if
it contains a
Constants.RESOURCE_SEPARATOR that is not at the
beginning or end of the string. |
static double |
lerp(double pos1,
double pos2,
double factor) |
static java.util.List<java.lang.Integer> |
makeIntList(int start,
int end)
Creates a list of integers starting at the first number and ending at the
second number.
|
static boolean |
openWebsite(java.lang.String domain)
Opens a website in the operating system's default browser.
|
static long |
scrambleSeed(int i)
Scrambles a single value into a seed that can be used for world gen.
|
static long |
scrambleSeed(int x,
int y)
Scrambles an x and a y value together into a seed that can be used for
world gen.
|
static long |
scrambleSeed(int x,
int y,
long seed)
Scrambles an x and a y value into a seed based on a different seed.
|
static long |
scrambleSeed(int i,
long seed)
Scrambles a value into a seed based on a different seed.
|
static long |
shiftScramble(long l)
Scrambles a seed in a predictable, always-equal, but seemingly random
way, making the output seem like a completely different number.
|
static void |
sleepSafe(long time)
Causes the current thread to sleep by the given amount of milliseconds,
ignoring any interruptions that might be thrown.
|
static int |
toGridPos(double worldPos)
Converts a given position in the world to a chunk grid position.
|
static int |
toWorldPos(int gridPos)
Converts a given position of a chunk into its world position.
|
public static final java.util.Random RANDOM
IChunkOrWorld.getSeed() should always
be used. For that, there are several utility methods at the bottom of
this class to help modify the world seed in a predictable pattern.IChunkOrWorld.getSeed(),
scrambleSeed(int, long)public static final com.google.gson.Gson GSON
public static final com.google.gson.JsonParser JSON_PARSER
public static double distance(double x1,
double y1,
double x2,
double y2)
distanceSq(double, double, double, double).x1 - The first point's xy1 - The first point's yx2 - The second point's xy2 - The second point's ydistanceSq(double, double, double, double)public static double distanceSq(double x1,
double y1,
double x2,
double y2)
x1 - The first point's xy1 - The first point's yx2 - The second point's xy2 - The second point's ydistance(double, double, double, double)public static double lerp(double pos1,
double pos2,
double factor)
public static double clamp(double num,
double min,
double max)
num - The number to clampmin - The minimummax - The maximumclamp(int, int, int)public static int clamp(int num,
int min,
int max)
num - The number to clampmin - The minimummax - The maximumclamp(double, double, double)public static int floor(double value)
Math.floor(double), in that it
simply typecasts the given value and then adjusts it accordingly. This
results in the integer that is closest to the given value (in the
direction of 0) will be returned.value - The value to floorpublic static int ceil(double value)
Math.ceil(double), in that it
simply typecasts the given value and then adjusts it accordingly. This
results in the integer that is closest to the given value (in the
direction of negative infinity, if the input is negative, or positive
infinity otherwise) will be returned.value - The value to ceilingpublic static int toGridPos(double worldPos)
worldPos - The world positionIChunk.getGridX(),
IChunk.getGridY()public static int toWorldPos(int gridPos)
gridPos - The chunk grid positionpublic static void deleteFolder(java.io.File file)
File.delete() will fail if it is a folder that
contains other files, so this method clears all of the files in a folder
first before deleting it.file - The folder to deletepublic static Entity createEntity(ResourceName name, IWorld world)
name - The registry name of the entityworld - The world that the entity should be inRegistries.ENTITY_REGISTRYpublic static long getTimeMillis()
System.currentTimeMillis() to a more sensible amount of
characters.public static boolean createAndOpen(java.io.File file)
Desktop.open(File) would cause an exception
if the folder does not existfile - The file to openpublic static boolean openWebsite(java.lang.String domain)
Desktop.browse(URI) can throw an exception.domain - The domain to openpublic static long shiftScramble(long l)
scrambleSeed(int, long).l - The long to scrambleIChunkOrWorld.getSeed(),
scrambleSeed(int, long)public static long scrambleSeed(int x,
int y)
x - The x valuey - The y valuepublic static long scrambleSeed(int i)
i - The valuepublic static long scrambleSeed(int x,
int y,
long seed)
x - The x valuey - The y valueseed - The original seedpublic static long scrambleSeed(int i,
long seed)
i - The valueseed - The original seedpublic static java.util.List<java.lang.Integer> makeIntList(int start,
int end)
IFilteredInventory instances with a lot of slots.start - The first number (inclusive)end - The second number (exclusive)IFilteredInventory.getInputSlots(ItemInstance, Direction),
IFilteredInventory.getOutputSlots(Direction)public static boolean isResourceName(java.lang.String s)
Constants.RESOURCE_SEPARATOR that is not at the
beginning or end of the string.s - The string to checkpublic static void sleepSafe(long time)
time - The time to sleep for