It lives
This commit is contained in:
parent
dccdea16ce
commit
144c4468ee
|
@ -1,10 +1,9 @@
|
||||||
# Forgelin
|
# Forgelin
|
||||||
**WARNING:** This project is no longer maintained. It has been superseded by Kotlin integration in [ShadowMC](https://github.com/shadowfacts/ShadowMC).
|
Fork of [Emberwalker's Forgelin](https://github.com/Emberwalker/Forgelin).
|
||||||
|
|
||||||
Fork of [Emberwalker's Forgelin](https://github.com/Emberwalker/Forgelin) with some sprinkles on top.
|
|
||||||
|
|
||||||
## Additions
|
## Additions
|
||||||
- Extensions for Minecraft/Forge code. See them in the [extensions package](https://github.com/shadowfacts/Forgelin/tree/master/src/main/kotlin/net/shadowfacts/forgelin/extensions/).
|
- Shades the Kotlin standard library, runtime, and reflect libraries so you don't have to.
|
||||||
|
- Provides a Forge `ILanguageAdapter` for using Kotlin `object` classes as your main mod class.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```groovy
|
```groovy
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
mod_version = 1.0.5
|
mod_version = 1.1.0
|
||||||
group = net.shadowfacts
|
group = net.shadowfacts
|
||||||
archivesBaseName = Forgelin
|
archivesBaseName = Forgelin
|
||||||
|
|
||||||
|
@ -6,4 +6,4 @@ mc_version = 1.10.2
|
||||||
mcp_mappings = snapshot_20160802
|
mcp_mappings = snapshot_20160802
|
||||||
forge_version = 12.18.1.2045
|
forge_version = 12.18.1.2045
|
||||||
|
|
||||||
kotlin_version = 1.0.3
|
kotlin_version = 1.0.5
|
||||||
|
|
|
@ -9,64 +9,59 @@ import java.lang.reflect.Field
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kotlin implementation of FML's ILanguageAdapter.
|
* Forge {@link ILanguageAdapter} for Kotlin
|
||||||
*
|
* Usage: Set the {@code modLanguageAdapter} field in your {@code @Mod} annotation to {@code net.shadowfacts.forgelin.KotlinAdapter}
|
||||||
* Use by setting <pre>modLanguageAdapter = "io.drakon.forgelinFR.KotlinAdapter"</pre> in the Mod annotation
|
* @author shadowfacts
|
||||||
* (Forge 1.8-11.14.1.1371 or above required).
|
|
||||||
*
|
|
||||||
* @author Arkan <arkan@drakon.io>
|
|
||||||
*/
|
*/
|
||||||
class KotlinAdapter : ILanguageAdapter {
|
class KotlinAdapter : ILanguageAdapter {
|
||||||
|
|
||||||
private val log = LogManager.getLogger("ILanguageAdapter/Kotlin")
|
private val log = LogManager.getLogger("KotlinAdapter")
|
||||||
|
|
||||||
override fun supportsStatics(): Boolean {
|
override fun supportsStatics(): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setProxy(target: Field, proxyTarget: Class<*>, proxy: Any) {
|
override fun setProxy(target: Field, proxyTarget: Class<*>, proxy: Any) {
|
||||||
log.debug("Setting proxy: {}.{} -> {}", target.declaringClass.simpleName, target.name, proxy)
|
log.debug("Setting proxy: ${target.declaringClass.simpleName}.${target.name} -> $proxy")
|
||||||
if (proxyTarget.fields.any { x -> x.name.equals("INSTANCE") }) {
|
if (proxyTarget.fields.any { x -> x.name == "INSTANCE" }) {
|
||||||
// Singleton
|
// Singleton
|
||||||
try {
|
try {
|
||||||
log.debug("Setting proxy on INSTANCE; singleton target.")
|
log.debug("Setting proxy on INSTANCE; singleton target")
|
||||||
val obj = proxyTarget.getField("INSTANCE").get(null)
|
val obj = proxyTarget.getField("INSTANCE").get(null)
|
||||||
target.set(obj, proxy)
|
target.set(obj, proxy)
|
||||||
} catch (ex: Exception) {
|
} catch (e: Exception) {
|
||||||
throw KotlinAdapterException(ex)
|
throw KotlinAdapterException(e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//TODO Log?
|
|
||||||
target.set(proxyTarget, proxy)
|
target.set(proxyTarget, proxy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNewInstance(container: FMLModContainer?, objectClass: Class<*>, classLoader: ClassLoader, factoryMarkedAnnotation: Method?): Any? {
|
override fun getNewInstance(container: FMLModContainer, objectClass: Class<*>, classLoader: ClassLoader, factoryMarkedAnnotation: Method?): Any {
|
||||||
log.debug("FML has asked for {} to be constructed...", objectClass.simpleName)
|
log.debug("FML has asked for ${objectClass.simpleName} to be constructed")
|
||||||
try {
|
try {
|
||||||
// Try looking for an object type
|
// Try looking for an object type
|
||||||
val f = objectClass.getField("INSTANCE")
|
val f = objectClass.getField("INSTANCE")
|
||||||
val obj = f.get(null) ?: throw NullPointerException()
|
val obj = f.get(null) ?: throw NullPointerException()
|
||||||
log.debug("Found an object INSTANCE reference in {}, using that. ({})", objectClass.simpleName, obj)
|
log.debug("Found an object INSTANCE reference in ${objectClass.simpleName}, using that. ${obj}")
|
||||||
return obj
|
return obj
|
||||||
} catch (ex: Exception) {
|
} catch (e: Exception) {
|
||||||
// Try looking for a class type
|
// Try looking for a class type
|
||||||
log.debug("Failed to get object reference, trying class construction.")
|
log.debug("Failed to get object reference, trying class construction")
|
||||||
try {
|
try {
|
||||||
val obj = objectClass.newInstance() ?: throw NullPointerException()
|
val obj = objectClass.newInstance() ?: throw NullPointerException()
|
||||||
log.debug("Constructed an object from a class type ({}), using that. ({})", objectClass, obj)
|
log.debug("Constructed an object from a class type ($objectClass), using that. $obj")
|
||||||
log.warn("Hey, you, modder who owns {} - you should be using 'object' instead of 'class' on your @Mod class.", objectClass.simpleName)
|
|
||||||
return obj
|
return obj
|
||||||
} catch (ex: Exception) {
|
} catch (e: Exception) {
|
||||||
throw KotlinAdapterException(ex)
|
throw KotlinAdapterException(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setInternalProxies(mod: ModContainer?, side: Side?, loader: ClassLoader?) {
|
override fun setInternalProxies(mod: ModContainer?, side: Side?, loader: ClassLoader?) {
|
||||||
// Nothing to do; FML's got this covered for Kotlin.
|
// 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)
|
private class KotlinAdapterException(e: Exception) : RuntimeException("Kotlin adapter error - do not report to Forge!", e)
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package net.shadowfacts.forgelin.extensions
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
fun List<ItemStack>.containsStack(stack: ItemStack): Boolean {
|
|
||||||
forEach {
|
|
||||||
if (it.item == stack.item && it.itemDamage == stack.itemDamage) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
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))
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue