Search in sources :

Example 21 with TIntList

use of gnu.trove.list.TIntList in project RecurrentComplex by Ivorforce.

the class ItemLootGenMultiTag method generateInInventory.

@Override
public void generateInInventory(WorldServer server, IItemHandlerModifiable inventory, Random random, ItemStack stack, int fromSlot) {
    LootTable lootTable = lootTable(stack);
    inventory.setStackInSlot(fromSlot, ItemStack.EMPTY);
    if (lootTable != 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.getSlots()) : emptySlots.removeAt(random.nextInt(emptySlots.size()));
            ItemStack generated = lootTable.getRandomItemStack(server, random);
            if (generated != null)
                inventory.setStackInSlot(slot, generated);
        }
    }
}
Also used : LootTable(ivorius.reccomplex.world.storage.loot.LootTable) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) TIntList(gnu.trove.list.TIntList) ItemStack(net.minecraft.item.ItemStack) GuiEditItemStack(ivorius.reccomplex.gui.loot.GuiEditItemStack)

Example 22 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, Set<BlockPos> surface, Predicate<BlockPos> predicate, int wHeight, double samples, Random random) {
    TIntList list = new TIntArrayList(surface.size());
    BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
    for (BlockPos surfacePos : surface) {
        // Added
        if (samples >= 1 || random.nextDouble() < samples) {
            pos.setPos(surfacePos.getX(), surfacePos.getY() + y, surfacePos.getZ());
            // if (structurebb.isVecInside(pos))
            {
                // Ignore voiding rays
                BlockPos found = findFirstBlock(pos, predicate, up, wHeight);
                if (found != null)
                    list.add(found.getY() - surfacePos.getY());
            }
        }
    }
    if (list.isEmpty())
        return -1;
    else
        return robustAverage(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 23 with TIntList

use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.

the class MD5AnimationLoader method createAnimation.

private MeshAnimationData createAnimation(MD5 md5) {
    List<String> boneNames = Lists.newArrayListWithCapacity(md5.numJoints);
    TIntList boneParents = new TIntArrayList(md5.numJoints);
    for (int i = 0; i < md5.numJoints; ++i) {
        boneNames.add(md5.joints[i].name);
        boneParents.add(md5.joints[i].parent);
    }
    float timePerFrame = 1.0f / md5.frameRate;
    List<MeshAnimationFrame> frames = Lists.newArrayList();
    for (int frameIndex = 0; frameIndex < md5.numFrames; ++frameIndex) {
        MD5Frame frame = md5.frames[frameIndex];
        List<Vector3f> positions = Lists.newArrayListWithExpectedSize(md5.numJoints);
        List<Vector3f> rawRotations = Lists.newArrayListWithExpectedSize(md5.numJoints);
        for (int i = 0; i < md5.numJoints; ++i) {
            positions.add(new Vector3f(md5.baseFramePosition[i]));
            rawRotations.add(new Vector3f(md5.baseFrameOrientation[i]));
        }
        for (int jointIndex = 0; jointIndex < md5.numJoints; ++jointIndex) {
            int compIndex = 0;
            if ((md5.joints[jointIndex].flags & POSITION_X_FLAG) != 0) {
                positions.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex];
                compIndex++;
            }
            if ((md5.joints[jointIndex].flags & POSITION_Y_FLAG) != 0) {
                positions.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex];
                compIndex++;
            }
            if ((md5.joints[jointIndex].flags & POSITION_Z_FLAG) != 0) {
                positions.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex];
                compIndex++;
            }
            if ((md5.joints[jointIndex].flags & ORIENTATION_X_FLAG) != 0) {
                rawRotations.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex];
                compIndex++;
            }
            if ((md5.joints[jointIndex].flags & ORIENTATION_Y_FLAG) != 0) {
                rawRotations.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex];
                compIndex++;
            }
            if ((md5.joints[jointIndex].flags & ORIENTATION_Z_FLAG) != 0) {
                rawRotations.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex];
            }
        }
        List<Quat4f> rotations = rawRotations.stream().map(rot -> MD5ParserCommon.completeQuat4f(rot.x, rot.y, rot.z)).collect(Collectors.toCollection(ArrayList::new));
        // Rotate just the root bone to correct for coordinate system differences
        rotations.set(0, MD5ParserCommon.correctQuat4f(rotations.get(0)));
        positions.set(0, MD5ParserCommon.correctOffset(positions.get(0)));
        frames.add(new MeshAnimationFrame(positions, rotations));
    }
    AABB aabb = AABB.createEncompassing(Arrays.asList(md5.bounds));
    return new MeshAnimationData(boneNames, boneParents, frames, timePerFrame, aabb);
}
Also used : Charsets(com.google.common.base.Charsets) TIntList(gnu.trove.list.TIntList) MeshAnimationFrame(org.terasology.rendering.assets.animation.MeshAnimationFrame) Arrays(java.util.Arrays) TIntArrayList(gnu.trove.list.array.TIntArrayList) Vector3f(org.terasology.math.geom.Vector3f) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) List(java.util.List) Lists(com.google.common.collect.Lists) Matcher(java.util.regex.Matcher) Quat4f(org.terasology.math.geom.Quat4f) AbstractAssetFileFormat(org.terasology.assets.format.AbstractAssetFileFormat) AssetDataFile(org.terasology.assets.format.AssetDataFile) AABB(org.terasology.math.AABB) RegisterAssetFileFormat(org.terasology.assets.module.annotations.RegisterAssetFileFormat) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) ResourceUrn(org.terasology.assets.ResourceUrn) InputStream(java.io.InputStream) MeshAnimationFrame(org.terasology.rendering.assets.animation.MeshAnimationFrame) TIntArrayList(gnu.trove.list.array.TIntArrayList) Vector3f(org.terasology.math.geom.Vector3f) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) TIntList(gnu.trove.list.TIntList) Quat4f(org.terasology.math.geom.Quat4f) AABB(org.terasology.math.AABB)

Example 24 with TIntList

use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.

the class RowLayout method calcWidths.

/**
 * Calculates the widths of each of the widgets in this layout's widget list.
 * Widths are first calculated for widgets with a relative width specified,
 * followed by widgets which follow their content width.
 * The remaining width is then split equally among the remaining widgets.
 *
 * @param canvas The {@link Canvas} on which this {@code RowLayout} is drawn
 * @return A list of the widths of the widgets in this layout's widget list, in pixels
 */
private TIntList calcWidths(Canvas canvas) {
    TIntList results = new TIntArrayList(contents.size());
    if (contents.size() > 0) {
        int width = canvas.size().x - horizontalSpacing * (contents.size() - 1);
        int totalWidthUsed = 0;
        int unprocessedWidgets = 0;
        for (UIWidget widget : contents) {
            RowLayoutHint hint = hints.get(widget);
            if (hint != null) {
                if (!hint.isUseContentWidth() && hint.getRelativeWidth() != 0) {
                    int elementWidth = TeraMath.floorToInt(hint.getRelativeWidth() * width);
                    results.add(elementWidth);
                    totalWidthUsed += elementWidth;
                } else {
                    results.add(0);
                    unprocessedWidgets++;
                }
            } else {
                results.add(0);
                unprocessedWidgets++;
            }
        }
        if (unprocessedWidgets > 0) {
            int remainingWidthPerElement = (width - totalWidthUsed) / unprocessedWidgets;
            for (int i = 0; i < results.size(); ++i) {
                if (results.get(i) == 0) {
                    RowLayoutHint hint = hints.get(contents.get(i));
                    if (hint != null) {
                        if (hint.isUseContentWidth()) {
                            Vector2i contentSize = contents.get(i).getPreferredContentSize(canvas, new Vector2i(remainingWidthPerElement, canvas.size().y));
                            results.set(i, contentSize.x);
                            totalWidthUsed += contentSize.x;
                            unprocessedWidgets--;
                        }
                    }
                }
            }
        }
        if (unprocessedWidgets > 0) {
            int remainingWidthPerElement = (width - totalWidthUsed) / unprocessedWidgets;
            for (int i = 0; i < results.size(); ++i) {
                if (results.get(i) == 0) {
                    results.set(i, remainingWidthPerElement);
                }
            }
        }
    }
    return results;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 25 with TIntList

use of gnu.trove.list.TIntList in project Terasology by MovingBlocks.

the class RowLayout method getPreferredContentSize.

/**
 * Retrieves the preferred content size of this {@code RowLayout}.
 * This is the minimum size this layout will take, given no space restrictions.
 *
 * @param canvas The {@code Canvas} on which this {@code RowLayout} is drawn
 * @param areaHint A {@link Vector2i} representing the space available for widgets to be drawn in this layout
 * @return A {@link Vector2i} representing the preferred content size of this {@code RowLayout}
 */
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
    TIntList widths = calcWidths(canvas);
    Vector2i result = new Vector2i(areaHint.x, 0);
    for (int i = 0; i < contents.size(); ++i) {
        Vector2i widgetSize = canvas.calculateRestrictedSize(contents.get(i), new Vector2i(TeraMath.floorToInt(widths.get(i)), areaHint.y));
        result.y = Math.max(result.y, widgetSize.y);
    }
    return result;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) 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