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);
}
}
}
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());
}
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);
}
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;
}
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;
}
Aggregations