use of slimeknights.tconstruct.shared.network.GeneratePartTexturesPacket.Operation in project TinkersConstruct by SlimeKnights.
the class ClientGeneratePartTexturesCommand method generateTextures.
/**
* Generates all textures using the resource pack list
*/
public static void generateTextures(Operation operation, String modId, String materialPath) {
long time = System.nanoTime();
ResourceManager manager = Minecraft.getInstance().getResourceManager();
// the forge mod bus is annoying, but stuck using it due to the normal bus not existing at datagen time
MaterialPartTextureGenerator.runCallbacks(null, manager);
Player player = Minecraft.getInstance().player;
// get the list of sprites
List<PartSpriteInfo> partSprites = loadPartSprites(manager);
if (partSprites.isEmpty()) {
if (player != null) {
player.displayClientMessage(NO_PARTS, false);
}
return;
}
// Predicate to check if a material ID is valid
Predicate<ResourceLocation> validMaterialId = loc -> (modId.isEmpty() || modId.equals(loc.getNamespace())) && (materialPath.isEmpty() || materialPath.equals(loc.getPath()));
// get all materials, filtered by the given parameters
List<MaterialSpriteInfo> materialSprites = loadMaterialRenderInfoGenerators(manager, validMaterialId);
if (materialSprites.isEmpty()) {
if (player != null) {
player.displayClientMessage(NO_MATERIALS, false);
}
return;
}
// prepare the output directory
Path path = Minecraft.getInstance().getResourcePackDirectory().toPath().resolve(PACK_NAME);
BiConsumer<ResourceLocation, NativeImage> saver = (outputPath, image) -> saveImage(path, outputPath, image);
// create a pack.mcmeta so its a valid resource pack
savePackMcmeta(path);
// predicate for whether we should generate the texture
AbstractSpriteReader spriteReader = new ResourceManagerSpriteReader(manager, MaterialPartTextureGenerator.FOLDER);
// keep track of how many generated
MutableInt generated = new MutableInt(0);
Predicate<ResourceLocation> shouldGenerate;
if (operation == Operation.ALL) {
shouldGenerate = exists -> {
generated.add(1);
return true;
};
} else {
shouldGenerate = loc -> {
if (!spriteReader.exists(loc)) {
generated.add(1);
return true;
}
return false;
};
}
// at this point in time we have all our materials, time to generate our sprites
for (MaterialSpriteInfo material : materialSprites) {
for (PartSpriteInfo part : partSprites) {
if (material.supportStatType(part.getStatType())) {
MaterialPartTextureGenerator.generateSprite(spriteReader, material, part, shouldGenerate, saver);
}
}
}
spriteReader.closeAll();
// success message
long deltaTime = System.nanoTime() - time;
int count = generated.getValue();
MaterialPartTextureGenerator.runCallbacks(null, null);
log.info("Finished generating {} textures in {} ms", count, deltaTime / 1000000f);
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.displayClientMessage(new TranslatableComponent(SUCCESS_KEY, count, (deltaTime / 1000000) / 1000f, getOutputComponent(path.toFile())), false);
}
}
Aggregations