Иконка ресурса

Some code using Kotlin 0.1

Нет прав для скачивания
Версия(и) Minecraft
1.7.10
Gui compass:
Автор мода и его версия на Java: click
Любые нарекания по коду – излагайте, буду принимать и исправлять.

Класс отрисовки компаса:
Kotlin:
package merisen.compas_kt

import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import net.minecraft.client.Minecraft
import net.minecraft.util.StatCollector
import net.minecraftforge.client.event.RenderGameOverlayEvent
import org.lwjgl.opengl.GL11

@SideOnly(Side.CLIENT)
class CompassScreen
{
    val mc = Minecraft.getMinecraft()!!

    @SubscribeEvent
    fun drawText(event: RenderGameOverlayEvent.Post)
    {
        when (event.type)
        {
            RenderGameOverlayEvent.ElementType.ALL ->
            {
                GL11.glPushMatrix()

                val min = event.resolution.scaledWidth / 3
                val max = event.resolution.scaledWidth - min * 2
                GL11.glScissor(min * event.resolution.scaleFactor, (event.resolution.scaledHeight - 20) * event.resolution.scaleFactor, min * event.resolution.scaleFactor, 235 * event.resolution.scaleFactor)
                GL11.glEnable(GL11.GL_SCISSOR_TEST)

                var deg = mc.thePlayer.rotationYaw + 180.0
                deg %= 360.0
                if (deg < 0) deg = 360.0 + deg

                GL11.glEnable(GL11.GL_BLEND)
                GL11.glDisable(GL11.GL_TEXTURE_2D)
                GL11.glColor4f(0.25f, 0.25f, 0.25f, 0.25f)
                mc.ingameGUI.drawTexturedModalRect(min, 0, 0, 0, max, 20)
                GL11.glEnable(GL11.GL_TEXTURE_2D)
                GL11.glDisable(GL11.GL_BLEND)

                mc.fontRenderer.drawString("§c^", event.resolution.scaledWidth / 2, 13, 0xFFFFFF)

                val offset = deg.toInt() / 15 * 15
                for (i in -12..35)
                {
                    val g = (i + 24) % 24 * 15
                    val setX = ((event.resolution.scaledWidth / 2).toDouble() + (if (g == 0) 2 else 0).toDouble() + (i - deg / 15) * 15).toInt()
                    GL11.glPushMatrix()
                    GL11.glTranslated(setX.toDouble(), 0.0, 0.0)

                    GL11.glPushMatrix()
                    if (!Minecraft.getMinecraft().fontRenderer.unicodeFlag) GL11.glScalef(0.75f, 0.75f, 0.75f)
                    mc.fontRenderer.drawString(when (g)
                    {
                        0 -> StatCollector.translateToLocal("§aN")
                        90 -> StatCollector.translateToLocal("§aE")
                        180 -> StatCollector.translateToLocal("§aS")
                        270 -> StatCollector.translateToLocal("§aW")
                        else -> Integer.toString(g)
                    }, if (g == 0) if (Minecraft.getMinecraft().fontRenderer.unicodeFlag) -2 else -3 else if (g == 90 || g == 180 || g == 270) 0 else -4, 2, 0xFFFFFF)
                    GL11.glPopMatrix()

                    mc.fontRenderer.drawString("|", if (g == 0) -1 else 1, 5, 0xDDDDDD)

                    GL11.glPopMatrix()
                }
                GL11.glDisable(GL11.GL_SCISSOR_TEST)
                GL11.glColor4f(1f, 1f, 1f, 1f)
                GL11.glPopMatrix()
            }
            else -> return
        }
    }
}
Главный класс:
Kotlin:
package merisen.compas_kt

import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.event.FMLPreInitializationEvent
import merisen.compas_kt.Compass.Companion.MOD_ID
import merisen.compas_kt.Compass.Companion.MOD_NAME
import merisen.compas_kt.Compass.Companion.MOD_VERSION
import net.minecraftforge.common.MinecraftForge

@Mod(modid = MOD_ID, name = MOD_NAME, version = MOD_VERSION)
class Compass
{
    @Mod.EventHandler
    fun preInit(event: FMLPreInitializationEvent)
    {
        println("Main author of mod -> $MAIN_AUTHOR")
        MinecraftForge.EVENT_BUS.register(CompassScreen())
    }

    companion object
    {
        const val MOD_ID = "compass_kt"
        const val MOD_NAME = "Kotlin Compass"
        const val MOD_VERSION = "0.1"

        const val MAIN_AUTHOR = "timaxa007"
    }
}
Автор
Merisen
Скачивания
2
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок

Другие ресурсы пользователя Merisen

Сверху