RandomSequences.java
net.minecraft.world.RandomSequences
信息
- 全限定名:net.minecraft.world.RandomSequences
- 类型:public class
- 包:net.minecraft.world
- 源码路径:src/main/java/net/minecraft/world/RandomSequences.java
- 起始行号:L17
- 继承:SavedData
- 职责:
TODO
字段/常量
-
CODEC- 类型:
Codec<RandomSequences> - 修饰符:
public static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
TYPE- 类型:
SavedDataType<RandomSequences> - 修饰符:
public static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
salt- 类型:
int - 修饰符:
private - 源码定位:
L30 - 说明:
TODO
- 类型:
-
includeWorldSeed- 类型:
boolean - 修饰符:
private - 源码定位:
L31 - 说明:
TODO
- 类型:
-
includeSequenceId- 类型:
boolean - 修饰符:
private - 源码定位:
L32 - 说明:
TODO
- 类型:
-
sequences- 类型:
Map<Identifier,RandomSequence> - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.world.RandomSequences.DirtyMarkingRandomSource- 类型:
class - 修饰符:
private - 源码定位:
L95 - 说明:
TODO
- 类型:
构造器
public RandomSequences() @ L35
- 构造器名:RandomSequences
- 源码定位:L35
- 修饰符:public
参数:
- 无
说明:
TODO
private RandomSequences(int salt, boolean includeWorldSeed, boolean includeSequenceId, Map<Identifier,RandomSequence> sequences) @ L38
- 构造器名:RandomSequences
- 源码定位:L38
- 修饰符:private
参数:
- salt: int
- includeWorldSeed: boolean
- includeSequenceId: boolean
- sequences: Map<Identifier,RandomSequence>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public RandomSource get(Identifier key, long worldSeed) @ L45
- 方法名:get
- 源码定位:L45
- 返回类型:RandomSource
- 修饰符:public
参数:
- key: Identifier
- worldSeed: long
说明:
TODO
private RandomSequence createSequence(Identifier key, long worldSeed) @ L50
- 方法名:createSequence
- 源码定位:L50
- 返回类型:RandomSequence
- 修饰符:private
参数:
- key: Identifier
- worldSeed: long
说明:
TODO
private RandomSequence createSequence(Identifier key, long worldSeed, int salt, boolean includeWorldSeed, boolean includeSequenceId) @ L54
- 方法名:createSequence
- 源码定位:L54
- 返回类型:RandomSequence
- 修饰符:private
参数:
- key: Identifier
- worldSeed: long
- salt: int
- includeWorldSeed: boolean
- includeSequenceId: boolean
说明:
TODO
public void forAllSequences(BiConsumer<Identifier,RandomSequence> consumer) @ L59
- 方法名:forAllSequences
- 源码定位:L59
- 返回类型:void
- 修饰符:public
参数:
- consumer: BiConsumer<Identifier,RandomSequence>
说明:
TODO
public void setSeedDefaults(int salt, boolean includeWorldSeed, boolean includeSequenceId) @ L63
- 方法名:setSeedDefaults
- 源码定位:L63
- 返回类型:void
- 修饰符:public
参数:
- salt: int
- includeWorldSeed: boolean
- includeSequenceId: boolean
说明:
TODO
public int clear() @ L69
- 方法名:clear
- 源码定位:L69
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void reset(Identifier id, long worldSeed) @ L75
- 方法名:reset
- 源码定位:L75
- 返回类型:void
- 修饰符:public
参数:
- id: Identifier
- worldSeed: long
说明:
TODO
public void reset(Identifier id, long worldSeed, int salt, boolean includeWorldSeed, boolean includeSequenceId) @ L79
- 方法名:reset
- 源码定位:L79
- 返回类型:void
- 修饰符:public
参数:
- id: Identifier
- worldSeed: long
- salt: int
- includeWorldSeed: boolean
- includeSequenceId: boolean
说明:
TODO
private int salt() @ L83
- 方法名:salt
- 源码定位:L83
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private boolean includeWorldSeed() @ L87
- 方法名:includeWorldSeed
- 源码定位:L87
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
private boolean includeSequenceId() @ L91
- 方法名:includeSequenceId
- 源码定位:L91
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
代码
public class RandomSequences extends SavedData {
public static final Codec<RandomSequences> CODEC = RecordCodecBuilder.create(
i -> i.group(
Codec.INT.fieldOf("salt").forGetter(RandomSequences::salt),
Codec.BOOL.optionalFieldOf("include_world_seed", true).forGetter(RandomSequences::includeWorldSeed),
Codec.BOOL.optionalFieldOf("include_sequence_id", true).forGetter(RandomSequences::includeSequenceId),
Codec.unboundedMap(Identifier.CODEC, RandomSequence.CODEC).fieldOf("sequences").forGetter(rs -> rs.sequences)
)
.apply(i, RandomSequences::new)
);
public static final SavedDataType<RandomSequences> TYPE = new SavedDataType<>(
Identifier.withDefaultNamespace("random_sequences"), RandomSequences::new, CODEC, DataFixTypes.SAVED_DATA_RANDOM_SEQUENCES
);
private int salt;
private boolean includeWorldSeed = true;
private boolean includeSequenceId = true;
private final Map<Identifier, RandomSequence> sequences = new Object2ObjectOpenHashMap<>();
public RandomSequences() {
}
private RandomSequences(int salt, boolean includeWorldSeed, boolean includeSequenceId, Map<Identifier, RandomSequence> sequences) {
this.salt = salt;
this.includeWorldSeed = includeWorldSeed;
this.includeSequenceId = includeSequenceId;
this.sequences.putAll(sequences);
}
public RandomSource get(Identifier key, long worldSeed) {
RandomSource random = this.sequences.computeIfAbsent(key, rl -> this.createSequence(rl, worldSeed)).random();
return new RandomSequences.DirtyMarkingRandomSource(random);
}
private RandomSequence createSequence(Identifier key, long worldSeed) {
return this.createSequence(key, worldSeed, this.salt, this.includeWorldSeed, this.includeSequenceId);
}
private RandomSequence createSequence(Identifier key, long worldSeed, int salt, boolean includeWorldSeed, boolean includeSequenceId) {
long seed = (includeWorldSeed ? worldSeed : 0L) ^ salt;
return new RandomSequence(seed, includeSequenceId ? Optional.of(key) : Optional.empty());
}
public void forAllSequences(BiConsumer<Identifier, RandomSequence> consumer) {
this.sequences.forEach(consumer);
}
public void setSeedDefaults(int salt, boolean includeWorldSeed, boolean includeSequenceId) {
this.salt = salt;
this.includeWorldSeed = includeWorldSeed;
this.includeSequenceId = includeSequenceId;
}
public int clear() {
int count = this.sequences.size();
this.sequences.clear();
return count;
}
public void reset(Identifier id, long worldSeed) {
this.sequences.put(id, this.createSequence(id, worldSeed));
}
public void reset(Identifier id, long worldSeed, int salt, boolean includeWorldSeed, boolean includeSequenceId) {
this.sequences.put(id, this.createSequence(id, worldSeed, salt, includeWorldSeed, includeSequenceId));
}
private int salt() {
return this.salt;
}
private boolean includeWorldSeed() {
return this.includeWorldSeed;
}
private boolean includeSequenceId() {
return this.includeSequenceId;
}
private class DirtyMarkingRandomSource implements RandomSource {
private final RandomSource random;
private DirtyMarkingRandomSource(RandomSource random) {
Objects.requireNonNull(RandomSequences.this);
super();
this.random = random;
}
@Override
public RandomSource fork() {
RandomSequences.this.setDirty();
return this.random.fork();
}
@Override
public PositionalRandomFactory forkPositional() {
RandomSequences.this.setDirty();
return this.random.forkPositional();
}
@Override
public void setSeed(long seed) {
RandomSequences.this.setDirty();
this.random.setSeed(seed);
}
@Override
public int nextInt() {
RandomSequences.this.setDirty();
return this.random.nextInt();
}
@Override
public int nextInt(int bound) {
RandomSequences.this.setDirty();
return this.random.nextInt(bound);
}
@Override
public long nextLong() {
RandomSequences.this.setDirty();
return this.random.nextLong();
}
@Override
public boolean nextBoolean() {
RandomSequences.this.setDirty();
return this.random.nextBoolean();
}
@Override
public float nextFloat() {
RandomSequences.this.setDirty();
return this.random.nextFloat();
}
@Override
public double nextDouble() {
RandomSequences.this.setDirty();
return this.random.nextDouble();
}
@Override
public double nextGaussian() {
RandomSequences.this.setDirty();
return this.random.nextGaussian();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else {
return obj instanceof RandomSequences.DirtyMarkingRandomSource other ? this.random.equals(other.random) : false;
}
}
}
}引用的其他类
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
RandomSequence()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段
- 引用位置: