Skip to content

Commit

Permalink
feat(legacy): Smooth hot-bar slot HUD module option. (CCBlueX#4266)
Browse files Browse the repository at this point in the history
  • Loading branch information
mems01 authored Oct 26, 2024
1 parent 0c142d4 commit 3aedab7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package net.ccbluex.liquidbounce.features.module.modules.render
import net.ccbluex.liquidbounce.LiquidBounce.CLIENT_NAME
import net.ccbluex.liquidbounce.LiquidBounce.hud
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.ui.client.hud.designer.GuiHudDesigner
import net.ccbluex.liquidbounce.ui.client.hud.element.Element.Companion.MAX_GRADIENT_COLORS
import net.ccbluex.liquidbounce.utils.render.ColorSettingsFloat
Expand All @@ -24,23 +24,21 @@ import net.minecraft.util.ResourceLocation
object HUD : Module("HUD", Category.RENDER, defaultInArray = false, gameDetecting = false, hideModule = true) {
val customHotbar by BoolValue("CustomHotbar", true)

val smoothHotbarSlot by BoolValue("SmoothHotbarSlot", true) { customHotbar }

val roundedHotbarRadius by FloatValue("RoundedHotbar-Radius", 0F, 0F..5F) { customHotbar }

val hotbarMode by ListValue("Hotbar-Color", arrayOf("Custom", "Rainbow", "Gradient"), "Custom") { customHotbar }

val hbHighlightColors = ColorSettingsInteger(this, "Hotbar-Highlight-Colors", applyMax = true)
{ customHotbar }.with(a = 100)
val hbBackgroundColors = ColorSettingsInteger(this, "Hotbar-Background-Colors")
{ customHotbar && hotbarMode == "Custom" }.with(a = 100)

val gradientHotbarSpeed by FloatValue("Hotbar-Gradient-Speed", 1f, 0.5f..10f)
{ customHotbar && hotbarMode == "Gradient" }

val maxHotbarGradientColors by IntegerValue("Max-Hotbar-Gradient-Colors", 4, 1..MAX_GRADIENT_COLORS)
{ customHotbar && hotbarMode == "Gradient" }
val bgGradColors = ColorSettingsFloat.create(this, "Hotbar-Gradient")
{ customHotbar && hotbarMode == "Gradient" && it <= maxHotbarGradientColors }

val hotbarBorder by FloatValue("HotbarBorder-Width", 0.5F, 0.5F..5F) { customHotbar }
val hbBorderColors = ColorSettingsInteger(this, "HotbarBorder", zeroAlphaCheck = true) { customHotbar }.with(a = 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.ccbluex.liquidbounce.features.module.modules.render.NoScoreboard;
import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer;
import net.ccbluex.liquidbounce.utils.ClassUtils;
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils;
import net.ccbluex.liquidbounce.utils.render.ColorSettingsKt;
import net.ccbluex.liquidbounce.utils.render.FakeItemRender;
import net.ccbluex.liquidbounce.utils.render.RenderUtils;
Expand Down Expand Up @@ -134,13 +135,17 @@ protected void renderTooltip(ScaledResolution sr, float partialTicks) {

if (mc.getRenderViewEntity() instanceof EntityPlayer) {
EntityPlayer entityPlayer = (EntityPlayer) mc.getRenderViewEntity();
int slot = entityPlayer.inventory.currentItem;
float slot = entityPlayer.inventory.currentItem;

if (FakeItemRender.INSTANCE.getFakeItem() != -1) {
slot = FakeItemRender.INSTANCE.getFakeItem();
}

if (hud.handleEvents() && hud.getCustomHotbar()) {
if (hud.getSmoothHotbarSlot()) {
slot = InventoryUtils.INSTANCE.getLerpedSlot();
}

int middleScreen = sr.getScaledWidth() / 2;
int height = sr.getScaledHeight() - 1;

Expand Down Expand Up @@ -191,7 +196,7 @@ protected void renderTooltip(ScaledResolution sr, float partialTicks) {
}

// Inner - Highlight
render.drawRoundedRectInt(
render.drawRoundedRect(
middleScreen - 91 - 1 + slot * 20 + 1, height - 22,
middleScreen - 91 - 1 + slot * 20 + 23, height - 23 - 1 + 24,
hud.getHbHighlightColors().color().getRGB(),
Expand All @@ -208,7 +213,7 @@ protected void renderTooltip(ScaledResolution sr, float partialTicks) {
);

// Border - Highlight
render.drawRoundedBorderInt(
render.drawRoundedBorder(
middleScreen - 91 - 1 + slot * 20 + 1, height - 22,
middleScreen - 91 - 1 + slot * 20 + 23, height - 23 - 1 + 24,
hud.getHotbarBorder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.ccbluex.liquidbounce.features.module.modules.misc.NoSlotSet
import net.ccbluex.liquidbounce.features.module.modules.world.ChestAura
import net.ccbluex.liquidbounce.utils.MinecraftInstance
import net.ccbluex.liquidbounce.utils.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.render.FakeItemRender
import net.ccbluex.liquidbounce.utils.timing.MSTimer
import net.ccbluex.liquidbounce.utils.timing.TickedActions
import net.minecraft.block.BlockBush
Expand Down Expand Up @@ -57,6 +58,8 @@ object InventoryUtils : MinecraftInstance(), Listenable {
private var _serverSlot = 0
private var _serverOpenInventory = false

var lerpedSlot = 0f

var isFirstInventoryClick = true

var timeSinceClosedInventory = 0L
Expand Down Expand Up @@ -177,7 +180,6 @@ object InventoryUtils : MinecraftInstance(), Listenable {

@EventTarget
fun onPacket(event: PacketEvent) {

if (event.isCancelled) return

when (val packet = event.packet) {
Expand Down Expand Up @@ -239,6 +241,19 @@ object InventoryUtils : MinecraftInstance(), Listenable {
}
}

@EventTarget
fun onRender3D(event: Render3DEvent) {
val slotToUse = if (FakeItemRender.fakeItem != -1) {
FakeItemRender.fakeItem
} else mc.thePlayer?.inventory?.currentItem ?: 0

// Could just use serverSlot, but that would also mean getting slots from modules like Scaffold
// Where AutoBlock Spoof mode could be enabled and the user would maybe not like to see that
// (SilentHotbar module needed for this one)

lerpedSlot += (slotToUse - lerpedSlot) * 0.1f
}

@EventTarget
fun onWorld(event: WorldEvent) {
// Reset flags to prevent de-sync
Expand Down

0 comments on commit 3aedab7

Please sign in to comment.