Search in sources :

Example 1 with AbstractBoundingBox

use of com.irtimaled.bbor.common.models.AbstractBoundingBox in project BoundingBoxOutlineReloaded by irtimaled.

the class ClientRenderer method getBoundingBoxes.

public static Stream<AbstractBoundingBox> getBoundingBoxes(DimensionId dimensionId) {
    Stream.Builder<AbstractBoundingBox> boundingBoxes = Stream.builder();
    for (IBoundingBoxProvider<?> provider : providers) {
        if (provider.canProvide(dimensionId)) {
            for (AbstractBoundingBox boundingBox : provider.get(dimensionId)) {
                if (isWithinRenderDistance(boundingBox)) {
                    boundingBoxes.accept(boundingBox);
                }
            }
        }
    }
    Point point = Player.getPoint();
    return boundingBoxes.build().sorted(Comparator.comparingDouble((AbstractBoundingBox boundingBox) -> boundingBox.getDistance(point.getX(), point.getY(), point.getZ())).reversed());
}
Also used : Stream(java.util.stream.Stream) AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox)

Example 2 with AbstractBoundingBox

use of com.irtimaled.bbor.common.models.AbstractBoundingBox in project BoundingBoxOutlineReloaded by irtimaled.

the class StructureProcessor method addStructures.

private void addStructures(BoundingBoxType type, Map<String, StructureStart> structureMap) {
    StructureStart structureStart = structureMap.get(type.getName());
    if (structureStart == null)
        return;
    MutableBoundingBox bb = structureStart.getBoundingBox();
    if (bb == null)
        return;
    AbstractBoundingBox boundingBox = buildStructure(bb, type);
    if (boundingBoxCache.isCached(boundingBox))
        return;
    Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
    for (StructurePiece structureComponent : structureStart.getComponents()) {
        structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
    }
    boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
}
Also used : MutableBoundingBox(net.minecraft.util.math.MutableBoundingBox) StructurePiece(net.minecraft.world.gen.feature.structure.StructurePiece) StructureStart(net.minecraft.world.gen.feature.structure.StructureStart) AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox) HashSet(java.util.HashSet)

Example 3 with AbstractBoundingBox

use of com.irtimaled.bbor.common.models.AbstractBoundingBox in project BoundingBoxOutlineReloaded by irtimaled.

the class CommonProxy method sendToPlayer.

private void sendToPlayer(int playerId, ServerPlayer player) {
    for (Map.Entry<DimensionId, BoundingBoxCache> entry : dimensionCache.entrySet()) {
        DimensionId dimensionId = entry.getKey();
        BoundingBoxCache boundingBoxCache = entry.getValue();
        if (boundingBoxCache == null)
            return;
        Set<AbstractBoundingBox> playerBoundingBoxes = playerBoundingBoxesCache.computeIfAbsent(playerId, k -> new HashSet<>());
        Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxMap = boundingBoxCache.getBoundingBoxes();
        for (AbstractBoundingBox key : boundingBoxMap.keySet()) {
            if (playerBoundingBoxes.contains(key)) {
                continue;
            }
            Set<AbstractBoundingBox> boundingBoxes = boundingBoxMap.get(key);
            PayloadBuilder payload = AddBoundingBox.getPayload(dimensionId, key, boundingBoxes);
            if (payload != null)
                player.sendPacket(payload);
            playerBoundingBoxes.add(key);
        }
    }
}
Also used : PayloadBuilder(com.irtimaled.bbor.common.messages.PayloadBuilder) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) DimensionId(com.irtimaled.bbor.common.models.DimensionId) AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox)

Example 4 with AbstractBoundingBox

use of com.irtimaled.bbor.common.models.AbstractBoundingBox in project BoundingBoxOutlineReloaded by irtimaled.

the class AddBoundingBox method getPayload.

public static PayloadBuilder getPayload(DimensionId dimensionId, AbstractBoundingBox key, Set<AbstractBoundingBox> boundingBoxes) {
    if (!BoundingBoxSerializer.canSerialize(key))
        return null;
    PayloadBuilder builder = PayloadBuilder.clientBound(NAME).writeDimensionId(dimensionId);
    BoundingBoxSerializer.serialize(key, builder);
    if (boundingBoxes != null && boundingBoxes.size() > 1) {
        for (AbstractBoundingBox boundingBox : boundingBoxes) {
            BoundingBoxSerializer.serialize(boundingBox, builder);
        }
    }
    return builder;
}
Also used : AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox)

Example 5 with AbstractBoundingBox

use of com.irtimaled.bbor.common.models.AbstractBoundingBox in project BoundingBoxOutlineReloaded by irtimaled.

the class AddBoundingBox method getEvent.

public static AddBoundingBoxReceived getEvent(PayloadReader reader, String name) {
    DimensionId dimensionId = getDimensionId(reader, name);
    AbstractBoundingBox key = BoundingBoxDeserializer.deserialize(reader);
    if (key == null)
        return null;
    Set<AbstractBoundingBox> boundingBoxes = new HashSet<>();
    while (reader.isReadable()) {
        AbstractBoundingBox boundingBox = BoundingBoxDeserializer.deserialize(reader);
        boundingBoxes.add(boundingBox);
    }
    if (boundingBoxes.size() == 0)
        boundingBoxes.add(key);
    return new AddBoundingBoxReceived(dimensionId, key, boundingBoxes);
}
Also used : AddBoundingBoxReceived(com.irtimaled.bbor.client.events.AddBoundingBoxReceived) DimensionId(com.irtimaled.bbor.common.models.DimensionId) AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox) HashSet(java.util.HashSet)

Aggregations

AbstractBoundingBox (com.irtimaled.bbor.common.models.AbstractBoundingBox)6 HashSet (java.util.HashSet)4 DimensionId (com.irtimaled.bbor.common.models.DimensionId)2 Map (java.util.Map)2 Set (java.util.Set)2 AddBoundingBoxReceived (com.irtimaled.bbor.client.events.AddBoundingBoxReceived)1 BoundingBoxCache (com.irtimaled.bbor.common.BoundingBoxCache)1 PayloadBuilder (com.irtimaled.bbor.common.messages.PayloadBuilder)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Stream (java.util.stream.Stream)1 MutableBoundingBox (net.minecraft.util.math.MutableBoundingBox)1 StructurePiece (net.minecraft.world.gen.feature.structure.StructurePiece)1 StructureStart (net.minecraft.world.gen.feature.structure.StructureStart)1