Skip to content

Commit baf076a

Browse files
committed
fix WAlternativeToggle
1 parent b9b0098 commit baf076a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/main/java/net/modfest/scatteredshards/client/screen/widget/WAlternativeToggle.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import juuxel.libninepatch.NinePatch;
1010
import net.fabricmc.api.EnvType;
1111
import net.fabricmc.api.Environment;
12+
import net.minecraft.client.Minecraft;
1213
import net.minecraft.client.gui.GuiGraphicsExtractor;
1314
import net.minecraft.client.input.MouseButtonEvent;
15+
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
1416
import net.minecraft.network.chat.Component;
1517
import net.minecraft.resources.Identifier;
18+
import net.minecraft.sounds.SoundEvents;
1619
import net.modfest.scatteredshards.ScatteredShards;
1720
import org.jetbrains.annotations.Nullable;
1821
import org.joml.Matrix3x2fStack;
@@ -175,19 +178,21 @@ public Rect2i getActiveRect(int x, int y) {
175178
return new Rect2i(x + xofs, y, halfWidth, getHeight());
176179
}
177180

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;
181184
return (x >= hoverX && y >= 0 && x < hoverX + halfWidth && y < getHeight());
182185
}
183186

184187
@Override
185188
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) {
187190
isRight = !isRight;
188191

189192
map(onLeft, onRight).run();
190193

194+
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
195+
191196
return InputResult.PROCESSED;
192197
} else {
193198
return InputResult.IGNORED;

0 commit comments

Comments
 (0)