first Kotlin version
This commit is contained in:
106
src/main/kotlin/mods/betterfoliage/loader/BetterFoliageCore.kt
Normal file
106
src/main/kotlin/mods/betterfoliage/loader/BetterFoliageCore.kt
Normal file
@@ -0,0 +1,106 @@
|
||||
package mods.betterfoliage.loader
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin
|
||||
import mods.octarinecore.metaprog.*
|
||||
import org.objectweb.asm.Opcodes.*
|
||||
|
||||
@IFMLLoadingPlugin.TransformerExclusions(
|
||||
"mods.betterfoliage.loader",
|
||||
"mods.octarinecore.metaprog",
|
||||
"kotlin",
|
||||
"mods.betterfoliage.kotlin"
|
||||
)
|
||||
class BetterFoliageLoader : ASMPlugin(BetterFoliageTransformer::class.java)
|
||||
|
||||
class BetterFoliageTransformer : Transformer() {
|
||||
|
||||
init {
|
||||
if (FMLLaunchHandler.side().isClient) setupClient()
|
||||
}
|
||||
|
||||
fun setupClient() {
|
||||
// where: RenderBlocks.renderBlockByRenderType()
|
||||
// what: invoke BF code to overrule the return value of Block.getRenderType()
|
||||
// why: allows us to use custom block renderers for any block, without touching block code
|
||||
transformMethod(Refs.renderBlockByRenderType) {
|
||||
find(varinsn(ISTORE, 5))?.insertAfter {
|
||||
log.info("Applying block render type override")
|
||||
varinsn(ALOAD, 0)
|
||||
getField(Refs.blockAccess)
|
||||
varinsn(ILOAD, 2)
|
||||
varinsn(ILOAD, 3)
|
||||
varinsn(ILOAD, 4)
|
||||
varinsn(ALOAD, 1)
|
||||
varinsn(ILOAD, 5)
|
||||
invokeStatic(Refs.getRenderTypeOverride)
|
||||
varinsn(ISTORE, 5)
|
||||
} ?: log.warn("Failed to apply block render type override!")
|
||||
}
|
||||
|
||||
// where: WorldClient.doVoidFogParticles(), right before the end of the loop
|
||||
// what: invoke BF code for every random display tick
|
||||
// why: allows us to catch random display ticks, without touching block code
|
||||
transformMethod(Refs.doVoidFogParticles) {
|
||||
find(IINC)?.insertBefore {
|
||||
log.info("Applying random display tick call hook")
|
||||
varinsn(ALOAD, 10)
|
||||
varinsn(ALOAD, 0)
|
||||
varinsn(ILOAD, 7)
|
||||
varinsn(ILOAD, 8)
|
||||
varinsn(ILOAD, 9)
|
||||
invokeStatic(Refs.onRandomDisplayTick)
|
||||
} ?: log.warn("Failed to apply random display tick call hook!")
|
||||
}
|
||||
|
||||
// where: shadersmodcore.client.Shaders.pushEntity()
|
||||
// what: invoke BF code to overrule block data
|
||||
// why: allows us to change the block ID seen by shader programs
|
||||
transformMethod(Refs.pushEntity) {
|
||||
find(IASTORE)?.insertBefore {
|
||||
log.info("Applying Shaders.pushEntity() block id override")
|
||||
varinsn(ALOAD, 1)
|
||||
invokeStatic(Refs.getBlockIdOverride)
|
||||
} ?: log.warn("Failed to apply Shaders.pushEntity() block id override!")
|
||||
}
|
||||
|
||||
// where: Block.getAmbientOcclusionLightValue()
|
||||
// what: invoke BF code to overrule AO transparency value
|
||||
// why: allows us to have light behave properly on non-solid log blocks without
|
||||
// messing with isOpaqueBlock(), which could have gameplay effects
|
||||
transformMethod(Refs.getAmbientOcclusionLightValue) {
|
||||
find(FRETURN)?.insertBefore {
|
||||
log.info("Applying Block.getAmbientOcclusionLightValue() override")
|
||||
varinsn(ALOAD, 0)
|
||||
invokeStatic(Refs.getAmbientOcclusionLightValueOverride)
|
||||
} ?: log.warn("Failed to apply Block.getAmbientOcclusionLightValue() override!")
|
||||
}
|
||||
|
||||
// where: Block.getUseNeighborBrightness()
|
||||
// what: invoke BF code to overrule _useNeighborBrightness_
|
||||
// why: allows us to have light behave properly on non-solid log blocks
|
||||
transformMethod(Refs.getUseNeighborBrightness) {
|
||||
find(IRETURN)?.insertBefore {
|
||||
log.info("Applying Block.getUseNeighborBrightness() override")
|
||||
varinsn(ALOAD, 0)
|
||||
invokeStatic(Refs.getUseNeighborBrightnessOverride)
|
||||
} ?: log.warn("Failed to apply Block.getUseNeighborBrightness() override!")
|
||||
}
|
||||
|
||||
// where: Block.shouldSideBeRendered()
|
||||
// what: invoke BF code to overrule condition
|
||||
// why: allows us to make log blocks non-solid without
|
||||
// messing with isOpaqueBlock(), which could have gameplay effects
|
||||
transformMethod(Refs.shouldSideBeRendered) {
|
||||
find(IRETURN)?.insertBefore {
|
||||
log.info("Applying Block.shouldSideBeRendered() override")
|
||||
varinsn(ALOAD, 1)
|
||||
varinsn(ILOAD, 2)
|
||||
varinsn(ILOAD, 3)
|
||||
varinsn(ILOAD, 4)
|
||||
varinsn(ILOAD, 5)
|
||||
invokeStatic(Refs.shouldRenderBlockSideOverride)
|
||||
} ?: log.warn("Failed to apply Block.shouldSideBeRendered() override!")
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/main/kotlin/mods/betterfoliage/loader/Refs.kt
Normal file
71
src/main/kotlin/mods/betterfoliage/loader/Refs.kt
Normal file
@@ -0,0 +1,71 @@
|
||||
package mods.betterfoliage.loader
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData
|
||||
import mods.octarinecore.metaprog.ClassRef
|
||||
import mods.octarinecore.metaprog.FieldRef
|
||||
import mods.octarinecore.metaprog.MethodRef
|
||||
|
||||
/** Singleton object holding references to foreign code elements. */
|
||||
object Refs {
|
||||
val mcVersion = FMLInjectionData.data()[4].toString()
|
||||
|
||||
// Java
|
||||
val Map = ClassRef("java.util.Map")
|
||||
val List = ClassRef("java.util.List")
|
||||
|
||||
// Minecraft
|
||||
val IBlockAccess = ClassRef("net.minecraft.world.IBlockAccess", "ahl")
|
||||
|
||||
val Block = ClassRef("net.minecraft.block.Block", "aji")
|
||||
val getAmbientOcclusionLightValue = MethodRef(Block, "getAmbientOcclusionLightValue", "func_149685_I", "I", ClassRef.float)
|
||||
val getUseNeighborBrightness = MethodRef(Block, "getUseNeighborBrightness", "func_149710_n", "n", ClassRef.boolean)
|
||||
val shouldSideBeRendered = MethodRef(Block, "shouldSideBeRendered", "func_149646_a", "a", ClassRef.boolean, IBlockAccess, ClassRef.int, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
|
||||
val RenderBlocks = ClassRef("net.minecraft.client.renderer.RenderBlocks", "blm")
|
||||
val blockAccess = FieldRef(RenderBlocks, "blockAccess", null, "a", IBlockAccess)
|
||||
val renderBlockByRenderType = MethodRef(RenderBlocks, "renderBlockByRenderType", null, "b", ClassRef.boolean, Block, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
|
||||
val WorldClient = ClassRef("net.minecraft.client.multiplayer.WorldClient", "bjf")
|
||||
val doVoidFogParticles = MethodRef(WorldClient, "doVoidFogParticles", null, "C", ClassRef.void, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
|
||||
val World = ClassRef("net.minecraft.world.World", "ahb")
|
||||
|
||||
val TextureMap = ClassRef("net.minecraft.client.renderer.texture.TextureMap", "bpr")
|
||||
val mapRegisteredSprites = FieldRef(TextureMap, "mapRegisteredSprites", "field_110574_e", "bpr", Map)
|
||||
|
||||
val IMetadataSerializer = ClassRef("net.minecraft.client.resources.data.IMetadataSerializer", "brw")
|
||||
val SimpleReloadableResourceManager = ClassRef("net.minecraft.client.resources.SimpleReloadableResourceManager", "brg")
|
||||
val metadataSerializer = FieldRef(SimpleReloadableResourceManager, "rmMetadataSerializer", "field_110547_c", "f", IMetadataSerializer)
|
||||
|
||||
val IIcon = ClassRef("net.minecraft.util.IIcon", "rf")
|
||||
val TextureAtlasSprite = ClassRef("net.minecraft.client.renderer.texture.TextureAtlasSprite", "bqd")
|
||||
|
||||
// Better Foliage
|
||||
val BetterFoliageHooks = ClassRef("mods.betterfoliage.client.Hooks")
|
||||
val getAmbientOcclusionLightValueOverride = MethodRef(BetterFoliageHooks, "getAmbientOcclusionLightValueOverride", ClassRef.float, ClassRef.float, Block)
|
||||
val getUseNeighborBrightnessOverride = MethodRef(BetterFoliageHooks, "getUseNeighborBrightnessOverride", ClassRef.boolean, ClassRef.boolean, Block)
|
||||
val shouldRenderBlockSideOverride = MethodRef(BetterFoliageHooks, "shouldRenderBlockSideOverride", ClassRef.boolean, ClassRef.boolean, IBlockAccess, ClassRef.int, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
val getRenderTypeOverride = MethodRef(BetterFoliageHooks, "getRenderTypeOverride", ClassRef.int, IBlockAccess, ClassRef.int, ClassRef.int, ClassRef.int, Block, ClassRef.int)
|
||||
val onRandomDisplayTick = MethodRef(BetterFoliageHooks, "onRandomDisplayTick", ClassRef.void, Block, World, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
|
||||
// Shaders mod
|
||||
val Shaders = ClassRef("shadersmodcore.client.Shaders")
|
||||
val pushEntity = MethodRef(Shaders, "pushEntity", ClassRef.void, RenderBlocks, Block, ClassRef.int, ClassRef.int, ClassRef.int)
|
||||
val pushEntity_I = MethodRef(Shaders, "pushEntity", ClassRef.void, ClassRef.int)
|
||||
val popEntity = MethodRef(Shaders, "popEntity", ClassRef.void)
|
||||
|
||||
val ShadersModIntegration = ClassRef("mods.betterfoliage.client.integration.ShadersModIntegration")
|
||||
val getBlockIdOverride = MethodRef(ShadersModIntegration, "getBlockIdOverride", ClassRef.int, ClassRef.int, Block)
|
||||
|
||||
// Optifine
|
||||
val ConnectedTextures = ClassRef("ConnectedTextures")
|
||||
val getConnectedTexture = MethodRef(ConnectedTextures, "getConnectedTexture", IIcon, IBlockAccess, Block, ClassRef.int, ClassRef.int, ClassRef.int, ClassRef.int, IIcon)
|
||||
val CTBlockProperties = FieldRef(ConnectedTextures, "blockProperties", null)
|
||||
val CTTileProperties = FieldRef(ConnectedTextures, "tileProperties", null)
|
||||
|
||||
val ConnectedProperties = ClassRef("ConnectedProperties")
|
||||
val CPTileIcons = FieldRef(ConnectedProperties, "tileIcons", null)
|
||||
|
||||
// Colored Lights Core
|
||||
val CLCLoadingPlugin = ClassRef("coloredlightscore.src.asm.ColoredLightsCoreLoadingPlugin")
|
||||
}
|
||||
Reference in New Issue
Block a user