ModCheck .java

net.minecraft.util.ModCheck (record, 44 lines): members: confidence, description, shouldReportAsModified, fullDescription, Confidence, identify, merge.

net.minecraft.utilrecord44 linescommon1.5 KB

API Surface (5)

record ModCheck(ModCheck.Confidence confidence, String description)
ModCheck identify(final String expectedBrand, final Supplier<String> actualBrand, final String component, final Class<?> canaryClass)
boolean shouldReportAsModified()
ModCheck merge(final ModCheck other)
String fullDescription()

String literals (6)

" brand changed to '"
" jar signature invalidated"
" jar signature and brand is untouched"
"Probably not."
"Very likely;"
"Definitely;"

Full Source

ModCheck.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util;
2
3
import java.util.function.Supplier;
4
import org.apache.commons.lang3.ObjectUtils;
5
6
public record ModCheck(ModCheck.Confidence confidence, String description) {
7
	public static ModCheck identify(final String expectedBrand, final Supplier<String> actualBrand, final String component, final Class<?> canaryClass) {
8
		String mod = actualBrand.get();
9
		if (!expectedBrand.equals(mod)) {
10
			return new ModCheck(ModCheck.Confidence.DEFINITELY, component + " brand changed to '" + mod + "'");
11
		} else {
12
			return canaryClass.getSigners() == null
13
				? new ModCheck(ModCheck.Confidence.VERY_LIKELY, component + " jar signature invalidated")
14
				: new ModCheck(ModCheck.Confidence.PROBABLY_NOT, component + " jar signature and brand is untouched");
15
		}
16
	}
17
18
	public boolean shouldReportAsModified() {
19
		return this.confidence.shouldReportAsModified;
20
	}
21
22
	public ModCheck merge(final ModCheck other) {
23
		return new ModCheck(ObjectUtils.max(this.confidence, other.confidence), this.description + "; " + other.description);
24
	}
25
26
	public String fullDescription() {
27
		return this.confidence.description + " " + this.description;
28
	}
29
30
	public enum Confidence {
31
		PROBABLY_NOT("Probably not.", false),
32
		VERY_LIKELY("Very likely;", true),
33
		DEFINITELY("Definitely;", true);
34
35
		private final String description;
36
		private final boolean shouldReportAsModified;
37
38
		Confidence(final String description, final boolean shouldReportAsModified) {
39
			this.description = description;
40
			this.shouldReportAsModified = shouldReportAsModified;
41
		}
42
	}
43
}
44

Decompiled Minecraft 26.3 source of ModCheck (net/minecraft/util/ModCheck.java) with Mojang official mappings, stored verbatim on the site.