CodeOfConductScreen .java

net.minecraft.client.gui.screens.multiplayer.CodeOfConductScreen (class): members: codeOfConductText, resultConsumer, CHECK, addFooterButtons, serverData.

net.minecraft.client.gui.screens.multiplayerclass75 linesclientextends WarningScreen2.8 KB

API Surface (3)

Layout addFooterButtons()
boolean shouldCloseOnEsc()
void tick()

Fields & Constants (6)

TITLE
CHECK
serverData
codeOfConductText
resultConsumer
parent

String literals (2)

"multiplayer.codeOfConduct.title"
"multiplayer.codeOfConduct.check"

Full Source

CodeOfConductScreen.java75 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.multiplayer;
2
3
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.ChatFormatting;
7
import net.minecraft.client.gui.components.Button;
8
import net.minecraft.client.gui.layouts.Layout;
9
import net.minecraft.client.gui.layouts.LinearLayout;
10
import net.minecraft.client.gui.screens.ConnectScreen;
11
import net.minecraft.client.gui.screens.Screen;
12
import net.minecraft.client.multiplayer.ServerData;
13
import net.minecraft.client.multiplayer.ServerList;
14
import net.minecraft.network.chat.CommonComponents;
15
import net.minecraft.network.chat.Component;
16
import org.jspecify.annotations.Nullable;
17
18
@Environment(EnvType.CLIENT)
19
public class CodeOfConductScreen extends WarningScreen {
20
	private static final Component TITLE = Component.translatable("multiplayer.codeOfConduct.title").withStyle(ChatFormatting.BOLD);
21
	private static final Component CHECK = Component.translatable("multiplayer.codeOfConduct.check");
22
	private final @Nullable ServerData serverData;
23
	private final String codeOfConductText;
24
	private final BooleanConsumer resultConsumer;
25
	private final Screen parent;
26
27
	private CodeOfConductScreen(
28
		final @Nullable ServerData serverData, final Screen parent, final Component contents, final String codeOfConductText, final BooleanConsumer resultConsumer
29
	) {
30
		super(TITLE, contents, CHECK, TITLE.copy().append("\n").append(contents));
31
		this.serverData = serverData;
32
		this.parent = parent;
33
		this.codeOfConductText = codeOfConductText;
34
		this.resultConsumer = resultConsumer;
35
	}
36
37
	public CodeOfConductScreen(final @Nullable ServerData serverData, final Screen parent, final String codeOfConductText, final BooleanConsumer resultConsumer) {
38
		this(serverData, parent, Component.literal(codeOfConductText), codeOfConductText, resultConsumer);
39
	}
40
41
	@Override
42
	protected Layout addFooterButtons() {
43
		LinearLayout footer = LinearLayout.horizontal().spacing(8);
44
		footer.addChild(Button.builder(CommonComponents.GUI_ACKNOWLEDGE, button -> this.onResult(true)).build());
45
		footer.addChild(Button.builder(CommonComponents.GUI_DISCONNECT, button -> this.onResult(false)).build());
46
		return footer;
47
	}
48
49
	private void onResult(final boolean accepted) {
50
		this.resultConsumer.accept(accepted);
51
		if (this.serverData != null) {
52
			if (accepted && this.stopShowing.selected()) {
53
				this.serverData.acceptCodeOfConduct(this.codeOfConductText);
54
			} else {
55
				this.serverData.clearCodeOfConduct();
56
			}
57
58
			ServerList.saveSingleServer(this.serverData);
59
		}
60
	}
61
62
	@Override
63
	public boolean shouldCloseOnEsc() {
64
		return false;
65
	}
66
67
	@Override
68
	public void tick() {
69
		super.tick();
70
		if (this.parent instanceof ConnectScreen || this.parent instanceof ServerReconfigScreen) {
71
			this.parent.tick();
72
		}
73
	}
74
}
75

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