minecraft-src/net/minecraft/client/gui/screens/inventory/PageButton.java
2025-07-04 02:00:41 +03:00

47 lines
2.1 KiB
Java

package net.minecraft.client.gui.screens.inventory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
@Environment(EnvType.CLIENT)
public class PageButton extends Button {
private static final ResourceLocation PAGE_FORWARD_HIGHLIGHTED_SPRITE = ResourceLocation.withDefaultNamespace("widget/page_forward_highlighted");
private static final ResourceLocation PAGE_FORWARD_SPRITE = ResourceLocation.withDefaultNamespace("widget/page_forward");
private static final ResourceLocation PAGE_BACKWARD_HIGHLIGHTED_SPRITE = ResourceLocation.withDefaultNamespace("widget/page_backward_highlighted");
private static final ResourceLocation PAGE_BACKWARD_SPRITE = ResourceLocation.withDefaultNamespace("widget/page_backward");
private final boolean isForward;
private final boolean playTurnSound;
public PageButton(int x, int y, boolean isForward, Button.OnPress onPress, boolean playTurnSound) {
super(x, y, 23, 13, CommonComponents.EMPTY, onPress, DEFAULT_NARRATION);
this.isForward = isForward;
this.playTurnSound = playTurnSound;
}
@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
ResourceLocation resourceLocation;
if (this.isForward) {
resourceLocation = this.isHoveredOrFocused() ? PAGE_FORWARD_HIGHLIGHTED_SPRITE : PAGE_FORWARD_SPRITE;
} else {
resourceLocation = this.isHoveredOrFocused() ? PAGE_BACKWARD_HIGHLIGHTED_SPRITE : PAGE_BACKWARD_SPRITE;
}
guiGraphics.blitSprite(RenderType::guiTextured, resourceLocation, this.getX(), this.getY(), 23, 13);
}
@Override
public void playDownSound(SoundManager handler) {
if (this.playTurnSound) {
handler.play(SimpleSoundInstance.forUI(SoundEvents.BOOK_PAGE_TURN, 1.0F));
}
}
}