package net.shadowfacts.phycon.client.util import net.minecraft.client.render.model.BakedModel import net.minecraft.client.render.model.ModelLoader import net.minecraft.client.render.model.ModelRotation import net.minecraft.client.texture.Sprite import net.minecraft.client.util.SpriteIdentifier import net.minecraft.util.DyeColor import net.minecraft.util.Identifier import net.shadowfacts.phycon.PhysicalConnectivity import java.util.function.Function /** * @author shadowfacts */ fun ModelLoader.bakeRecoloredCable( id: Identifier, rot: ModelRotation, textureGetter: Function, color: DyeColor ): BakedModel { val unbaked = getOrLoadModel(id) val wrappedTextureGetter: (SpriteIdentifier) -> Sprite = { var newId = it if (it.textureId.namespace == PhysicalConnectivity.MODID && it.textureId.path.startsWith("block/cable/color/")) { val newPath = it.textureId.path.replace("block/cable/color/", "block/cable/${color.getName()}/") newId = SpriteIdentifier(it.atlasId, Identifier(PhysicalConnectivity.MODID, newPath)) } textureGetter.apply(newId) } return unbaked.bake(this, wrappedTextureGetter, rot, id)!! }