CommandBlockEditScreen .java

net.minecraft.client.gui.screens.inventory.CommandBlockEditScreen (class): members: conditionalButton, autoCommandBlock, autoexecButton, modeButton, mode.

net.minecraft.client.gui.screens.inventoryclass113 linesclientextends AbstractCommandBlockEditScreen3.9 KB

API Surface (7)

BaseCommandBlock getCommandBlock()
int getPreviousY()
void init()
void addExtraControls()
void updateGui()
void resize(final int width, final int height)
void populateAndSendPacket()

Fields & Constants (7)

autoCommandBlock
modeButton
conditionalButton
autoexecButton
mode
conditional
autoexec

String literals (10)

"advMode.mode.sequence"
"advMode.mode.auto"
"advMode.mode.redstone"
"advMode.mode"
"advMode.mode.conditional"
"advMode.mode.unconditional"
"advMode.type"
"advMode.mode.autoexec.bat"
"advMode.mode.redstoneTriggered"
"advMode.triggering"

Full Source

CommandBlockEditScreen.java113 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.inventory;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.components.CycleButton;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.network.protocol.game.ServerboundSetCommandBlockPacket;
8
import net.minecraft.world.level.BaseCommandBlock;
9
import net.minecraft.world.level.block.entity.CommandBlockEntity;
10
import net.minecraft.world.level.block.entity.CommandBlockEntity.Mode;
11
12
@Environment(EnvType.CLIENT)
13
public class CommandBlockEditScreen extends AbstractCommandBlockEditScreen {
14
	private final CommandBlockEntity autoCommandBlock;
15
	private CycleButton<Mode> modeButton;
16
	private CycleButton<Boolean> conditionalButton;
17
	private CycleButton<Boolean> autoexecButton;
18
	private Mode mode = Mode.REDSTONE;
19
	private boolean conditional;
20
	private boolean autoexec;
21
22
	public CommandBlockEditScreen(final CommandBlockEntity commandBlock) {
23
		this.autoCommandBlock = commandBlock;
24
	}
25
26
	@Override
27
	protected BaseCommandBlock getCommandBlock() {
28
		return this.autoCommandBlock.getCommandBlock();
29
	}
30
31
	@Override
32
	protected int getPreviousY() {
33
		return 135;
34
	}
35
36
	@Override
37
	protected void init() {
38
		super.init();
39
		this.enableControls(false);
40
	}
41
42
	@Override
43
	protected void addExtraControls() {
44
		this.modeButton = this.addRenderableWidget(
45
			CycleButton.<Mode>builder(mode -> {
46
					return switch (mode) {
47
						case SEQUENCE -> Component.translatable("advMode.mode.sequence");
48
						case AUTO -> Component.translatable("advMode.mode.auto");
49
						case REDSTONE -> Component.translatable("advMode.mode.redstone");
50
					};
51
				}, this.mode)
52
				.withValues(Mode.values())
53
				.displayOnlyValue()
54
				.create(this.width / 2 - 50 - 100 - 4, 165, 100, 20, Component.translatable("advMode.mode"), (button, value) -> this.mode = value)
55
		);
56
		this.conditionalButton = this.addRenderableWidget(
57
			CycleButton.booleanBuilder(Component.translatable("advMode.mode.conditional"), Component.translatable("advMode.mode.unconditional"), this.conditional)
58
				.displayOnlyValue()
59
				.create(this.width / 2 - 50, 165, 100, 20, Component.translatable("advMode.type"), (button, value) -> this.conditional = value)
60
		);
61
		this.autoexecButton = this.addRenderableWidget(
62
			CycleButton.booleanBuilder(Component.translatable("advMode.mode.autoexec.bat"), Component.translatable("advMode.mode.redstoneTriggered"), this.autoexec)
63
				.displayOnlyValue()
64
				.create(this.width / 2 + 50 + 4, 165, 100, 20, Component.translatable("advMode.triggering"), (button, value) -> this.autoexec = value)
65
		);
66
	}
67
68
	private void enableControls(final boolean state) {
69
		this.doneButton.active = state;
70
		this.outputButton.active = state;
71
		this.modeButton.active = state;
72
		this.conditionalButton.active = state;
73
		this.autoexecButton.active = state;
74
	}
75
76
	public void updateGui() {
77
		BaseCommandBlock commandBlock = this.autoCommandBlock.getCommandBlock();
78
		this.commandEdit.setValue(commandBlock.getCommand());
79
		boolean trackOutput = commandBlock.isTrackOutput();
80
		this.mode = this.autoCommandBlock.getMode();
81
		this.conditional = this.autoCommandBlock.isConditional();
82
		this.autoexec = this.autoCommandBlock.isAutomatic();
83
		this.outputButton.setValue(trackOutput);
84
		this.modeButton.setValue(this.mode);
85
		this.conditionalButton.setValue(this.conditional);
86
		this.autoexecButton.setValue(this.autoexec);
87
		this.updatePreviousOutput(trackOutput);
88
		this.enableControls(true);
89
	}
90
91
	@Override
92
	public void resize(final int width, final int height) {
93
		super.resize(width, height);
94
		this.enableControls(true);
95
	}
96
97
	@Override
98
	protected void populateAndSendPacket() {
99
		this.minecraft
100
			.getConnection()
101
			.send(
102
				new ServerboundSetCommandBlockPacket(
103
					this.autoCommandBlock.getBlockPos(),
104
					this.commandEdit.getValue(),
105
					this.mode,
106
					this.autoCommandBlock.getCommandBlock().isTrackOutput(),
107
					this.conditional,
108
					this.autoexec
109
				)
110
			);
111
	}
112
}
113

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