Skip to content

Utils

Bento Util has a Utils class that currently only contains tryParse and stringify methods I frequently use in other Bento modules. Maybe this can be useful to you too!

If you need tryParse methods for ints, longs, floats, or doubles, you can use the com.google.common.primitives package.

Examples:

// Numbers
Byte byteVal = Utils.tryParseByte("127");
Short shortVal = Utils.tryParseShort("32767");
BigInteger bigInteger = Utils.tryParseBigInteger("340282366920938463463374607431768211455");
BigDecimal bigDecimal = Utils.tryParseBigDecimal("3.14159265358979323846264338327950288419716939937510");
// Vectors
Vec2f vec2f = Utils.tryParseVec2f("0.5, -1.5");
Vec3i vec3i = Utils.tryParseVec3i("-5, 0, 5");
Vec3d vec3d = Utils.tryParseVec3d("-0.003, 54.4, 30");
BlockPos blockPos = Utils.tryParseBlockPos("-10, 0, 10");
ChunkPos chunkPos = Utils.tryParseChunkPos("42, 0");

There is a collection of stringify methods that work on the following types:

  • Item
  • Block
  • EntityType
  • Vec2f
  • Vec3i
  • Vec3d
  • BlockPos
  • ChunkPos

Items, blocks, and entities are formatted as identifier strings, and if the namespace is minecraft it is excluded. All vectors are formatted as either x, y, z or x, y.

Example:

Utils.stringify(Items.DIAMOND); // "diamond"