Search in sources :

Example 26 with TIntList

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

the class LocalChunkProvider method createBatchBlockEventMappings.

private TShortObjectMap<TIntList> createBatchBlockEventMappings(Chunk chunk) {
    TShortObjectMap<TIntList> batchBlockMap = new TShortObjectHashMap<>();
    blockManager.listRegisteredBlocks().stream().filter(Block::isLifecycleEventsRequired).forEach(block -> batchBlockMap.put(block.getId(), new TIntArrayList()));
    ChunkBlockIterator i = chunk.getBlockIterator();
    while (i.next()) {
        if (i.getBlock().isLifecycleEventsRequired()) {
            TIntList positionList = batchBlockMap.get(i.getBlock().getId());
            positionList.add(i.getBlockPos().x);
            positionList.add(i.getBlockPos().y);
            positionList.add(i.getBlockPos().z);
        }
    }
    return batchBlockMap;
}
Also used : TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) ChunkBlockIterator(org.terasology.world.chunks.ChunkBlockIterator)

Example 27 with TIntList

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

the class LocalChunkProvider method deactivateBlocks.

private void deactivateBlocks() {
    List<TShortObjectMap<TIntList>> deactivatedBlockSets = Lists.newArrayListWithExpectedSize(deactivateBlocksQueue.size());
    deactivateBlocksQueue.drainTo(deactivatedBlockSets);
    for (TShortObjectMap<TIntList> deactivatedBlockSet : deactivatedBlockSets) {
        deactivatedBlockSet.forEachEntry((id, positions) -> {
            if (positions.size() > 0) {
                blockManager.getBlock(id).getEntity().send(new BeforeDeactivateBlocks(positions, registry));
            }
            return true;
        });
    }
}
Also used : TShortObjectMap(gnu.trove.map.TShortObjectMap) TIntList(gnu.trove.list.TIntList) BeforeDeactivateBlocks(org.terasology.world.block.BeforeDeactivateBlocks)

Example 28 with TIntList

use of gnu.trove.list.TIntList in project Charset by CharsetMC.

the class PacketRequestScroll method apply.

@Override
public void apply(INetHandler handler) {
    EntityPlayer player = getPlayer(handler);
    ItemStack currStack = player.inventory.getStackInSlot(currPos);
    ShiftScrollHandler.Provider provider = ShiftScrollHandler.INSTANCE.getMatchingProvider(currStack);
    if (!currStack.isEmpty() && provider != null) {
        if (player.isCreative()) {
            NonNullList<ItemStack> stacks = NonNullList.create();
            provider.addAllMatching(stacks);
            int id = -1;
            for (int i = 0; i < stacks.size(); i++) {
                ItemStack compStack = stacks.get(i);
                if (ItemUtils.equals(currStack, compStack, false, currStack.getHasSubtypes(), true)) {
                    id = i;
                    break;
                }
            }
            for (int i = 0; i < stacks.size(); i++) {
                ItemStack compStack = stacks.get(i);
                if (ItemUtils.equals(currStack, compStack, false, currStack.getHasSubtypes(), false)) {
                    id = i;
                    break;
                }
            }
            if (id >= 0) {
                int newPos = (id + (wheel < 0 ? 1 : -1)) % stacks.size();
                while (newPos < 0) newPos += stacks.size();
                ItemStack newStack = stacks.get(newPos).copy();
                newStack.setCount(currStack.getCount());
                player.setHeldItem(EnumHand.MAIN_HAND, newStack);
                return;
            }
        } else {
            NonNullList<ItemStack> mainInv = player.inventory.mainInventory;
            TIntList intList = new TIntArrayList(mainInv.size());
            for (int i = 0; i < mainInv.size(); i++) {
                int pos = (player.inventory.currentItem + (wheel < 0 ? -i : i)) % mainInv.size();
                while (pos < 0) pos += mainInv.size();
                ItemStack compStack = mainInv.get(pos);
                if (provider.matches(compStack)) {
                    intList.add(pos);
                }
            }
            if (intList.size() >= 2) {
                ItemStack temp = null;
                for (int i = 0; i < intList.size() + 1; i++) {
                    int pos = intList.get(i % intList.size());
                    if (temp == null) {
                        temp = mainInv.get(pos);
                    } else {
                        ItemStack target = mainInv.get(pos);
                        player.inventory.setInventorySlotContents(pos, temp);
                        temp = target;
                    }
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 29 with TIntList

use of gnu.trove.list.TIntList in project Charset by CharsetMC.

the class IngredientGroup method createMatchingStacks.

@Override
protected ItemStack[][] createMatchingStacks() {
    TIntList list = new TIntArrayList();
    Entry e = entryMap.get(type);
    if (e == null) {
        return new ItemStack[0][0];
    }
    TIntIterator iterator = e.typeMap.keySet().iterator();
    while (iterator.hasNext()) {
        int id = iterator.next();
        if (!blacklistedIds.contains(id)) {
            list.add(id);
        }
    }
    ItemStack[][] stacks = new ItemStack[list.size()][];
    for (int i = 0; i < stacks.length; i++) {
        Collection c = e.typeMap.get(list.get(i));
        int length = 0;
        for (Object o : c) {
            if (o instanceof String) {
                length += OreDictionary.getOres((String) o).size();
            } else if (o instanceof ItemStack) {
                length++;
            }
        }
        stacks[i] = new ItemStack[length];
        int j = 0;
        for (Object o : c) {
            if (o instanceof String) {
                NonNullList<ItemStack> stackList = OreDictionary.getOres((String) o);
                for (ItemStack stack : stackList) {
                    stacks[i][j++] = stack;
                }
            } else if (o instanceof ItemStack) {
                stacks[i][j++] = (ItemStack) o;
            }
        }
    }
    return stacks;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) JsonObject(com.google.gson.JsonObject) TIntList(gnu.trove.list.TIntList) ItemStack(net.minecraft.item.ItemStack) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 30 with TIntList

use of gnu.trove.list.TIntList in project OpenTripPlanner by opentripplanner.

the class Ride method getSortedStoptimes.

/* Maybe store transfer distances by stop pair, and look them up. */
/**
 * @param arrivals find arrival times rather than departure times for this Ride.
 * @return a list of sorted departure or arrival times within the window.
 * FIXME this is a hot spot in execution, about 50 percent of runtime.
 */
public TIntList getSortedStoptimes(TimeWindow window, boolean arrivals) {
    // Using Lists because we don't know the length in advance
    TIntList times = new TIntArrayList();
    // non-exact (headway-based) frequency trips will be handled elsewhere since they don't have specific boarding times.
    for (PatternRide patternRide : patternRides) {
        for (TripTimes tt : patternRide.pattern.scheduledTimetable.tripTimes) {
            if (window.servicesRunning.get(tt.serviceCode)) {
                int t = arrivals ? tt.getArrivalTime(patternRide.toIndex) : tt.getDepartureTime(patternRide.fromIndex);
                if (window.includes(t))
                    times.add(t);
            }
        }
    }
    times.sort();
    return times;
}
Also used : TripTimes(org.opentripplanner.routing.trippattern.TripTimes) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList)

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