Skip to content

Commit

Permalink
refactor: renamed equalsOneOf and changed to extention function
Browse files Browse the repository at this point in the history
  • Loading branch information
TakoTheDev committed Oct 4, 2024
1 parent 77661ee commit 09f0c39
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import dev.falsehonesty.asmhelper.dsl.instructions.JumpCondition
import dev.falsehonesty.asmhelper.dsl.instructions.Local
import dev.falsehonesty.asmhelper.dsl.modify
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import gg.skytils.skytilsmod.utils.matches
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*

fun injectScoreboardScoreRemover() = modify("net/minecraft/client/gui/GuiIngame") {
classNode.methods.find {
Utils.equalsOneOf(it.name, "renderScoreboard", "a") && Utils.equalsOneOf(
it.desc,
it.name.equalsAnyOf("renderScoreboard", "a") && it.desc.equalsAnyOf(
"(Lauk;Lavr;)V",
"(Lnet/minecraft/scoreboard/ScoreObjective;Lnet/minecraft/client/gui/ScaledResolution;)V"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ import dev.falsehonesty.asmhelper.dsl.instructions.InsnListBuilder
import dev.falsehonesty.asmhelper.dsl.instructions.JumpCondition
import dev.falsehonesty.asmhelper.dsl.modify
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.*

fun injectNullCheck() = modify("net.minecraft.client.gui.GuiNewChat") {
classNode.methods.find {
Utils.equalsOneOf(it.name, "drawChat", "avt") && it.desc == "(I)V"
it.name.equalsAnyOf("drawChat", "avt") && it.desc == "(I)V"
}?.apply {
var chatLineVar: VarInsnNode? = null
for (insn in instructions) {
if (chatLineVar == null && insn is VarInsnNode && insn.opcode == Opcodes.ASTORE) {
val prev = insn.previous
if (prev is TypeInsnNode && prev.opcode == Opcodes.CHECKCAST && Utils.equalsOneOf(
prev.desc,
if (prev is TypeInsnNode && prev.opcode == Opcodes.CHECKCAST && prev.desc.equalsAnyOf(
"net/minecraft/client/gui/ChatLine", "ava"
)
)
chatLineVar = insn
}
if (chatLineVar != null && insn is MethodInsnNode && insn.owner == classNode.name && Utils.equalsOneOf(
insn.name,
if (chatLineVar != null && insn is MethodInsnNode && insn.owner == classNode.name && insn.name.equalsAnyOf(
"drawRect", "a"
) && insn.desc == "(IIIII)V"
) {
Expand All @@ -58,14 +57,12 @@ fun injectNullCheck() = modify("net.minecraft.client.gui.GuiNewChat") {
}
}
classNode.methods.find {
Utils.equalsOneOf(it.name, "setChatLine", "a") && Utils.equalsOneOf(
it.desc,
it.name.equalsAnyOf("setChatLine", "a") && it.desc.equalsAnyOf(
"(Lnet/minecraft/util/IChatComponent;IIZ)V", "(Leu;IIZ)V"
)
}?.apply {
for (insn in instructions) {
if (insn.opcode == Opcodes.INVOKESPECIAL && insn is MethodInsnNode && insn.name == "<init>" && Utils.equalsOneOf(
insn.owner,
if (insn.opcode == Opcodes.INVOKESPECIAL && insn is MethodInsnNode && insn.name == "<init>" && insn.owner.equalsAnyOf(
"net/minecraft/client/gui/ChatLine", "ava"
)
) {
Expand All @@ -82,7 +79,7 @@ fun injectNullCheck() = modify("net.minecraft.client.gui.GuiNewChat") {
}
}
classNode.methods.find {
Utils.equalsOneOf(it.name, "refreshChat", "b") && it.desc == "()V"
it.name.equalsAnyOf("refreshChat", "b") && it.desc == "()V"
}?.apply {
var labelNode: LabelNode? = null
var incInsn: VarInsnNode? = null
Expand All @@ -100,11 +97,10 @@ fun injectNullCheck() = modify("net.minecraft.client.gui.GuiNewChat") {
2 -> prev.opcode == Opcodes.ISUB
3 -> prev.opcode == Opcodes.ICONST_1
4 -> prev is MethodInsnNode && prev.owner == "java/util/List" && prev.name == "size"
5 -> prev is FieldInsnNode && prev.opcode == Opcodes.GETFIELD && Utils.equalsOneOf(
prev.owner,
5 -> prev is FieldInsnNode && prev.opcode == Opcodes.GETFIELD && prev.owner.equalsAnyOf(
"net/minecraft/client/gui/GuiNewChat",
"avt"
) && Utils.equalsOneOf(prev.name, "chatLines", "h") && prev.desc == "Ljava/util/List;"
) && prev.name.equalsAnyOf("chatLines", "h") && prev.desc == "Ljava/util/List;"

else -> throw NotImplementedError()
}
Expand All @@ -117,11 +113,10 @@ fun injectNullCheck() = modify("net.minecraft.client.gui.GuiNewChat") {
}
if (labelNode != null && incInsn != null && insn is VarInsnNode && insn.opcode == Opcodes.ASTORE) {
val temp = insn.previous?.previous?.previous?.previous ?: continue
if (temp.opcode == Opcodes.GETFIELD && temp is FieldInsnNode && Utils.equalsOneOf(
temp.owner,
if (temp.opcode == Opcodes.GETFIELD && temp is FieldInsnNode && temp.owner.equalsAnyOf(
"net/minecraft/client/gui/GuiNewChat",
"avt"
) && Utils.equalsOneOf(temp.name, "chatLines", "h") && temp.desc == "Ljava/util/List;"
) && temp.name.equalsAnyOf("chatLines", "h") && temp.desc == "Ljava/util/List;"
) {
instructions.insert(insn, InsnListBuilder(this).apply {
aload(insn.`var`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,32 @@ package gg.skytils.skytilsmod.asm.transformers
import dev.falsehonesty.asmhelper.dsl.instructions.InsnListBuilder
import dev.falsehonesty.asmhelper.dsl.modify
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.VarInsnNode

fun changeRenderedName() = modify("net.minecraft.client.renderer.entity.RendererLivingEntity") {
classNode.apply {
this.methods.find {
Utils.equalsOneOf(
it.name,
it.name.equalsAnyOf(
"renderName",
"b"
) && Utils.equalsOneOf(it.desc, "(Lnet/minecraft/entity/EntityLivingBase;DDD)V", "(Lpr;DDD)V")
) && it.desc.equalsAnyOf("(Lnet/minecraft/entity/EntityLivingBase;DDD)V", "(Lpr;DDD)V")
}?.apply {
for (insn in instructions) {
if (insn is VarInsnNode && insn.opcode == Opcodes.ASTORE) {
var prev = insn.previous
if (prev is MethodInsnNode && prev.opcode == Opcodes.INVOKEINTERFACE &&
Utils.equalsOneOf(prev.owner, "net/minecraft/util/IChatComponent", "eu") && Utils.equalsOneOf(
prev.name,
prev.owner.equalsAnyOf("net/minecraft/util/IChatComponent", "eu") && prev.name.equalsAnyOf(
"getFormattedText", "d"
) && prev.desc == "()Ljava/lang/String;"
) {
prev = prev.previous
if (prev is MethodInsnNode && prev.opcode == Opcodes.INVOKEVIRTUAL
&& Utils.equalsOneOf(prev.owner, "net/minecraft/entity/EntityLivingBase", "pr")
&& Utils.equalsOneOf(prev.name, "getDisplayName", "f_")
&& Utils.equalsOneOf(prev.desc, "()Lnet/minecraft/util/IChatComponent;", "()Leu;")
&& prev.owner.equalsAnyOf("net/minecraft/entity/EntityLivingBase", "pr")
&& prev.name.equalsAnyOf("getDisplayName", "f_")
&& prev.desc.equalsAnyOf("()Lnet/minecraft/util/IChatComponent;", "()Leu;")
) {
prev = prev.previous
if (prev is VarInsnNode && prev.opcode == Opcodes.ALOAD && prev.`var` == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorC0EPacketClic
import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorEnumDyeColor
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsmod.utils.ItemUtil.setLore
import gg.skytils.skytilsmod.utils.Utils.equalsOneOf
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer.TextAlignment
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
Expand Down Expand Up @@ -268,8 +267,8 @@ object DungeonFeatures {
if (!Utils.inDungeons) return
val displayData = event.displayData
val unformatted = event.displayData.displayName.unformattedText.stripControlCodes()
if (equalsOneOf(dungeonFloor, "F7", "M7")) {
if (equalsOneOf(unformatted, "Maxor", "Storm", "Goldor", "Necron")) {
if (dungeonFloor.equalsAnyOf("F7", "M7")) {
if (unformatted.equalsAnyOf("Maxor", "Storm", "Goldor", "Necron")) {
when (Skytils.config.necronHealth) {
2 -> {
BossStatus.healthScale = displayData.health / displayData.maxHealth
Expand Down Expand Up @@ -306,7 +305,7 @@ object DungeonFeatures {
}
return
}
if (equalsOneOf(dungeonFloor, "F6", "M6")) {
if (dungeonFloor.equalsAnyOf("F6", "M6")) {
if (terracottaEndTime == -1.0) {
if (unformatted.contains("Sadan's Interest Level")) {
val length = if (dungeonFloor == "F6") 105 else 115
Expand Down Expand Up @@ -416,8 +415,7 @@ object DungeonFeatures {
fun onRenderLivingPre(event: RenderLivingEvent.Pre<*>) {
if (Utils.inDungeons) {
val matrixStack = UMatrixStack()
if (Skytils.config.boxSpiritBow && hasBossSpawned && event.entity.isInvisible && equalsOneOf(
dungeonFloor,
if (Skytils.config.boxSpiritBow && hasBossSpawned && event.entity.isInvisible && dungeonFloor.equalsAnyOf(
"F4",
"M4"
) && event.entity is EntityArmorStand && event.entity.heldItem?.item == Items.bow
Expand Down Expand Up @@ -465,12 +463,10 @@ object DungeonFeatures {
if (!mc.renderManager.isDebugBoundingBox) {
if (!event.entity.isInvisible) {
if (event.entity is EntityBat && Skytils.config.showBatHitboxes && !hasBossSpawned &&
if (MayorInfo.currentMayor == "Derpy") equalsOneOf(
event.entity.maxHealth,
if (MayorInfo.currentMayor == "Derpy") event.entity.maxHealth.equalsAnyOf(
200f,
800f
) else equalsOneOf(
event.entity.maxHealth,
) else event.entity.maxHealth.equalsAnyOf(
100f,
400f
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.utils.SBInfo
import gg.skytils.skytilsmod.utils.SkyblockIsland
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
Expand Down Expand Up @@ -184,8 +185,7 @@ object CatlasElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {

val name = mutableListOf<String>()

if ((CatlasConfig.mapRoomNames != 0 && roomType == RoomType.PUZZLE) || (CatlasConfig.mapRoomNames >= 2 && roomType == RoomType.TRAP) || (CatlasConfig.mapRoomNames == 3 && Utils.equalsOneOf(
roomType,
if ((CatlasConfig.mapRoomNames != 0 && roomType == RoomType.PUZZLE) || (CatlasConfig.mapRoomNames >= 2 && roomType == RoomType.TRAP) || (CatlasConfig.mapRoomNames == 3 && roomType.equalsAnyOf(
RoomType.NORMAL, RoomType.RARE, RoomType.CHAMPION
))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map

import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf

enum class Puzzle(val roomDataName: String, val tabName: String = roomDataName) {
BOMB_DEFUSE("Bomb Defuse"),
Expand All @@ -36,7 +37,7 @@ enum class Puzzle(val roomDataName: String, val tabName: String = roomDataName)

companion object {
fun fromName(name: String): Puzzle? {
return entries.find { Utils.equalsOneOf(name, it.roomDataName, it.tabName) }
return entries.find { name.equalsAnyOf(it.roomDataName, it.tabName) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.catlas.utils.MapUtils.mapZ
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.utils.MapUtils.yaw
import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
import net.minecraft.world.storage.MapData
Expand Down Expand Up @@ -86,7 +87,7 @@ object MapUpdater {
}
}

if (room is Door && Utils.equalsOneOf(room.type, DoorType.ENTRANCE, DoorType.WITHER, DoorType.BLOOD)) {
if (room is Door && room.type.equalsAnyOf(DoorType.ENTRANCE, DoorType.WITHER, DoorType.BLOOD)) {
if (mapTile is Door && mapTile.type == DoorType.WITHER) {
room.opened = false
} else if (!room.opened) {
Expand All @@ -96,7 +97,7 @@ object MapUpdater {
)
if (chunk.isLoaded) {
if (chunk.getBlockState(BlockPos(room.x, 69, room.z)).block == Blocks.air)
room.opened = true
room.opened = true
} else if (mapTile is Door && mapTile.state == RoomState.DISCOVERED) {
if (room.type == DoorType.BLOOD) {
val bloodRoom = DungeonInfo.uniqueRooms.find { r ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonMapColorParser
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import net.minecraft.item.ItemMap
import net.minecraft.util.Vec4b
import net.minecraft.world.storage.MapData
Expand Down Expand Up @@ -55,7 +56,7 @@ object MapUtils {
*/
fun calibrateMap(): Boolean {
val (start, size) = findEntranceCorner()
if (Utils.equalsOneOf(size, 16, 18)) {
if (size.equalsAnyOf(16, 18)) {
mapRoomSize = size
startCorner = when (DungeonFeatures.dungeonFloorNumber) {
0 -> Pair(22, 22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.CatlasConfig
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.CatlasElement
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.DungeonMapPlayer
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.ItemUtil
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.bindColor
import gg.skytils.skytilsmod.utils.ifNull
import gg.skytils.skytilsmod.utils.*
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
Expand Down Expand Up @@ -189,10 +186,10 @@ object RenderUtils {
}

// Handle player names
if (CatlasConfig.playerHeads == 2 || CatlasConfig.playerHeads == 1 && Utils.equalsOneOf(
ItemUtil.getSkyBlockItemID(mc.thePlayer.heldItem),
"SPIRIT_LEAP", "INFINITE_SPIRIT_LEAP", "HAUNT_ABILITY"
)
if (CatlasConfig.playerHeads == 2 || CatlasConfig.playerHeads == 1 && ItemUtil.getSkyBlockItemID(mc.thePlayer.heldItem)
.equalsAnyOf(
"SPIRIT_LEAP", "INFINITE_SPIRIT_LEAP", "HAUNT_ABILITY"
)
) {
if (!CatlasConfig.mapRotate) {
GlStateManager.rotate(-player.yaw + 180f, 0f, 0f, 1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map.RoomData
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.decodeFromStream
import net.minecraft.block.Block
Expand Down Expand Up @@ -68,7 +69,7 @@ object ScanUtils {
val chunk = mc.theWorld.getChunkFromBlockCoords(BlockPos(x, 0, z))
for (y in 140 downTo 12) {
val id = Block.blockRegistry.getIDForObject(chunk.getBlock(BlockPos(x, y, z)))
if (!Utils.equalsOneOf(id, 5, 54, 146)) {
if (!id.equalsAnyOf(5, 54, 146)) {
sb.append(id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.utils.DevTools
import gg.skytils.skytilsmod.utils.RenderUtil
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.equalsAnyOf
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.init.Blocks
import net.minecraft.network.play.server.S08PacketPlayerPosLook
Expand Down Expand Up @@ -65,8 +66,7 @@ object TeleportMazeSolver {
event.packet.apply {
when (this) {
is S08PacketPlayerPosLook -> {
if (y == 69.5 && Utils.equalsOneOf(
mc.thePlayer.posY,
if (y == 69.5 && mc.thePlayer.posY.equalsAnyOf(
69.5,
69.8125
) && abs(x % 1) == 0.5 && abs(z % 1) == 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ object AlignmentTaskSolver {
if (grid.size < 25) {
@Suppress("UNCHECKED_CAST")
val frames = mc.theWorld.loadedEntityList.filter {
it is EntityItemFrame && box.contains(it.position) && it.displayedItem != null && Utils.equalsOneOf(
it.displayedItem.item,
it is EntityItemFrame && box.contains(it.position) && it.displayedItem != null && it.displayedItem.item.equalsAnyOf(
Items.arrow,
Item.getItemFromBlock(Blocks.wool)
)
Expand Down
Loading

0 comments on commit 09f0c39

Please sign in to comment.