IntegerProperty .java

net.minecraft.world.level.block.state.properties.IntegerProperty (class): members: generateHashCode, getPossibleValues, getInternalIndex, min, max, values.

net.minecraft.world.level.block.state.propertiesclass69 linescommonextends Property<Integer>1.8 KB

API Surface (7)

List<Integer> getPossibleValues()
boolean equals(final Object o)
int generateHashCode()
IntegerProperty create(final String name, final int min, final int max)
Optional<Integer> getValue(final String name)
String getName(final Integer value)
int getInternalIndex(final Integer value)

Fields & Constants (3)

values
min
max

String literals (4)

"Min value of "
" must be 0 or greater"
"Max value of "
" must be greater than min ("

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

IntegerProperty.java69 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.state.properties;
2
3
import it.unimi.dsi.fastutil.ints.IntImmutableList;
4
import java.util.List;
5
import java.util.Optional;
6
import java.util.stream.IntStream;
7
8
public final class IntegerProperty extends Property<Integer> {
9
	private final IntImmutableList values;
10
	private final int min;
11
	private final int max;
12
13
	private IntegerProperty(final String name, final int min, final int max) {
14
		super(name, Integer.class);
15
		if (min < 0) {
16
			throw new IllegalArgumentException("Min value of " + name + " must be 0 or greater");
17
		}
18
19
		if (max <= min) {
20
			throw new IllegalArgumentException("Max value of " + name + " must be greater than min (" + min + ")");
21
		}
22
23
		this.min = min;
24
		this.max = max;
25
		this.values = IntImmutableList.toList(IntStream.range(min, max + 1));
26
	}
27
28
	@Override
29
	public List<Integer> getPossibleValues() {
30
		return this.values;
31
	}
32
33
	@Override
34
	public boolean equals(final Object o) {
35
		if (this == o) {
36
			return true;
37
		} else {
38
			return o instanceof IntegerProperty that && super.equals(o) ? this.values.equals(that.values) : false;
39
		}
40
	}
41
42
	@Override
43
	public int generateHashCode() {
44
		return 31 * super.generateHashCode() + this.values.hashCode();
45
	}
46
47
	public static IntegerProperty create(final String name, final int min, final int max) {
48
		return new IntegerProperty(name, min, max);
49
	}
50
51
	@Override
52
	public Optional<Integer> getValue(final String name) {
53
		try {
54
			int value = Integer.parseInt(name);
55
			return value >= this.min && value <= this.max ? Optional.of(value) : Optional.empty();
56
		} catch (NumberFormatException ignored) {
57
			return Optional.empty();
58
		}
59
	}
60
61
	public String getName(final Integer value) {
62
		return value.toString();
63
	}
64
65
	public int getInternalIndex(final Integer value) {
66
		return value <= this.max ? value - this.min : -1;
67
	}
68
}
69

Decompiled Minecraft 26.3 source of IntegerProperty (net/minecraft/world/level/block/state/properties/IntegerProperty.java) with Mojang official mappings, stored verbatim on the site.