Merge branch 'kotlin-1.8' into kotlin-1.8.8

This commit is contained in:
octarine-noise
2016-01-29 11:32:33 +01:00
14 changed files with 170 additions and 35 deletions

View File

@@ -2,7 +2,7 @@ apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: 'kotlin'
group = 'com.github.octarine-noise'
version = "2.0.2"
version = "2.0.3"
archivesBaseName = rootProject.name + '-MC1.8.x'
buildscript {

View File

@@ -2,6 +2,7 @@ package mods.betterfoliage.client
import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.gui.ConfigGuiFactory
import mods.betterfoliage.client.integration.OptifineCTM
import mods.betterfoliage.client.integration.ShadersModIntegration
import mods.betterfoliage.client.render.*
import mods.betterfoliage.client.texture.GrassGenerator
@@ -66,7 +67,8 @@ object Client {
GrassRegistry,
LeafWindTracker,
RisingSoulTextures,
ShadersModIntegration
ShadersModIntegration,
OptifineCTM
)
fun log(level: Level, msg: String) = BetterFoliageMod.log!!.log(level, msg)

View File

@@ -0,0 +1,86 @@
package mods.betterfoliage.client.integration
import mods.betterfoliage.client.Client
import mods.betterfoliage.loader.Refs
import mods.octarinecore.ThreadLocalDelegate
import mods.octarinecore.client.render.BlockContext
import mods.octarinecore.metaprog.allAvailable
import net.minecraft.block.Block
import net.minecraft.block.state.BlockStateBase
import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.world.IBlockAccess
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import org.apache.logging.log4j.Level.INFO
/**
* Integration for OptiFine.
*/
@Suppress("UNCHECKED_CAST")
@SideOnly(Side.CLIENT)
object OptifineCTM {
val isAvailable = allAvailable(Refs.ConnectedTextures, Refs.ConnectedProperties, Refs.getConnectedTexture,
Refs.CTblockProperties, Refs.CTtileProperties, Refs.CPtileIcons, Refs.CPmatchesBlock, Refs.CPmatchesIcon)
init {
Client.log(INFO, "Optifine CTM support is ${if (isAvailable) "enabled" else "disabled" }")
}
val renderEnv by ThreadLocalDelegate { OptifineRenderEnv() }
val connectedProperties: Iterable<Any> get() {
val result = hashSetOf<Any>()
(Refs.CTblockProperties.getStatic() as Array<Array<Any?>?>?)?.forEach { cpArray ->
cpArray?.forEach { if (it != null) result.add(it) }
}
(Refs.CTtileProperties.getStatic() as Array<Array<Any?>?>?)?.forEach { cpArray ->
cpArray?.forEach { if (it != null) result.add(it) }
}
return result
}
/** Get all the CTM [TextureAtlasSprite]s that could possibly be used for this block. */
fun getAllCTM(state: IBlockState, icon: TextureAtlasSprite): Collection<TextureAtlasSprite> {
val result = hashSetOf<TextureAtlasSprite>()
if (state !is BlockStateBase) return result
connectedProperties.forEach { cp ->
if (Refs.CPmatchesBlock.invoke(cp, state) as Boolean &&
Refs.CPmatchesIcon.invoke(cp, icon) as Boolean) {
Client.log(INFO, "Match for block: ${state.toString()}, icon: ${icon.iconName} -> CP: ${cp.toString()}")
result.addAll(Refs.CPtileIcons.get(cp) as Array<TextureAtlasSprite>)
}
}
return result
}
fun override(texture: TextureAtlasSprite, ctx: BlockContext, face: EnumFacing) =
override(texture, ctx.world!!, ctx.pos, face)
fun override(texture: TextureAtlasSprite, world: IBlockAccess, pos: BlockPos, face: EnumFacing): TextureAtlasSprite {
if (!isAvailable) return texture
val state = world.getBlockState(pos)
return renderEnv.let {
it.reset(world, state, pos)
Refs.getConnectedTexture.invokeStatic(world, state, pos, face, texture, it.wrapped) as TextureAtlasSprite
}
}
}
class OptifineRenderEnv {
val wrapped: Any = Refs.RenderEnv.element!!.getDeclaredConstructor(
Refs.IBlockAccess.element, Refs.IBlockState.element, Refs.BlockPos.element
).let {
it.isAccessible = true
it.newInstance(null, null, null)
}
fun reset(blockAccess: IBlockAccess, state: IBlockState, pos: BlockPos) {
Refs.RenderEnv_reset.invoke(wrapped, blockAccess, state, pos)
}
}

View File

@@ -27,7 +27,7 @@ open class ColumnTextures(val matcher: BlockMatcher) : BlockTextureInspector<Col
matchClassAndModel(matcher, "block/column_side", listOf("end", "end", "side"))
matchClassAndModel(matcher, "block/cube_column", listOf("end", "end", "side"))
}
override fun processTextures(textures: List<TextureAtlasSprite>, atlas: TextureMap) =
override fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap) =
ColumnInfo(textures[0], textures[1], textures[2])
}

