генерируем перекрашенные текстуры в рантайме
AMD User — Сегодня, в 15:29 no wae imagemagick in my meinkraft coed!!1?/
@ -49,6 +49,7 @@ import ru.dbotthepony.mc.otm.datagen.loot.LootModifiers
|
||||
import ru.dbotthepony.mc.otm.datagen.recipes.*
|
||||
import ru.dbotthepony.mc.otm.datagen.tags.TagsProvider
|
||||
import ru.dbotthepony.mc.otm.datagen.tags.addTags
|
||||
import ru.dbotthepony.mc.otm.datagen.textures.ColorizedSpritesProvider
|
||||
import ru.dbotthepony.mc.otm.matter.MatterDataProvider
|
||||
import ru.dbotthepony.mc.otm.registry.objects.ColoredDecorativeBlock
|
||||
import ru.dbotthepony.mc.otm.registry.objects.DecorativeBlock
|
||||
@ -484,6 +485,7 @@ object DataGen {
|
||||
@SubscribeEvent
|
||||
@Suppress("unused")
|
||||
fun onGatherData(event: GatherDataEvent) {
|
||||
val colorizedSpritesProvider = ColorizedSpritesProvider(event)
|
||||
val blockModelProvider = MatteryBlockModelProvider(event)
|
||||
val blockStateProvider = MatteryBlockStateProvider(event)
|
||||
val itemModelProvider = MatteryItemModelProvider(event)
|
||||
@ -514,6 +516,7 @@ object DataGen {
|
||||
|
||||
addTags(tagsProvider)
|
||||
|
||||
event.generator.addProvider(event.includeClient(), colorizedSpritesProvider)
|
||||
event.generator.addProvider(event.includeClient(), blockModelProvider)
|
||||
event.generator.addProvider(event.includeServer(), blockStateProvider)
|
||||
event.generator.addProvider(event.includeClient(), itemModelProvider)
|
||||
|
@ -104,7 +104,10 @@ class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(eve
|
||||
val model = withExistingParent(modelName + "_${color.name.lowercase()}$suffix", modLocation(modelName + suffix))
|
||||
|
||||
for ((key, value) in textureKeys) {
|
||||
model.texture(key, modLocation("block/$value/${color.name.lowercase()}"))
|
||||
val loc = modLocation("block/$value/${color.name.lowercase()}")
|
||||
|
||||
existingFileHelper.trackGenerated(loc, TEXTURE)
|
||||
model.texture(key, loc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
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
|
||||
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() {
|
||||
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"
|
||||
)))
|
||||
)
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ import ru.dbotthepony.mc.otm.client.onClientDisconnected
|
||||
import ru.dbotthepony.mc.otm.client.onClientPostRender
|
||||
import ru.dbotthepony.mc.otm.client.tooltipEvent
|
||||
import ru.dbotthepony.mc.otm.client.render.ChartTooltipElement
|
||||
import ru.dbotthepony.mc.otm.client.render.ColorizedSpriteSource
|
||||
import ru.dbotthepony.mc.otm.client.render.ShockwaveRenderer
|
||||
import ru.dbotthepony.mc.otm.client.render.blockentity.BatteryBankRenderer
|
||||
import ru.dbotthepony.mc.otm.client.render.blockentity.MatterBatteryBankRenderer
|
||||
@ -132,6 +133,8 @@ object OverdriveThatMatters {
|
||||
MOD_BUS.addListener(EventPriority.NORMAL, ChartTooltipElement.Companion::register)
|
||||
MOD_BUS.addListener(EventPriority.NORMAL, MatteryTooltipComponents::registerComponents)
|
||||
|
||||
MOD_BUS.addListener(EventPriority.NORMAL, ColorizedSpriteSource::register)
|
||||
|
||||
MOD_BUS.addListener(EventPriority.HIGH, MatteryGUI::registerGuiLayers)
|
||||
|
||||
MBlockColors.register(MOD_BUS)
|
||||
|
@ -0,0 +1,92 @@
|
||||
package ru.dbotthepony.mc.otm.client.render
|
||||
|
||||
import com.mojang.serialization.Codec
|
||||
import com.mojang.serialization.MapCodec
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import net.minecraft.client.renderer.texture.SpriteContents
|
||||
import net.minecraft.client.renderer.texture.atlas.SpriteResourceLoader
|
||||
import net.minecraft.client.renderer.texture.atlas.SpriteSource
|
||||
import net.minecraft.client.renderer.texture.atlas.SpriteSource.TEXTURE_ID_CONVERTER
|
||||
import net.minecraft.client.renderer.texture.atlas.SpriteSourceType
|
||||
import net.minecraft.client.renderer.texture.atlas.sources.LazyLoadedImage
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
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 ru.dbotthepony.kommons.math.RGBAColor
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters.loc
|
||||
|
||||
class ColorizedSpriteSource(val textures: Map<ResourceLocation, ResourceLocation>) : 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()
|
||||
|
||||
DyeColor.entries.forEach {
|
||||
val outputLocation = entry.key.withSuffix("/" + it.serializedName)
|
||||
|
||||
val baseImage = LazyLoadedImage(entry.key, baseRes, 1)
|
||||
val maskImage = LazyLoadedImage(entry.value, maskRes, 1)
|
||||
|
||||
output.add(outputLocation, Supplier(baseImage, maskImage, it, outputLocation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun type(): SpriteSourceType {
|
||||
return SPRITE_SOURCE!!
|
||||
}
|
||||
|
||||
class Supplier(val baseImage: LazyLoadedImage, val maskImage: LazyLoadedImage, val color: DyeColor, val outputLocation: ResourceLocation) : SpriteSource.SpriteSupplier {
|
||||
override fun apply(t: SpriteResourceLoader?): SpriteContents? {
|
||||
val base = baseImage.get()
|
||||
val mask = maskImage.get()
|
||||
|
||||
if (base.width != mask.width || base.height != mask.height) {
|
||||
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
|
||||
|
||||
RGBAColor(r * diffCol.red, g * diffCol.green, b * diffCol.blue, a).toRGBA()
|
||||
}
|
||||
|
||||
for (i in 0 until base.width) {
|
||||
for (j in 0 until base.height) {
|
||||
base.blendPixel(i, j, mask.getPixelRGBA(i, j))
|
||||
}
|
||||
}
|
||||
|
||||
maskImage.release()
|
||||
|
||||
return SpriteContents(outputLocation, FrameSize(base.width, base.height), base, ResourceMetadata.EMPTY)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LOCATION = loc("colorized")
|
||||
|
||||
private val CODEC: MapCodec<ColorizedSpriteSource> = RecordCodecBuilder.mapCodec {
|
||||
it.group(
|
||||
Codec.unboundedMap(ResourceLocation.CODEC, ResourceLocation.CODEC).fieldOf("textures").forGetter { it.textures }
|
||||
).apply(it, ::ColorizedSpriteSource)
|
||||
}
|
||||
|
||||
var SPRITE_SOURCE: SpriteSourceType? = null
|
||||
|
||||
fun register(event: RegisterSpriteSourceTypesEvent) {
|
||||
SPRITE_SOURCE = event.register(LOCATION, CODEC)
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 607 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 732 B |
Before Width: | Height: | Size: 648 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 793 B |
Before Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 787 B |
Before Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 586 B |