Skip to content

Commit

Permalink
Internal Change: Code Cleanup (#661)
Browse files Browse the repository at this point in the history
Code cleanup #661
  • Loading branch information
walkerselby authored Nov 26, 2023
1 parent 46e531a commit 0721f25
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ object Commands {
ConfigGuiManager.openConfigGui(it.joinToString(" "))
}
} else {
val arr = mutableListOf<String>()
ConfigGuiManager.openConfigGui()
}
}
Expand Down
42 changes: 0 additions & 42 deletions src/main/java/at/hannibal2/skyhanni/data/OtherMod.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class ChromaFontRenderer(private val baseColor: Int) {
}

fun restoreChromaEnv() {
if (ShaderHelper.areShadersSupported()) {
if (!chromaOn) ChromaShaderManager.end()
}
if (ShaderHelper.areShadersSupported() && !chromaOn) ChromaShaderManager.end()
}

fun newChromaEnv(): ChromaFontRenderer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ import net.minecraft.client.Minecraft
* Credit: [ChromaShader.java](https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaShader.java)
*/
object ChromaShader : Shader("chroma", "chroma") {

val config get() = SkyHanniMod.feature.chroma
val INSTANCE: ChromaShader
get() = this

override fun registerUniforms() {
registerUniform(Uniform.UniformType.FLOAT, "chromaSize") {
SkyHanniMod.feature.chroma.chromaSize * (Minecraft.getMinecraft().displayWidth / 100f)
config.chromaSize * (Minecraft.getMinecraft().displayWidth / 100f)
}
registerUniform(Uniform.UniformType.FLOAT, "timeOffset") {
var ticks =
(MinecraftData.totalTicks / 2) + (Minecraft.getMinecraft() as AccessorMinecraft).timer.renderPartialTicks

ticks = when (SkyHanniMod.feature.chroma.chromaDirection) {
ticks = when (config.chromaDirection) {
0, 2 -> ticks
1, 3 -> -ticks
else -> ticks
}

val chromaSpeed = SkyHanniMod.feature.chroma.chromaSpeed / 360f
val chromaSpeed = config.chromaSpeed / 360f
ticks * chromaSpeed
}
registerUniform(Uniform.UniformType.FLOAT, "saturation") {
SkyHanniMod.feature.chroma.chromaSaturation
config.chromaSaturation
}
registerUniform(Uniform.UniformType.BOOL, "forwardDirection") {
when (SkyHanniMod.feature.chroma.chromaDirection) {
when (config.chromaDirection) {
0, 1 -> true
2, 3 -> false
else -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ItemDisplayOverlayFeatures {
private val config get() = SkyHanniMod.feature.inventory

private val rancherBootsSpeedCapPattern = "§7Current Speed Cap: §a(?<cap>.*)".toPattern()
private val petLevelPattern = "\\[Lvl (?<level>.*)] .*".toPattern()
private val gardenVacuumPatterm = "§7Vacuum Bag: §6(?<amount>\\d*) Pests?".toPattern()
Expand Down Expand Up @@ -91,7 +90,7 @@ class ItemDisplayOverlayFeatures {
return last.romanToDecimal().toString()
}

if (SkyHanniMod.feature.inventory.displaySackName && ItemUtils.isSack(item)) {
if (config.displaySackName && ItemUtils.isSack(item)) {
val sackName = grabSackName(itemName)
return (if (itemName.contains("Enchanted")) "§5" else "") + sackName.substring(0, 2)
}
Expand All @@ -109,7 +108,8 @@ class ItemDisplayOverlayFeatures {

if (itemNumberAsStackSize.contains(9) &&
InventoryUtils.openInventoryName() == "Your Skills" &&
item.getLore().any { it.contains("Click to view!") }
item.getLore()
.any { it.contains("Click to view!") }
) {
if (CollectionAPI.isCollectionTier0(item.getLore())) return "0"
val split = itemName.split(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ItemStars {

private val config get() = SkyHanniMod.feature.inventory

private val armorNames = mutableListOf<String>()
private val tiers = mutableMapOf<String, Int>()
private val STAR_FIND_PATCHER = "(.*)§.✪(.*)".toPattern()
private val starFindPattern = "(.*)§.✪(.*)".toPattern()
private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots")

@SubscribeEvent(priority = EventPriority.LOW)
fun onTooltip(event: ItemTooltipEvent) {
if (!LorenzUtils.inSkyBlock) return

if (!isEnabled()) return
val stack = event.itemStack ?: return
if (stack.stackSize != 1) return
if (!SkyHanniMod.feature.inventory.itemStars) return


val itemName = stack.name ?: return
val stars = getStars(itemName)

if (stars > 0) {
var name = itemName
while (STAR_FIND_PATCHER.matcher(name).matches()) {
while (starFindPattern.matcher(name).matches()) {
name = name.replaceFirst("§.✪".toRegex(), "")
}
name = name.trim()
Expand All @@ -51,7 +52,7 @@ class ItemStars {

@SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
if (!SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(6)) return
if (!config.itemNumberAsStackSize.contains(6)) return
val stack = event.stack
val number = getCrimsonStars(stack.name ?: return)
if (number != -1) {
Expand Down Expand Up @@ -120,4 +121,6 @@ class ItemStars {

return -1
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.itemStars
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class MarkedPlayerManager {

private val config get() = SkyHanniMod.feature.markedPlayers

companion object {
val playerNamesToMark = mutableListOf<String>()
private val markedPlayers = mutableMapOf<String, EntityOtherPlayerMP>()
Expand Down Expand Up @@ -64,7 +66,7 @@ class MarkedPlayerManager {

@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
SkyHanniMod.feature.markedPlayers.markOwnName.whenChanged { _, new ->
config.markOwnName.whenChanged { _, new ->
val name = LorenzUtils.getPlayerName()
if (new) {
if (!playerNamesToMark.contains(name)) {
Expand All @@ -87,8 +89,7 @@ class MarkedPlayerManager {

@SubscribeEvent
fun onRenderMobColored(event: RenderMobColoredEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniMod.feature.markedPlayers.highlightInWorld) return
if (!isEnabled()) return

val entity = event.entity
if (entity in markedPlayers.values) {
Expand All @@ -98,8 +99,7 @@ class MarkedPlayerManager {

@SubscribeEvent
fun onResetEntityHurtTime(event: ResetEntityHurtEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniMod.feature.markedPlayers.highlightInWorld) return
if (!isEnabled()) return

val entity = event.entity
if (entity in markedPlayers.values) {
Expand All @@ -112,11 +112,13 @@ class MarkedPlayerManager {
if (Minecraft.getMinecraft().thePlayer == null) return

markedPlayers.clear()
if (SkyHanniMod.feature.markedPlayers.markOwnName.get()) {
if (config.markOwnName.get()) {
val name = LorenzUtils.getPlayerName()
if (!playerNamesToMark.contains(name)) {
playerNamesToMark.add(name)
}
}
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.highlightInWorld
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HideMobNames {
private val patterns = mutableListOf<Pattern>()

init {
// TODO USE SH-REPO
addMobToHide("Zombie")
addMobToHide("Zombie")
addMobToHide("Zombie Villager")
Expand Down Expand Up @@ -84,4 +85,4 @@ class HideMobNames {

return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.time.Duration.Companion.seconds
class SlayerBossSpawnSoon {

private val config get() = SkyHanniMod.feature.slayer.slayerBossWarning
private val pattern = " \\(?(?<progress>[0-9.,k]+)\\/(?<total>[0-9.,k]+)\\)?.*".toPattern()
private val pattern = " \\(?(?<progress>[0-9.,k]+)/(?<total>[0-9.,k]+)\\)?.*".toPattern()
private var lastCompletion = 0f
private var warned = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class SummoningMobManager {
private var searchMobs = false

//§aYou have spawned your Tank Zombie §r§asoul! §r§d(249 Mana)
private val spawnPatter = "§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)".toPattern()
private val despawnPatter = "§cYou have despawned your (monster|monsters)!".toPattern()
private val spawnPattern = "§aYou have spawned your (.+) §r§asoul! §r§d\\((\\d+) Mana\\)".toPattern()
private val despawnPattern = "§cYou have despawned your (monster|monsters)!".toPattern()

//§a§ohannibal2's Tank Zombie§r §a160k§c❤
private val healthPattern = "§a§o(.+)'s (.+)§r §[ae]([\\dkm]+)§c❤".toPattern()
Expand All @@ -50,7 +50,7 @@ class SummoningMobManager {
if (!LorenzUtils.inSkyBlock) return

val message = event.message
spawnPatter.matchMatcher(message) {
spawnPattern.matchMatcher(message) {
if (config.summoningMobDisplay) {
event.blockedReason = "summoning_soul"
}
Expand All @@ -59,7 +59,7 @@ class SummoningMobManager {
searchMobs = true
}

if (despawnPatter.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) {
if (despawnPattern.matcher(message).matches() || message.startsWith("§c ☠ §r§7You ")) {
despawned()
if (config.summoningMobDisplay && !message.contains("")) {
event.blockedReason = "summoning_soul"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import net.minecraft.network.Packet
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo

fun onReceivePacket(packet: Packet<*>, ci: CallbackInfo) {
if (packet != null && PacketEvent.ReceiveEvent(packet).postAndCatch()) ci.cancel()
}
if (PacketEvent.ReceiveEvent(packet).postAndCatch()) ci.cancel()
}

0 comments on commit 0721f25

Please sign in to comment.