aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-10-15 22:08:04 -0400
committerMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-10-15 22:08:04 -0400
commitd64361cbc01c61f4d7e412f7074601e3cfffe43f (patch)
tree506c200d3b9462327dfa6f036c58345740e3d296 /src/main
parent8172e5d52e86d8fd65198dfc409117938662a29d (diff)
downloadSkytilsMod-d64361cbc01c61f4d7e412f7074601e3cfffe43f.tar.gz
SkytilsMod-d64361cbc01c61f4d7e412f7074601e3cfffe43f.tar.bz2
SkytilsMod-d64361cbc01c61f4d7e412f7074601e3cfffe43f.zip
add the ability to edit the display names
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/skytils/skytilsmod/mixins/transformers/entity/MixinEntityLivingBase.java10
-rw-r--r--src/main/kotlin/skytils/skytilsmod/Skytils.kt16
-rw-r--r--src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt31
-rw-r--r--src/main/kotlin/skytils/skytilsmod/asm/transformers/RendererLivingEntityTransformer.kt80
-rw-r--r--src/main/kotlin/skytils/skytilsmod/mixins/extensions/ExtensionEntityLivingBase.kt25
-rw-r--r--src/main/kotlin/skytils/skytilsmod/mixins/hooks/entity/EntityLivingBaseHook.kt7
-rw-r--r--src/main/kotlin/skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHook.kt8
-rw-r--r--src/main/kotlin/skytils/skytilsmod/utils/Utils.kt15
-rw-r--r--src/main/resources/mixins.skytils.json2
9 files changed, 186 insertions, 8 deletions
diff --git a/src/main/java/skytils/skytilsmod/mixins/transformers/entity/MixinEntityLivingBase.java b/src/main/java/skytils/skytilsmod/mixins/transformers/entity/MixinEntityLivingBase.java
index 9cebd32c..30a5cece 100644
--- a/src/main/java/skytils/skytilsmod/mixins/transformers/entity/MixinEntityLivingBase.java
+++ b/src/main/java/skytils/skytilsmod/mixins/transformers/entity/MixinEntityLivingBase.java
@@ -23,16 +23,18 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
+import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import skytils.skytilsmod.mixins.extensions.ExtensionEntityLivingBase;
import skytils.skytilsmod.mixins.hooks.entity.EntityLivingBaseHook;
@Mixin(EntityLivingBase.class)
-public abstract class MixinEntityLivingBase extends Entity {
+public abstract class MixinEntityLivingBase extends Entity implements ExtensionEntityLivingBase {
@Unique
private final EntityLivingBaseHook hook = new EntityLivingBaseHook((EntityLivingBase) (Object) this);
@@ -60,4 +62,10 @@ public abstract class MixinEntityLivingBase extends Entity {
private void setChildState(CallbackInfoReturnable<Boolean> cir) {
hook.isChild(cir);
}
+
+ @NotNull
+ @Override
+ public EntityLivingBaseHook getSkytilsHook() {
+ return hook;
+ }
}
diff --git a/src/main/kotlin/skytils/skytilsmod/Skytils.kt b/src/main/kotlin/skytils/skytilsmod/Skytils.kt
index 8db48ce0..9b6c397b 100644
--- a/src/main/kotlin/skytils/skytilsmod/Skytils.kt
+++ b/src/main/kotlin/skytils/skytilsmod/Skytils.kt
@@ -28,6 +28,7 @@ import net.minecraft.client.gui.GuiIngameMenu
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.settings.KeyBinding
import net.minecraft.network.play.client.C01PacketChatMessage
+import net.minecraft.network.play.server.S1CPacketEntityMetadata
import net.minecraft.util.IChatComponent
import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.client.event.GuiOpenEvent
@@ -74,6 +75,7 @@ import skytils.skytilsmod.gui.OptionsGui
import skytils.skytilsmod.gui.ReopenableGUI
import skytils.skytilsmod.listeners.ChatListener
import skytils.skytilsmod.listeners.DungeonListener
+import skytils.skytilsmod.mixins.extensions.ExtensionEntityLivingBase
import skytils.skytilsmod.mixins.transformers.accessors.AccessorCommandHandler
import skytils.skytilsmod.mixins.transformers.accessors.AccessorGuiNewChat
import skytils.skytilsmod.mixins.transformers.accessors.AccessorSettingsGui
@@ -426,4 +428,18 @@ class Skytils {
}
}
}
+
+ @SubscribeEvent
+ fun onReceivePacket(event: PacketEvent.ReceiveEvent) {
+ if (event.packet is S1CPacketEntityMetadata) {
+ val nameObj = event.packet.func_149376_c()?.find { it.dataValueId == 2 }
+ if (nameObj != null) {
+ val entity = mc.theWorld.getEntityByID(event.packet.entityId)
+
+ if (entity is ExtensionEntityLivingBase) {
+ entity.skytilsHook.onNewDisplayName(nameObj.`object` as String)
+ }
+ }
+ }
+ }
}
diff --git a/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt b/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
index 13bbb930..2e6d9b44 100644
--- a/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
+++ b/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
@@ -18,18 +18,41 @@
package skytils.skytilsmod.asm
+import dev.falsehonesty.asmhelper.AsmHelper
import dev.falsehonesty.asmhelper.BaseClassTransformer
-import skytils.skytilsmod.asm.transformers.addColoredNamesCheck
-import skytils.skytilsmod.asm.transformers.injectSplashProgressTransformer
+import net.minecraft.launchwrapper.LaunchClassLoader
+import skytils.skytilsmod.asm.transformers.*
+import java.util.*
class SkytilsTransformer : BaseClassTransformer() {
+
+ companion object {
+ /*
+ * Key is srg name, value is deobf name
+ */
+ val methodMaps: WeakHashMap<String, String> = WeakHashMap()
+ }
+
var madeTransformers = false
+ override fun setup(classLoader: LaunchClassLoader) {
+ methodMaps + mapOf(
+ "func_150254_d" to "getFormattedText",
+ "func_145748_c_" to "getDisplayName",
+ "func_177067_a" to "renderName"
+ )
+ }
+
override fun makeTransformers() {
if (!madeTransformers) {
madeTransformers = true
- addColoredNamesCheck()
- injectSplashProgressTransformer()
+ try {
+ addColoredNamesCheck()
+ injectSplashProgressTransformer()
+ changeRenderedName()
+ } catch (e: Throwable) {
+ e.printStackTrace()
+ }
}
}
} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/asm/transformers/RendererLivingEntityTransformer.kt b/src/main/kotlin/skytils/skytilsmod/asm/transformers/RendererLivingEntityTransformer.kt
new file mode 100644
index 00000000..d14f6190
--- /dev/null
+++ b/src/main/kotlin/skytils/skytilsmod/asm/transformers/RendererLivingEntityTransformer.kt
@@ -0,0 +1,80 @@
+/*
+ * Skytils - Hypixel Skyblock Quality of Life Mod
+ * Copyright (C) 2021 Skytils
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package skytils.skytilsmod.asm.transformers
+
+import dev.falsehonesty.asmhelper.AsmHelper
+import dev.falsehonesty.asmhelper.dsl.instructions.Descriptor
+import dev.falsehonesty.asmhelper.dsl.instructions.InsnListBuilder
+import dev.falsehonesty.asmhelper.dsl.modify
+import org.objectweb.asm.Opcodes
+import org.objectweb.asm.tree.MethodInsnNode
+import org.objectweb.asm.tree.VarInsnNode
+import skytils.skytilsmod.asm.SkytilsTransformer
+import skytils.skytilsmod.utils.descriptor
+import skytils.skytilsmod.utils.getOrSelf
+
+fun changeRenderedName() = modify("net.minecraft.client.renderer.entity.RendererLivingEntity") {
+ classNode.apply {
+ this.methods.find {
+ SkytilsTransformer.methodMaps.getOrSelf(
+ AsmHelper.remapper.remapMethodName(
+ "net/minecraft/client/renderer/entity/RendererLivingEntity",
+ it.name,
+ it.desc
+ )
+ ) == "renderName" && AsmHelper.remapper.remapDesc(it.desc) == "(Lnet/minecraft/entity/EntityLivingBase;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 && prev.descriptor == Descriptor(
+ "net/minecraft/util/IChatComponent",
+ "getFormattedText",
+ "()Ljava/lang/String;"
+ )
+ ) {
+ prev = prev.previous
+ if (prev is MethodInsnNode && prev.opcode == Opcodes.INVOKEVIRTUAL && prev.descriptor == Descriptor(
+ "net/minecraft/entity/EntityLivingBase",
+ "getDisplayName",
+ "()Lnet/minecraft/util/IChatComponent;"
+ )
+ ) {
+ prev = prev.previous
+ if (prev is VarInsnNode && prev.opcode == Opcodes.ALOAD && prev.`var` == 1) {
+ instructions.insert(insn, InsnListBuilder(this).apply {
+ invokeStatic(
+ "skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHookKt",
+ "replaceEntityName",
+ "(Lnet/minecraft/entity/EntityLivingBase;Ljava/lang/String;)Ljava/lang/String;"
+ ) {
+ aload(1)
+ aload(insn.`var`)
+ }
+ astore(insn.`var`)
+ }.build())
+ break
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/mixins/extensions/ExtensionEntityLivingBase.kt b/src/main/kotlin/skytils/skytilsmod/mixins/extensions/ExtensionEntityLivingBase.kt
new file mode 100644
index 00000000..38a4b31e
--- /dev/null
+++ b/src/main/kotlin/skytils/skytilsmod/mixins/extensions/ExtensionEntityLivingBase.kt
@@ -0,0 +1,25 @@
+/*
+ * Skytils - Hypixel Skyblock Quality of Life Mod
+ * Copyright (C) 2021 Skytils
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package skytils.skytilsmod.mixins.extensions
+
+import skytils.skytilsmod.mixins.hooks.entity.EntityLivingBaseHook
+
+interface ExtensionEntityLivingBase {
+ val skytilsHook: EntityLivingBaseHook
+} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/entity/EntityLivingBaseHook.kt b/src/main/kotlin/skytils/skytilsmod/mixins/hooks/entity/EntityLivingBaseHook.kt
index 949d254c..a2b43901 100644
--- a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/entity/EntityLivingBaseHook.kt
+++ b/src/main/kotlin/skytils/skytilsmod/mixins/hooks/entity/EntityLivingBaseHook.kt
@@ -22,6 +22,7 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.potion.Potion
import net.minecraft.util.EnumParticleTypes
+import net.minecraft.util.IChatComponent
import net.minecraft.world.World
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import skytils.skytilsmod.Skytils
@@ -37,6 +38,12 @@ class EntityLivingBaseHook(val entity: EntityLivingBase) {
}
}
+ var overrideDisplayName: String? = null
+
+ fun onNewDisplayName(s: String) {
+ if (!Utils.inSkyblock) return
+ }
+
val isBreefing by lazy {
entity.name == "Breefing" && (Utils.breefingdog || Random.nextInt(
100
diff --git a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHook.kt b/src/main/kotlin/skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHook.kt
index 7816fed5..34b4f97e 100644
--- a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHook.kt
+++ b/src/main/kotlin/skytils/skytilsmod/mixins/hooks/renderer/RendererLivingEntityHook.kt
@@ -25,6 +25,8 @@ import skytils.skytilsmod.Skytils
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import net.minecraft.entity.monster.EntityEnderman
import net.minecraft.entity.Entity
+import net.minecraft.entity.EntityLivingBase
+import skytils.skytilsmod.mixins.extensions.ExtensionEntityLivingBase
import skytils.skytilsmod.utils.*
fun setColorMultiplier(
@@ -44,4 +46,10 @@ fun setColorMultiplier(
cir.setReturnValue(Skytils.config.seraphHitsPhaseColor.withAlpha(169))
} else cir.setReturnValue(Skytils.config.seraphNormalPhaseColor.withAlpha(169))
}
+}
+
+fun replaceEntityName(entity: EntityLivingBase, currName: String): String {
+ entity as ExtensionEntityLivingBase
+
+ return entity.skytilsHook.overrideDisplayName ?: currName
} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/utils/Utils.kt b/src/main/kotlin/skytils/skytilsmod/utils/Utils.kt
index aa65b4ec..1d180401 100644
--- a/src/main/kotlin/skytils/skytilsmod/utils/Utils.kt
+++ b/src/main/kotlin/skytils/skytilsmod/utils/Utils.kt
@@ -17,6 +17,8 @@
*/
package skytils.skytilsmod.utils
+import dev.falsehonesty.asmhelper.AsmHelper
+import dev.falsehonesty.asmhelper.dsl.instructions.Descriptor
import gg.essential.universal.UResolution
import gg.essential.universal.wrappers.message.UMessage
import gg.essential.universal.wrappers.message.UTextComponent
@@ -38,8 +40,10 @@ import net.minecraft.util.MathHelper
import net.minecraft.util.Vec3
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.common.MinecraftForge
+import org.objectweb.asm.tree.MethodInsnNode
import skytils.skytilsmod.Skytils
import skytils.skytilsmod.Skytils.Companion.mc
+import skytils.skytilsmod.asm.SkytilsTransformer
import skytils.skytilsmod.events.impl.PacketEvent.ReceiveEvent
import skytils.skytilsmod.mixins.transformers.accessors.AccessorGuiNewChat
import skytils.skytilsmod.utils.graphics.colors.ColorFactory.web
@@ -285,4 +289,13 @@ fun BlockPos?.toVec3() = if (this == null) null else Vec3(this)
fun <T : Any> T?.ifNull(run: () -> Unit): T? {
if (this == null) run()
return this
-} \ No newline at end of file
+}
+
+val MethodInsnNode.descriptor: Descriptor
+ get() = Descriptor(
+ AsmHelper.remapper.remapClassName(this.owner),
+ SkytilsTransformer.methodMaps.getOrSelf(AsmHelper.remapper.remapMethodName(this.owner, this.name, this.desc)),
+ AsmHelper.remapper.remapDesc(this.desc)
+ )
+
+fun <T : Any> Map<T, T>.getOrSelf(key: T): T = this.getOrDefault(key, key) \ No newline at end of file
diff --git a/src/main/resources/mixins.skytils.json b/src/main/resources/mixins.skytils.json
index c6678f2b..721f3155 100644
--- a/src/main/resources/mixins.skytils.json
+++ b/src/main/resources/mixins.skytils.json
@@ -11,7 +11,6 @@
"accessors.AccessorGuiContainer",
"accessors.AccessorGuiEditSign",
"accessors.AccessorGuiNewChat",
- "accessors.AccessorMetadataCollection",
"accessors.AccessorMinecraft",
"accessors.AccessorRenderItem",
"accessors.AccessorServerListEntryNormal",
@@ -26,7 +25,6 @@
"entity.MixinEntityBlaze",
"entity.MixinEntityLivingBase",
"entity.MixinEntityPlayerSP",
- "fml.discovery.MixinJarDiscoverer",
"gui.MixinGuiContainer",
"gui.MixinGuiIngame",
"gui.MixinGuiIngameForge",