Search in sources :

Example 16 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project OpenTripPlanner by opentripplanner.

the class Ride method calcStatsForBoarding.

/**
 * Produce stats about boarding an initial Ride, which has no previous ride.
 * This assumes arrival times are uniformly distributed during the window.
 * The Ride must contain some trips, and the window must have a positive duration.
 */
public Stats calcStatsForBoarding(TimeWindow window) {
    Stats stats = new Stats();
    // You can always arrive just before a train departs.
    stats.min = 0;
    TIntList departures = getSortedStoptimes(window, false);
    int last = window.from;
    double avgAccumulated = 0.0;
    /* All departures in the list are known to be running and within the window. */
    for (TIntIterator it = departures.iterator(); it.hasNext(); ) {
        int dep = it.next();
        int maxWait = dep - last;
        if (maxWait > stats.max)
            stats.max = maxWait;
        /* Weight the average of each interval by the number of seconds it contains. */
        avgAccumulated += (maxWait / 2.0) * maxWait;
        stats.num += maxWait;
        last = dep;
    }
    if (stats.num > 0) {
        stats.avg = (int) (avgAccumulated / stats.num);
    }
    return stats;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) TIntList(gnu.trove.list.TIntList)

Example 17 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project BiomeTweaker by superckl.

the class BlockReplacer method runReplacement.

public static void runReplacement(final PlacementStage stage, final World world, final Random rand, final ChunkPos pos, final ChunkPrimer primer) {
    try {
        final BlockReplacementManager manager = BlockReplacementManager.getManagerForWorld(world.provider.getDimension());
        if (!manager.hasReplacements(stage))
            return;
        final TIntObjectMap<BlockReplacementEntryList> previousReplacements = manager.findMap(pos);
        final Chunk chunk = primer == null ? world.getChunkFromChunkCoords(pos.x, pos.z) : null;
        final MutableBlockPos biomeCheckPos = new MutableBlockPos();
        final MutableBlockPos blockSetPos = new MutableBlockPos();
        for (int x = 0; x < 16; ++x) for (int z = 0; z < 16; ++z) {
            // e.biomeArray[l + (k * 16)];
            final Biome biomegenbase = world.getBiome(biomeCheckPos.setPos((pos.x << 4) + x, 0, (pos.z << 4) + z));
            final int id = Biome.getIdForBiome(biomegenbase);
            if (!manager.hasReplacements(id, stage))
                continue;
            if (!previousReplacements.containsKey(id))
                previousReplacements.put(id, new BlockReplacementEntryList());
            final BlockReplacementEntryList previousReplacementsBiome = previousReplacements.get(id);
            final BlockReplacementEntryList list = manager.findReplacementEntryList(id, stage);
            final Set<IBlockState> noReps = Sets.newIdentityHashSet();
            // assuming height of 256 since blockArray no longer exposed, results in ((16*16)*256)/256=256
            final int k1 = 256;
            for (int y = 0; y < k1; y++) {
                final IBlockState state = primer == null ? chunk.getBlockState(x, y, z) : primer.getBlockState(x, y, z);
                if (noReps.contains(state))
                    continue;
                final Block block = state.getBlock();
                WeightedBlockEntry toUse = null;
                final BlockReplacementEntry previousEntry = previousReplacementsBiome.findEntry(state);
                final int meta = block.getMetaFromState(state);
                if (previousEntry != null) {
                    toUse = previousEntry.findEntriesForMeta(meta).get(0);
                    if (!BlockReplacer.verifyBoundaries(pos, x, y, z, toUse.getConstraints()))
                        toUse = null;
                }
                if (toUse == null) {
                    final BlockReplacementEntry entry = list.findEntry(state);
                    if (entry != null) {
                        final List<WeightedBlockEntry> entries = entry.findEntriesForMeta(meta);
                        if (entries == null || entries.isEmpty())
                            continue;
                        toUse = WeightedRandom.getRandomItem(rand, entries);
                        if (!BlockReplacer.verifyBoundaries(pos, x, y, z, toUse.getConstraints())) {
                            final List<WeightedBlockEntry> copy = new ArrayList<>(entries);
                            copy.remove(toUse);
                            boolean isWholeChunk = BlockReplacer.isWholeChunk(pos, toUse.getConstraints(), world.getHeight());
                            toUse = null;
                            while (!copy.isEmpty()) {
                                toUse = WeightedRandom.getRandomItem(rand, copy);
                                if (BlockReplacer.verifyBoundaries(pos, x, y, z, toUse.getConstraints())) {
                                    previousReplacementsBiome.registerReplacement(toUse.itemWeight, state, toUse.getConstraints());
                                    break;
                                }
                                if (!BlockReplacer.isWholeChunk(pos, toUse.getConstraints(), world.getHeight()))
                                    isWholeChunk = false;
                                toUse = null;
                            }
                            if (toUse == null && isWholeChunk)
                                noReps.add(state);
                        }
                    }
                }
                if (toUse != null)
                    if (primer != null)
                        primer.setBlockState(x, y, z, toUse.getConstraints().getState());
                    else
                        chunk.setBlockState(blockSetPos.setPos(x, y, z), toUse.getConstraints().getState());
            }
        }
        final TIntIterator it = previousReplacements.keySet().iterator();
        while (it.hasNext()) if (!manager.isContiguousReplacement(it.next()))
            it.remove();
        manager.trackReplacement(pos, previousReplacements);
    } catch (final Exception e1) {
        LogHelper.error("Failed to process replace biome blocks event.");
        e1.printStackTrace();
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) Set(java.util.Set) IBlockState(net.minecraft.block.state.IBlockState) Chunk(net.minecraft.world.chunk.Chunk) Biome(net.minecraft.world.biome.Biome) WeightedBlockEntry(me.superckl.biometweaker.common.world.gen.BlockReplacementManager.WeightedBlockEntry) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos)

