use of org.terasology.utilities.random.Random in project Terasology by MovingBlocks.
the class TextureAssetResolverTest method testColorTextures.
@Test
public void testColorTextures() {
Random r = new FastRandom(123456);
for (int i = 0; i < 10; i++) {
int rgba = r.nextInt();
Color red = new Color(rgba);
ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red);
String simpleString = textureUriForColor.toString();
Optional<Texture> tex = Assets.getTexture(simpleString);
assertTrue(tex.isPresent());
ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0];
int firstPixel = dataBuffer.asIntBuffer().get(0);
Assert.assertEquals(rgba, firstPixel);
}
}
use of org.terasology.utilities.random.Random in project Terasology by MovingBlocks.
the class TextureDataFactory method createWhiteNoiseTexture.
public static TextureData createWhiteNoiseTexture(int size, long seed, int min, int max) {
int width = size;
int height = size;
ByteBuffer data = ByteBuffer.allocateDirect(4 * width * height);
Random rng = new FastRandom(seed);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255));
data.put((byte) 255);
}
}
// The buffer must be reset back to the initial position before passing it onward.
data.rewind();
return new TextureData(width, height, new ByteBuffer[] { data }, WrapMode.REPEAT, FilterMode.NEAREST);
}
use of org.terasology.utilities.random.Random in project Terasology by MovingBlocks.
the class PlayerConfig method defaultPlayerColor.
/**
* Randomly generates a default color for the player via a random int generator using FastRandom object.
*
* @return a Color object with the player's default color.
*/
private Color defaultPlayerColor() {
Random rng = new FastRandom();
List<Color> colors = CieCamColors.L65C65;
return colors.get(rng.nextInt(colors.size()));
}
use of org.terasology.utilities.random.Random in project Terasology by MovingBlocks.
the class TreeRasterizer method generateChunk.
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
TreeFacet facet = chunkRegion.getFacet(TreeFacet.class);
for (Map.Entry<BaseVector3i, TreeGenerator> entry : facet.getRelativeEntries().entrySet()) {
BaseVector3i pos = entry.getKey();
TreeGenerator treeGen = entry.getValue();
int seed = relativeToWorld(facet, pos).hashCode();
Random random = new FastRandom(seed);
treeGen.generate(blockManager, chunk, random, pos.x(), pos.y(), pos.z());
}
}
use of org.terasology.utilities.random.Random in project Terasology by MovingBlocks.
the class TreeTests method computeAABB.
private Vector3i computeAABB(TreeGenerator treeGen, long seed) {
Vector3i pos = new Vector3i(ChunkConstants.SIZE_X / 2, 0, ChunkConstants.SIZE_Z / 2);
final Vector3i min = new Vector3i(pos);
final Vector3i max = new Vector3i(pos);
Rect2i chunks = Rect2i.createFromMinAndMax(-1, -1, 1, 1);
for (BaseVector2i chunkPos : chunks.contents()) {
Chunk chunk = new ChunkImpl(chunkPos.getX(), 0, chunkPos.getY(), blockManager, biomeManager) {
@Override
public Block setBlock(int x, int y, int z, Block block) {
Vector3i world = chunkToWorldPosition(x, y, z);
minimize(min, world);
maximize(max, world);
return null;
}
};
Random random = new MersenneRandom(seed);
BlockManager blockManagerLocal = CoreRegistry.get(BlockManager.class);
Vector3i relPos = chunk.chunkToWorldPosition(0, 0, 0).sub(pos).invert();
treeGen.generate(blockManagerLocal, chunk, random, relPos.x, relPos.y, relPos.z);
}
Vector3i ext = new Vector3i(max).sub(min);
return ext;
}
Aggregations