use of buildcraft.api.schematics.ISchematicEntity 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;
}
}
use of buildcraft.api.schematics.ISchematicEntity in project BuildCraft by BuildCraft.
the class SchematicEntityManager method getSchematicEntity.
@SuppressWarnings("WeakerAccess")
public static ISchematicEntity getSchematicEntity(SchematicEntityContext context) {
for (SchematicEntityFactory<?> schematicEntityFactory : Lists.reverse(SchematicEntityFactoryRegistry.getFactories())) {
if (schematicEntityFactory.predicate.test(context)) {
ISchematicEntity schematicEntity = schematicEntityFactory.supplier.get();
schematicEntity.init(context);
return schematicEntity;
}
}
return null;
}
use of buildcraft.api.schematics.ISchematicEntity in project BuildCraft by BuildCraft.
the class SchematicEntityManager method readFromNBT.
@Nonnull
public static ISchematicEntity readFromNBT(NBTTagCompound schematicEntityTag) throws InvalidInputDataException {
ResourceLocation name = new ResourceLocation(schematicEntityTag.getString("name"));
SchematicEntityFactory<?> factory = SchematicEntityFactoryRegistry.getFactoryByName(name);
if (factory == null) {
throw new InvalidInputDataException("Unknown schematic type " + name);
}
ISchematicEntity schematicEntity = factory.supplier.get();
NBTTagCompound data = schematicEntityTag.getCompoundTag("data");
try {
schematicEntity.deserializeNBT(data);
return schematicEntity;
} catch (InvalidInputDataException e) {
throw new InvalidInputDataException("Failed to load the schematic from " + data, e);
}
}
Aggregations