Example 18 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SpatialDetector method getBlockPosArrayList.

public List<BlockPos> getBlockPosArrayList() {
    List<BlockPos> detectedBlockPos = new ArrayList<BlockPos>(foundSet.size());
    TIntIterator intIter = foundSet.iterator();
    while (intIter.hasNext()) {
        int hash = intIter.next();
        BlockPos fromHash = getPosWithRespectTo(hash, firstBlock);
        if (fromHash.getY() + 128 - firstBlock.getY() < 0) {
            System.err.println("I really hope this doesnt happen");
            return new ArrayList<BlockPos>();
        }
        detectedBlockPos.add(fromHash);
    }
    return detectedBlockPos;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) ArrayList(java.util.ArrayList) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 19 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SmallBlockPosSet method forEach.

@Override
public void forEach(@Nonnull VSIterationUtils.IntTernaryConsumer action) {
    TIntIterator iterator = compressedBlockPosList.iterator();
    while (iterator.hasNext()) {
        int compressed = iterator.next();
        // Repeated code from decompress() because java has no output parameters.
        int z = compressed >> 20;
        int y = (compressed >> 12) & BOT_8_BITS;
        // this basically left-pads the int when casting so that the sign is preserved
        // not sure if there is a better way
        int x = (compressed & BOT_12_BITS) << 20 >> 20;
        action.accept(x + centerX, y, z + centerZ);
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator)

Example 20 with TIntIterator

use of gnu.trove.iterator.TIntIterator in project Terasology by MovingBlocks.

the class NetClient method sendDirtyEntities.

private void sendDirtyEntities(NetData.NetMessage.Builder message) {
    TIntIterator dirtyIterator = netDirty.iterator();
    while (dirtyIterator.hasNext()) {
        int netId = dirtyIterator.next();
        EntityRef entity = networkSystem.getEntity(netId);
        if (!entity.exists()) {
            logger.error("Sending non-existent entity update for netId {}", netId);
        }
        boolean isOwner = networkSystem.getOwner(entity) == this;
        EntityData.PackedEntity entityData = entitySerializer.serialize(entity, addedComponents.get(netId), dirtyComponents.get(netId), removedComponents.get(netId), new ServerComponentFieldCheck(isOwner, false));
        if (entityData != null) {
            message.addUpdateEntity(NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId));
        }
    }
    netDirty.clear();
    addedComponents.clear();
    removedComponents.clear();
    dirtyComponents.clear();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) EntityData(org.terasology.protobuf.EntityData) ServerComponentFieldCheck(org.terasology.engine.network.serialization.ServerComponentFieldCheck) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

TIntIterator (gnu.trove.iterator.TIntIterator)39 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)13 BlockPos (net.minecraft.util.math.BlockPos)8 ArrayList (java.util.ArrayList)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)4 TIntHashSet (gnu.trove.set.hash.TIntHashSet)4 IBlockState (net.minecraft.block.state.IBlockState)4 Chunk (net.minecraft.world.chunk.Chunk)4 EntityData (org.terasology.protobuf.EntityData)4 TIntList (gnu.trove.list.TIntList)3 HashSet (java.util.HashSet)3 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)3 Vector (ValkyrienWarfareBase.API.Vector)2 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 VWChunkCache (ValkyrienWarfareBase.Relocation.VWChunkCache)1