From a5c540d977a3510812cac7fac340fe17e7d10983 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 14 Jul 2022 12:06:07 +0200 Subject: renamed mod to SkyHanni --- src/main/java/at/lorenz/mod/utils/APIUtil.kt | 48 --- src/main/java/at/lorenz/mod/utils/BlockUtils.kt | 23 -- src/main/java/at/lorenz/mod/utils/GuiRender.kt | 32 -- src/main/java/at/lorenz/mod/utils/ItemUtil.kt | 213 ------------- src/main/java/at/lorenz/mod/utils/ItemUtils.kt | 72 ----- src/main/java/at/lorenz/mod/utils/LorenzColor.kt | 27 -- src/main/java/at/lorenz/mod/utils/LorenzDebug.kt | 16 - src/main/java/at/lorenz/mod/utils/LorenzLogger.kt | 70 ----- src/main/java/at/lorenz/mod/utils/LorenzUtils.kt | 130 -------- src/main/java/at/lorenz/mod/utils/LorenzVec.kt | 61 ---- src/main/java/at/lorenz/mod/utils/NumberUtil.kt | 152 --------- src/main/java/at/lorenz/mod/utils/RenderUtils.kt | 355 ---------------------- 12 files changed, 1199 deletions(-) delete mode 100644 src/main/java/at/lorenz/mod/utils/APIUtil.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/BlockUtils.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/GuiRender.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/ItemUtil.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/ItemUtils.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/LorenzColor.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/LorenzDebug.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/LorenzLogger.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/LorenzUtils.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/LorenzVec.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/NumberUtil.kt delete mode 100644 src/main/java/at/lorenz/mod/utils/RenderUtils.kt (limited to 'src/main/java/at/lorenz/mod/utils') diff --git a/src/main/java/at/lorenz/mod/utils/APIUtil.kt b/src/main/java/at/lorenz/mod/utils/APIUtil.kt deleted file mode 100644 index 7e0193f50..000000000 --- a/src/main/java/at/lorenz/mod/utils/APIUtil.kt +++ /dev/null @@ -1,48 +0,0 @@ -package at.lorenz.mod.utils - -import com.google.gson.JsonObject -import com.google.gson.JsonParser -import org.apache.http.client.config.RequestConfig -import org.apache.http.client.methods.HttpGet -import org.apache.http.impl.client.HttpClientBuilder -import org.apache.http.impl.client.HttpClients -import org.apache.http.message.BasicHeader -import org.apache.http.util.EntityUtils - - -object APIUtil { - private val parser = JsonParser() - - val builder: HttpClientBuilder = - HttpClients.custom().setUserAgent("LorenzMod") - .setDefaultHeaders( - mutableListOf( - BasicHeader("Pragma", "no-cache"), - BasicHeader("Cache-Control", "no-cache") - ) - ) - .setDefaultRequestConfig( - RequestConfig.custom() - .build() - ) - .useSystemProperties() - - fun getJSONResponse(urlString: String): JsonObject { - val client = builder.build() - try { - client.execute(HttpGet(urlString)).use { response -> - val entity = response.entity - if (entity != null) { - val retSrc = EntityUtils.toString(entity) - return parser.parse(retSrc) as JsonObject - } - } - } catch (ex: Throwable) { - ex.printStackTrace() - LorenzUtils.error("Lorenz Mod ran into an ${ex::class.simpleName ?: "error"} whilst fetching a resource. See logs for more details.") - } finally { - client.close() - } - return JsonObject() - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/BlockUtils.kt b/src/main/java/at/lorenz/mod/utils/BlockUtils.kt deleted file mode 100644 index d16194c70..000000000 --- a/src/main/java/at/lorenz/mod/utils/BlockUtils.kt +++ /dev/null @@ -1,23 +0,0 @@ -package at.lorenz.mod.utils - -import net.minecraft.block.Block -import net.minecraft.client.Minecraft -import net.minecraft.tileentity.TileEntitySkull -import net.minecraft.util.BlockPos -import net.minecraftforge.common.util.Constants - -object BlockUtils { - - fun LorenzVec.getBlockAt(): Block = - Minecraft.getMinecraft().theWorld.getBlockState(toBlocPos()).block - - fun LorenzVec.isInLoadedChunk(): Boolean = - Minecraft.getMinecraft().theWorld.chunkProvider.provideChunk(toBlocPos()).isLoaded - - fun getSkinFromSkull(position: BlockPos?): String? { - val entity = Minecraft.getMinecraft().theWorld.getTileEntity(position) as TileEntitySkull - val serializeNBT = entity.serializeNBT() - return serializeNBT.getCompoundTag("Owner").getCompoundTag("Properties") - .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/GuiRender.kt b/src/main/java/at/lorenz/mod/utils/GuiRender.kt deleted file mode 100644 index 03918fb66..000000000 --- a/src/main/java/at/lorenz/mod/utils/GuiRender.kt +++ /dev/null @@ -1,32 +0,0 @@ -package at.lorenz.mod.utils - -import at.lorenz.mod.utils.LorenzUtils.removeColorCodes -import at.lorenz.mod.config.core.config.Position -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.ScaledResolution -import net.minecraft.client.renderer.GlStateManager - -object GuiRender { - - fun Position.renderString(string: String) { - val textToRender = "§f$string" - - GlStateManager.pushMatrix() - val resolution = ScaledResolution(Minecraft.getMinecraft()) - - val renderer = Minecraft.getMinecraft().renderManager.fontRenderer - - val offsetX = (200 - renderer.getStringWidth(textToRender.removeColorCodes())) / 2 - - val x = getAbsX(resolution, 200) + offsetX - val y = getAbsY(resolution, 16) - - - - GlStateManager.translate(x + 1.0, y + 1.0, 0.0) - renderer.drawStringWithShadow(textToRender, 0f, 0f, 0) - - - GlStateManager.popMatrix() - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/ItemUtil.kt b/src/main/java/at/lorenz/mod/utils/ItemUtil.kt deleted file mode 100644 index 341b94ca8..000000000 --- a/src/main/java/at/lorenz/mod/utils/ItemUtil.kt +++ /dev/null @@ -1,213 +0,0 @@ -package at.lorenz.mod.utils - -import net.minecraft.init.Items -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound -import net.minecraft.nbt.NBTTagList -import net.minecraft.nbt.NBTTagString -import net.minecraftforge.common.util.Constants -import java.util.* - -object ItemUtil { - private val PET_PATTERN = "§7\\[Lvl \\d+] (?§[0-9a-fk-or]).+".toRegex() - const val NBT_INTEGER = 3 - private const val NBT_STRING = 8 - private const val NBT_LIST = 9 - private const val NBT_COMPOUND = 10 - - /** - * Returns the display name of a given item - * @author Mojang - * @param item the Item to get the display name of - * @return the display name of the item - */ - @JvmStatic - fun getDisplayName(item: ItemStack): String { - var s = item.item.getItemStackDisplayName(item) - if (item.tagCompound != null && item.tagCompound.hasKey("display", 10)) { - val nbtTagCompound = item.tagCompound.getCompoundTag("display") - if (nbtTagCompound.hasKey("Name", 8)) { - s = nbtTagCompound.getString("Name") - } - } - return s - } - - /** - * Returns the Skyblock Item ID of a given Skyblock item - * - * @author BiscuitDevelopment - * @param item the Skyblock item to check - * @return the Skyblock Item ID of this item or `null` if this isn't a valid Skyblock item - */ - @JvmStatic - fun getSkyBlockItemID(item: ItemStack?): String? { - if (item == null) { - return null - } - val extraAttributes = getExtraAttributes(item) ?: return null - return if (!extraAttributes.hasKey("id", NBT_STRING)) { - null - } else extraAttributes.getString("id") - } - - /** - * Returns the `ExtraAttributes` compound tag from the item's NBT data. - * - * @author BiscuitDevelopment - * @param item the item to get the tag from - * @return the item's `ExtraAttributes` compound tag or `null` if the item doesn't have one - */ - @JvmStatic - fun getExtraAttributes(item: ItemStack?): NBTTagCompound? { - return if (item == null || !item.hasTagCompound()) { - null - } else item.getSubCompound("ExtraAttributes", false) - } - - /** - * Returns the Skyblock Item ID of a given Skyblock Extra Attributes NBT Compound - * - * @author BiscuitDevelopment - * @param extraAttributes the NBT to check - * @return the Skyblock Item ID of this item or `null` if this isn't a valid Skyblock NBT - */ - @JvmStatic - fun getSkyBlockItemID(extraAttributes: NBTTagCompound?): String? { - if (extraAttributes != null) { - val itemId = extraAttributes.getString("id") - if (itemId.isNotEmpty()) { - return itemId - } - } - return null - } - - /** - * Returns a string list containing the nbt lore of an ItemStack, or - * an empty list if this item doesn't have a lore. The returned lore - * list is unmodifiable since it has been converted from an NBTTagList. - * - * @author BiscuitDevelopment - * @param itemStack the ItemStack to get the lore from - * @return the lore of an ItemStack as a string list - */ - @JvmStatic - fun getItemLore(itemStack: ItemStack): List { - if (itemStack.hasTagCompound() && itemStack.tagCompound.hasKey("display", NBT_COMPOUND)) { - val display = itemStack.tagCompound.getCompoundTag("display") - if (display.hasKey("Lore", NBT_LIST)) { - val lore = display.getTagList("Lore", NBT_STRING) - val loreAsList = ArrayList(lore.tagCount()) - for (lineNumber in 0 until lore.tagCount()) { - loreAsList.add(lore.getStringTagAt(lineNumber)) - } - return Collections.unmodifiableList(loreAsList) - } - } - return emptyList() - } - -// @JvmStatic -// fun hasRightClickAbility(itemStack: ItemStack): Boolean { -// for (line in getItemLore(itemStack)) { -// val stripped = line.stripControlCodes() -// if (stripped.startsWith("Item Ability:") && stripped.endsWith("RIGHT CLICK")) return true -// } -// return false -// } - -// /** -// * Returns the rarity of a given Skyblock item -// * Modified -// * @author BiscuitDevelopment -// * @param item the Skyblock item to check -// * @return the rarity of the item if a valid rarity is found, `null` if no rarity is found, `null` if item is `null` -// */ -// fun getRarity(item: ItemStack?): ItemRarity { -// if (item == null || !item.hasTagCompound()) { -// return ItemRarity.NONE -// } -// val display = item.getSubCompound("display", false) -// if (display == null || !display.hasKey("Lore")) { -// return ItemRarity.NONE -// } -// val lore = display.getTagList("Lore", Constants.NBT.TAG_STRING) -// val name = display.getString("Name") -// -// // Determine the item's rarity -// for (i in (lore.tagCount() - 1) downTo 0) { -// val currentLine = lore.getStringTagAt(i) -// val rarityMatcher = RARITY_PATTERN.find(currentLine) -// if (rarityMatcher != null) { -// val rarity = rarityMatcher.groups["rarity"]?.value ?: continue -// ItemRarity.values().find { -// it.rarityName == rarity.stripControlCodes().substringAfter("SHINY ") -// }?.let { -// return it -// } -// } -// } -// val petRarityMatcher = PET_PATTERN.find(name) -// if (petRarityMatcher != null) { -// val color = petRarityMatcher.groupValues.getOrNull(1) ?: return ItemRarity.NONE -// return ItemRarity.byBaseColor(color) ?: ItemRarity.NONE -// } -// -// // If the item doesn't have a valid rarity, return null -// return ItemRarity.NONE -// } - - fun isPet(item: ItemStack?): Boolean { - if (item == null || !item.hasTagCompound()) { - return false - } - val display = item.getSubCompound("display", false) - if (display == null || !display.hasKey("Lore")) { - return false - } - val name = display.getString("Name") - - return PET_PATTERN.matches(name) - } - - fun setSkullTexture(item: ItemStack, texture: String, SkullOwner: String): ItemStack { - val textureTagCompound = NBTTagCompound() - textureTagCompound.setString("Value", texture) - - val textures = NBTTagList() - textures.appendTag(textureTagCompound) - - val properties = NBTTagCompound() - properties.setTag("textures", textures) - - val skullOwner = NBTTagCompound() - skullOwner.setString("Id", SkullOwner) - skullOwner.setTag("Properties", properties) - - val nbtTag = NBTTagCompound() - nbtTag.setTag("SkullOwner", skullOwner) - - item.tagCompound = nbtTag - return item - } - - fun getSkullTexture(item: ItemStack): String? { - if (item.item != Items.skull) return null - val nbt = item.tagCompound - if (!nbt.hasKey("SkullOwner")) return null - return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties") - .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") - } - - fun ItemStack.setLore(lines: List): ItemStack { - setTagInfo("display", getSubCompound("display", true).apply { - setTag("Lore", NBTTagList().apply { - for (line in lines) appendTag(NBTTagString(line)) - }) - }) - return this - } - - fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt b/src/main/java/at/lorenz/mod/utils/ItemUtils.kt deleted file mode 100644 index 6d5bf57da..000000000 --- a/src/main/java/at/lorenz/mod/utils/ItemUtils.kt +++ /dev/null @@ -1,72 +0,0 @@ -package at.lorenz.mod.utils - -import at.lorenz.mod.utils.LorenzUtils.matchRegex -import at.lorenz.mod.utils.LorenzUtils.removeColorCodes -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.item.ItemStack - -object ItemUtils { - - fun ItemStack.cleanName() = this.displayName.removeColorCodes() - - fun getItemsInOpenChest(): List { - val list = mutableListOf() - val guiChest = Minecraft.getMinecraft().currentScreen as GuiChest - val inventorySlots = guiChest.inventorySlots.inventorySlots - val skipAt = inventorySlots.size - 9 * 4 - var i = 0 - for (slot in inventorySlots) { - val stack = slot.stack - if (stack != null) { - list.add(stack) - } - i++ - if (i == skipAt) break - } - return list - } - - fun isSack(name: String): Boolean = name.endsWith(" Sack") - - fun ItemStack.getLore() = ItemUtil.getItemLore(this) - - fun isCoOpSoulBound(stack: ItemStack): Boolean = stack.getLore().any { it.contains("Co-op Soulbound") } - - fun isRecombobulated(stack: ItemStack): Boolean = stack.getLore().any { it.contains("§k") } - - fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ).any { name.contains(it) } - - fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 - - fun getItemsInInventoryWithSlots(withCursorItem: Boolean = false): Map { - val map: LinkedHashMap = LinkedHashMap() - val player = Minecraft.getMinecraft().thePlayer - if (player == null) { - LorenzUtils.warning("getItemsInInventoryWithSlots: player is null!") - return map - } - for (slot in player.openContainer.inventorySlots) { - if (slot.hasStack) { - map[slot.stack] = slot.slotNumber - } - } - - if (withCursorItem) { - if (player.inventory != null) { - if (player.inventory.itemStack != null) { - map[player.inventory.itemStack] = -1 - } - } - } - - return map - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzColor.kt b/src/main/java/at/lorenz/mod/utils/LorenzColor.kt deleted file mode 100644 index e60d6d8d1..000000000 --- a/src/main/java/at/lorenz/mod/utils/LorenzColor.kt +++ /dev/null @@ -1,27 +0,0 @@ -package at.lorenz.mod.utils - -import java.awt.Color - -enum class LorenzColor(private var chatColorCode: Char, private val color: Color) { - BLACK('0', Color(0, 0, 0)), - DARK_BLUE('1', Color(0, 0, 170)), - DARK_GREEN('2', Color(0, 170, 0)), - DARK_AQUA('3', Color(0, 170, 170)), - DARK_RED('4', Color(170, 0, 0)), - DARK_PURPLE('5', Color(170, 0, 170)), - GOLD('6', Color(255, 170, 0)), - GRAY('7', Color(170, 170, 170)), - DARK_GRAY('8', Color(85, 85, 85)), - BLUE('9', Color(85, 85, 255)), - GREEN('a', Color(85, 255, 85)), - AQUA('b', Color(85, 255, 255)), - RED('c', Color(255, 85, 85)), - LIGHT_PURPLE('d', Color(255, 85, 255)), - YELLOW('e', Color(255, 255, 85)), - WHITE('f', Color(255, 255, 255)), - ; - - fun getChatColor(): String = "§$chatColorCode" - - fun toColor(): Color = color -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzDebug.kt b/src/main/java/at/lorenz/mod/utils/LorenzDebug.kt deleted file mode 100644 index 32e4ac6f0..000000000 --- a/src/main/java/at/lorenz/mod/utils/LorenzDebug.kt +++ /dev/null @@ -1,16 +0,0 @@ -package at.lorenz.mod.utils - -object LorenzDebug { - - private val logger = LorenzLogger("debug") - - fun log(text: String) { - logger.log(text) - println("debug logger: $text") - } - - fun writeAndLog(text: String) { - LorenzUtils.debug(text) - log(text) - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt b/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt deleted file mode 100644 index 48bfc6099..000000000 --- a/src/main/java/at/lorenz/mod/utils/LorenzLogger.kt +++ /dev/null @@ -1,70 +0,0 @@ -package at.lorenz.mod.utils - -import at.lorenz.mod.utils.LorenzUtils.formatCurrentTime -import java.io.File -import java.io.IOException -import java.text.SimpleDateFormat -import java.util.logging.FileHandler -import java.util.logging.Formatter -import java.util.logging.LogRecord -import java.util.logging.Logger - -class LorenzLogger(filePath: String) { - private val format = SimpleDateFormat("HH:mm:ss") - private val fileName = "$PREFIX_PATH$filePath.log" - - companion object { - private var PREFIX_PATH: String - - init { - val format = SimpleDateFormat("yyyy_MM_dd/HH_mm_ss").formatCurrentTime() - PREFIX_PATH = "mods/LorenzMod/logs/$format/" - } - } - - private lateinit var logger: Logger - - private fun getLogger(): Logger { - if (::logger.isInitialized) { - return logger - } - - val initLogger = initLogger() - this.logger = initLogger - return initLogger - } - - private fun initLogger(): Logger { - val logger = Logger.getLogger("" + System.nanoTime()) - try { - createParent(File(fileName)) - val handler = FileHandler(fileName) - handler.encoding ="utf-8" - logger.addHandler(handler) - handler.formatter = object : Formatter() { - override fun format(logRecord: LogRecord): String { - val message = logRecord.message - return format.formatCurrentTime() + " $message\n" - } - } - } catch (e: SecurityException) { - e.printStackTrace() - } catch (e: IOException) { - e.printStackTrace() - } - return logger - } - - private fun createParent(file: File) { - val parent = file.parentFile - if (parent != null) { - if (!parent.isDirectory) { - parent.mkdirs() - } - } - } - - fun log(text: String?) { - getLogger().info(text) - } -} diff --git a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt b/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt deleted file mode 100644 index 875b41af5..000000000 --- a/src/main/java/at/lorenz/mod/utils/LorenzUtils.kt +++ /dev/null @@ -1,130 +0,0 @@ -package at.lorenz.mod.utils - -import at.lorenz.mod.misc.HypixelData -import net.minecraft.client.Minecraft -import net.minecraft.entity.EntityLivingBase -import net.minecraft.entity.SharedMonsterAttributes -import net.minecraft.util.ChatComponentText -import org.intellij.lang.annotations.Language -import java.text.DecimalFormat -import java.text.SimpleDateFormat - -object LorenzUtils { - - val isOnHypixel: Boolean - get() = HypixelData.hypixel - - val inSkyblock: Boolean - get() = HypixelData.hypixel && HypixelData.skyblock - - val inDungeons: Boolean - get() = HypixelData.hypixel && HypixelData.skyblock && HypixelData.dungeon - - const val DEBUG_PREFIX = "[Debug] §7" - - fun debug(message: String) { - internalChat(DEBUG_PREFIX + message) - } - - fun warning(message: String) { - internalChat("§cWarning! $message") - } - - fun error(message: String) { - internalChat("§4$message") - } - - fun chat(message: String) { - internalChat(message) - } - - private fun internalChat(message: String) { - val minecraft = Minecraft.getMinecraft() - if (minecraft == null) { - println(message) - return - } - - val thePlayer = minecraft.thePlayer - if (thePlayer == null) { - println(message) - return - } - - thePlayer.addChatMessage(ChatComponentText(message)) - } - - fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - - fun String.removeColorCodes(): String { - val builder = StringBuilder() - var skipNext = false - for (c in this.toCharArray()) { - if (c == '§') { - skipNext = true - continue - } - if (skipNext) { - skipNext = false - continue - } - builder.append(c) - } - - return builder.toString() - } - - fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) - - fun stripVanillaMessage(originalMessage: String): String { - var message = originalMessage - - while (message.startsWith("§r")) { - message = message.substring(2) - } - while (message.endsWith("§r")) { - message = message.substring(0, message.length - 2) - } - -// if (!message.startsWith(LorenzUtils.DEBUG_PREFIX + "chat api got (123)")) { -// if (message.matchRegex("(.*)§r§7 \\((.{1,3})\\)")) { -// val indexOf = message.lastIndexOf("(") -//// LorenzAddons.testLogger.log("chat api got (123)!") -//// LorenzAddons.testLogger.log("before: '$message'") -// message = message.substring(0, indexOf - 5) -//// LorenzAddons.testLogger.log("after: '$message'") -//// LorenzAddons.testLogger.log("") -//// LorenzUtils.debug("chat api got (123)") -//// } else if (message.endsWith("§r§7 (2)")) { -////// LorenzAddons.testLogger.log("other variant: '$message'") -////// LorenzAddons.testLogger.log("") -//// LorenzUtils.debug("chat api got WRONG (123)") -// } -// } - - return message - } - - fun Double.round(decimals: Int): Double { - var multiplier = 1.0 - repeat(decimals) { multiplier *= 10 } - return kotlin.math.round(this * multiplier) / multiplier - } - - fun String.between(start: String, end: String): String = this.split(start, end)[1] - - val EntityLivingBase.baseMaxHealth: Double - get() = this.getEntityAttribute(SharedMonsterAttributes.maxHealth).baseValue - - fun formatPercentage(percentage: Double): String = formatPercentage(percentage, "0.00") - - fun formatPercentage(percentage: Double, format: String?): String = - DecimalFormat(format).format(percentage * 100).replace(',', '.') + "%" - - fun formatInteger(i: Int): String = DecimalFormat("#,##0").format(i.toLong()).replace(',', '.') - - fun formatDouble(d: Double, format: String?): String = - DecimalFormat(format).format(d).replace(',', 'x').replace('.', ',').replace('x', '.') - - fun formatDouble(d: Double): String = formatDouble(d, "#,##0.0") -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/LorenzVec.kt b/src/main/java/at/lorenz/mod/utils/LorenzVec.kt deleted file mode 100644 index 7dc29b369..000000000 --- a/src/main/java/at/lorenz/mod/utils/LorenzVec.kt +++ /dev/null @@ -1,61 +0,0 @@ -package at.lorenz.mod.utils - -import net.minecraft.entity.Entity -import net.minecraft.util.BlockPos -import net.minecraft.util.Vec3 -import kotlin.math.pow - -data class LorenzVec( - val x: Double, - val y: Double, - val z: Double -) { - constructor(x: Int, y: Int, z: Int) : this(x.toDouble(), y.toDouble(), z.toDouble()) - - fun toBlocPos(): BlockPos = BlockPos(x, y, z) - - fun toVec3(): Vec3 = Vec3(x, y, z) - - fun distance(other: LorenzVec): Double = distanceSq(other).pow(0.5) - - fun distanceSq(x: Double, y: Double, z: Double): Double = distanceSq(LorenzVec(x, y, z)) - - fun distance(x: Double, y: Double, z: Double): Double = distance(LorenzVec(x, y, z)) - - fun distanceSq(other: LorenzVec): Double { - val dx = (other.x - x) - val dy = (other.y - y) - val dz = (other.z - z) - return (dx * dx + dy * dy + dz * dz) - } - - fun add(x: Double, y: Double, z: Double): LorenzVec = LorenzVec(this.x + x, this.y + y, this.z + z) - - fun add(x: Int, y: Int, z: Int): LorenzVec = LorenzVec(this.x + x, this.y + y, this.z + z) - - override fun toString(): String { - return "LorenzVec{" + - "x=" + x + - ", y=" + y + - ", z=" + z + - '}' - } - - fun multiply(d: Double): LorenzVec = LorenzVec(x multiplyZeroSave d, y multiplyZeroSave d, z multiplyZeroSave d) - - fun multiply(d: Int): LorenzVec = - LorenzVec(x multiplyZeroSave d.toDouble(), y multiplyZeroSave d.toDouble(), z multiplyZeroSave d.toDouble()) - - fun add(other: LorenzVec) = LorenzVec(x + other.x, y + other.y, z + other.z) -} - -private infix fun Double.multiplyZeroSave(other: Double): Double { - val result = this * other - return if (result == -0.0) 0.0 else result -} - -fun BlockPos.toLorenzVec(): LorenzVec = LorenzVec(x, y, z) - -fun Entity.getLorenzVec(): LorenzVec = LorenzVec(posX, posY, posZ) - -fun Vec3.toLorenzVec(): LorenzVec = LorenzVec(xCoord, yCoord, zCoord) \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/NumberUtil.kt b/src/main/java/at/lorenz/mod/utils/NumberUtil.kt deleted file mode 100644 index 12040bd07..000000000 --- a/src/main/java/at/lorenz/mod/utils/NumberUtil.kt +++ /dev/null @@ -1,152 +0,0 @@ -package at.lorenz.mod.utils - -import java.text.NumberFormat -import java.util.* -import kotlin.math.pow -import kotlin.math.roundToInt - -object NumberUtil { - @JvmField - val nf: NumberFormat = NumberFormat.getInstance(Locale.US) - private val suffixes = TreeMap().apply { - this[1000L] = "k" - this[1000000L] = "M" - this[1000000000L] = "B" - this[1000000000000L] = "T" - this[1000000000000000L] = "P" - this[1000000000000000000L] = "E" - } - private val romanSymbols = TreeMap( - mapOf( - 1000 to "M", - 900 to "CM", - 500 to "D", - 400 to "CD", - 100 to "C", - 90 to "XC", - 50 to "L", - 40 to "XL", - 10 to "X", - 9 to "IX", - 5 to "V", - 4 to "IV", - 1 to "I", - ) - ) - - /** - * This code was unmodified and taken under CC BY-SA 3.0 license - * @link https://stackoverflow.com/a/30661479 - * @author assylias - */ - @JvmStatic - fun format(value: Number): String { - @Suppress("NAME_SHADOWING") - val value = value.toLong() - //Long.MIN_VALUE == -Long.MIN_VALUE so we need an adjustment here - if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1) - if (value < 0) return "-" + format(-value) - if (value < 1000) return value.toString() //deal with easy case - val (divideBy, suffix) = suffixes.floorEntry(value) - val truncated = value / (divideBy / 10) //the number part of the output times 10 - val hasDecimal = truncated < 100 && truncated / 10.0 != (truncated / 10).toDouble() - return if (hasDecimal) (truncated / 10.0).toString() + suffix else (truncated / 10).toString() + suffix - } - - @JvmStatic - fun unformat(value: String): Long { - val suffix = value.filter { !it.isDigit() }.lowercase() - val num = value.filter { it.isDigit() }.toLong() - return num * (suffixes.entries.find { it.value.lowercase() == suffix }?.key ?: 1) - } - - /** - * This code was unmodified and taken under CC BY-SA 3.0 license - * @link https://stackoverflow.com/a/22186845 - * @author jpdymond - */ - fun Double.roundToPrecision(precision: Int): Double { - val scale = 10.0.pow(precision).toInt() - return (this * scale).roundToInt().toDouble() / scale - } - - /** - * This code was unmodified and taken under CC BY-SA 3.0 license - * @link https://stackoverflow.com/a/22186845 - * @author jpdymond - */ - fun Float.roundToPrecision(precision: Int): Float { - val scale = 10.0.pow(precision).toInt() - return (this * scale).roundToInt().toFloat() / scale - } - - fun Number.addSuffix(): String { - val long = this.toLong() - if (long in 11..13) return "${this}th" - return when (long % 10) { - 1L -> "${this}st" - 2L -> "${this}nd" - 3L -> "${this}rd" - else -> "${this}th" - } - } - - /** - * This code was converted to Kotlin and taken under CC BY-SA 3.0 license - * @link https://stackoverflow.com/a/9073310 - */ - fun String.romanToDecimal(): Int { - var decimal = 0 - var lastNumber = 0 - val romanNumeral = this.uppercase() - for (x in romanNumeral.length - 1 downTo 0) { - when (romanNumeral[x]) { - 'M' -> { - decimal = processDecimal(1000, lastNumber, decimal) - lastNumber = 1000 - } - 'D' -> { - decimal = processDecimal(500, lastNumber, decimal) - lastNumber = 500 - } - 'C' -> { - decimal = processDecimal(100, lastNumber, decimal) - lastNumber = 100 - } - 'L' -> { - decimal = processDecimal(50, lastNumber, decimal) - lastNumber = 50 - } - 'X' -> { - decimal = processDecimal(10, lastNumber, decimal) - lastNumber = 10 - } - 'V' -> { - decimal = processDecimal(5, lastNumber, decimal) - lastNumber = 5 - } - 'I' -> { - decimal = processDecimal(1, lastNumber, decimal) - lastNumber = 1 - } - } - } - return decimal - } - - fun Int.toRoman(): String { - if (this <= 0) error("$this must be positive!") - val l = romanSymbols.floorKey(this) - return if (this == l) { - romanSymbols[this]!! - } else romanSymbols[l] + (this - l).toRoman() - } - - private fun processDecimal(decimal: Int, lastNumber: Int, lastDecimal: Int): Int { - return if (lastNumber > decimal) { - lastDecimal - decimal - } else { - lastDecimal + decimal - } - } -} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/utils/RenderUtils.kt b/src/main/java/at/lorenz/mod/utils/RenderUtils.kt deleted file mode 100644 index 2e422ed6a..000000000 --- a/src/main/java/at/lorenz/mod/utils/RenderUtils.kt +++ /dev/null @@ -1,355 +0,0 @@ -package at.lorenz.mod.utils - -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.Gui -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.Tessellator -import net.minecraft.client.renderer.vertex.DefaultVertexFormats -import net.minecraft.inventory.Slot -import net.minecraft.util.AxisAlignedBB -import net.minecraft.util.MathHelper -import net.minecraft.util.ResourceLocation -import net.minecraft.util.Vec3 -import net.minecraftforge.client.event.RenderWorldLastEvent -import org.lwjgl.opengl.GL11 -import java.awt.Color -import kotlin.math.cos -import kotlin.math.sin -import kotlin.math.sqrt - -object RenderUtils { - - val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png") - - infix fun Slot.highlight(color: LorenzColor) { - Gui.drawRect( - this.xDisplayPosition, - this.yDisplayPosition, - this.xDisplayPosition + 16, - this.yDisplayPosition + 16, - color.toColor().rgb - ) - } - - fun RenderWorldLastEvent.drawColor(location: LorenzVec, color: LorenzColor, beacon: Boolean = false) { - val (viewerX, viewerY, viewerZ) = getViewerPos(partialTicks) - val x = location.x - viewerX - val y = location.y - viewerY - val z = location.z - viewerZ - val distSq = x * x + y * y + z * z - GlStateManager.disableDepth() - GlStateManager.disableCull() - drawFilledBoundingBox( - AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1).expandBlock(), - color.toColor(), - (0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(0.2f) - ) - GlStateManager.disableTexture2D() - if (distSq > 5 * 5 && beacon) renderBeaconBeam(x, y + 1, z, color.toColor().rgb, 1.0f, partialTicks) - GlStateManager.disableLighting() - GlStateManager.enableTexture2D() - GlStateManager.enableDepth() - GlStateManager.enableCull() - } - - - fun getViewerPos(partialTicks: Float): LorenzVec { - val viewer = Minecraft.getMinecraft().renderViewEntity - val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks - val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks - val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks - return LorenzVec(viewerX, viewerY, viewerZ) - } - - /** - * Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0 - * https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE - * @author Moulberry - * @author Mojang - */ - private fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) { - GlStateManager.enableBlend() - GlStateManager.disableLighting() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.disableTexture2D() - val tessellator = Tessellator.getInstance() - val worldRenderer = tessellator.worldRenderer - GlStateManager.color(c.red / 255f, c.green / 255f, c.blue / 255f, c.alpha / 255f * alphaMultiplier) - - //vertical - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() - tessellator.draw() - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() - tessellator.draw() - GlStateManager.color( - c.red / 255f * 0.8f, - c.green / 255f * 0.8f, - c.blue / 255f * 0.8f, - c.alpha / 255f * alphaMultiplier - ) - - //x - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() - tessellator.draw() - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() - tessellator.draw() - GlStateManager.color( - c.red / 255f * 0.9f, - c.green / 255f * 0.9f, - c.blue / 255f * 0.9f, - c.alpha / 255f * alphaMultiplier - ) - //z - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() - tessellator.draw() - worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) - worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() - worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() - tessellator.draw() - GlStateManager.enableTexture2D() - GlStateManager.disableBlend() - } - - fun AxisAlignedBB.expandBlock() = expand(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026) - - /** - * Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0 - * https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE - * @author Moulberry - * @author Mojang - */ - fun renderBeaconBeam(x: Double, y: Double, z: Double, rgb: Int, alphaMultiplier: Float, partialTicks: Float) { - val height = 300 - val bottomOffset = 0 - val topOffset = bottomOffset + height - val tessellator = Tessellator.getInstance() - val worldrenderer = tessellator.worldRenderer - Minecraft.getMinecraft().textureManager.bindTexture(beaconBeam) - GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0f) - GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0f) - GlStateManager.disableLighting() - GlStateManager.enableCull() - GlStateManager.enableTexture2D() - GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0) - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - val time = Minecraft.getMinecraft().theWorld.totalWorldTime + partialTicks.toDouble() - val d1 = MathHelper.func_181162_h( - -time * 0.2 - MathHelper.floor_double(-time * 0.1) - .toDouble() - ) - val r = (rgb shr 16 and 0xFF) / 255f - val g = (rgb shr 8 and 0xFF) / 255f - val b = (rgb and 0xFF) / 255f - val d2 = time * 0.025 * -1.5 - val d4 = 0.5 + cos(d2 + 2.356194490192345) * 0.2 - val d5 = 0.5 + sin(d2 + 2.356194490192345) * 0.2 - val d6 = 0.5 + cos(d2 + Math.PI / 4.0) * 0.2 - val d7 = 0.5 + sin(d2 + Math.PI / 4.0) * 0.2 - val d8 = 0.5 + cos(d2 + 3.9269908169872414) * 0.2 - val d9 = 0.5 + sin(d2 + 3.9269908169872414) * 0.2 - val d10 = 0.5 + cos(d2 + 5.497787143782138) * 0.2 - val d11 = 0.5 + sin(d2 + 5.497787143782138) * 0.2 - val d14 = -1.0 + d1 - val d15 = height.toDouble() * 2.5 + d14 - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR) - worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0, d14).color(r, g, b, 1.0f).endVertex() - worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier) - .endVertex() - tessellator.draw() - GlStateManager.disableCull() - val d12 = -1.0 + d1 - val d13 = height + d12 - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR) - worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex() - worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier) - .endVertex() - tessellator.draw() - } - - fun RenderWorldLastEvent.drawString(location: LorenzVec, text: String, seeThroughBlocks: Boolean = false) { - GlStateManager.alphaFunc(516, 0.1f) - GlStateManager.pushMatrix() - val viewer = Minecraft.getMinecraft().renderViewEntity - val renderManager = Minecraft.getMinecraft().renderManager - var x = location.x - renderManager.viewerPosX - var y = location.y - renderManager.viewerPosY - viewer.eyeHeight - var z = location.z - renderManager.viewerPosZ - val distSq = x * x + y * y + z * z - val dist = sqrt(distSq) - if (distSq > 144) { - x *= 12 / dist - y *= 12 / dist - z *= 12 / dist - } - - if (seeThroughBlocks) { - GlStateManager.disableDepth() - GlStateManager.disableCull() - } - - GlStateManager.translate(x, y, z) - GlStateManager.translate(0f, viewer.eyeHeight, 0f) - drawNametag(text) - GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f) - GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f) - GlStateManager.translate(0f, -0.25f, 0f) - GlStateManager.rotate(-renderManager.playerViewX, 1.0f, 0.0f, 0.0f) - GlStateManager.rotate(renderManager.playerViewY, 0.0f, 1.0f, 0.0f) -// RenderUtil.drawNametag(EnumChatFormatting.YELLOW.toString() + dist.roundToInt() + "m") - GlStateManager.popMatrix() - GlStateManager.disableLighting() - - - if (seeThroughBlocks) { - GlStateManager.enableDepth() - GlStateManager.enableCull() - } - } - - /** - * @author Mojang - */ - fun drawNametag(str: String?) { - val fontRenderer = Minecraft.getMinecraft().fontRendererObj - val f1 = 0.02666667f - GlStateManager.pushMatrix() - GL11.glNormal3f(0.0f, 1.0f, 0.0f) - GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f) - GlStateManager.rotate( - Minecraft.getMinecraft().renderManager.playerViewX, - 1.0f, - 0.0f, - 0.0f - ) - GlStateManager.scale(-f1, -f1, f1) - GlStateManager.disableLighting() - GlStateManager.depthMask(false) - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - val tessellator = Tessellator.getInstance() - val worldrenderer = tessellator.worldRenderer - val i = 0 - val j = fontRenderer.getStringWidth(str) / 2 - GlStateManager.disableTexture2D() - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR) - worldrenderer.pos((-j - 1).toDouble(), (-1 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() - worldrenderer.pos((-j - 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() - worldrenderer.pos((j + 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() - worldrenderer.pos((j + 1).toDouble(), (-1 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex() - tessellator.draw() - GlStateManager.enableTexture2D() - fontRenderer.drawString(str, -j, i, 553648127) - GlStateManager.depthMask(true) - fontRenderer.drawString(str, -j, i, -1) - GlStateManager.enableBlend() - GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) - GlStateManager.popMatrix() - } - - /** - * @author Mojang - */ - fun drawLabel( - pos: Vec3, - text: String, - color: Color, - partialTicks: Float, - shadow: Boolean = false, - scale: Float = 1f - ) { - var mc = Minecraft.getMinecraft() - val player = mc.thePlayer - val x = - pos.xCoord - player.lastTickPosX + (pos.xCoord - player.posX - (pos.xCoord - player.lastTickPosX)) * partialTicks - val y = - pos.yCoord - player.lastTickPosY + (pos.yCoord - player.posY - (pos.yCoord - player.lastTickPosY)) * partialTicks - val z = - pos.zCoord - player.lastTickPosZ + (pos.zCoord - player.posZ - (pos.zCoord - player.lastTickPosZ)) * partialTicks - val renderManager = mc.renderManager - val f1 = 0.0266666688 - val width = mc.fontRendererObj.getStringWidth(text) / 2 - GlStateManager.pushMatrix() - GlStateManager.translate(x, y, z) - GL11.glNormal3f(0f, 1f, 0f) - GlStateManager.rotate(-renderManager.playerViewY, 0f, 1f, 0f) - GlStateManager.rotate(renderManager.playerViewX, 1f, 0f, 0f) - GlStateManager.scale(-f1, -f1, -f1) - GlStateManager.scale(scale, scale, scale) - GlStateManager.enableBlend() - GlStateManager.disableLighting() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - GlStateManager.enableTexture2D() - mc.fontRendererObj.drawString(text, (-width).toFloat(), 0f, color.rgb, shadow) - GlStateManager.disableBlend() - GlStateManager.popMatrix() - } - - fun interpolate(currentValue: Double, lastValue: Double, multiplier: Float): Double { - return lastValue + (currentValue - lastValue) * multiplier - } -} \ No newline at end of file -- cgit