[WIP] more fixes and final touch-up

This commit is contained in:
octarine-noise
2020-01-17 17:33:32 +01:00
parent 2252fb3b42
commit 802862f151
16 changed files with 70 additions and 61 deletions

View File

@@ -1,7 +1,6 @@
package mods.betterfoliage.mixin;
import mods.betterfoliage.BetterFoliage;
import mods.octarinecore.client.resource.AsnycSpriteProviderManager;
import net.minecraft.client.renderer.model.ModelBakery;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.profiler.IProfiler;
@@ -19,9 +18,12 @@ abstract public class MixinModelBakery {
@Redirect(method = processLoading, at = @At(value = "INVOKE", target = stitch))
AtlasTexture.SheetData onStitchModelTextures(AtlasTexture atlas, IResourceManager manager, Iterable<ResourceLocation> idList, IProfiler profiler) {
AsnycSpriteProviderManager.StitchWrapper wrapper = BetterFoliage.INSTANCE.getBlockSprites().prepare(this, atlas, manager, idList, profiler);
AtlasTexture.SheetData sheet = atlas.stitch(manager, wrapper.getIdList(), profiler);
wrapper.complete(sheet);
return sheet;
return BetterFoliage.INSTANCE.getBlockSprites().finish(
atlas.stitch(
manager,
BetterFoliage.INSTANCE.getBlockSprites().prepare(this, manager, idList, profiler),
profiler
), profiler
);
}
}

View File

@@ -21,9 +21,13 @@ public class MixinParticleManager {
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "*", at = @At(value = "INVOKE", target = stitch))
AtlasTexture.SheetData onStitchModelTextures(AtlasTexture atlas, IResourceManager manager, Iterable<ResourceLocation> idList, IProfiler profiler) {
AsnycSpriteProviderManager.StitchWrapper wrapper = BetterFoliage.INSTANCE.getParticleSprites().prepare(this, atlas, manager, idList, profiler);
AtlasTexture.SheetData sheet = atlas.stitch(manager, wrapper.getIdList(), profiler);
wrapper.complete(sheet);
return sheet;
return BetterFoliage.INSTANCE.getParticleSprites().finish(
atlas.stitch(
manager,
BetterFoliage.INSTANCE.getParticleSprites().prepare(this, manager, idList, profiler),
profiler
), profiler
);
}
}

View File

