|
9 | 9 | import juuxel.libninepatch.NinePatch; |
10 | 10 | import net.fabricmc.api.EnvType; |
11 | 11 | import net.fabricmc.api.Environment; |
| 12 | +import net.minecraft.client.Minecraft; |
12 | 13 | import net.minecraft.client.gui.GuiGraphicsExtractor; |
13 | 14 | import net.minecraft.client.input.MouseButtonEvent; |
| 15 | +import net.minecraft.client.resources.sounds.SimpleSoundInstance; |
14 | 16 | import net.minecraft.network.chat.Component; |
15 | 17 | import net.minecraft.resources.Identifier; |
| 18 | +import net.minecraft.sounds.SoundEvents; |
16 | 19 | import net.modfest.scatteredshards.ScatteredShards; |
17 | 20 | import org.jetbrains.annotations.Nullable; |
18 | 21 | import org.joml.Matrix3x2fStack; |
@@ -175,19 +178,21 @@ public Rect2i getActiveRect(int x, int y) { |
175 | 178 | return new Rect2i(x + xofs, y, halfWidth, getHeight()); |
176 | 179 | } |
177 | 180 |
|
178 | | - public boolean hitActive(int x, int y) { |
179 | | - int halfWidth = (int) Math.ceil(this.width / 2.0); |
180 | | - int hoverX = (isRight) ? 0 : halfWidth - 1; |
| 181 | + public boolean hitActive(double x, double y) { |
| 182 | + var halfWidth = Math.ceil(this.width / 2.0); |
| 183 | + var hoverX = (isRight) ? 0 : halfWidth - 1; |
181 | 184 | return (x >= hoverX && y >= 0 && x < hoverX + halfWidth && y < getHeight()); |
182 | 185 | } |
183 | 186 |
|
184 | 187 | @Override |
185 | 188 | public InputResult onClick(MouseButtonEvent click, boolean doubled) { |
186 | | - if (hitActive(x, y) && click.button() == 0) { |
| 189 | + if (hitActive(click.x(), click.y()) && click.button() == 0) { |
187 | 190 | isRight = !isRight; |
188 | 191 |
|
189 | 192 | map(onLeft, onRight).run(); |
190 | 193 |
|
| 194 | + Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); |
| 195 | + |
191 | 196 | return InputResult.PROCESSED; |
192 | 197 | } else { |
193 | 198 | return InputResult.IGNORED; |
|
0 commit comments