47 lines
		
	
	
	
		
			1,001 B
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1,001 B
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.util.valueproviders;
 | |
| 
 | |
| import com.mojang.serialization.Codec;
 | |
| import com.mojang.serialization.MapCodec;
 | |
| import net.minecraft.util.RandomSource;
 | |
| 
 | |
| public class ConstantInt extends IntProvider {
 | |
| 	public static final ConstantInt ZERO = new ConstantInt(0);
 | |
| 	public static final MapCodec<ConstantInt> CODEC = Codec.INT.fieldOf("value").xmap(ConstantInt::of, ConstantInt::getValue);
 | |
| 	private final int value;
 | |
| 
 | |
| 	public static ConstantInt of(int value) {
 | |
| 		return value == 0 ? ZERO : new ConstantInt(value);
 | |
| 	}
 | |
| 
 | |
| 	private ConstantInt(int value) {
 | |
| 		this.value = value;
 | |
| 	}
 | |
| 
 | |
| 	public int getValue() {
 | |
| 		return this.value;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int sample(RandomSource random) {
 | |
| 		return this.value;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getMinValue() {
 | |
| 		return this.value;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getMaxValue() {
 | |
| 		return this.value;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public IntProviderType<?> getType() {
 | |
| 		return IntProviderType.CONSTANT;
 | |
| 	}
 | |
| 
 | |
| 	public String toString() {
 | |
| 		return Integer.toString(this.value);
 | |
| 	}
 | |
| }
 |