генерация colomposed текстур и автотрек текстур для датагена

This commit is contained in:
YuRaNnNzZZ 2025-01-09 19:34:32 +03:00
parent 13d76df9fa
commit cc8a149c25
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D
243 changed files with 114 additions and 69 deletions

View File

@ -104,10 +104,7 @@ class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(eve
val model = withExistingParent(modelName + "_${color.name.lowercase()}$suffix", modLocation(modelName + suffix))
for ((key, value) in textureKeys) {
val loc = modLocation("block/$value/${color.name.lowercase()}")
existingFileHelper.trackGenerated(loc, TEXTURE)
model.texture(key, loc)
model.texture(key, modLocation("block/$value/${color.name.lowercase()}"))
}
}
}

View File

@ -1,6 +1,5 @@
package ru.dbotthepony.mc.otm.datagen.textures
import net.minecraft.resources.ResourceLocation
import net.neoforged.neoforge.common.data.SpriteSourceProvider
import net.neoforged.neoforge.data.event.GatherDataEvent
import ru.dbotthepony.mc.otm.client.render.ColorizedSpriteSource
@ -8,54 +7,57 @@ import ru.dbotthepony.mc.otm.datagen.DataGen
import ru.dbotthepony.mc.otm.datagen.modLocation
class ColorizedSpritesProvider(event: GatherDataEvent) : SpriteSourceProvider(event.generator.packOutput, event.lookupProvider, DataGen.MOD_ID, event.existingFileHelper) {
fun getMaskedTextureMap(paths: List<String>) : Map<ResourceLocation, ResourceLocation> {
val map: MutableMap<ResourceLocation, ResourceLocation> = mutableMapOf()
paths.forEach { map[modLocation(it)] = modLocation(it + "_mask") }
return map
}
override fun gather() {
listOf(
"block/android_charger",
"block/android_station_base",
"block/batterybank_frame",
"block/chemical_generator",
"block/cobblestone_generator",
"block/decorative/computer_base",
"block/decorative/computer_screen",
"block/drive_viewer",
"block/electric_furnace",
"block/electric_furnace_offline",
"block/energy_counter",
"block/energy_servo",
"block/essence_storage",
"block/induction_furnace",
"block/induction_furnace_offline",
"block/item_monitor",
"block/matter_bottler",
"block/matter_decomposer",
"block/matter_panel",
"block/matter_reconstructor",
"block/matter_recycler",
"block/matter_replicator_base",
"block/matter_replicator_halted",
"block/matter_replicator",
"block/matter_replicator_offline",
"block/matter_scanner",
"block/mattercapacitorbank_frame",
"block/plate_press",
"block/plate_press2",
"block/powered_smoker_base",
"block/powered_smoker_interior_0",
"block/powered_smoker_interior_1",
"block/powered_smoker_interior_2",
"block/decorative/star_chair",
"block/storage_power_supplier",
"block/water_source"
).forEach {
atlas(BLOCKS_ATLAS).addSource(
ColorizedSpriteSource(modLocation(it), modLocation(it).withSuffix("_mask"), modLocation(it)).trackGeneratedTextures(existingFileHelper)
)
}
atlas(BLOCKS_ATLAS).addSource(
ColorizedSpriteSource(getMaskedTextureMap(listOf(
"block/android_charger",
"block/android_station_base",
"block/batterybank_frame",
"block/chemical_generator",
"block/cobblestone_generator",
"block/decorative/computer_base",
"block/decorative/computer_screen",
"block/drive_viewer",
"block/electric_furnace",
"block/electric_furnace_offline",
"block/energy_counter",
"block/energy_servo",
"block/essence_storage",
"block/induction_furnace",
"block/induction_furnace_offline",
"block/item_monitor",
"block/matter_bottler",
"block/matter_decomposer",
"block/matter_panel",
"block/matter_reconstructor",
"block/matter_recycler",
"block/matter_replicator_base",
"block/matter_replicator_halted",
"block/matter_replicator",
"block/matter_replicator_offline",
"block/matter_scanner",
"block/mattercapacitorbank_frame",
"block/plate_press",
"block/plate_press2",
"block/powered_smoker_base",
"block/powered_smoker_interior_0",
"block/powered_smoker_interior_1",
"block/powered_smoker_interior_2",
"block/decorative/star_chair",
"block/storage_power_supplier",
"block/water_source"
)))
ColorizedSpriteSource(
modLocation("block/decorative/tritanium_striped_block_colorless_base"),
modLocation("block/decorative/tritanium_striped_block_colorless_stripe"),
modLocation("block/decorative/stripe/tritanium_striped_block"),
"_", true, true
).trackGeneratedTextures(existingFileHelper)
)
}
}

View File

