port to MC 1.8
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package mods.betterfoliage.client.integration
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import mods.betterfoliage.client.Client
|
||||
import mods.betterfoliage.client.config.Config
|
||||
import mods.betterfoliage.loader.Refs
|
||||
import mods.octarinecore.metaprog.allAvailable
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockTallGrass
|
||||
import net.minecraft.block.state.IBlockState
|
||||
import net.minecraft.client.renderer.WorldRenderer
|
||||
import net.minecraft.init.Blocks
|
||||
import org.apache.logging.log4j.Level.*
|
||||
import net.minecraftforge.fml.relauncher.Side
|
||||
import net.minecraftforge.fml.relauncher.SideOnly
|
||||
import org.apache.logging.log4j.Level.INFO
|
||||
|
||||
/**
|
||||
* Integration for ShadersMod.
|
||||
@@ -17,37 +20,53 @@ import org.apache.logging.log4j.Level.*
|
||||
object ShadersModIntegration {
|
||||
|
||||
@JvmStatic var isPresent = false
|
||||
@JvmStatic val tallGrassEntityData = Block.blockRegistry.getIDForObject(Blocks.tallgrass) and 65535 or (Blocks.tallgrass.renderType shl 16)
|
||||
@JvmStatic val leavesEntityData = Block.blockRegistry.getIDForObject(Blocks.leaves) and 65535 or (Blocks.leaves.renderType shl 16)
|
||||
@JvmStatic val tallGrassEntityData = entityDataFor(Blocks.tallgrass.defaultState.withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.GRASS))
|
||||
@JvmStatic val leavesEntityData = entityDataFor(Blocks.leaves.defaultState)
|
||||
|
||||
fun entityDataFor(blockState: IBlockState) =
|
||||
(Block.blockRegistry.getIDForObject(blockState.block).toLong() and 65535) or
|
||||
((blockState.block.renderType.toLong() and 65535) shl 16) or
|
||||
(blockState.block.getMetaFromState(blockState).toLong() shl 32)
|
||||
|
||||
|
||||
/**
|
||||
* Called from transformed ShadersMod code.
|
||||
* @see mods.betterfoliage.loader.BetterFoliageTransformer
|
||||
*/
|
||||
@JvmStatic fun getBlockIdOverride(original: Int, block: Block): Int {
|
||||
if (Config.blocks.leaves.matchesID(original and 65535)) return leavesEntityData
|
||||
if (Config.blocks.crops.matchesID(original and 65535)) return tallGrassEntityData
|
||||
@JvmStatic fun getBlockIdOverride(original: Long, blockState: IBlockState): Long {
|
||||
if (Config.blocks.leaves.matchesID(blockState.block)) return leavesEntityData
|
||||
if (Config.blocks.crops.matchesID(blockState.block)) return tallGrassEntityData
|
||||
return original
|
||||
}
|
||||
|
||||
init {
|
||||
if (allAvailable(Refs.pushEntity_I, Refs.popEntity)) {
|
||||
if (allAvailable(Refs.sVertexBuilder, Refs.pushEntity_state, Refs.pushEntity_num, Refs.popEntity)) {
|
||||
Client.log(INFO, "ShadersMod integration enabled")
|
||||
isPresent = true
|
||||
}
|
||||
}
|
||||
|
||||
/** Quads rendered inside this block will behave as tallgrass blocks in shader programs. */
|
||||
inline fun grass(enabled: Boolean = true, func: ()->Unit) {
|
||||
if (isPresent && enabled) Refs.pushEntity_I.invokeStatic(tallGrassEntityData)
|
||||
func()
|
||||
if (isPresent && enabled) Refs.popEntity.invokeStatic()
|
||||
inline fun grass(renderer: WorldRenderer, enabled: Boolean = true, func: ()->Unit) {
|
||||
if ((isPresent && enabled)) {
|
||||
val vertexBuilder = Refs.sVertexBuilder.get(renderer)!!
|
||||
Refs.pushEntity_num.invoke(vertexBuilder, tallGrassEntityData)
|
||||
func()
|
||||
Refs.popEntity.invoke(vertexBuilder)
|
||||
} else {
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
/** Quads rendered inside this block will behave as leaf blocks in shader programs. */
|
||||
inline fun leaves(enabled: Boolean = true, func: ()->Unit) {
|
||||
if (isPresent && enabled) Refs.pushEntity_I.invokeStatic(leavesEntityData)
|
||||
func()
|
||||
if (isPresent && enabled) Refs.popEntity.invokeStatic()
|
||||
inline fun leaves(renderer: WorldRenderer, enabled: Boolean = true, func: ()->Unit) {
|
||||
if ((isPresent && enabled)) {
|
||||
val vertexBuilder = Refs.sVertexBuilder.get(renderer)!!
|
||||
Refs.pushEntity_num.invoke(vertexBuilder, leavesEntityData.toLong())
|
||||
func()
|
||||
Refs.popEntity.invoke(vertexBuilder)
|
||||
} else {
|
||||
func()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user