use of gnu.trove.list.TIntList in project RecurrentComplex by Ivorforce.
the class RayAverageMatcher method getAverageGroundLevel.
// From StructureVillagePieces
public static int getAverageGroundLevel(boolean up, int y, StructureBoundingBox boundingBox, Predicate<BlockPos> predicate, int wHeight, double samples, Random random) {
TIntList list = new TIntArrayList(boundingBox.getXSize() * boundingBox.getZSize());
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
for (int k = boundingBox.minZ; k <= boundingBox.maxZ; ++k) {
for (int l = boundingBox.minX; l <= boundingBox.maxX; ++l) {
// Added
if (samples >= 1 || random.nextDouble() < samples) {
pos.setPos(l, y, k);
// if (structurebb.isVecInside(pos))
{
list.add(findFirstBlock(pos, predicate, up, wHeight).getY());
}
}
}
}
if (list.isEmpty())
return -1;
else
return averageIgnoringErrors(list.toArray());
}
use of gnu.trove.list.TIntList in project RecurrentComplex by Ivorforce.
the class ItemInventoryGenMultiTag method generateInInventory.
@Override
public void generateInInventory(WorldServer server, IInventory inventory, Random random, ItemStack stack, int fromSlot) {
WeightedItemCollection weightedItemCollection = inventoryGenerator(stack);
inventory.setInventorySlotContents(fromSlot, ItemStack.EMPTY);
if (weightedItemCollection != null) {
IntegerRange range = getGenerationCount(stack);
int amount = range.getMin() < range.getMax() ? random.nextInt(range.getMax() - range.getMin() + 1) + range.getMin() : 0;
TIntList emptySlots = emptySlots(inventory);
for (int i = 0; i < amount; i++) {
int slot = emptySlots.isEmpty() ? random.nextInt(inventory.getSizeInventory()) : emptySlots.removeAt(random.nextInt(emptySlots.size()));
ItemStack generated = weightedItemCollection.getRandomItemStack(server, random);
if (generated != null)
inventory.setInventorySlotContents(slot, generated);
}
}
}
use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.
the class RowLayout method onDraw.
/**
* Draws the widgets contained in this layout's widget list,
* according to the widths calculated in {@link #calcWidths(Canvas)}.
* This is called every frame.
*
* @param canvas The {@link Canvas} on which this {@code RowLayout} is drawn
*/
@Override
public void onDraw(Canvas canvas) {
TIntList widths = calcWidths(canvas);
if (!contents.isEmpty()) {
int xOffset = 0;
for (int i = 0; i < contents.size(); ++i) {
int itemWidth = widths.get(i);
Rect2i region = Rect2i.createFromMinAndSize(xOffset, 0, itemWidth, canvas.size().y);
canvas.drawWidget(contents.get(i), region);
xOffset += itemWidth;
xOffset += horizontalSpacing;
}
}
}
use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.
the class OpenGLMesh method buildMesh.
private void buildMesh(MeshData newData) {
this.data = newData;
List<TFloatIterator> parts = Lists.newArrayList();
TIntList partSizes = new TIntArrayList();
int vertexCount = newData.getVertices().size() / VERTEX_SIZE;
int vertexSize = VERTEX_SIZE;
parts.add(newData.getVertices().iterator());
partSizes.add(VERTEX_SIZE);
if (newData.getTexCoord0() != null && newData.getTexCoord0().size() / TEX_COORD_0_SIZE == vertexCount) {
parts.add(newData.getTexCoord0().iterator());
partSizes.add(TEX_COORD_0_SIZE);
texCoord0Offset = vertexSize * FLOAT_SIZE;
vertexSize += TEX_COORD_0_SIZE;
hasTexCoord0 = true;
}
if (newData.getTexCoord1() != null && newData.getTexCoord1().size() / TEX_COORD_1_SIZE == vertexCount) {
parts.add(newData.getTexCoord1().iterator());
partSizes.add(TEX_COORD_1_SIZE);
texCoord1Offset = vertexSize * FLOAT_SIZE;
vertexSize += TEX_COORD_1_SIZE;
hasTexCoord1 = true;
}
if (newData.getNormals() != null && newData.getNormals().size() / NORMAL_SIZE == vertexCount) {
parts.add(newData.getNormals().iterator());
partSizes.add(NORMAL_SIZE);
normalOffset = vertexSize * FLOAT_SIZE;
vertexSize += NORMAL_SIZE;
hasNormal = true;
}
if (newData.getColors() != null && newData.getColors().size() / COLOR_SIZE == vertexCount) {
parts.add(newData.getColors().iterator());
partSizes.add(COLOR_SIZE);
colorOffset = vertexSize * FLOAT_SIZE;
vertexSize += COLOR_SIZE;
hasColor = true;
}
stride = vertexSize * FLOAT_SIZE;
indexCount = newData.getIndices().size();
createVertexBuffer(parts, partSizes, vertexCount, vertexSize);
createIndexBuffer(newData.getIndices());
aabb = AABB.createEncompasing(newData.getVertices());
}
use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.
the class MD5SkeletonLoader method load.
@Override
public SkeletalMeshData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
try (InputStream stream = inputs.get(0).openStream()) {
MD5 md5 = parse(stream);
SkeletalMeshDataBuilder skeletonBuilder = new SkeletalMeshDataBuilder();
List<Bone> bones = Lists.newArrayListWithCapacity(md5.numJoints);
for (int i = 0; i < md5.numJoints; ++i) {
MD5Joint joint = md5.joints[i];
Bone bone = new Bone(i, joint.name, joint.position, joint.orientation);
bones.add(bone);
if (joint.parent != -1) {
bones.get(joint.parent).addChild(bone);
}
skeletonBuilder.addBone(bone);
}
if (md5.meshes.length > 0) {
// TODO: Support multiple mesh somehow?
MD5Mesh mesh = md5.meshes[0];
for (MD5Weight weight : mesh.weightList) {
skeletonBuilder.addWeight(new BoneWeight(weight.position, weight.bias, weight.jointIndex));
}
List<Vector2f> uvs = Lists.newArrayList();
TIntList vertexStartWeight = new TIntArrayList(mesh.numVertices);
TIntList vertexWeightCount = new TIntArrayList(mesh.numVertices);
for (MD5Vertex vert : mesh.vertexList) {
uvs.add(vert.uv);
vertexStartWeight.add(vert.startWeight);
vertexWeightCount.add(vert.countWeight);
}
skeletonBuilder.setVertexWeights(vertexStartWeight, vertexWeightCount);
skeletonBuilder.setUvs(uvs);
TIntList indices = new TIntArrayList(mesh.indexList.length);
for (int i = 0; i < mesh.numTriangles; ++i) {
indices.add(mesh.indexList[i * 3]);
indices.add(mesh.indexList[i * 3 + 2]);
indices.add(mesh.indexList[i * 3 + 1]);
}
skeletonBuilder.setIndices(indices);
}
return skeletonBuilder.build();
} catch (NumberFormatException e) {
throw new IOException("Error parsing " + inputs.get(0).getFilename(), e);
}
}
Aggregations