Skip to content

Commit 01df988

Browse files
committed
Merge branch '1.21.5' into refactor/mixins
2 parents fa2e846 + 38996e8 commit 01df988

File tree

4 files changed

+62
-47
lines changed

4 files changed

+62
-47
lines changed

src/main/kotlin/com/lambda/config/Setting.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.lambda.brigadier.executeWithResult
2929
import com.lambda.brigadier.required
3030
import com.lambda.command.CommandRegistry
3131
import com.lambda.command.commands.ConfigCommand
32+
import com.lambda.config.Setting.ValueListener
3233
import com.lambda.context.SafeContext
3334
import com.lambda.gui.dsl.ImGuiBuilder
3435
import com.lambda.threading.runSafe
@@ -98,6 +99,15 @@ abstract class SettingCore<T : Any>(
9899
val type: Type
99100
) {
100101
var value = defaultValue
102+
set(value) {
103+
val oldValue = field
104+
field = value
105+
listeners.forEach {
106+
if (it.requiresValueChange && oldValue == value) return@forEach
107+
it.execute(oldValue, value)
108+
}
109+
}
110+
val listeners = mutableListOf<ValueListener<T>>()
101111

102112
context(setting: Setting<*, T>)
103113
abstract fun ImGuiBuilder.buildLayout()
@@ -148,7 +158,6 @@ class Setting<T : SettingCore<R>, R : Any>(
148158
val visibility: () -> Boolean,
149159
) : Nameable, Describable {
150160
val originalCore = core
151-
val listeners = mutableListOf<ValueListener<R>>()
152161
var disabled = { false }
153162
var groups: MutableList<List<NamedEnum>> = mutableListOf()
154163

@@ -158,12 +167,7 @@ class Setting<T : SettingCore<R>, R : Any>(
158167

159168
operator fun getValue(thisRef: Any?, property: KProperty<*>) = core.value
160169
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: R) {
161-
val oldValue = core.value
162170
core.value = value
163-
listeners.forEach {
164-
if (it.requiresValueChange && oldValue == value) return@forEach
165-
it.execute(oldValue, value)
166-
}
167171
}
168172

169173
fun reset(silent: Boolean = false) {
@@ -192,19 +196,19 @@ class Setting<T : SettingCore<R>, R : Any>(
192196
* E.g., if the variable is a list, it will only register if the list reference changes, not if the content of the list changes.
193197
*/
194198
fun onValueChange(block: SafeContext.(from: R, to: R) -> Unit) = apply {
195-
listeners.add(ValueListener(true) { from, to ->
199+
core.listeners.add(ValueListener(true) { from, to ->
196200
runSafe {
197201
block(from, to)
198202
}
199203
})
200204
}
201205

202206
fun onValueChangeUnsafe(block: (from: R, to: R) -> Unit) = apply {
203-
listeners.add(ValueListener(true, block))
207+
core.listeners.add(ValueListener(true, block))
204208
}
205209

206210
fun onValueSet(block: (from: R, to: R) -> Unit) = apply {
207-
listeners.add(ValueListener(false, block))
211+
core.listeners.add(ValueListener(false, block))
208212
}
209213

210214
fun disabled(predicate: () -> Boolean) = apply {

src/main/kotlin/com/lambda/gui/components/ClickGuiLayout.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,15 @@ object ClickGuiLayout : Loadable, Configurable(GuiConfig) {
301301
// For the time being I have removed the ability to collapse the windows so the titles
302302
// have more space lol.
303303
window(tag.name, flags = ImGuiWindowFlags.AlwaysAutoResize or ImGuiWindowFlags.NoCollapse) {
304-
// Start drag if the user just pressed while hovering this window
305304
if (activeDragWindowName == null && mousePressedThisFrameGlobal && ImGui.isWindowHovered()) {
306305
val mx = io.mousePos.x
307306
val my = io.mousePos.y
308-
activeDragWindowName = tag.name
309-
dragOffsetX = mx - windowPos.x
310-
dragOffsetY = my - windowPos.y
307+
val titleBarHeight = ImGui.getFrameHeight()
308+
if (my >= windowPos.y && my <= windowPos.y + titleBarHeight) {
309+
activeDragWindowName = tag.name
310+
dragOffsetX = mx - windowPos.x
311+
dragOffsetY = my - windowPos.y
312+
}
311313
}
312314

313315
ModuleRegistry.modules

src/main/kotlin/com/lambda/module/modules/network/PacketLimiter.kt

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,56 @@ import net.minecraft.network.packet.c2s.play.TeleportConfirmC2SPacket
3333

3434
// ToDo: HUD info
3535
object PacketLimiter : Module(
36-
name = "PacketLimiter",
37-
description = "Limits the amount of packets sent to the server",
38-
tag = ModuleTag.NETWORK,
36+
name = "PacketLimiter",
37+
description = "Limits the amount of packets sent to the server",
38+
tag = ModuleTag.NETWORK,
3939
) {
40-
private var packetQueue = LimitedDecayQueue<PacketEvent.Send.Pre>(99, 1000)
41-
private val limit by setting("Limit", 99, 1..100, 1, "The maximum amount of packets to send per given time interval", unit = " packets")
42-
.onValueChange { _, to -> packetQueue.setSizeLimit(to) }
40+
private var packetQueueMap = mutableMapOf<String, LimitedDecayQueue<PacketEvent.Send.Pre>>()
41+
private val globalQueue = LimitedDecayQueue<PacketEvent.Send.Pre>(1, 1)
4342

44-
private val interval by setting("Duration", 4000L, 1L..10000L, 50L, "The interval / duration in milliseconds to limit packets for", unit = " ms")
45-
.onValueChange { _, to -> packetQueue.setDecayTime(to) }
43+
private val limit by setting("Limit per packet", 99, 1..100, 1, "The maximum amount of packets to send per given time interval", unit = " packets")
44+
.onValueChange { _, to -> packetQueueMap.forEach { (t, u) -> u.setSizeLimit(to) } }
45+
private val globalLimit by setting("Global Limit", 1000, 100..5000, 50, "The maximum amount of packets to send overall per given time interval", unit = " packets")
46+
.onValueChange { _, to -> globalQueue.setSizeLimit(to) }
4647

47-
private val defaultIgnorePackets = setOf(
48-
nameOf<CommonPongC2SPacket>(),
49-
nameOf<PositionAndOnGround>(),
50-
nameOf<Full>(),
51-
nameOf<LookAndOnGround>(),
52-
nameOf<OnGroundOnly>(),
53-
nameOf<TeleportConfirmC2SPacket>()
54-
)
48+
private val interval by setting("Duration", 4000L, 1L..10000L, 50L, "The interval / duration in milliseconds to limit packets for", unit = " ms")
49+
.onValueChange { _, to -> packetQueueMap.forEach { (t, u) -> u.setDecayTime(to) }; globalQueue.setDecayTime(to) }
5550

56-
inline fun <reified T> nameOf(): String = T::class.className
51+
private val defaultIgnorePackets = setOf(
52+
nameOf<CommonPongC2SPacket>(),
53+
nameOf<PositionAndOnGround>(),
54+
nameOf<Full>(),
55+
nameOf<LookAndOnGround>(),
56+
nameOf<OnGroundOnly>(),
57+
nameOf<TeleportConfirmC2SPacket>()
58+
)
5759

58-
// ToDo: Find a way to have a list of serverbound packets
59-
private val ignorePackets by setting("Ignore Packets", defaultIgnorePackets, description = "Packets to ignore when limiting")
60+
inline fun <reified T> nameOf(): String = T::class.className
6061

61-
init {
62-
onEnable {
63-
packetQueue = LimitedDecayQueue(limit, interval)
64-
}
62+
// ToDo: Find a way to have a list of serverbound packets
63+
private val ignorePackets by setting("Ignore Packets", defaultIgnorePackets, description = "Packets to ignore when limiting")
6564

66-
listen<PacketEvent.Send.Pre>(Int.MAX_VALUE) {
67-
if (it.packet::class.java.name in ignorePackets) return@listen
65+
init {
66+
onEnable {
67+
packetQueueMap.clear()
68+
globalQueue.setDecayTime(interval)
69+
globalQueue.setSizeLimit(globalLimit)
70+
}
6871

69-
// [email protected]("Packet sent: ${it.packet::class.simpleName} (${packetQueue.size} / $limit) ${Instant.now()}")
70-
if (packetQueue.add(it)) return@listen
72+
listen<PacketEvent.Send.Pre>(Int.MAX_VALUE) {
73+
if (it.packet::class.java.name in ignorePackets) return@listen
7174

72-
it.cancel()
73-
this@PacketLimiter.info("Packet limit reached, dropping packet: ${it.packet::class.simpleName} (${packetQueue.size} / $limit)")
74-
}
75-
}
75+
if (!globalQueue.add(it)) {
76+
it.cancel()
77+
}
78+
// [email protected]("Packet sent: ${it.packet::class.simpleName} (${packetQueue.size} / $limit) ${Instant.now()}")
79+
val queue = packetQueueMap.getOrPut(it.packet::class.java.name) {
80+
LimitedDecayQueue(limit, interval)
81+
}
82+
if (queue.add(it)) return@listen
83+
84+
it.cancel()
85+
this@PacketLimiter.info("Packet limit reached, dropping packet: ${it.packet::class.simpleName} (${queue.size} / $limit)")
86+
}
87+
}
7688
}

src/main/kotlin/com/lambda/module/modules/render/ContainerPreview.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.lambda.util.item.ItemUtils.shulkerBoxes
2828
import net.minecraft.block.ShulkerBoxBlock
2929
import net.minecraft.client.font.TextRenderer
3030
import net.minecraft.client.gui.DrawContext
31-
import net.minecraft.client.gui.screen.Screen
3231
import net.minecraft.client.gui.tooltip.TooltipComponent
3332
import net.minecraft.client.render.RenderLayer
3433
import net.minecraft.item.BlockItem
@@ -45,7 +44,6 @@ object ContainerPreview : Module(
4544
tag = ModuleTag.RENDER,
4645
) {
4746
private val lockKey by setting("Lock Key", Bind(KeyCode.LeftShift.code, 0, -1), "Key to lock the tooltip in place for item interaction")
48-
private val useShift by setting("Use Shift", true, "Use shift key to lock tooltip (overrides lock key)")
4947
private val colorTint by setting("Color Tint", true, "Tint the background with the shulker box color")
5048

5149
private val background = Identifier.ofVanilla("textures/gui/container/shulker_box.png")
@@ -71,7 +69,6 @@ object ContainerPreview : Module(
7169
@JvmStatic
7270
fun isLockKeyPressed(): Boolean {
7371
if (!isEnabled) return false
74-
if (useShift) return Screen.hasShiftDown()
7572
val handle = mc.window.handle
7673
return GLFW.glfwGetKey(handle, lockKey.key) == GLFW.GLFW_PRESS
7774
}

0 commit comments

Comments
 (0)