@@ -57,10 +57,10 @@ object Client {
// init mod integrations
val integrations = listOf(
ShadersModIntegration,
OptifineCustomColors,
ForestryIntegration,
IC2RubberIntegration,
TechRebornRubberIntegration
OptifineCustomColors
// ForestryIntegration,
// IC2RubberIntegration,
// TechRebornRubberIntegration
)
LeafParticleRegistry.init()

View File

@@ -120,7 +120,7 @@ object Config : DelegatingConfig(BetterFoliageMod.MOD_ID, BetterFoliageMod.MOD_I
val windStrength by double(min=0.1, max=2.0, default=0.5)
val stormStrength by double(min=0.1, max=2.0, default=0.8)
val size by double(min=0.25, max=1.5, default=0.75).lang("size")
val chance by double(min=0.001, max=1.0, default=0.05)
val chance by double(min=0.001, max=1.0, default=0.02)
val perturb by double(min=0.01, max=1.0, default=0.25)
val lifetime by double(min=1.0, max=15.0, default=5.0)
val opacityHack by boolean(true)
@@ -153,10 +153,7 @@ object BlockConfig {
val crops = blocks("crop_default.cfg")
val logBlocks = blocks("log_blocks_default.cfg")
val logModels = models("log_models_default.cfg")
val sand = blocks("sand_default.cfg")
val lilypad = blocks("lilypad_default.cfg")
val cactus = blocks("cactus_default.cfg")
val netherrack = blocks("netherrack_blocks_default.cfg")
init { BetterFoliageMod.bus.register(this) }
private fun blocks(cfgName: String) = ConfigurableBlockMatcher(BetterFoliage.logDetail, ResourceLocation(BetterFoliageMod.MOD_ID, cfgName)).apply { list.add(this) }

View File

@@ -54,6 +54,7 @@ val ILeafSpriteProvider_getSprite = MethodRef(ILeafSpriteProvider, "getSprite",
object ForestryIntegration {
init {
if (ModList.get().isLoaded("forestry") && allAvailable(TileLeaves_getLeaveSprite, IAlleleTreeSpecies_getLeafSpriteProvider, ILeafSpriteProvider_getSprite)) {
// Just keep it inactive for now until Forestry updates
}
}
}

View File

@@ -4,6 +4,7 @@ import mods.betterfoliage.BetterFoliage
import mods.betterfoliage.client.render.LogRegistry
import mods.betterfoliage.client.render.column.ColumnTextureInfo
import mods.betterfoliage.client.render.column.SimpleColumnInfo
import mods.betterfoliage.client.resource.Sprite
import mods.octarinecore.client.render.CombinedContext
import mods.octarinecore.client.render.Quad
import mods.octarinecore.client.render.lighting.QuadIconResolver
@@ -12,7 +13,6 @@ import mods.octarinecore.common.rotate
import mods.octarinecore.metaprog.ClassRef
import mods.octarinecore.metaprog.allAvailable
import net.minecraft.client.renderer.model.BlockModel
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.util.Direction
import net.minecraft.util.Direction.*
import net.minecraft.util.ResourceLocation
@@ -20,19 +20,23 @@ import net.minecraftforge.fml.ModList
import org.apache.logging.log4j.Level
import java.util.concurrent.CompletableFuture
object IC2RubberIntegration {
val BlockRubWood = ClassRef<Any>("ic2.core.block.BlockRubWood")
init {
if (ModList.get().isLoaded("ic2") && allAvailable(BlockRubWood)) {
BetterFoliage.log(Level.INFO, "IC2 rubber support initialized")
LogRegistry.registries.add(IC2LogDiscovery)
BetterFoliage.blockSprites.providers.add(IC2LogDiscovery)
// keep it inactive for now until IC2 updates
// BetterFoliage.log(Level.INFO, "IC2 rubber support initialized")
// LogRegistry.registries.add(IC2LogDiscovery)
// BetterFoliage.blockSprites.providers.add(IC2LogDiscovery)
}
}
}
// Probably unneeded, as TechReborn went Fabric-only
/*
object TechRebornRubberIntegration {
val BlockRubberLog = ClassRef<Any>("techreborn.blocks.BlockRubberLog")
@@ -45,14 +49,15 @@ object TechRebornRubberIntegration {
}
}
}
*/
class RubberLogInfo(
axis: Axis?,
val spotDir: Direction,
topTexture: TextureAtlasSprite,
bottomTexture: TextureAtlasSprite,
val spotTexture: TextureAtlasSprite,
sideTextures: List<TextureAtlasSprite>
topTexture: Sprite,
bottomTexture: Sprite,
val spotTexture: Sprite,
sideTextures: List<Sprite>
) : SimpleColumnInfo(axis, topTexture, bottomTexture, sideTextures) {
override val side: QuadIconResolver = { ctx: CombinedContext, idx: Int, quad: Quad ->
@@ -116,6 +121,7 @@ object IC2LogDiscovery : ModelDiscovery<ColumnTextureInfo>() {
}
}
/*
object TechRebornLogDiscovery : ModelDiscovery<ColumnTextureInfo>() {
override val logger = BetterFoliage.logDetail
@@ -152,4 +158,5 @@ object TechRebornLogDiscovery : ModelDiscovery<ColumnTextureInfo>() {
}
return null
}
}
}
*/

View File

@@ -26,7 +26,7 @@ object ShadersModIntegration {
@JvmStatic val isAvailable = allAvailable(SVertexBuilder, SVertexBuilder.pushState, SVertexBuilder.pushNum, SVertexBuilder.pop)
val defaultLeaves = Blocks.OAK_LEAVES.defaultState
val defaultGrass = Blocks.TALL_GRASS.defaultState
val defaultGrass = Blocks.GRASS.defaultState
/**
* Called from transformed ShadersMod code.

View File

@@ -10,6 +10,7 @@ import mods.octarinecore.client.render.lighting.*
import mods.octarinecore.common.allDirections
import mods.octarinecore.random
import net.minecraft.block.material.Material
import net.minecraft.tags.BlockTags
import net.minecraft.util.Direction.Axis
import net.minecraft.util.Direction.UP
import net.minecraft.util.ResourceLocation
@@ -41,7 +42,7 @@ class RenderCoral : RenderDecorator(BetterFoliageMod.MOD_ID, BetterFoliageMod.bu
Config.enabled && Config.coral.enabled &&
(ctx.state(up2).material == Material.WATER || Config.coral.shallowWater) &&
ctx.state(up1).material == Material.WATER &&
BlockConfig.sand.matchesClass(ctx.state.block) &&
BlockTags.SAND.contains(ctx.state.block) &&
ctx.biome.category.let { it == Biome.Category.OCEAN || it == Biome.Category.BEACH } &&
noise[ctx.pos] < Config.coral.population

View File

@@ -40,8 +40,8 @@ class RenderGrass : RenderDecorator(BetterFoliageMod.MOD_ID, BetterFoliageMod.bu
val normalIcons = spriteSet { idx -> Identifier(BetterFoliageMod.MOD_ID, "blocks/better_grass_long_$idx") }
val snowedIcons = spriteSet { idx -> Identifier(BetterFoliageMod.MOD_ID, "blocks/better_grass_snowed_$idx") }
val normalGenIcon by sprite { GeneratedGrass(sprite = "minecraft:blocks/tallgrass", isSnowed = false).register(BetterFoliage.asyncPack) }
val snowedGenIcon by sprite { GeneratedGrass(sprite = "minecraft:blocks/tallgrass", isSnowed = true).register(BetterFoliage.asyncPack) }
val normalGenIcon by sprite { GeneratedGrass(sprite = "minecraft:blocks/tall_grass_top", isSnowed = false).register(BetterFoliage.asyncPack) }
val snowedGenIcon by sprite { GeneratedGrass(sprite = "minecraft:blocks/tall_grass_top", isSnowed = true).register(BetterFoliage.asyncPack) }
val grassModels = modelSet(64) { idx -> grassTopQuads(Config.shortGrass.heightMin, Config.shortGrass.heightMax)(idx) }

View File

@@ -9,6 +9,7 @@ import mods.betterfoliage.client.resource.Identifier
import mods.octarinecore.client.render.*
import mods.octarinecore.client.render.lighting.*
import mods.octarinecore.random
import net.minecraft.block.Blocks
import net.minecraft.util.Direction.Axis
import net.minecraft.util.Direction.*
import org.apache.logging.log4j.Level.DEBUG
@@ -25,10 +26,8 @@ class RenderNetherrack : RenderDecorator(BetterFoliageMod.MOD_ID, BetterFoliageM
}
override fun isEligible(ctx: CombinedContext): Boolean {
if (!Config.enabled || !Config.netherrack.enabled) return false
return BlockConfig.netherrack.matchesClass(ctx.state.block)
}
override fun isEligible(ctx: CombinedContext) =
Config.enabled && Config.netherrack.enabled && ctx.state.block == Blocks.NETHERRACK
override fun render(ctx: CombinedContext) {
ctx.render()

View File

@@ -10,7 +10,6 @@ import mods.octarinecore.client.resource.Atlas
import mods.octarinecore.common.sinkAsync
import net.minecraft.client.particle.ParticleManager
import net.minecraft.resources.IResourceManager
import net.minecraft.util.ResourceLocation
import java.util.concurrent.CompletableFuture
class FixedSpriteSet(val sprites: List<Sprite>) : SpriteSet {
@@ -58,7 +57,7 @@ object LeafParticleRegistry : AsyncSpriteProvider<ParticleManager> {
class TextureMatcher {
data class Mapping(val domain: String?, val path: String, val type: String) {
fun matches(iconLocation: ResourceLocation): Boolean {
fun matches(iconLocation: Identifier): Boolean {
return (domain == null || domain == iconLocation.namespace) &&
iconLocation.path.stripStart("blocks/").contains(path, ignoreCase = true)
}
@@ -66,10 +65,10 @@ class TextureMatcher {
val mappings: MutableList<Mapping> = mutableListOf()
fun getType(resource: ResourceLocation) = mappings.filter { it.matches(resource) }.map { it.type }.firstOrNull()
fun getType(iconName: String) = ResourceLocation(iconName).let { getType(it) }
fun getType(resource: Identifier) = mappings.filter { it.matches(resource) }.map { it.type }.firstOrNull()
fun getType(iconName: String) = Identifier(iconName).let { getType(it) }
fun loadMappings(mappingLocation: ResourceLocation) {
fun loadMappings(mappingLocation: Identifier) {
mappings.clear()
resourceManager[mappingLocation]?.getLines()?.let { lines ->
lines.filter { !it.startsWith("//") }.filter { !it.isEmpty() }.forEach { line ->

View File

@@ -34,22 +34,30 @@ class AsnycSpriteProviderManager<SOURCE: Any>(val profilerSection: String) {
fun complete(sheet: AtlasTexture.SheetData) = onComplete(sheet)
}
var currentAtlas: AtlasFuture? = null
var currentPhases: List<StitchPhases> = emptyList()
@Suppress("UNCHECKED_CAST")
fun prepare(sourceObj: Any, atlas: AtlasTexture, manager: IResourceManager, idList: Iterable<Identifier>, profiler: IProfiler): StitchWrapper {
fun prepare(sourceObj: Any, manager: IResourceManager, idList: Iterable<Identifier>, profiler: IProfiler): Set<Identifier> {
profiler.startSection(profilerSection)
val source = CompletableFuture<SOURCE>()
val atlasFuture = AtlasFuture(idList)
currentAtlas = AtlasFuture(idList)
val phases = providers.map { it.setup(manager, source, atlasFuture) }
currentPhases = providers.map { it.setup(manager, source, currentAtlas!!) }
source.complete(sourceObj as SOURCE)
phases.forEach { it.discovery.get() }
currentPhases.forEach { it.discovery.get() }
return StitchWrapper(atlasFuture.idSet) { sheet ->
atlasFuture.complete(sheet)
phases.forEach { it.cleanup.get() }
profiler.endSection()
}
return currentAtlas!!.idSet
}
fun finish(sheetData: AtlasTexture.SheetData, profiler: IProfiler): AtlasTexture.SheetData {
currentAtlas!!.complete(sheetData)
currentPhases.forEach { it.cleanup.get() }
currentAtlas = null
currentPhases = emptyList()
profiler.endSection()
return sheetData
}
}

View File

@@ -64,9 +64,9 @@ open class ResourceHandler(
// ============================
fun sprite(id: Identifier) = sprite { id }
fun sprite(idFunc: ()->Identifier) = AsyncSpriteDelegate(idFunc).apply { BetterFoliage.getSpriteManager(targetAtlas).providers.add(this) }
fun spriteSet(idFunc: (Int)->Identifier) = AsyncSpriteSet(idFunc).apply { BetterFoliage.getSpriteManager(targetAtlas).providers.add(this) }
fun spriteSet(idFunc: (Int)->Identifier) = AsyncSpriteSet(targetAtlas, idFunc).apply { BetterFoliage.getSpriteManager(targetAtlas).providers.add(this) }
fun spriteSetTransformed(check: (Int)->Identifier, register: (Identifier)->Identifier) =
AsyncSpriteSet(check, register).apply { BetterFoliage.getSpriteManager(targetAtlas).providers.add(this) }
AsyncSpriteSet(targetAtlas, check, register).apply { BetterFoliage.getSpriteManager(targetAtlas).providers.add(this) }
fun model(init: Model.()->Unit) = ModelHolder(init).apply { resources.add(this) }
fun modelSet(num: Int, init: Model.(Int)->Unit) = ModelSet(num, init).apply { resources.add(this) }
fun vectorSet(num: Int, init: (Int)-> Double3) = VectorSet(num, init).apply { resources.add(this) }
@@ -108,7 +108,7 @@ interface SpriteSet {
operator fun get(idx: Int): Sprite
}
class AsyncSpriteSet(val idFunc: (Int)->Identifier, val transform: (Identifier)->Identifier = { it }) : AsyncSpriteProvider<Any> {
class AsyncSpriteSet(val targetAtlas: Atlas = Atlas.BLOCKS, val idFunc: (Int)->Identifier, val transform: (Identifier)->Identifier = { it }) : AsyncSpriteProvider<Any> {
var num = 0
protected set
protected var sprites: List<Sprite> = emptyList()
@@ -119,7 +119,7 @@ class AsyncSpriteSet(val idFunc: (Int)->Identifier, val transform: (Identifier)-
return StitchPhases(
discovery = sourceF.sink {
list = (0 until 16).map { idFunc(it) }
.filter { manager.hasResource( Atlas.BLOCKS.wrap(it)) }
.filter { manager.hasResource( targetAtlas.wrap(it)) }
.map { transform(it) }
.map { atlas.sprite(it) }
},

View File

@@ -1,2 +0,0 @@
// Vanilla
net.minecraft.block.CactusBlock

View File

@@ -1,2 +0,0 @@
// Vanilla
net.minecraft.block.NetherrackBlock

View File

@@ -1,5 +0,0 @@
// Vanilla
net.minecraft.block.BlockSand
// TerraFirmaCraft
com.bioxx.tfc.Blocks.Terrain.BlockSand