Fully remove Optifine CTM code
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
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.common.Int3
|
||||
import mods.octarinecore.metaprog.allAvailable
|
||||
import mods.octarinecore.metaprog.reflectField
|
||||
import net.minecraft.block.state.BlockStateBase
|
||||
import net.minecraft.block.state.IBlockState
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
|
||||
import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.util.math.BlockPos
|
||||
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 CTM.
|
||||
*
|
||||
* Currently broken and unused
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@SideOnly(Side.CLIENT)
|
||||
object OptifineCTM {
|
||||
|
||||
val isCTMAvailable = allAvailable(
|
||||
Refs.ConnectedTextures, Refs.ConnectedProperties,
|
||||
Refs.getConnectedTexture,
|
||||
Refs.CTblockProperties, Refs.CTtileProperties,
|
||||
Refs.CPtileIcons, Refs.CPmatchesIcon
|
||||
)
|
||||
|
||||
init {
|
||||
Client.log(INFO, "Optifine CTM support is ${if (isCTMAvailable) "enabled" else "disabled" }")
|
||||
}
|
||||
|
||||
val renderEnv by ThreadLocalDelegate { OptifineRenderEnv() }
|
||||
|
||||
val isCustomColors: Boolean get() = if (!isCTMAvailable) false else Minecraft.getMinecraft().gameSettings.reflectField<Boolean>("ofCustomColors") ?: false
|
||||
|
||||
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 || !isCTMAvailable) return result
|
||||
|
||||
connectedProperties.forEach { cp ->
|
||||
if (Refs.CPmatchesBlock.invoke(cp, Refs.getBlockId.invoke(state), Refs.getMetadata.invoke(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 getAllCTM(states: List<IBlockState>, icon: TextureAtlasSprite): Collection<TextureAtlasSprite> =
|
||||
states.flatMap { getAllCTM(it, icon) }.toSet()
|
||||
|
||||
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 (!isCTMAvailable) 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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,18 @@ 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.common.Int3
|
||||
import mods.octarinecore.metaprog.allAvailable
|
||||
import mods.octarinecore.metaprog.reflectField
|
||||
import net.minecraft.block.state.IBlockState
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
|
||||
import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.fml.relauncher.Side
|
||||
import net.minecraftforge.fml.relauncher.SideOnly
|
||||
import org.apache.logging.log4j.Level
|
||||
@@ -29,13 +33,28 @@ object OptifineCustomColors {
|
||||
Client.log(Level.INFO, "Optifine custom color support is ${if (isColorAvailable) "enabled" else "disabled" }")
|
||||
}
|
||||
|
||||
val renderEnv by ThreadLocalDelegate { OptifineRenderEnv() }
|
||||
val fakeQuad = BakedQuad(IntArray(0), 1, EnumFacing.UP, null, true, DefaultVertexFormats.BLOCK)
|
||||
|
||||
fun getBlockColor(ctx: BlockContext): Int {
|
||||
val ofColor = if (isColorAvailable && Minecraft.getMinecraft().gameSettings.reflectField<Boolean>("ofCustomColors") == true) {
|
||||
OptifineCTM.renderEnv.reset(ctx.world!!, ctx.blockState(Int3.zero), ctx.pos)
|
||||
Refs.getColorMultiplier.invokeStatic(fakeQuad, ctx.blockState(Int3.zero), ctx.world!!, ctx.pos, OptifineCTM.renderEnv.wrapped) as? Int
|
||||
renderEnv.reset(ctx.world!!, ctx.blockState(Int3.zero), ctx.pos)
|
||||
Refs.getColorMultiplier.invokeStatic(fakeQuad, ctx.blockState(Int3.zero), ctx.world!!, ctx.pos, renderEnv.wrapped) as? Int
|
||||
} else null
|
||||
return if (ofColor == null || ofColor == -1) ctx.blockData(Int3.zero).color else ofColor
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ 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.OptifineCustomColors
|
||||
import mods.betterfoliage.client.integration.ShadersModIntegration
|
||||
import mods.betterfoliage.client.texture.GrassRegistry
|
||||
|
||||
@@ -3,7 +3,6 @@ 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.OptifineCustomColors
|
||||
import mods.betterfoliage.client.integration.ShadersModIntegration
|
||||
import mods.betterfoliage.client.texture.LeafRegistry
|
||||
|
||||
@@ -2,7 +2,6 @@ package mods.betterfoliage.client.texture
|
||||
|
||||
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.HSB
|
||||
import mods.octarinecore.client.resource.*
|
||||
|
||||
@@ -3,7 +3,6 @@ package mods.betterfoliage.client.texture
|
||||
import mods.betterfoliage.BetterFoliageMod
|
||||
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.*
|
||||
import mods.octarinecore.common.Int3
|
||||
|
||||
@@ -26,6 +26,7 @@ object Refs {
|
||||
|
||||
val World = ClassRef("net.minecraft.world.World")
|
||||
val WorldClient = ClassRef("net.minecraft.client.multiplayer.WorldClient")
|
||||
val ChunkCache = ClassRef("net.minecraft.world.ChunkCache")
|
||||
val showBarrierParticles = MethodRef(WorldClient, "showBarrierParticles", "func_184153_a", ClassRef.void, ClassRef.int, ClassRef.int, ClassRef.int, ClassRef.int, Random, ClassRef.boolean, MutableBlockPos)
|
||||
|
||||
val Block = ClassRef("net.minecraft.block.Block")
|
||||
@@ -89,30 +90,21 @@ object Refs {
|
||||
|
||||
// Optifine
|
||||
val OptifineClassTransformer = ClassRef("optifine.OptiFineClassTransformer")
|
||||
val OptifineChunkCache = ClassRef("net.optifine.override.ChunkCacheOF")
|
||||
val CCOFChunkCache = FieldRef(OptifineChunkCache, "chunkCache", ChunkCache)
|
||||
|
||||
val getBlockId = MethodRef(BlockStateBase, "getBlockId", ClassRef.int);
|
||||
val getMetadata = MethodRef(BlockStateBase, "getMetadata", ClassRef.int);
|
||||
|
||||
// Optifine: CTM
|
||||
// Optifine
|
||||
val RenderEnv = ClassRef("net.optifine.render.RenderEnv")
|
||||
val RenderEnv_reset = MethodRef(RenderEnv, "reset", ClassRef.void, IBlockAccess, IBlockState, BlockPos)
|
||||
val ConnectedTextures = ClassRef("net.optifine.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("net.optifine.ConnectedProperties")
|
||||
val CPtileIcons = FieldRef(ConnectedProperties, "tileIcons", null)
|
||||
val CPmatchesBlock = MethodRef(ConnectedProperties, "matchesBlock", ClassRef.boolean, ClassRef.int, ClassRef.int)
|
||||
val CPmatchesIcon = MethodRef(ConnectedProperties, "matchesIcon", ClassRef.boolean, TextureAtlasSprite)
|
||||
|
||||
val quadSprite = FieldRef(BufferBuilder, "quadSprite", TextureAtlasSprite)
|
||||
|
||||
// Optifine: custom colors
|
||||
val CustomColors = ClassRef("net.optifine.CustomColors")
|
||||
val getColorMultiplier = MethodRef(CustomColors, "getColorMultiplier", ClassRef.int, BakedQuad, IBlockState, IBlockAccess, BlockPos, RenderEnv)
|
||||
|
||||
|
||||
// Optifine: shaders
|
||||
val SVertexBuilder = ClassRef("net.optifine.shaders.SVertexBuilder")
|
||||
val sVertexBuilder = FieldRef(BufferBuilder, "sVertexBuilder", SVertexBuilder)
|
||||
|
||||
Reference in New Issue
Block a user