Initial Commit

This commit is contained in:
Shadowfacts 2016-08-06 10:28:05 -04:00
commit 16bea29c08
12 changed files with 358 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
.DS_Store
/download
/eclipseBin
# gradle
/.gradle
/build
# ForgeGradle
/run
# eclipse
/eclipse
/.settings
/.metdata
/.classpath
/.project
/bin
# intellij
/out
/.idea
/*.iml
/*.ipr
/*.iws

97
build.gradle Normal file
View File

@ -0,0 +1,97 @@
buildscript {
repositories {
jcenter()
maven {
name "forge"
url "http://files.minecraftforge.net/maven/"
}
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
}
}
plugins {
id "com.github.johnrengelman.shadow" version "1.2.3"
}
apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: "kotlin"
version = mc_version + "-" + mod_version
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
minecraft {
version = mc_version + "-" + forge_version
runDir = "run"
mappings = mcp_mappings
replaceIn "Reference.kt"
replaceIn "Reference.kt"
replace "@VERSION@", mod_version
useDepAts = true
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from (sourceSets.main.resources.srcDirs) {
include "mcmod.info"
expand "version": project.version, "mcversion": mc_version
}
from (sourceSets.main.resources.srcDirs) {
exclude "mcmod.info"
}
}
repositories {
maven {
name "shadowfacts"
url "http://mvn.rx14.co.uk/shadowfacts/"
}
maven {
url "http://dvs1.progwml6.com/files/maven"
}
maven {
url "http://maven.epoxide.xyz"
}
}
dependencies {
compile group: "org.jetbrains.kotlin", name: "kotlin-stdlib", version: kotlin_version
compile group: "org.jetbrains.kotlin", name: "kotlin-reflect", version: kotlin_version
compile group: "org.jetbrains.kotlin", name: "kotlin-runtime", version: kotlin_version
deobfCompile group: "net.shadowfacts", name: "ShadowMC", version: mc_version + "-" + shadowmc_version
}
jar {
manifest {
attributes "FMLCorePlugin": "net.shadowfacts.forgelin.ForgelinCorePlugin"
attributes "FMLCorePluginContainsFMLMod": "true"
}
}
shadowJar {
classifier = ""
dependencies {
include(dependency("org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"))
include(dependency("org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}"))
include(dependency("org.jetbrains.kotlin:kotlin-runtime:${kotlin_version}"))
}
manifest {
attributes "FMLCorePlugin": "net.shadowfacts.forgelin.ForgelinCorePlugin"
}
}
tasks.build.dependsOn shadowJar
artifacts {
archives shadowJar
}

11
gradle.properties Normal file
View File

@ -0,0 +1,11 @@
mod_version = 1.0.0
group = net.shadowfacts
archivesBaseName = ShadowForgelin
mc_version = 1.10.2
mcp_mappings = snapshot_20160802
forge_version = 12.18.1.2045
kotlin_version = 1.0.3
shadowmc_version = 3.4.5-SNAPSHOT

View File

@ -0,0 +1,27 @@
package net.shadowfacts.forgelin;
import net.minecraftforge.fml.relauncher.IFMLCallHook;
import java.util.Map;
/**
* @author shadowfacts
*/
public class ForgelinSetup implements IFMLCallHook {
@Override
public void injectData(Map<String, Object> data) {
ClassLoader loader = (ClassLoader)data.get("classLoader");
try {
loader.loadClass("net.shadowfacts.forgelin.ForgelinAdapter");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
public Void call() throws Exception {
return null;
}
}

View File

@ -0,0 +1,37 @@
package net.shadowfacts.forgelin;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import java.util.Map;
/**
* @author shadowfacts
*/
public class ForglinPlugin implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return new String[0];
}
@Override
public String getModContainerClass() {
return null;
}
@Override
public String getSetupClass() {
return "net.shadowfacts.forgelin.ForgelinSetup";
}
@Override
public void injectData(Map<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
}

View File

@ -0,0 +1,78 @@
package net.shadowfacts.forgelin
import net.minecraftforge.fml.common.FMLModContainer
import net.minecraftforge.fml.common.ILanguageAdapter
import net.minecraftforge.fml.common.ModContainer
import net.minecraftforge.fml.relauncher.Side
import org.apache.logging.log4j.LogManager
import java.lang.reflect.Field
import java.lang.reflect.Method
/**
* Kotlin implementation of FML's ILanguageAdapter.
*
* Use by setting <pre>modLanguageAdapter = "io.drakon.forgelinFR.KotlinAdapter"</pre> in the Mod annotation
* (Forge 1.8-11.14.1.1371 or above required).
*
* @author Arkan <arkan@drakon.io>
*/
public class KotlinAdapter : ILanguageAdapter {
companion object metadata {
public final val ADAPTER_VERSION: String = "@VERSION@-@KOTLIN@"
}
private val log = LogManager.getLogger("ILanguageAdapter/Kotlin")
override fun supportsStatics(): Boolean {
return false
}
override fun setProxy(target: Field, proxyTarget: Class<*>, proxy: Any) {
log.debug("Setting proxy: {}.{} -> {}", target.getDeclaringClass().getSimpleName(), target.getName(), proxy)
if (proxyTarget.getFields().any { x -> x.getName().equals("INSTANCE$") }) {
// Singleton
try {
log.debug("Setting proxy on INSTANCE$; singleton target.")
val obj = proxyTarget.getField("INSTANCE$").get(null)
target.set(obj, proxy)
} catch (ex: Exception) {
throw KotlinAdapterException(ex)
}
} else {
//TODO Log?
target.set(proxyTarget, proxy)
}
}
override fun getNewInstance(container: FMLModContainer?, objectClass: Class<*>, classLoader: ClassLoader, factoryMarkedAnnotation: Method?): Any? {
log.debug("FML has asked for {} to be constructed...", objectClass.getSimpleName())
try {
// Try looking for an object type
val f = objectClass.getField("INSTANCE$")
val obj = f.get(null)
if (obj == null) throw NullPointerException()
log.debug("Found an object INSTANCE$ reference in {}, using that. ({})", objectClass.getSimpleName(), obj)
return obj
} catch (ex: Exception) {
// Try looking for a class type
log.debug("Failed to get object reference, trying class construction.")
try {
val obj = objectClass.newInstance()
if (obj == null) throw NullPointerException()
log.debug("Constructed an object from a class type ({}), using that. ({})", objectClass, obj)
log.warn("Hey, you, modder who owns {} - you should be using 'object' instead of 'class' on your @Mod class.", objectClass.getSimpleName())
return obj
} catch (ex: Exception) {
throw KotlinAdapterException(ex)
}
}
}
override fun setInternalProxies(mod: ModContainer?, side: Side?, loader: ClassLoader?) {
// Nothing to do; FML's got this covered for Kotlin.
}
private class KotlinAdapterException(ex: Exception) : RuntimeException("Kotlin adapter error - do not report to Forge!", ex)
}

View File

@ -0,0 +1,19 @@
package net.shadowfacts.forgelin.extensions
import net.minecraft.util.EnumFacing
import net.minecraft.util.math.AxisAlignedBB
/**
* @author shadowfacts
*/
fun AxisAlignedBB.rotateFace(side: EnumFacing): AxisAlignedBB {
when (side) {
EnumFacing.DOWN -> return this
EnumFacing.UP -> return AxisAlignedBB(minX, 1 - maxY, minZ, maxX, 1 - minY, maxZ)
EnumFacing.NORTH -> return AxisAlignedBB(minX, minZ, minY, maxX, maxZ, maxY)
EnumFacing.SOUTH -> return AxisAlignedBB(minX, minZ, 1 - maxY, maxX, maxZ, 1 - minY)
EnumFacing.WEST -> return AxisAlignedBB(minY, minZ, minX, maxY, maxZ, maxX)
EnumFacing.EAST -> return AxisAlignedBB(1 - maxY, minZ, minX, 1 - minY, maxZ, maxX)
else -> return this
}
}

View File

@ -0,0 +1,10 @@
package net.shadowfacts.forgelin.extensions
import net.minecraftforge.common.config.Configuration
/**
* @author shadowfacts
*/
fun Configuration.getLong(name: String, category: String, defaultInt: Int, defaultLong: Long, minValue: Int, maxValue: Int, comment: String): Long {
return get(category, name, defaultInt, comment, minValue, maxValue).getLong(defaultLong)
}

View File

@ -0,0 +1,14 @@
package net.shadowfacts.forgelin.extensions
import net.minecraft.entity.Entity
import net.minecraft.util.math.RayTraceResult
/**
* @author shadowfacts
*/
fun Entity.rayTrace(distance: Double): RayTraceResult? {
val eyePos = getPositionEyes(0f)
val lookVec = getLook(0f)
val vec = eyePos.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance)
return worldObj.rayTraceBlocks(eyePos, vec, false, false, true)
}

View File

@ -0,0 +1,13 @@
package net.shadowfacts.forgelin.extensions
import net.minecraft.nbt.NBTBase
import net.minecraft.nbt.NBTTagList
/**
* @author shadowfacts
*/
fun NBTTagList.forEach(action: (NBTBase) -> Unit) {
for (i in 0.until(tagCount())) {
action(get(i))
}
}

View File

@ -0,0 +1,15 @@
package net.shadowfacts.forgelin.extensions
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.text.TextComponentString
/**
* @author shadowfacts
*/
fun EntityPlayer.addChatMsg(msg: String) {
addChatComponentMessage(TextComponentString(msg))
}
fun EntityPlayer.addChatMsg(msg: String, vararg params: Any) {
addChatMsg(String.format(msg, params))
}

View File

@ -0,0 +1,11 @@
package net.shadowfacts.forgelin.extensions.client
import net.minecraft.client.settings.GameSettings
import net.minecraft.client.settings.KeyBinding
/**
* @author shadowfacts
*/
fun KeyBinding.getDisplayString(): String {
return GameSettings.getKeyDisplayString(keyCode)
}