diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 69 insertions, 7 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 |