Search in sources :

Example 1 with TIntList

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());
}
Also used : IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) TIntList(gnu.trove.list.TIntList) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with TIntList

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);
        }
    }
}
Also used : IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WeightedItemCollection(ivorius.reccomplex.world.storage.loot.WeightedItemCollection) TIntList(gnu.trove.list.TIntList) GuiEditItemStack(ivorius.reccomplex.gui.inventorygen.GuiEditItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TIntList

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;
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) TIntList(gnu.trove.list.TIntList)

Example 4 with TIntList

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());
}
Also used : TFloatIterator(gnu.trove.iterator.TFloatIterator) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 5 with TIntList

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);
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) TIntArrayList(gnu.trove.list.array.TIntArrayList) BoneWeight(org.terasology.rendering.assets.skeletalmesh.BoneWeight) SkeletalMeshDataBuilder(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder) Vector2f(org.terasology.math.geom.Vector2f) Bone(org.terasology.rendering.assets.skeletalmesh.Bone) TIntList(gnu.trove.list.TIntList)

Aggregations

TIntList (gnu.trove.list.TIntList)35 TIntArrayList (gnu.trove.list.array.TIntArrayList)21 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 List (java.util.List)5 TFloatList (gnu.trove.list.TFloatList)4 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vector2f (org.terasology.math.geom.Vector2f)4 Vector3i (org.terasology.math.geom.Vector3i)4 TIntIterator (gnu.trove.iterator.TIntIterator)3 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)3 InputStream (java.io.InputStream)3 Arrays (java.util.Arrays)3 Vector3f (org.terasology.math.geom.Vector3f)3 Lists (com.google.common.collect.Lists)2 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)2 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)2 IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)2 Consumer (java.util.function.Consumer)2