@ -15,26 +15,34 @@ import net.minecraft.server.packs.resources.ResourceManager
import net.minecraft.server.packs.resources.ResourceMetadata
import net.minecraft.world.item.DyeColor
import net.neoforged.neoforge.client.event.RegisterSpriteSourceTypesEvent
import net.neoforged.neoforge.client.model.generators.ModelProvider
import net.neoforged.neoforge.common.data.ExistingFileHelper
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.OverdriveThatMatters.loc
class ColorizedSpriteSource(val textures: Map<ResourceLocation, ResourceLocation>) : SpriteSource {
class ColorizedSpriteSource(val base: ResourceLocation, val overlay: ResourceLocation, val outputPathBase: ResourceLocation, val outputPathSuffix: String = "/", val tintBase: Boolean = false, val tintOverlay: Boolean = true) : SpriteSource {
override fun run(
manager: ResourceManager,
output: SpriteSource.Output
) {
for (entry in textures) {
val baseRes = manager.getResource(TEXTURE_ID_CONVERTER.idToFile(entry.key)).get()
val maskRes = manager.getResource(TEXTURE_ID_CONVERTER.idToFile(entry.value)).get()
val baseRes = manager.getResource(TEXTURE_ID_CONVERTER.idToFile(base)).get()
val maskRes = manager.getResource(TEXTURE_ID_CONVERTER.idToFile(overlay)).get()
DyeColor.entries.forEach {
val outputLocation = entry.key.withSuffix("/" + it.serializedName)
for (baseTint in DyeColor.entries) {
for (overlayTint in DyeColor.entries) {
if (tintBase && baseTint == overlayTint) continue
val baseImage = LazyLoadedImage(entry.key, baseRes, 1)
val maskImage = LazyLoadedImage(entry.value, maskRes, 1)
var outputLocation = outputPathBase
if (tintBase) outputLocation = outputLocation.withSuffix(outputPathSuffix + baseTint.serializedName)
if (tintOverlay) outputLocation = outputLocation.withSuffix(outputPathSuffix + overlayTint.serializedName)
output.add(outputLocation, Supplier(baseImage, maskImage, it, outputLocation))
val baseImage = LazyLoadedImage(base, baseRes, 1)
val maskImage = LazyLoadedImage(overlay, maskRes, 1)
output.add(outputLocation, Supplier(baseImage, if (tintBase) baseTint else null, maskImage, if (tintOverlay) overlayTint else null, outputLocation))
}
if (!tintBase) return
}
}
@ -42,7 +50,25 @@ class ColorizedSpriteSource(val textures: Map<ResourceLocation, ResourceLocation
return SPRITE_SOURCE!!
}
class Supplier(val baseImage: LazyLoadedImage, val maskImage: LazyLoadedImage, val color: DyeColor, val outputLocation: ResourceLocation) : SpriteSource.SpriteSupplier {
fun trackGeneratedTextures(efh: ExistingFileHelper) : ColorizedSpriteSource {
for (baseTint in DyeColor.entries) {
for (overlayTint in DyeColor.entries) {
if (tintBase && baseTint == overlayTint) continue
var outputLocation = outputPathBase
if (tintBase) outputLocation = outputLocation.withSuffix(outputPathSuffix + baseTint.serializedName)
if (tintOverlay) outputLocation = outputLocation.withSuffix(outputPathSuffix + overlayTint.serializedName)
efh.trackGenerated(outputLocation, ModelProvider.TEXTURE)
}
if (!tintBase) return this
}
return this
}
class Supplier(val baseImage: LazyLoadedImage, val baseTint: DyeColor?, val maskImage: LazyLoadedImage, val maskTint: DyeColor?, val outputLocation: ResourceLocation) : SpriteSource.SpriteSupplier {
override fun apply(t: SpriteResourceLoader?): SpriteContents? {
val base = baseImage.get()
val mask = maskImage.get()
@ -51,14 +77,28 @@ class ColorizedSpriteSource(val textures: Map<ResourceLocation, ResourceLocation
throw IllegalArgumentException("Base image doesn't match mask in texture size")
}
val diffCol = RGBAColor.argb(color.textureDiffuseColor)
mask.applyToAllPixels {
val a = (it and -0x1000000 ushr 24) / 255f
val b = (it and 0xFF0000 ushr 16) / 255f
val g = (it and 0xFF00 ushr 8) / 255f
val r = (it and 0xFF) / 255f
if (baseTint != null) {
val baseDiffCol = RGBAColor.argb(baseTint.textureDiffuseColor)
base.applyToAllPixels {
val a = (it and -0x1000000 ushr 24) / 255f
val b = (it and 0xFF0000 ushr 16) / 255f
val g = (it and 0xFF00 ushr 8) / 255f
val r = (it and 0xFF) / 255f
RGBAColor(r * diffCol.red, g * diffCol.green, b * diffCol.blue, a).toRGBA()
RGBAColor(r * baseDiffCol.red, g * baseDiffCol.green, b * baseDiffCol.blue, a).toRGBA()
}
}
if (maskTint != null) {
val maskDiffCol = RGBAColor.argb(maskTint.textureDiffuseColor)
mask.applyToAllPixels {
val a = (it and -0x1000000 ushr 24) / 255f
val b = (it and 0xFF0000 ushr 16) / 255f
val g = (it and 0xFF00 ushr 8) / 255f
val r = (it and 0xFF) / 255f
RGBAColor(r * maskDiffCol.red, g * maskDiffCol.green, b * maskDiffCol.blue, a).toRGBA()
}
}
for (i in 0 until base.width) {
@ -79,7 +119,13 @@ class ColorizedSpriteSource(val textures: Map<ResourceLocation, ResourceLocation
private val CODEC: MapCodec<ColorizedSpriteSource> = RecordCodecBuilder.mapCodec {
it.group(
Codec.unboundedMap(ResourceLocation.CODEC, ResourceLocation.CODEC).fieldOf("textures").forGetter { it.textures }
ResourceLocation.CODEC.fieldOf("base").forGetter { it.base },
ResourceLocation.CODEC.fieldOf("overlay").forGetter { it.overlay },
ResourceLocation.CODEC.fieldOf("output_path_base").forGetter { it.outputPathBase },
Codec.STRING.optionalFieldOf("output_path_suffix", "/").forGetter { it.outputPathSuffix },
Codec.BOOL.optionalFieldOf("base_tint", false).forGetter { it.tintBase },
Codec.BOOL.optionalFieldOf("overlay_tint", true).forGetter{ it.tintOverlay }
).apply(it, ::ColorizedSpriteSource)
}

Some files were not shown because too many files have changed in this diff Show More