LockIconButton .java

net.minecraft.client.gui.components.LockIconButton (class, 66 lines): members: setLocked, Icon, createNarrationMessage, isLocked, locked, extractContents.

net.minecraft.client.gui.componentsclass66 linesclientextends Button2.4 KB

API Surface (4)

MutableComponent createNarrationMessage()
boolean isLocked()
void setLocked(final boolean locked)
void extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)

Fields & Constants (1)

locked

String literals (9)

"narrator.button.difficulty_lock"
"narrator.button.difficulty_lock.locked"
"narrator.button.difficulty_lock.unlocked"
"widget/locked_button"
"widget/locked_button_highlighted"
"widget/locked_button_disabled"
"widget/unlocked_button"
"widget/unlocked_button_highlighted"
"widget/unlocked_button_disabled"

Full Source

LockIconButton.java66 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.components;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.GuiGraphicsExtractor;
6
import net.minecraft.client.renderer.RenderPipelines;
7
import net.minecraft.network.chat.CommonComponents;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.MutableComponent;
10
import net.minecraft.resources.Identifier;
11
12
@Environment(EnvType.CLIENT)
13
public class LockIconButton extends Button {
14
	private boolean locked;
15
16
	public LockIconButton(final int x, final int y, final Button.OnPress onPress) {
17
		super(x, y, 20, 20, Component.translatable("narrator.button.difficulty_lock"), onPress, DEFAULT_NARRATION);
18
	}
19
20
	@Override
21
	protected MutableComponent createNarrationMessage() {
22
		return CommonComponents.joinForNarration(
23
			super.createNarrationMessage(),
24
			this.isLocked() ? Component.translatable("narrator.button.difficulty_lock.locked") : Component.translatable("narrator.button.difficulty_lock.unlocked")
25
		);
26
	}
27
28
	public boolean isLocked() {
29
		return this.locked;
30
	}
31
32
	public void setLocked(final boolean locked) {
33
		this.locked = locked;
34
	}
35
36
	@Override
37
	public void extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
38
		LockIconButton.Icon icon;
39
		if (!this.active) {
40
			icon = this.locked ? LockIconButton.Icon.LOCKED_DISABLED : LockIconButton.Icon.UNLOCKED_DISABLED;
41
		} else if (this.isHoveredOrFocused()) {
42
			icon = this.locked ? LockIconButton.Icon.LOCKED_HOVER : LockIconButton.Icon.UNLOCKED_HOVER;
43
		} else {
44
			icon = this.locked ? LockIconButton.Icon.LOCKED : LockIconButton.Icon.UNLOCKED;
45
		}
46
47
		graphics.blitSprite(RenderPipelines.GUI_TEXTURED, icon.sprite, this.getX(), this.getY(), this.width, this.height);
48
	}
49
50
	@Environment(EnvType.CLIENT)
51
	private enum Icon {
52
		LOCKED(Identifier.withDefaultNamespace("widget/locked_button")),
53
		LOCKED_HOVER(Identifier.withDefaultNamespace("widget/locked_button_highlighted")),
54
		LOCKED_DISABLED(Identifier.withDefaultNamespace("widget/locked_button_disabled")),
55
		UNLOCKED(Identifier.withDefaultNamespace("widget/unlocked_button")),
56
		UNLOCKED_HOVER(Identifier.withDefaultNamespace("widget/unlocked_button_highlighted")),
57
		UNLOCKED_DISABLED(Identifier.withDefaultNamespace("widget/unlocked_button_disabled"));
58
59
		private final Identifier sprite;
60
61
		Icon(final Identifier sprite) {
62
			this.sprite = sprite;
63
		}
64
	}
65
}
66

Decompiled Minecraft 26.3 source of LockIconButton (net/minecraft/client/gui/components/LockIconButton.java) with Mojang official mappings, stored verbatim on the site.