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