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