use of org.terasology.utilities.random.FastRandom in project Terasology by MovingBlocks.
the class WhiteNoiseTest method testDistribution.
@Test
public void testDistribution() {
FastRandom rng = new FastRandom(0xBEEF);
WhiteNoise noiseGen = new WhiteNoise(0xDEADC0DE);
int count = 100000;
int bucketCount = 20;
int[] buckets = new int[bucketCount];
for (int i = 0; i < count; i++) {
float posX = rng.nextFloat() * 100f;
float posY = rng.nextFloat() * 100f;
float posZ = rng.nextFloat() * 100f;
float noise = 0.5f + 0.5f * noiseGen.noise(posX, posY, posZ);
int idx = (int) (noise * bucketCount);
if (idx == bucketCount) {
idx = bucketCount - 1;
}
buckets[idx]++;
}
float avg = count / bucketCount;
for (int i = 0; i < bucketCount; i++) {
float val = Math.abs((buckets[i] - avg) / avg);
// less than 5% deviation from the expected average
Assert.assertTrue(val < 0.05);
}
}
use of org.terasology.utilities.random.FastRandom in project Terasology by MovingBlocks.
the class BlockDropGrammarSystem method initialise.
@Override
public void initialise() {
blockItemFactory = new BlockItemFactory(entityManager);
random = new FastRandom();
}
use of org.terasology.utilities.random.FastRandom 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.FastRandom in project Terasology by MovingBlocks.
the class BlockInventorySystem method dropContentsOfInventory.
@ReceiveEvent(components = { InventoryComponent.class, DropBlockInventoryComponent.class, LocationComponent.class })
public void dropContentsOfInventory(DoDestroyEvent event, EntityRef entity) {
Vector3f position = entity.getComponent(LocationComponent.class).getWorldPosition();
FastRandom random = new FastRandom();
int slotCount = InventoryUtils.getSlotCount(entity);
for (int i = 0; i < slotCount; i++) {
EntityRef itemInSlot = InventoryUtils.getItemAt(entity, i);
if (itemInSlot.exists()) {
inventoryManager.removeItem(entity, entity, itemInSlot, false);
itemInSlot.send(new DropItemEvent(position));
itemInSlot.send(new ImpulseEvent(random.nextVector3f(30.0f)));
}
}
}
Aggregations