Skip to content

Commit 2e8f85d

Browse files
authored
update: Minecraft 1.21.10 (#35)
1 parent b36a84c commit 2e8f85d

File tree

14 files changed

+90
-64
lines changed

14 files changed

+90
-64
lines changed

api/src/main/java/com/noxcrew/sheeplib/mixin/ChatScreenMixin.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import net.minecraft.client.gui.components.events.GuiEventListener;
66
import net.minecraft.client.gui.screens.ChatScreen;
77
import net.minecraft.client.gui.screens.Screen;
8+
import net.minecraft.client.input.CharacterEvent;
9+
import net.minecraft.client.input.KeyEvent;
10+
import net.minecraft.client.input.MouseButtonEvent;
811
import net.minecraft.network.chat.Component;
912
import org.lwjgl.glfw.GLFW;
1013
import org.spongepowered.asm.mixin.Mixin;
@@ -35,7 +38,7 @@ protected ChatScreenMixin(Component component) {
3538
method = "<init>",
3639
at = @At("TAIL")
3740
)
38-
public void init(String string, CallbackInfo ci) {
41+
public void init(String string, boolean bl, CallbackInfo ci) {
3942
this.addWidget(DialogContainer.INSTANCE);
4043
}
4144

@@ -71,9 +74,9 @@ public void mouseScrolled(double d, double e, double f, double g, CallbackInfoRe
7174
at = @At("HEAD"),
7275
cancellable = true
7376
)
74-
public void mouseClicked(double d, double e, int i, CallbackInfoReturnable<Boolean> cir) {
77+
public void mouseClicked(MouseButtonEvent mouseButtonEvent, boolean bl, CallbackInfoReturnable<Boolean> cir) {
7578
for (final var child : children()) {
76-
if (child != null && child.mouseClicked(d, e, i)) {
79+
if (child != null && child.mouseClicked(mouseButtonEvent, bl)) {
7780
cir.setReturnValue(true);
7881
return;
7982
}
@@ -85,28 +88,28 @@ public void mouseClicked(double d, double e, int i, CallbackInfoReturnable<Boole
8588
* Delegate mouse release to all children.
8689
*/
8790
@Override
88-
public boolean mouseReleased(double d, double e, int i) {
91+
public boolean mouseReleased(MouseButtonEvent mouseButtonEvent) {
8992
setDragging(false);
9093
for (final var child : children()) {
91-
if (child != null && child.mouseReleased(d, e, i)) {
94+
if (child != null && child.mouseReleased(mouseButtonEvent)) {
9295
return true;
9396
}
9497
}
9598
return false;
9699
}
97100

98101
@Override
99-
public boolean mouseDragged(double d, double e, int i, double f, double g) {
100-
return DialogContainer.INSTANCE.mouseDragged(d, e, i, f, g);
102+
public boolean mouseDragged(MouseButtonEvent mouseButtonEvent, double d, double e) {
103+
return DialogContainer.INSTANCE.mouseDragged(mouseButtonEvent, d, e);
101104
}
102105

103106
/**
104107
* Attempt to pass char type events to {@link DialogContainer} first.
105108
* This is necessary as {@link ChatScreen} assumes that the input element is the only child.
106109
*/
107110
@Override
108-
public boolean charTyped(char c, int i) {
109-
return DialogContainer.INSTANCE.charTyped(c, i) || input.charTyped(c, i);
111+
public boolean charTyped(CharacterEvent characterEvent) {
112+
return DialogContainer.INSTANCE.charTyped(characterEvent) || input.charTyped(characterEvent);
110113
}
111114

112115
/**
@@ -117,8 +120,8 @@ public boolean charTyped(char c, int i) {
117120
at = @At("HEAD"),
118121
cancellable = true
119122
)
120-
public void keyPressed(int i, int j, int k, CallbackInfoReturnable<Boolean> cir) {
121-
if (DialogContainer.INSTANCE.keyPressed(i, j, k)) {
123+
public void keyPressed(KeyEvent keyEvent, CallbackInfoReturnable<Boolean> cir) {
124+
if (DialogContainer.INSTANCE.keyPressed(keyEvent)) {
122125
cir.setReturnValue(true);
123126
}
124127
}
@@ -127,13 +130,13 @@ public void keyPressed(int i, int j, int k, CallbackInfoReturnable<Boolean> cir)
127130
method = "keyPressed",
128131
at = @At(
129132
value = "INVOKE",
130-
target = "Lnet/minecraft/client/gui/screens/Screen;keyPressed(III)Z"
133+
target = "Lnet/minecraft/client/gui/screens/Screen;keyPressed(Lnet/minecraft/client/input/KeyEvent;)Z"
131134
)
132135
)
133-
public boolean redirectSuper(Screen instance, int i, int j, int k) {
134-
return i != GLFW.GLFW_KEY_UP &&
135-
i != GLFW.GLFW_KEY_DOWN &&
136-
super.keyPressed(i, j, k);
136+
public boolean redirectSuper(Screen instance, KeyEvent keyEvent) {
137+
return keyEvent.key() != GLFW.GLFW_KEY_UP &&
138+
keyEvent.key() != GLFW.GLFW_KEY_DOWN &&
139+
super.keyPressed(keyEvent);
137140
}
138141

139142
/**

api/src/main/kotlin/com/noxcrew/sheeplib/CompoundWidget.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener
99
import net.minecraft.client.gui.layouts.Layout
1010
import net.minecraft.client.gui.narration.NarrationElementOutput
1111
import net.minecraft.client.gui.navigation.FocusNavigationEvent
12+
import net.minecraft.client.input.MouseButtonEvent
1213
import net.minecraft.network.chat.Component
1314
import kotlin.jvm.optionals.getOrNull
1415

@@ -87,23 +88,23 @@ public abstract class CompoundWidget(x: Int, y: Int, width: Int, height: Int) :
8788
// --
8889
// Mouse
8990
// --
90-
public override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
91-
if (getChildAt(d, e)
91+
public override fun mouseClicked(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Boolean {
92+
if (getChildAt(mouseButtonEvent.x, mouseButtonEvent.y)
9293
.getOrNull()
93-
?.takeIf { it.mouseClicked(d, e, i) }
94+
?.takeIf { it.mouseClicked(mouseButtonEvent, bl) }
9495
?.also { setFocused(it) } != null
9596
) return true
9697
setFocused(null)
9798
return false
9899
}
99100

100-
public override fun mouseReleased(d: Double, e: Double, i: Int): Boolean =
101-
super<ContainerEventHandler>.mouseReleased(d, e, i)
101+
public override fun mouseReleased(mouseButtonEvent: MouseButtonEvent): Boolean =
102+
super<ContainerEventHandler>.mouseReleased(mouseButtonEvent)
102103

103-
public override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean =
104+
public override fun mouseDragged(mouseButtonEvent: MouseButtonEvent, d: Double, e: Double): Boolean =
104105
getChildAt(d, e)
105106
.getOrNull()
106-
?.mouseDragged(d, e, i, f, g) == true
107+
?.mouseDragged(mouseButtonEvent, d, e) == true
107108

108109

109110
private var isDragging: Boolean = false

api/src/main/kotlin/com/noxcrew/sheeplib/DialogContainer.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener
1313
import net.minecraft.client.gui.narration.NarratableEntry
1414
import net.minecraft.client.gui.narration.NarrationElementOutput
1515
import net.minecraft.client.gui.screens.ChatScreen
16+
import net.minecraft.client.input.MouseButtonEvent
1617
import net.minecraft.network.chat.Component
1718
import org.slf4j.LoggerFactory
1819
import kotlin.reflect.jvm.jvmName
@@ -105,24 +106,24 @@ public object DialogContainer : ContainerEventHandler, NarratableEntry {
105106
* Handle mouse click in reverse order.
106107
* This is to match rendering order, children rendered last (at the top of the screen) handle clicks first.
107108
*/
108-
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
109+
override fun mouseClicked(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Boolean {
109110
val child = children().lastOrNull {
110-
it.mouseClicked(d, e, i)
111+
it.mouseClicked(mouseButtonEvent, bl)
111112
} ?: return false
112113

113114
if (focused != child && child is Dialog && !child.state.isClosing) {
114115
setFocused(child)
115116
moveToTop(child)
116117
}
117118

118-
if (i == 0) {
119+
if (mouseButtonEvent.button() == 0) {
119120
isDragging = true
120121
}
121122
return true
122123
}
123124

124-
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean =
125-
children.value.lastOrNull { it.mouseDragged(d, e, i, f, g) } != null
125+
override fun mouseDragged(mouseButtonEvent: MouseButtonEvent, d: Double, e: Double): Boolean =
126+
children.value.lastOrNull { it.mouseDragged(mouseButtonEvent, d, e) } != null
126127

127128
override fun isDragging(): Boolean = isDragging
128129

api/src/main/kotlin/com/noxcrew/sheeplib/dialog/Dialog.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import net.minecraft.client.Minecraft
1212
import net.minecraft.client.gui.GuiGraphics
1313
import net.minecraft.client.gui.components.AbstractWidget
1414
import net.minecraft.client.gui.layouts.Layout
15+
import net.minecraft.client.input.MouseButtonEvent
1516
import net.minecraft.client.renderer.RenderPipelines
1617
import net.minecraft.network.chat.Component
1718
import net.minecraft.util.ARGB
@@ -162,26 +163,26 @@ public abstract class Dialog(
162163
if (state == State.READY) init()
163164
}
164165

165-
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
166-
if ((popup?.mouseClicked(d, e, i) == true) || super.mouseClicked(d, e, i)) return true
167-
if (!isMouseOver(d, e)) return false
166+
override fun mouseClicked(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Boolean {
167+
if ((popup?.mouseClicked(mouseButtonEvent, bl) == true) || super.mouseClicked(mouseButtonEvent, bl)) return true
168+
if (!isMouseOver(mouseButtonEvent.x, mouseButtonEvent.y)) return false
168169
isDragging = true
169-
dragStartX = x - d.toInt()
170-
dragStartY = y - e.toInt()
170+
dragStartX = x - mouseButtonEvent.x.toInt()
171+
dragStartY = y - mouseButtonEvent.y.toInt()
171172
return true
172173
}
173174

174-
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
175-
popup?.mouseReleased(d, e, i)
175+
override fun mouseReleased(mouseButtonEvent: MouseButtonEvent): Boolean {
176+
popup?.mouseReleased(mouseButtonEvent)
176177
dragStartX = -1
177-
return super.mouseReleased(d, e, i)
178+
return super.mouseReleased(mouseButtonEvent)
178179
}
179180

180-
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
181-
if ((popup?.mouseDragged(d, e, i, f, g) == true) || super.mouseDragged(d, e, i, f, g)) return true
181+
override fun mouseDragged(mouseButtonEvent: MouseButtonEvent, d: Double, e: Double): Boolean {
182+
if ((popup?.mouseDragged(mouseButtonEvent, d, e) == true) || super.mouseDragged(mouseButtonEvent, d, e)) return true
182183
if (!isDragging || dragStartX == -1) return false
183-
x = dragStartX + d.toInt()
184-
y = dragStartY + e.toInt()
184+
x = dragStartX + mouseButtonEvent.x.toInt()
185+
y = dragStartY + mouseButtonEvent.y.toInt()
185186
return true
186187
}
187188

@@ -200,7 +201,21 @@ public abstract class Dialog(
200201
y + getHeight(),
201202
if (isPopupFocused()) ARGB.color(ARGB.alpha(baseColor) * POPUP_FOCUSED_OPACITY, baseColor) else baseColor
202203
)
203-
if (theme.dialogBorders) graphics.renderOutline(x, y, getWidth(), getHeight(), theme.colors.border)
204+
205+
// graphics.submitOutline(...) is deferred and causes the outline to be drawn on the wrong z layer
206+
if (theme.dialogBorders) {
207+
val color = theme.colors.border
208+
graphics.fill(x, y, x + getWidth(), y + 1, color)
209+
graphics.fill(x, y + getHeight() - 1, x + getWidth(), y + getHeight(), color)
210+
graphics.fill(x, y + 1, x + 1, y + getHeight() - 1, color)
211+
graphics.fill(
212+
x + getWidth() - 1,
213+
y + 1,
214+
x + getWidth(),
215+
y + getHeight() - 1,
216+
color
217+
)
218+
}
204219
}
205220

206221
override fun renderWidget(graphics: GuiGraphics, i: Int, j: Int, f: Float) {

api/src/main/kotlin/com/noxcrew/sheeplib/util/ComponentBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package com.noxcrew.sheeplib.util
22

33
import net.minecraft.network.chat.ClickEvent
44
import net.minecraft.network.chat.Component
5+
import net.minecraft.network.chat.FontDescription
56
import net.minecraft.network.chat.HoverEvent
67
import net.minecraft.network.chat.MutableComponent
78
import net.minecraft.network.chat.TextColor
8-
import net.minecraft.resources.ResourceLocation
99

1010
@DslMarker @Target(AnnotationTarget.CLASS)
1111
private annotation class ComponentBuilderDsl
@@ -73,7 +73,7 @@ public class ComponentBuilder(public val component: MutableComponent) {
7373
/**
7474
* The component's font.
7575
*/
76-
public var font: ResourceLocation?
76+
public var font: FontDescription?
7777
get() = component.style.font
7878
set(value) {
7979
component.style = component.style.withFont(value)

api/src/main/kotlin/com/noxcrew/sheeplib/widget/DropdownButton.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft
99
import net.minecraft.client.gui.GuiGraphics
1010
import net.minecraft.client.gui.layouts.Layout
1111
import net.minecraft.client.gui.layouts.LinearLayout
12+
import net.minecraft.client.input.MouseButtonEvent
1213
import net.minecraft.network.chat.Component
1314

1415
/**
@@ -73,7 +74,7 @@ public class DropdownButton<T : Any>(
7374
}
7475
}
7576

76-
override fun onClick(d: Double, e: Double) {
77+
override fun onClick(mouseButtonEvent: MouseButtonEvent, bl: Boolean) {
7778
if (isOpen()) return
7879
selectionPopup = SelectionPopup(x, y).also {
7980
parent.popup(it, false)
@@ -110,12 +111,12 @@ public class DropdownButton<T : Any>(
110111
close()
111112
}
112113

113-
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
114-
if (!this@DropdownButton.isHoveredOrFocused and !isMouseOver(d, e)) {
114+
override fun mouseClicked(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Boolean {
115+
if (!this@DropdownButton.isHoveredOrFocused and !isMouseOver(mouseButtonEvent.x, mouseButtonEvent.y)) {
115116
close()
116117
return false
117118
}
118-
return super.mouseClicked(d, e, i)
119+
return super.mouseClicked(mouseButtonEvent, bl)
119120
}
120121
}
121122
}

api/src/main/kotlin/com/noxcrew/sheeplib/widget/IconButton.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import net.minecraft.client.Minecraft
55
import net.minecraft.client.gui.GuiGraphics
66
import net.minecraft.client.gui.components.AbstractWidget
77
import net.minecraft.client.gui.narration.NarrationElementOutput
8+
import net.minecraft.client.input.MouseButtonEvent
89
import net.minecraft.network.chat.Component
910

1011
/**
@@ -31,7 +32,7 @@ public class IconButton(
3132
}
3233
}
3334

34-
override fun onClick(d: Double, e: Double): Unit = clickHandler(x, y)
35+
override fun onClick(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Unit = clickHandler(x, y)
3536
override fun updateWidgetNarration(narrationElementOutput: NarrationElementOutput): Unit = Unit
3637
}
3738

api/src/main/kotlin/com/noxcrew/sheeplib/widget/SliderWidget.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.noxcrew.sheeplib.theme.Themed
44
import net.minecraft.client.gui.GuiGraphics
55
import net.minecraft.client.gui.components.AbstractWidget
66
import net.minecraft.client.gui.narration.NarrationElementOutput
7+
import net.minecraft.client.input.MouseButtonEvent
78
import net.minecraft.network.chat.Component
89
import kotlin.math.abs
910
import kotlin.math.roundToInt
@@ -61,8 +62,8 @@ public class SliderWidget(
6162
currentIndex = offsets.withIndex().minBy { abs(it.value - offsetX) }.index
6263
}
6364

64-
override fun onClick(d: Double, e: Double): Unit = updatePosition(d.toInt())
65-
override fun onDrag(d: Double, e: Double, f: Double, g: Double): Unit = updatePosition(d.toInt())
65+
override fun onClick(mouseButtonEvent: MouseButtonEvent, bl: Boolean): Unit = updatePosition(mouseButtonEvent.x.toInt())
66+
override fun onDrag(mouseButtonEvent: MouseButtonEvent, d: Double, e: Double): Unit = updatePosition(mouseButtonEvent.x.toInt())
6667
override fun renderWidget(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) {
6768
guiGraphics.fill(x, y + (HEIGHT / 2 - 1), x + width, y + (HEIGHT / 2 + 1), theme.colors.textSecondary)
6869

api/src/main/kotlin/com/noxcrew/sheeplib/widget/ThemedButton.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft
66
import net.minecraft.client.gui.GuiGraphics
77
import net.minecraft.client.gui.components.AbstractWidget
88
import net.minecraft.client.gui.narration.NarrationElementOutput
9+
import net.minecraft.client.input.MouseButtonEvent
910
import net.minecraft.network.chat.Component
1011

1112
/**
@@ -92,7 +93,7 @@ public open class ThemedButton(
9293
/**
9394
* Call the click callback when clicked.
9495
*/
95-
override fun onClick(d: Double, e: Double) {
96+
override fun onClick(mouseButtonEvent: MouseButtonEvent, bl: Boolean) {
9697
if (isEnabled) clickHandler()
9798
}
9899

api/src/main/kotlin/com/noxcrew/sheeplib/widget/ToggleButton.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.noxcrew.sheeplib.widget
22

33
import com.noxcrew.sheeplib.theme.Theme
44
import com.noxcrew.sheeplib.theme.Themed
5+
import net.minecraft.client.input.MouseButtonEvent
56
import net.minecraft.network.chat.Component
67
import kotlin.reflect.KProperty
78

@@ -63,7 +64,7 @@ public class ToggleButton<T>(
6364
/** If the current entry has its own style, use that, otherwise use the button's own style. */
6465
override val style: Theme.ButtonStyle get() = current.style ?: super.style
6566

66-
override fun onClick(d: Double, e: Double) {
67+
override fun onClick(mouseButtonEvent: MouseButtonEvent, bl: Boolean) {
6768
if (!isEnabled) return
6869
currentIndex = (currentIndex + 1) % entries.size
6970
current = entries[currentIndex]

0 commit comments

Comments
 (0)