View File

@@ -11,6 +11,7 @@ import mods.octarinecore.random
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.WorldRenderer
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing.*
import net.minecraft.util.MathHelper
import net.minecraft.world.World
import net.minecraftforge.common.MinecraftForge
@@ -42,7 +43,7 @@ AbstractEntityFX(world, pos.x.toDouble() + 0.5, pos.y.toDouble(), pos.z.toDouble
particleScale = Config.fallingLeaves.size.toFloat() * 0.1f
val state = world.getBlockState(pos)
LeafRegistry[world.getBlockState(pos)]?.let {
LeafRegistry[state, world, pos, DOWN]?.let {
particleIcon = it.particleTextures[rand.nextInt(1024)]
calculateParticleColor(it.averageColor, state.block.colorMultiplier(world, pos))
}

View File

@@ -3,6 +3,7 @@ package mods.betterfoliage.client.render
import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.Client
import mods.betterfoliage.client.config.Config
import mods.betterfoliage.client.integration.OptifineCTM
import mods.betterfoliage.client.integration.ShadersModIntegration
import mods.betterfoliage.client.texture.GrassRegistry
import mods.octarinecore.client.render.*
@@ -55,6 +56,8 @@ class RenderGrass : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
val connectedGrass = isConnected && Config.connectedGrass.enabled && (!isSnowed || Config.connectedGrass.snowEnabled)
val grassInfo = GrassRegistry[ctx.blockState(Int3.zero)] ?: return renderWorldBlockBase(ctx, dispatcher, renderer, layer)
val grassTopTexture = OptifineCTM.override(grassInfo.grassTopTexture, ctx, UP)
val blockColor = ctx.blockData(Int3.zero, 0).color
if (connectedGrass) {
@@ -67,7 +70,7 @@ class RenderGrass : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
fullCube,
Rotation.identity,
ctx.blockCenter,
icon = { ctx, qi, q -> grassInfo.grassTopTexture },
icon = { ctx, qi, q -> grassTopTexture },
rotateUV = { 2 },
postProcess = { ctx, qi, q, vi, v ->
if (isSnowed) { if(!ctx.aoEnabled) setGrey(1.4f) }

View File

@@ -2,6 +2,7 @@ package mods.betterfoliage.client.render
import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.config.Config
import mods.betterfoliage.client.integration.OptifineCTM
import mods.betterfoliage.client.integration.ShadersModIntegration
import mods.betterfoliage.client.texture.LeafRegistry
import mods.octarinecore.PI2
@@ -15,9 +16,8 @@ import net.minecraft.block.material.Material
import net.minecraft.client.renderer.BlockRendererDispatcher
import net.minecraft.client.renderer.WorldRenderer
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumFacing.UP
import net.minecraft.util.EnumFacing.*
import net.minecraft.util.EnumWorldBlockLayer
import net.minecraft.util.EnumFacing.Axis
import java.lang.Math.cos
import java.lang.Math.sin
@@ -49,7 +49,7 @@ class RenderLeaves : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
it == Material.snow || it == Material.craftedSnow
}
renderWorldBlockBase(ctx, dispatcher, renderer, null)
val leafInfo = LeafRegistry[ctx.blockState(Int3.zero)] ?: return true
val leafInfo = LeafRegistry[ctx, DOWN] ?: return false
val blockColor = ctx.blockData(Int3.zero, 0).color
modelRenderer.updateShading(Int3.zero, allFaces)

View File

@@ -2,16 +2,17 @@ package mods.betterfoliage.client.render
import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.config.Config
import mods.betterfoliage.client.integration.OptifineCTM
import mods.octarinecore.client.render.BlockContext
import mods.octarinecore.client.render.Quad
import mods.octarinecore.client.render.ShadingContext
import mods.octarinecore.client.resource.BlockTextureInspector
import mods.octarinecore.client.render.blockContext
import mods.octarinecore.common.Int3
import mods.octarinecore.common.rotate
import mods.octarinecore.tryDefault
import net.minecraft.block.BlockLog
import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.renderer.texture.TextureMap
import net.minecraft.util.EnumFacing.Axis
import net.minecraft.util.EnumFacing.*
class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
@@ -21,7 +22,8 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
Config.blocks.logs.matchesID(ctx.block)
override var axisFunc = { state: IBlockState ->
when (state.getValue(BlockLog.LOG_AXIS).toString()) {
val axis = tryDefault("none") { state.getValue(BlockLog.LOG_AXIS).toString() }
when (axis) {
"x" -> Axis.X
"z" -> Axis.Z
else -> Axis.Y
@@ -40,12 +42,20 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
override val radiusSmall: Double get() = Config.roundLogs.radiusSmall
override val downTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.bottomTexture
columnTextures[ctx.blockData(Int3.zero).state]?.bottomTexture?.let { base ->
OptifineCTM.override(base, blockContext, DOWN.rotate(ctx.rotation))
}
}
override val sideTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.sideTexture
columnTextures[ctx.blockData(Int3.zero).state]?.sideTexture?.let { base ->
OptifineCTM.override(base, blockContext, (if ((idx and 1) == 0) SOUTH else EAST).rotate(ctx.rotation))
}
}
override val upTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.topTexture
columnTextures[ctx.blockData(Int3.zero).state]?.topTexture?.let { base ->
OptifineCTM.override(base, blockContext, UP.rotate(ctx.rotation))
}
}
}

View File

@@ -3,15 +3,11 @@ package mods.betterfoliage.client.texture
import mods.betterfoliage.client.Client
import mods.betterfoliage.client.config.Config
import mods.octarinecore.client.render.HSB
import mods.octarinecore.client.resource.*
import mods.octarinecore.client.resource.BlockTextureInspector
import mods.octarinecore.client.resource.averageColor
import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.renderer.texture.TextureMap
import net.minecraft.client.resources.model.ModelResourceLocation
import net.minecraftforge.client.event.TextureStitchEvent
import net.minecraftforge.client.model.IModel
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import org.apache.logging.log4j.Level.INFO
@@ -46,7 +42,7 @@ object GrassRegistry : BlockTextureInspector<GrassInfo>() {
Client.log(INFO, "Inspecting grass textures")
}
override fun processTextures(textures: List<TextureAtlasSprite>, atlas: TextureMap): GrassInfo {
override fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap): GrassInfo {
val hsb = HSB.fromColor(textures[0].averageColor ?: defaultGrassColor)
val overrideColor = if (hsb.saturation > Config.shortGrass.saturationThreshold) hsb.copy(brightness = 0.8f).asColor else null
return GrassInfo(textures[0], overrideColor)

View File

@@ -2,12 +2,19 @@ package mods.betterfoliage.client.texture
import mods.betterfoliage.client.Client
import mods.betterfoliage.client.config.Config
import mods.betterfoliage.client.integration.OptifineCTM
import mods.octarinecore.client.render.BlockContext
import mods.octarinecore.client.resource.BlockTextureInspector
import mods.octarinecore.client.resource.IconSet
import mods.octarinecore.client.resource.averageColor
import mods.octarinecore.common.Int3
import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.renderer.texture.TextureMap
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.ResourceLocation
import net.minecraft.world.IBlockAccess
import net.minecraftforge.client.event.TextureStitchEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -35,8 +42,9 @@ class LeafInfo(
/** Collects and manages rendering-related information for leaf blocks. */
@SideOnly(Side.CLIENT)
object LeafRegistry : BlockTextureInspector<LeafInfo>() {
object LeafRegistry : BlockTextureInspector<TextureAtlasSprite>() {
val leaves: MutableMap<TextureAtlasSprite, LeafInfo> = hashMapOf()
val particles: MutableMap<String, IconSet> = hashMapOf()
val typeMappings = TextureMatcher()
@@ -44,6 +52,13 @@ object LeafRegistry : BlockTextureInspector<LeafInfo>() {
matchClassAndModel(Config.blocks.leaves, "minecraft:block/leaves", listOf("all"))
}
operator fun get(state: IBlockState, world: IBlockAccess, pos: BlockPos, face: EnumFacing): LeafInfo? {
val baseTexture = get(state) ?: return null
return leaves[OptifineCTM.override(baseTexture, world, pos, face)] ?: leaves[baseTexture]
}
operator fun get(ctx: BlockContext, face: EnumFacing) = get(ctx.blockState(Int3.zero), ctx.world!!, ctx.pos, face)
override fun onAfterModelLoad() {
super.onAfterModelLoad()
Client.log(INFO, "Inspecting leaf textures")
@@ -51,8 +66,14 @@ object LeafRegistry : BlockTextureInspector<LeafInfo>() {
typeMappings.loadMappings(ResourceLocation("betterfoliage", "leafTextureMappings.cfg"))
}
override fun processTextures(textures: List<TextureAtlasSprite>, atlas: TextureMap): LeafInfo {
override fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap): TextureAtlasSprite {
val texture = textures[0]
registerLeaf(texture, atlas)
OptifineCTM.getAllCTM(state, texture).forEach { registerLeaf(it, atlas) }
return texture
}
fun registerLeaf(texture: TextureAtlasSprite, atlas: TextureMap) {
var leafType = typeMappings.getType(texture) ?: "default"
val generated = atlas.registerSprite(
Client.genLeaves.generatedResource(texture.iconName, "type" to leafType)
@@ -69,6 +90,6 @@ object LeafRegistry : BlockTextureInspector<LeafInfo>() {
}
}
return LeafInfo(generated as TextureAtlasSprite, leafType)
leaves[texture] = LeafInfo(generated, leafType)
}
}

View File

@@ -17,6 +17,7 @@ object Refs {
// Minecraft
val IBlockAccess = ClassRef("net.minecraft.world.IBlockAccess", "adq")
val IBlockState = ClassRef("net.minecraft.block.state.IBlockState", "alz")
val BlockStateBase = ClassRef("net.minecraft.block.state.BlockStateBase", "aly")
val BlockPos = ClassRef("net.minecraft.util.BlockPos", "cj")
val EnumWorldBlockLayer = ClassRef("net.minecraft.util.EnumWorldBlockLayer", "adf")
val EnumFacing = ClassRef("net.minecraft.util.EnumFacing", "cq")
@@ -79,6 +80,18 @@ object Refs {
// Optifine
val OptifineClassTransformer = ClassRef("optifine.OptiFineClassTransformer")
val RenderEnv = ClassRef("RenderEnv")
val RenderEnv_reset = MethodRef(RenderEnv, "reset", ClassRef.void, IBlockAccess, IBlockState, BlockPos)
val ConnectedTextures = ClassRef("ConnectedTextures")
val getConnectedTexture = MethodRef(ConnectedTextures, "getConnectedTextureMultiPass", TextureAtlasSprite, IBlockAccess, IBlockState, BlockPos, EnumFacing, TextureAtlasSprite, RenderEnv)
val CTblockProperties = FieldRef(ConnectedTextures, "blockProperties", null)
val CTtileProperties = FieldRef(ConnectedTextures, "tileProperties", null)
val ConnectedProperties = ClassRef("ConnectedProperties")
val CPtileIcons = FieldRef(ConnectedProperties, "tileIcons", null)
val CPmatchesBlock = MethodRef(ConnectedProperties, "matchesBlock", ClassRef.boolean, BlockStateBase)
val CPmatchesIcon = MethodRef(ConnectedProperties, "matchesIcon", ClassRef.boolean, TextureAtlasSprite)
// ShadersMod
val SVertexBuilder = ClassRef("shadersmod.client.SVertexBuilder")
val sVertexBuilder = FieldRef(WorldRenderer, "sVertexBuilder", SVertexBuilder)

View File

@@ -17,6 +17,7 @@ import net.minecraftforge.client.model.IModel
import net.minecraftforge.client.model.ModelLoader
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.eventhandler.Event
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class LoadModelDataEvent(val loader: ModelLoader) : Event()
@@ -33,7 +34,7 @@ abstract class ModelDataInspector {
@SubscribeEvent
fun handleLoadModelData(event: LoadModelDataEvent) {
val stateMappings = Block.blockRegistry.flatMap { block ->
((event.loader.blockModelShapes.blockStateMapper.blockStateMap[block]as? IStateMapper ?: DefaultStateMapper())
((event.loader.blockModelShapes.blockStateMapper.blockStateMap[block] as? IStateMapper ?: DefaultStateMapper())
.putStateModelLocations(block as Block) as Map<IBlockState, ModelResourceLocation>).entries
}
val stateModels = Refs.stateModels.get(event.loader) as Map<ModelResourceLocation, IModel>
@@ -48,7 +49,7 @@ abstract class ModelDataInspector {
}
}
@SubscribeEvent
@SubscribeEvent(priority = EventPriority.LOW)
fun handleTextureReload(event: TextureStitchEvent.Pre) { onStitch(event.map) }
}
@@ -56,17 +57,17 @@ abstract class BlockTextureInspector<T> : ModelDataInspector() {
val state2Names = hashMapOf<IBlockState, Iterable<String>>()
val modelMappings = linkedListOf<Pair<(IBlockState, IModel)->Boolean, Iterable<String>>>()
val infoMap = hashMapOf<IBlockState, T>()
val stateMap = hashMapOf<IBlockState, T>()
fun match(textureNames: Iterable<String>, predicate: (IBlockState, IModel)->Boolean) =
modelMappings.add(predicate to textureNames)
fun matchClassAndModel(blockClass: BlockMatcher, modelLocation: String, textureNames: Iterable<String>) =
match(textureNames) { state, model -> blockClass.matchesClass(state.block) && model.derivesFromModel(modelLocation) }
operator fun get(state: IBlockState) = infoMap[state]
operator fun get(state: IBlockState) = stateMap[state]
override fun onAfterModelLoad() {
infoMap.clear()
stateMap.clear()
}
override fun processModelDefinition(state: IBlockState, modelDefLoc: ModelResourceLocation, model: IModel) {
@@ -89,14 +90,14 @@ abstract class BlockTextureInspector<T> : ModelDataInspector() {
val textures = textureNames.map { atlas.getTextureExtry(ResourceLocation(it).toString()) }
if (textures.all { it != null }) {
state2Texture.put(state, textures)
if (textures !in texture2Info) texture2Info.put(textures, processTextures(textures, atlas))
if (textures !in texture2Info) texture2Info.put(textures, processTextures(state, textures, atlas))
}
}
state2Texture.forEach { state, texture -> infoMap.put(state, texture2Info[texture]!!) }
state2Texture.forEach { state, texture -> stateMap.put(state, texture2Info[texture]!!) }
state2Names.clear()
}
abstract fun processTextures(textures: List<TextureAtlasSprite>, atlas: TextureMap): T
abstract fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap): T
}
@Suppress("UNCHECKED_CAST")

View File

@@ -93,6 +93,7 @@ class IconSet(val domain: String, val namePattern: String) : IStitchListener {
override fun onStitch(atlas: TextureMap) {
num = 0;
(0..15).forEach { idx ->
icons[idx] = null
val locReal = ResourceLocation(domain, "textures/${namePattern.format(idx)}.png")
if (resourceManager[locReal] != null) icons[num++] = atlas.registerSprite(ResourceLocation(domain, namePattern.format(idx)))
}

View File

@@ -87,5 +87,6 @@ val TextureAtlasSprite.averageColor: Int? get() {
* Get the actual location of a texture from the name of its [TextureAtlasSprite].
*/
fun textureLocation(iconName: String) = ResourceLocation(iconName).let {
ResourceLocation(it.resourceDomain, "textures/${it.resourcePath}")
if (it.resourcePath.startsWith("mcpatcher")) it
else ResourceLocation(it.resourceDomain, "textures/${it.resourcePath}")
}