aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-09-03 21:41:29 +0200
committerLorenz <lo.scherf@gmail.com>2022-09-03 21:41:29 +0200
commitb7013e82739ed7a9d28eef21fe0ec11496dffd0e (patch)
treec11428dbc8fabc275cc169e8cb055112d416c1a9 /src/main
parent637506306077e4df63c7aef30a37eb8ad27c06f4 (diff)
downloadskyhanni-b7013e82739ed7a9d28eef21fe0ec11496dffd0e.tar.gz
skyhanni-b7013e82739ed7a9d28eef21fe0ec11496dffd0e.tar.bz2
skyhanni-b7013e82739ed7a9d28eef21fe0ec11496dffd0e.zip
added option to mark the own summoning mobs in green
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt40
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java30
-rw-r--r--src/main/resources/mixins.skyhanni.json3
4 files changed, 71 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java
index 6a6995b23..b9a69ed8c 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java
@@ -38,4 +38,10 @@ public class Abilities {
@ConfigEditorBoolean
@ConfigAccordionId(id = 0)
public boolean summoningMobHideNametag = false;
+
+ @Expose
+ @ConfigOption(name = "Summoning Mob Color", desc = "Marks own summoning mobs green")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 0)
+ public boolean summoningMobColored = false;
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt
index 5b31248d7..877db7e6a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/SummoningMobManager.kt
@@ -2,12 +2,9 @@ package at.hannibal2.skyhanni.features
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.utils.LocationUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
-import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.getLorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.entity.EntityLiving
import net.minecraft.entity.EntityLivingBase
@@ -18,11 +15,40 @@ import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
+import java.awt.Color
import java.util.regex.Pattern
class SummoningMobManager {
- private val summoningMobs = mutableMapOf<EntityLiving, SummoningMob>()
+ companion object {
+
+ @JvmStatic
+ fun <T> setColorMultiplier(
+ entity: T,
+ lightBrightness: Float,
+ partialTickTime: Float,
+ cir: CallbackInfoReturnable<Int>,
+ ) {
+ if (SkyHanniMod.feature.abilities.summoningMobColored) {
+ if (entity is EntityLiving && entity in summoningMobs.keys) {
+ cir.returnValue = LorenzColor.GREEN.toColor().withAlpha(127)
+ }
+ }
+ }
+
+ @JvmStatic
+ fun replaceHurtTime(entity: EntityLivingBase): Int {
+ return if (SkyHanniMod.feature.abilities.summoningMobColored
+ && entity in summoningMobs.keys
+ ) 0 else entity.hurtTime
+ }
+
+ fun Color.withAlpha(alpha: Int): Int = (alpha.coerceIn(0, 255) shl 24) or (this.rgb and 0x00ffffff)
+
+ private val summoningMobs = mutableMapOf<EntityLiving, SummoningMob>()
+ }
+
private val summoningMobNametags = mutableListOf<EntityArmorStand>()
private var summoningsSpawned = 0
private var searchArmorStands = false
@@ -95,7 +121,7 @@ class SummoningMobManager {
it is EntityLiving && it !in summoningMobs.keys && it.getLorenzVec().distance(playerLocation) < 3
}
.forEach {
- if (it.ticksExisted == 0) {
+ if (it.ticksExisted < 2) {
summoningMobs[it as EntityLiving] = SummoningMob(System.currentTimeMillis(), name = "Mob")
updateData()
if (summoningMobs.size == summoningsSpawned) {
@@ -117,7 +143,7 @@ class SummoningMobManager {
val name = summoningMob.name
if (currentHealth == 0) {
summoningMobs.remove(entityLiving)
- LorenzUtils.chat("§e[SkyHanni] your Summoning Mob just §cdied!")
+ LorenzUtils.chat("§e[SkyHanni] Your Summoning Mob just §cdied!")
continue
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java
new file mode 100644
index 000000000..7ac89c711
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java
@@ -0,0 +1,30 @@
+package at.hannibal2.skyhanni.mixins.transformers.renderer;
+
+import at.hannibal2.skyhanni.features.SummoningMobManager;
+import net.minecraft.client.renderer.entity.Render;
+import net.minecraft.client.renderer.entity.RenderManager;
+import net.minecraft.client.renderer.entity.RendererLivingEntity;
+import net.minecraft.entity.EntityLivingBase;
+import org.objectweb.asm.Opcodes;
+import org.spongepowered.asm.mixin.Mixin;
+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;
+
+@Mixin(RendererLivingEntity.class)
+public abstract class MixinRendererLivingEntity<T extends EntityLivingBase> extends Render<T> {
+ protected MixinRendererLivingEntity(RenderManager renderManager) {
+ super(renderManager);
+ }
+
+ @Inject(method = "getColorMultiplier", at = @At("HEAD"), cancellable = true)
+ private void setColorMultiplier(T entity, float lightBrightness, float partialTickTime, CallbackInfoReturnable<Integer> cir) {
+ SummoningMobManager.setColorMultiplier(entity, lightBrightness, partialTickTime, cir);
+ }
+
+ @Redirect(method = "setBrightness", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/EntityLivingBase;hurtTime:I", opcode = Opcodes.GETFIELD))
+ private int changeHurtTime(EntityLivingBase instance) {
+ return SummoningMobManager.replaceHurtTime(instance);
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/mixins.skyhanni.json b/src/main/resources/mixins.skyhanni.json
index 44d3e1e96..1c1feff06 100644
--- a/src/main/resources/mixins.skyhanni.json
+++ b/src/main/resources/mixins.skyhanni.json
@@ -11,6 +11,7 @@
"gui.MixinGuiContainer",
"gui.inventory.GuiEditSignMixin",
"tileentity.TileEntitySignMixin",
- "renderer.MixinBlockRendererDispatcher"
+ "renderer.MixinBlockRendererDispatcher",
+ "renderer.MixinRendererLivingEntity"
]
}