use of buildcraft.api.schematics.SchematicEntityContext in project BuildCraft by BuildCraft.
the class BlueprintBuilder method tick.
@Override
public boolean tick() {
if (tile.getWorldBC().isRemote) {
return super.tick();
}
tile.getWorldBC().profiler.startSection("entitiesWithinBox");
List<Entity> entitiesWithinBox = tile.getWorldBC().getEntitiesWithinAABB(Entity.class, getBuildingInfo().box.getBoundingBox(), Objects::nonNull);
tile.getWorldBC().profiler.endSection();
tile.getWorldBC().profiler.startSection("toSpawn");
List<ISchematicEntity> toSpawn = getBuildingInfo().entities.stream().filter(schematicEntity -> entitiesWithinBox.stream().map(Entity::getPositionVector).map(schematicEntity.getPos().add(new Vec3d(getBuildingInfo().offsetPos))::distanceTo).noneMatch(distance -> distance < MAX_ENTITY_DISTANCE)).collect(Collectors.toList());
tile.getWorldBC().profiler.endSection();
// Compute needed stacks
tile.getWorldBC().profiler.startSection("remainingDisplayRequired");
remainingDisplayRequired.clear();
remainingDisplayRequired.addAll(StackUtil.mergeSameItems(Stream.concat(remainingDisplayRequiredBlocksConcat.stream(), toSpawn.stream().flatMap(schematicEntity -> getDisplayRequired(getBuildingInfo().entitiesRequiredItems.get(schematicEntity), getBuildingInfo().entitiesRequiredFluids.get(schematicEntity)))).collect(Collectors.toList())));
tile.getWorldBC().profiler.endSection();
// Kill not needed entities
tile.getWorldBC().profiler.startSection("toKill");
List<Entity> toKill = entitiesWithinBox.stream().filter(entity -> entity != null && getBuildingInfo().entities.stream().map(ISchematicEntity::getPos).map(new Vec3d(getBuildingInfo().offsetPos)::add).map(entity.getPositionVector()::distanceTo).noneMatch(distance -> distance < MAX_ENTITY_DISTANCE) && SchematicEntityManager.getSchematicEntity(new SchematicEntityContext(tile.getWorldBC(), BlockPos.ORIGIN, entity)) != null).collect(Collectors.toList());
if (!toKill.isEmpty()) {
if (!tile.getBattery().isFull()) {
return false;
} else {
tile.getWorldBC().profiler.startSection("kill");
toKill.forEach(Entity::setDead);
tile.getWorldBC().profiler.endSection();
}
}
tile.getWorldBC().profiler.endSection();
// Call superclass method
if (super.tick()) {
// Spawn needed entities
if (!toSpawn.isEmpty()) {
if (!tile.getBattery().isFull()) {
return false;
} else {
tile.getWorldBC().profiler.startSection("spawn");
toSpawn.stream().filter(schematicEntity -> tryExtractRequired(getBuildingInfo().entitiesRequiredItems.get(schematicEntity), getBuildingInfo().entitiesRequiredFluids.get(schematicEntity), true).isPresent()).filter(schematicEntity -> schematicEntity.build(tile.getWorldBC(), getBuildingInfo().offsetPos) != null).forEach(schematicEntity -> tryExtractRequired(getBuildingInfo().entitiesRequiredItems.get(schematicEntity), getBuildingInfo().entitiesRequiredFluids.get(schematicEntity), false));
tile.getWorldBC().profiler.endSection();
}
}
return true;
} else {
return false;
}
}
Aggregations