trurwsuieghfdskg

This commit is contained in:
2025-06-08 00:02:04 +09:00
commit 56c8ad5bc2
14172 changed files with 1139672 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package net.minecraft.util;
import java.util.function.Consumer;
@FunctionalInterface
public interface AbortableIterationConsumer<T> {
AbortableIterationConsumer.Continuation accept(T p_261708_);
static <T> AbortableIterationConsumer<T> forConsumer(Consumer<T> p_261477_) {
return (p_261916_) -> {
p_261477_.accept(p_261916_);
return AbortableIterationConsumer.Continuation.CONTINUE;
};
}
public static enum Continuation {
CONTINUE,
ABORT;
public boolean shouldAbort() {
return this == ABORT;
}
}
}

View File

@@ -0,0 +1,23 @@
package net.minecraft.util;
import java.util.function.IntConsumer;
public interface BitStorage {
int getAndSet(int p_13517_, int p_13518_);
void set(int p_13525_, int p_13526_);
int get(int p_13515_);
long[] getRaw();
int getSize();
int getBits();
void getAll(IntConsumer p_13520_);
void unpack(int[] p_198162_);
BitStorage copy();
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public record Brightness(int block, int sky) {
public static final Codec<Integer> LIGHT_VALUE_CODEC = ExtraCodecs.intRange(0, 15);
public static final Codec<Brightness> CODEC = RecordCodecBuilder.create((p_270774_) -> {
return p_270774_.group(LIGHT_VALUE_CODEC.fieldOf("block").forGetter(Brightness::block), LIGHT_VALUE_CODEC.fieldOf("sky").forGetter(Brightness::sky)).apply(p_270774_, Brightness::new);
});
public static Brightness FULL_BRIGHT = new Brightness(15, 15);
public int pack() {
return this.block << 4 | this.sky << 20;
}
public static Brightness unpack(int p_270207_) {
int i = p_270207_ >> 4 & '\uffff';
int j = p_270207_ >> 20 & '\uffff';
return new Brightness(i, j);
}
}

View File

@@ -0,0 +1,101 @@
package net.minecraft.util;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.IntFunction;
import java.util.function.ToIntFunction;
public class ByIdMap {
private static <T> IntFunction<T> createMap(ToIntFunction<T> p_263047_, T[] p_263043_) {
if (p_263043_.length == 0) {
throw new IllegalArgumentException("Empty value list");
} else {
Int2ObjectMap<T> int2objectmap = new Int2ObjectOpenHashMap<>();
for(T t : p_263043_) {
int i = p_263047_.applyAsInt(t);
T t1 = int2objectmap.put(i, t);
if (t1 != null) {
throw new IllegalArgumentException("Duplicate entry on id " + i + ": current=" + t + ", previous=" + t1);
}
}
return int2objectmap;
}
}
public static <T> IntFunction<T> sparse(ToIntFunction<T> p_262952_, T[] p_263085_, T p_262981_) {
IntFunction<T> intfunction = createMap(p_262952_, p_263085_);
return (p_262932_) -> {
return Objects.requireNonNullElse(intfunction.apply(p_262932_), p_262981_);
};
}
private static <T> T[] createSortedArray(ToIntFunction<T> p_262976_, T[] p_263053_) {
int i = p_263053_.length;
if (i == 0) {
throw new IllegalArgumentException("Empty value list");
} else {
T[] at = (T[])((Object[])p_263053_.clone());
Arrays.fill(at, (Object)null);
for(T t : p_263053_) {
int j = p_262976_.applyAsInt(t);
if (j < 0 || j >= i) {
throw new IllegalArgumentException("Values are not continous, found index " + j + " for value " + t);
}
T t1 = at[j];
if (t1 != null) {
throw new IllegalArgumentException("Duplicate entry on id " + j + ": current=" + t + ", previous=" + t1);
}
at[j] = t;
}
for(int k = 0; k < i; ++k) {
if (at[k] == null) {
throw new IllegalArgumentException("Missing value at index: " + k);
}
}
return at;
}
}
public static <T> IntFunction<T> continuous(ToIntFunction<T> p_263112_, T[] p_262975_, ByIdMap.OutOfBoundsStrategy p_263075_) {
T[] at = createSortedArray(p_263112_, p_262975_);
int i = at.length;
IntFunction intfunction;
switch (p_263075_) {
case ZERO:
T t = at[0];
intfunction = (p_262927_) -> {
return p_262927_ >= 0 && p_262927_ < i ? at[p_262927_] : t;
};
break;
case WRAP:
intfunction = (p_262977_) -> {
return at[Mth.positiveModulo(p_262977_, i)];
};
break;
case CLAMP:
intfunction = (p_263013_) -> {
return at[Mth.clamp(p_263013_, 0, i - 1)];
};
break;
default:
throw new IncompatibleClassChangeError();
}
return intfunction;
}
public static enum OutOfBoundsStrategy {
ZERO,
WRAP,
CLAMP;
}
}

View File

@@ -0,0 +1,76 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ClassInstanceMultiMap<T> extends AbstractCollection<T> {
private final Map<Class<?>, List<T>> byClass = Maps.newHashMap();
private final Class<T> baseClass;
private final List<T> allInstances = Lists.newArrayList();
public ClassInstanceMultiMap(Class<T> p_13531_) {
this.baseClass = p_13531_;
this.byClass.put(p_13531_, this.allInstances);
}
public boolean add(T p_13536_) {
boolean flag = false;
for(Map.Entry<Class<?>, List<T>> entry : this.byClass.entrySet()) {
if (entry.getKey().isInstance(p_13536_)) {
flag |= entry.getValue().add(p_13536_);
}
}
return flag;
}
public boolean remove(Object p_13543_) {
boolean flag = false;
for(Map.Entry<Class<?>, List<T>> entry : this.byClass.entrySet()) {
if (entry.getKey().isInstance(p_13543_)) {
List<T> list = entry.getValue();
flag |= list.remove(p_13543_);
}
}
return flag;
}
public boolean contains(Object p_13540_) {
return this.find(p_13540_.getClass()).contains(p_13540_);
}
public <S> Collection<S> find(Class<S> p_13534_) {
if (!this.baseClass.isAssignableFrom(p_13534_)) {
throw new IllegalArgumentException("Don't know how to search for " + p_13534_);
} else {
List<? extends T> list = this.byClass.computeIfAbsent(p_13534_, (p_13538_) -> {
return this.allInstances.stream().filter(p_13538_::isInstance).collect(Collectors.toList());
});
return (Collection<S>)Collections.unmodifiableCollection(list);
}
}
public Iterator<T> iterator() {
return (Iterator<T>)(this.allInstances.isEmpty() ? Collections.emptyIterator() : Iterators.unmodifiableIterator(this.allInstances.iterator()));
}
public List<T> getAllInstances() {
return ImmutableList.copyOf(this.allInstances);
}
public int size() {
return this.allInstances.size();
}
}

View File

@@ -0,0 +1,8 @@
package net.minecraft.util;
public class CommonColors {
public static final int WHITE = -1;
public static final int BLACK = -16777216;
public static final int GRAY = -6250336;
public static final int RED = -65536;
}

View File

@@ -0,0 +1,31 @@
package net.minecraft.util;
public class CommonLinks {
public static final String GDPR = "https://aka.ms/MinecraftGDPR";
public static final String EULA = "https://aka.ms/MinecraftEULA";
public static final String ATTRIBUTION = "https://aka.ms/MinecraftJavaAttribution";
public static final String LICENSES = "https://aka.ms/MinecraftJavaLicenses";
public static final String BUY_MINECRAFT_JAVA = "https://aka.ms/BuyMinecraftJava";
public static final String ACCOUNT_SETTINGS = "https://aka.ms/JavaAccountSettings";
public static final String SNAPSHOT_FEEDBACK = "https://aka.ms/snapshotfeedback?ref=game";
public static final String RELEASE_FEEDBACK = "https://aka.ms/javafeedback?ref=game";
public static final String SNAPSHOT_BUGS_FEEDBACK = "https://aka.ms/snapshotbugs?ref=game";
public static final String ACCESSIBILITY_HELP = "https://aka.ms/MinecraftJavaAccessibility";
public static final String REPORTING_HELP = "https://aka.ms/aboutjavareporting";
public static final String SUSPENSION_HELP = "https://aka.ms/mcjavamoderation";
public static final String BLOCKING_HELP = "https://aka.ms/javablocking";
public static final String SYMLINK_HELP = "https://aka.ms/MinecraftSymLinks";
public static final String START_REALMS_TRIAL = "https://aka.ms/startjavarealmstrial";
public static final String BUY_REALMS = "https://aka.ms/BuyJavaRealms";
public static final String REALMS_TERMS = "https://aka.ms/MinecraftRealmsTerms";
public static final String REALMS_CONTENT_CREATION = "https://aka.ms/MinecraftRealmsContentCreator";
public static final String REALMS_UPDATE_MOJANG_ACCOUNT = "https://aka.ms/UpdateMojangAccount";
public static String extendRealms(String p_276321_, String p_276293_, boolean p_276266_) {
return extendRealms(p_276321_, p_276293_) + "&ref=" + (p_276266_ ? "expiredTrial" : "expiredRealm");
}
public static String extendRealms(String p_276318_, String p_276285_) {
return "https://aka.ms/ExtendJavaRealms?subscriptionId=" + p_276318_ + "&profileId=" + p_276285_;
}
}

View File

@@ -0,0 +1,174 @@
package net.minecraft.util;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
import java.util.Arrays;
import java.util.Iterator;
import javax.annotation.Nullable;
import net.minecraft.core.IdMap;
public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
private static final int NOT_FOUND = -1;
private static final Object EMPTY_SLOT = null;
private static final float LOADFACTOR = 0.8F;
private K[] keys;
private int[] values;
private K[] byId;
private int nextId;
private int size;
private CrudeIncrementalIntIdentityHashBiMap(int p_13553_) {
this.keys = (K[])(new Object[p_13553_]);
this.values = new int[p_13553_];
this.byId = (K[])(new Object[p_13553_]);
}
private CrudeIncrementalIntIdentityHashBiMap(K[] p_199841_, int[] p_199842_, K[] p_199843_, int p_199844_, int p_199845_) {
this.keys = p_199841_;
this.values = p_199842_;
this.byId = p_199843_;
this.nextId = p_199844_;
this.size = p_199845_;
}
public static <A> CrudeIncrementalIntIdentityHashBiMap<A> create(int p_184238_) {
return new CrudeIncrementalIntIdentityHashBiMap<>((int)((float)p_184238_ / 0.8F));
}
public int getId(@Nullable K p_13558_) {
return this.getValue(this.indexOf(p_13558_, this.hash(p_13558_)));
}
@Nullable
public K byId(int p_13556_) {
return (K)(p_13556_ >= 0 && p_13556_ < this.byId.length ? this.byId[p_13556_] : null);
}
private int getValue(int p_13568_) {
return p_13568_ == -1 ? -1 : this.values[p_13568_];
}
public boolean contains(K p_144610_) {
return this.getId(p_144610_) != -1;
}
public boolean contains(int p_144608_) {
return this.byId(p_144608_) != null;
}
public int add(K p_13570_) {
int i = this.nextId();
this.addMapping(p_13570_, i);
return i;
}
private int nextId() {
while(this.nextId < this.byId.length && this.byId[this.nextId] != null) {
++this.nextId;
}
return this.nextId;
}
private void grow(int p_13572_) {
K[] ak = this.keys;
int[] aint = this.values;
CrudeIncrementalIntIdentityHashBiMap<K> crudeincrementalintidentityhashbimap = new CrudeIncrementalIntIdentityHashBiMap<>(p_13572_);
for(int i = 0; i < ak.length; ++i) {
if (ak[i] != null) {
crudeincrementalintidentityhashbimap.addMapping(ak[i], aint[i]);
}
}
this.keys = crudeincrementalintidentityhashbimap.keys;
this.values = crudeincrementalintidentityhashbimap.values;
this.byId = crudeincrementalintidentityhashbimap.byId;
this.nextId = crudeincrementalintidentityhashbimap.nextId;
this.size = crudeincrementalintidentityhashbimap.size;
}
public void addMapping(K p_13560_, int p_13561_) {
int i = Math.max(p_13561_, this.size + 1);
if ((float)i >= (float)this.keys.length * 0.8F) {
int j;
for(j = this.keys.length << 1; j < p_13561_; j <<= 1) {
}
this.grow(j);
}
int k = this.findEmpty(this.hash(p_13560_));
this.keys[k] = p_13560_;
this.values[k] = p_13561_;
this.byId[p_13561_] = p_13560_;
++this.size;
if (p_13561_ == this.nextId) {
++this.nextId;
}
}
private int hash(@Nullable K p_13574_) {
return (Mth.murmurHash3Mixer(System.identityHashCode(p_13574_)) & Integer.MAX_VALUE) % this.keys.length;
}
private int indexOf(@Nullable K p_13564_, int p_13565_) {
for(int i = p_13565_; i < this.keys.length; ++i) {
if (this.keys[i] == p_13564_) {
return i;
}
if (this.keys[i] == EMPTY_SLOT) {
return -1;
}
}
for(int j = 0; j < p_13565_; ++j) {
if (this.keys[j] == p_13564_) {
return j;
}
if (this.keys[j] == EMPTY_SLOT) {
return -1;
}
}
return -1;
}
private int findEmpty(int p_13576_) {
for(int i = p_13576_; i < this.keys.length; ++i) {
if (this.keys[i] == EMPTY_SLOT) {
return i;
}
}
for(int j = 0; j < p_13576_; ++j) {
if (this.keys[j] == EMPTY_SLOT) {
return j;
}
}
throw new RuntimeException("Overflowed :(");
}
public Iterator<K> iterator() {
return Iterators.filter(Iterators.forArray(this.byId), Predicates.notNull());
}
public void clear() {
Arrays.fill(this.keys, (Object)null);
Arrays.fill(this.byId, (Object)null);
this.nextId = 0;
this.size = 0;
}
public int size() {
return this.size;
}
public CrudeIncrementalIntIdentityHashBiMap<K> copy() {
return new CrudeIncrementalIntIdentityHashBiMap<>((K[])((Object[])this.keys.clone()), (int[])this.values.clone(), (K[])((Object[])this.byId.clone()), this.nextId, this.size);
}
}

View File

@@ -0,0 +1,228 @@
package net.minecraft.util;
import com.google.common.primitives.Longs;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import it.unimi.dsi.fastutil.bytes.ByteArrays;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.spec.EncodedKeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import net.minecraft.network.FriendlyByteBuf;
public class Crypt {
private static final String SYMMETRIC_ALGORITHM = "AES";
private static final int SYMMETRIC_BITS = 128;
private static final String ASYMMETRIC_ALGORITHM = "RSA";
private static final int ASYMMETRIC_BITS = 1024;
private static final String BYTE_ENCODING = "ISO_8859_1";
private static final String HASH_ALGORITHM = "SHA-1";
public static final String SIGNING_ALGORITHM = "SHA256withRSA";
public static final int SIGNATURE_BYTES = 256;
private static final String PEM_RSA_PRIVATE_KEY_HEADER = "-----BEGIN RSA PRIVATE KEY-----";
private static final String PEM_RSA_PRIVATE_KEY_FOOTER = "-----END RSA PRIVATE KEY-----";
public static final String RSA_PUBLIC_KEY_HEADER = "-----BEGIN RSA PUBLIC KEY-----";
private static final String RSA_PUBLIC_KEY_FOOTER = "-----END RSA PUBLIC KEY-----";
public static final String MIME_LINE_SEPARATOR = "\n";
public static final Base64.Encoder MIME_ENCODER = Base64.getMimeEncoder(76, "\n".getBytes(StandardCharsets.UTF_8));
public static final Codec<PublicKey> PUBLIC_KEY_CODEC = Codec.STRING.comapFlatMap((p_274846_) -> {
try {
return DataResult.success(stringToRsaPublicKey(p_274846_));
} catch (CryptException cryptexception) {
return DataResult.error(cryptexception::getMessage);
}
}, Crypt::rsaPublicKeyToString);
public static final Codec<PrivateKey> PRIVATE_KEY_CODEC = Codec.STRING.comapFlatMap((p_274845_) -> {
try {
return DataResult.success(stringToPemRsaPrivateKey(p_274845_));
} catch (CryptException cryptexception) {
return DataResult.error(cryptexception::getMessage);
}
}, Crypt::pemRsaPrivateKeyToString);
public static SecretKey generateSecretKey() throws CryptException {
try {
KeyGenerator keygenerator = KeyGenerator.getInstance("AES");
keygenerator.init(128);
return keygenerator.generateKey();
} catch (Exception exception) {
throw new CryptException(exception);
}
}
public static KeyPair generateKeyPair() throws CryptException {
try {
KeyPairGenerator keypairgenerator = KeyPairGenerator.getInstance("RSA");
keypairgenerator.initialize(1024);
return keypairgenerator.generateKeyPair();
} catch (Exception exception) {
throw new CryptException(exception);
}
}
public static byte[] digestData(String p_13591_, PublicKey p_13592_, SecretKey p_13593_) throws CryptException {
try {
return digestData(p_13591_.getBytes("ISO_8859_1"), p_13593_.getEncoded(), p_13592_.getEncoded());
} catch (Exception exception) {
throw new CryptException(exception);
}
}
private static byte[] digestData(byte[]... p_13603_) throws Exception {
MessageDigest messagedigest = MessageDigest.getInstance("SHA-1");
for(byte[] abyte : p_13603_) {
messagedigest.update(abyte);
}
return messagedigest.digest();
}
private static <T extends Key> T rsaStringToKey(String p_216072_, String p_216073_, String p_216074_, Crypt.ByteArrayToKeyFunction<T> p_216075_) throws CryptException {
int i = p_216072_.indexOf(p_216073_);
if (i != -1) {
i += p_216073_.length();
int j = p_216072_.indexOf(p_216074_, i);
p_216072_ = p_216072_.substring(i, j + 1);
}
try {
return p_216075_.apply(Base64.getMimeDecoder().decode(p_216072_));
} catch (IllegalArgumentException illegalargumentexception) {
throw new CryptException(illegalargumentexception);
}
}
public static PrivateKey stringToPemRsaPrivateKey(String p_216070_) throws CryptException {
return rsaStringToKey(p_216070_, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", Crypt::byteToPrivateKey);
}
public static PublicKey stringToRsaPublicKey(String p_216081_) throws CryptException {
return rsaStringToKey(p_216081_, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----", Crypt::byteToPublicKey);
}
public static String rsaPublicKeyToString(PublicKey p_216079_) {
if (!"RSA".equals(p_216079_.getAlgorithm())) {
throw new IllegalArgumentException("Public key must be RSA");
} else {
return "-----BEGIN RSA PUBLIC KEY-----\n" + MIME_ENCODER.encodeToString(p_216079_.getEncoded()) + "\n-----END RSA PUBLIC KEY-----\n";
}
}
public static String pemRsaPrivateKeyToString(PrivateKey p_216077_) {
if (!"RSA".equals(p_216077_.getAlgorithm())) {
throw new IllegalArgumentException("Private key must be RSA");
} else {
return "-----BEGIN RSA PRIVATE KEY-----\n" + MIME_ENCODER.encodeToString(p_216077_.getEncoded()) + "\n-----END RSA PRIVATE KEY-----\n";
}
}
private static PrivateKey byteToPrivateKey(byte[] p_216083_) throws CryptException {
try {
EncodedKeySpec encodedkeyspec = new PKCS8EncodedKeySpec(p_216083_);
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
return keyfactory.generatePrivate(encodedkeyspec);
} catch (Exception exception) {
throw new CryptException(exception);
}
}
public static PublicKey byteToPublicKey(byte[] p_13601_) throws CryptException {
try {
EncodedKeySpec encodedkeyspec = new X509EncodedKeySpec(p_13601_);
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
return keyfactory.generatePublic(encodedkeyspec);
} catch (Exception exception) {
throw new CryptException(exception);
}
}
public static SecretKey decryptByteToSecretKey(PrivateKey p_13598_, byte[] p_13599_) throws CryptException {
byte[] abyte = decryptUsingKey(p_13598_, p_13599_);
try {
return new SecretKeySpec(abyte, "AES");
} catch (Exception exception) {
throw new CryptException(exception);
}
}
public static byte[] encryptUsingKey(Key p_13595_, byte[] p_13596_) throws CryptException {
return cipherData(1, p_13595_, p_13596_);
}
public static byte[] decryptUsingKey(Key p_13606_, byte[] p_13607_) throws CryptException {
return cipherData(2, p_13606_, p_13607_);
}
private static byte[] cipherData(int p_13587_, Key p_13588_, byte[] p_13589_) throws CryptException {
try {
return setupCipher(p_13587_, p_13588_.getAlgorithm(), p_13588_).doFinal(p_13589_);
} catch (Exception exception) {
throw new CryptException(exception);
}
}
private static Cipher setupCipher(int p_13580_, String p_13581_, Key p_13582_) throws Exception {
Cipher cipher = Cipher.getInstance(p_13581_);
cipher.init(p_13580_, p_13582_);
return cipher;
}
public static Cipher getCipher(int p_13584_, Key p_13585_) throws CryptException {
try {
Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding");
cipher.init(p_13584_, p_13585_, new IvParameterSpec(p_13585_.getEncoded()));
return cipher;
} catch (Exception exception) {
throw new CryptException(exception);
}
}
interface ByteArrayToKeyFunction<T extends Key> {
T apply(byte[] p_216089_) throws CryptException;
}
public static record SaltSignaturePair(long salt, byte[] signature) {
public static final Crypt.SaltSignaturePair EMPTY = new Crypt.SaltSignaturePair(0L, ByteArrays.EMPTY_ARRAY);
public SaltSignaturePair(FriendlyByteBuf p_216098_) {
this(p_216098_.readLong(), p_216098_.readByteArray());
}
public boolean isValid() {
return this.signature.length > 0;
}
public static void write(FriendlyByteBuf p_216101_, Crypt.SaltSignaturePair p_216102_) {
p_216101_.writeLong(p_216102_.salt);
p_216101_.writeByteArray(p_216102_.signature);
}
public byte[] saltAsBytes() {
return Longs.toByteArray(this.salt);
}
}
public static class SaltSupplier {
private static final SecureRandom secureRandom = new SecureRandom();
public static long getLong() {
return secureRandom.nextLong();
}
}
}

View File

@@ -0,0 +1,7 @@
package net.minecraft.util;
public class CryptException extends Exception {
public CryptException(Throwable p_13609_) {
super(p_13609_);
}
}

View File

@@ -0,0 +1,56 @@
package net.minecraft.util;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringEscapeUtils;
public class CsvOutput {
private static final String LINE_SEPARATOR = "\r\n";
private static final String FIELD_SEPARATOR = ",";
private final Writer output;
private final int columnCount;
CsvOutput(Writer p_13613_, List<String> p_13614_) throws IOException {
this.output = p_13613_;
this.columnCount = p_13614_.size();
this.writeLine(p_13614_.stream());
}
public static CsvOutput.Builder builder() {
return new CsvOutput.Builder();
}
public void writeRow(Object... p_13625_) throws IOException {
if (p_13625_.length != this.columnCount) {
throw new IllegalArgumentException("Invalid number of columns, expected " + this.columnCount + ", but got " + p_13625_.length);
} else {
this.writeLine(Stream.of(p_13625_));
}
}
private void writeLine(Stream<?> p_13623_) throws IOException {
this.output.write((String)p_13623_.map(CsvOutput::getStringValue).collect(Collectors.joining(",")) + "\r\n");
}
private static String getStringValue(@Nullable Object p_13621_) {
return StringEscapeUtils.escapeCsv(p_13621_ != null ? p_13621_.toString() : "[null]");
}
public static class Builder {
private final List<String> headers = Lists.newArrayList();
public CsvOutput.Builder addColumn(String p_13631_) {
this.headers.add(p_13631_);
return this;
}
public CsvOutput build(Writer p_13629_) throws IOException {
return new CsvOutput(p_13629_, this.headers);
}
}
}

View File

@@ -0,0 +1,48 @@
package net.minecraft.util;
import net.minecraft.world.phys.Vec3;
public class CubicSampler {
private static final int GAUSSIAN_SAMPLE_RADIUS = 2;
private static final int GAUSSIAN_SAMPLE_BREADTH = 6;
private static final double[] GAUSSIAN_SAMPLE_KERNEL = new double[]{0.0D, 1.0D, 4.0D, 6.0D, 4.0D, 1.0D, 0.0D};
private CubicSampler() {
}
public static Vec3 gaussianSampleVec3(Vec3 p_130039_, CubicSampler.Vec3Fetcher p_130040_) {
int i = Mth.floor(p_130039_.x());
int j = Mth.floor(p_130039_.y());
int k = Mth.floor(p_130039_.z());
double d0 = p_130039_.x() - (double)i;
double d1 = p_130039_.y() - (double)j;
double d2 = p_130039_.z() - (double)k;
double d3 = 0.0D;
Vec3 vec3 = Vec3.ZERO;
for(int l = 0; l < 6; ++l) {
double d4 = Mth.lerp(d0, GAUSSIAN_SAMPLE_KERNEL[l + 1], GAUSSIAN_SAMPLE_KERNEL[l]);
int i1 = i - 2 + l;
for(int j1 = 0; j1 < 6; ++j1) {
double d5 = Mth.lerp(d1, GAUSSIAN_SAMPLE_KERNEL[j1 + 1], GAUSSIAN_SAMPLE_KERNEL[j1]);
int k1 = j - 2 + j1;
for(int l1 = 0; l1 < 6; ++l1) {
double d6 = Mth.lerp(d2, GAUSSIAN_SAMPLE_KERNEL[l1 + 1], GAUSSIAN_SAMPLE_KERNEL[l1]);
int i2 = k - 2 + l1;
double d7 = d4 * d5 * d6;
d3 += d7;
vec3 = vec3.add(p_130040_.fetch(i1, k1, i2).scale(d7));
}
}
}
return vec3.scale(1.0D / d3);
}
@FunctionalInterface
public interface Vec3Fetcher {
Vec3 fetch(int p_130042_, int p_130043_, int p_130044_);
}
}

View File

@@ -0,0 +1,292 @@
package net.minecraft.util;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.floats.FloatList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.lang3.mutable.MutableObject;
public interface CubicSpline<C, I extends ToFloatFunction<C>> extends ToFloatFunction<C> {
@VisibleForDebug
String parityString();
CubicSpline<C, I> mapAll(CubicSpline.CoordinateVisitor<I> p_211579_);
static <C, I extends ToFloatFunction<C>> Codec<CubicSpline<C, I>> codec(Codec<I> p_184263_) {
MutableObject<Codec<CubicSpline<C, I>>> mutableobject = new MutableObject<>();
record Point<C, I extends ToFloatFunction<C>>(float location, CubicSpline<C, I> value, float derivative) {
}
Codec<Point<C, I>> codec = RecordCodecBuilder.create((p_184270_) -> {
return p_184270_.group(Codec.FLOAT.fieldOf("location").forGetter(Point::location), ExtraCodecs.lazyInitializedCodec(mutableobject::getValue).fieldOf("value").forGetter(Point::value), Codec.FLOAT.fieldOf("derivative").forGetter(Point::derivative)).apply(p_184270_, (p_184242_, p_184243_, p_184244_) -> {
return new Point<>((float)p_184242_, p_184243_, (float)p_184244_);
});
});
Codec<CubicSpline.Multipoint<C, I>> codec1 = RecordCodecBuilder.create((p_184267_) -> {
return p_184267_.group(p_184263_.fieldOf("coordinate").forGetter(CubicSpline.Multipoint::coordinate), ExtraCodecs.nonEmptyList(codec.listOf()).fieldOf("points").forGetter((p_184272_) -> {
return IntStream.range(0, p_184272_.locations.length).mapToObj((p_184249_) -> {
return new Point<>(p_184272_.locations()[p_184249_], p_184272_.values().get(p_184249_), p_184272_.derivatives()[p_184249_]);
}).toList();
})).apply(p_184267_, (p_184258_, p_184259_) -> {
float[] afloat = new float[p_184259_.size()];
ImmutableList.Builder<CubicSpline<C, I>> builder = ImmutableList.builder();
float[] afloat1 = new float[p_184259_.size()];
for(int i = 0; i < p_184259_.size(); ++i) {
Point<C, I> point = p_184259_.get(i);
afloat[i] = point.location();
builder.add(point.value());
afloat1[i] = point.derivative();
}
return CubicSpline.Multipoint.create(p_184258_, afloat, builder.build(), afloat1);
});
});
mutableobject.setValue(Codec.either(Codec.FLOAT, codec1).xmap((p_184261_) -> {
return p_184261_.map(CubicSpline.Constant::new, (p_184246_) -> {
return p_184246_;
});
}, (p_184251_) -> {
Either either;
if (p_184251_ instanceof CubicSpline.Constant<C, I> constant) {
either = Either.left(constant.value());
} else {
either = Either.right(p_184251_);
}
return either;
}));
return mutableobject.getValue();
}
static <C, I extends ToFloatFunction<C>> CubicSpline<C, I> constant(float p_184240_) {
return new CubicSpline.Constant<>(p_184240_);
}
static <C, I extends ToFloatFunction<C>> CubicSpline.Builder<C, I> builder(I p_184253_) {
return new CubicSpline.Builder<>(p_184253_);
}
static <C, I extends ToFloatFunction<C>> CubicSpline.Builder<C, I> builder(I p_184255_, ToFloatFunction<Float> p_184256_) {
return new CubicSpline.Builder<>(p_184255_, p_184256_);
}
public static final class Builder<C, I extends ToFloatFunction<C>> {
private final I coordinate;
private final ToFloatFunction<Float> valueTransformer;
private final FloatList locations = new FloatArrayList();
private final List<CubicSpline<C, I>> values = Lists.newArrayList();
private final FloatList derivatives = new FloatArrayList();
protected Builder(I p_184293_) {
this(p_184293_, ToFloatFunction.IDENTITY);
}
protected Builder(I p_184295_, ToFloatFunction<Float> p_184296_) {
this.coordinate = p_184295_;
this.valueTransformer = p_184296_;
}
public CubicSpline.Builder<C, I> addPoint(float p_216115_, float p_216116_) {
return this.addPoint(p_216115_, new CubicSpline.Constant<>(this.valueTransformer.apply(p_216116_)), 0.0F);
}
public CubicSpline.Builder<C, I> addPoint(float p_184299_, float p_184300_, float p_184301_) {
return this.addPoint(p_184299_, new CubicSpline.Constant<>(this.valueTransformer.apply(p_184300_)), p_184301_);
}
public CubicSpline.Builder<C, I> addPoint(float p_216118_, CubicSpline<C, I> p_216119_) {
return this.addPoint(p_216118_, p_216119_, 0.0F);
}
private CubicSpline.Builder<C, I> addPoint(float p_184303_, CubicSpline<C, I> p_184304_, float p_184305_) {
if (!this.locations.isEmpty() && p_184303_ <= this.locations.getFloat(this.locations.size() - 1)) {
throw new IllegalArgumentException("Please register points in ascending order");
} else {
this.locations.add(p_184303_);
this.values.add(p_184304_);
this.derivatives.add(p_184305_);
return this;
}
}
public CubicSpline<C, I> build() {
if (this.locations.isEmpty()) {
throw new IllegalStateException("No elements added");
} else {
return CubicSpline.Multipoint.create(this.coordinate, this.locations.toFloatArray(), ImmutableList.copyOf(this.values), this.derivatives.toFloatArray());
}
}
}
@VisibleForDebug
public static record Constant<C, I extends ToFloatFunction<C>>(float value) implements CubicSpline<C, I> {
public float apply(C p_184313_) {
return this.value;
}
public String parityString() {
return String.format(Locale.ROOT, "k=%.3f", this.value);
}
public float minValue() {
return this.value;
}
public float maxValue() {
return this.value;
}
public CubicSpline<C, I> mapAll(CubicSpline.CoordinateVisitor<I> p_211581_) {
return this;
}
}
public interface CoordinateVisitor<I> {
I visit(I p_216123_);
}
@VisibleForDebug
public static record Multipoint<C, I extends ToFloatFunction<C>>(I coordinate, float[] locations, List<CubicSpline<C, I>> values, float[] derivatives, float minValue, float maxValue) implements CubicSpline<C, I> {
public Multipoint {
validateSizes(locations, values, derivatives);
}
static <C, I extends ToFloatFunction<C>> CubicSpline.Multipoint<C, I> create(I p_216144_, float[] p_216145_, List<CubicSpline<C, I>> p_216146_, float[] p_216147_) {
validateSizes(p_216145_, p_216146_, p_216147_);
int i = p_216145_.length - 1;
float f = Float.POSITIVE_INFINITY;
float f1 = Float.NEGATIVE_INFINITY;
float f2 = p_216144_.minValue();
float f3 = p_216144_.maxValue();
if (f2 < p_216145_[0]) {
float f4 = linearExtend(f2, p_216145_, p_216146_.get(0).minValue(), p_216147_, 0);
float f5 = linearExtend(f2, p_216145_, p_216146_.get(0).maxValue(), p_216147_, 0);
f = Math.min(f, Math.min(f4, f5));
f1 = Math.max(f1, Math.max(f4, f5));
}
if (f3 > p_216145_[i]) {
float f24 = linearExtend(f3, p_216145_, p_216146_.get(i).minValue(), p_216147_, i);
float f25 = linearExtend(f3, p_216145_, p_216146_.get(i).maxValue(), p_216147_, i);
f = Math.min(f, Math.min(f24, f25));
f1 = Math.max(f1, Math.max(f24, f25));
}
for(CubicSpline<C, I> cubicspline2 : p_216146_) {
f = Math.min(f, cubicspline2.minValue());
f1 = Math.max(f1, cubicspline2.maxValue());
}
for(int j = 0; j < i; ++j) {
float f26 = p_216145_[j];
float f6 = p_216145_[j + 1];
float f7 = f6 - f26;
CubicSpline<C, I> cubicspline = p_216146_.get(j);
CubicSpline<C, I> cubicspline1 = p_216146_.get(j + 1);
float f8 = cubicspline.minValue();
float f9 = cubicspline.maxValue();
float f10 = cubicspline1.minValue();
float f11 = cubicspline1.maxValue();
float f12 = p_216147_[j];
float f13 = p_216147_[j + 1];
if (f12 != 0.0F || f13 != 0.0F) {
float f14 = f12 * f7;
float f15 = f13 * f7;
float f16 = Math.min(f8, f10);
float f17 = Math.max(f9, f11);
float f18 = f14 - f11 + f8;
float f19 = f14 - f10 + f9;
float f20 = -f15 + f10 - f9;
float f21 = -f15 + f11 - f8;
float f22 = Math.min(f18, f20);
float f23 = Math.max(f19, f21);
f = Math.min(f, f16 + 0.25F * f22);
f1 = Math.max(f1, f17 + 0.25F * f23);
}
}
return new CubicSpline.Multipoint<>(p_216144_, p_216145_, p_216146_, p_216147_, f, f1);
}
private static float linearExtend(float p_216134_, float[] p_216135_, float p_216136_, float[] p_216137_, int p_216138_) {
float f = p_216137_[p_216138_];
return f == 0.0F ? p_216136_ : p_216136_ + f * (p_216134_ - p_216135_[p_216138_]);
}
private static <C, I extends ToFloatFunction<C>> void validateSizes(float[] p_216152_, List<CubicSpline<C, I>> p_216153_, float[] p_216154_) {
if (p_216152_.length == p_216153_.size() && p_216152_.length == p_216154_.length) {
if (p_216152_.length == 0) {
throw new IllegalArgumentException("Cannot create a multipoint spline with no points");
}
} else {
throw new IllegalArgumentException("All lengths must be equal, got: " + p_216152_.length + " " + p_216153_.size() + " " + p_216154_.length);
}
}
public float apply(C p_184340_) {
float f = this.coordinate.apply(p_184340_);
int i = findIntervalStart(this.locations, f);
int j = this.locations.length - 1;
if (i < 0) {
return linearExtend(f, this.locations, this.values.get(0).apply(p_184340_), this.derivatives, 0);
} else if (i == j) {
return linearExtend(f, this.locations, this.values.get(j).apply(p_184340_), this.derivatives, j);
} else {
float f1 = this.locations[i];
float f2 = this.locations[i + 1];
float f3 = (f - f1) / (f2 - f1);
ToFloatFunction<C> tofloatfunction = this.values.get(i);
ToFloatFunction<C> tofloatfunction1 = this.values.get(i + 1);
float f4 = this.derivatives[i];
float f5 = this.derivatives[i + 1];
float f6 = tofloatfunction.apply(p_184340_);
float f7 = tofloatfunction1.apply(p_184340_);
float f8 = f4 * (f2 - f1) - (f7 - f6);
float f9 = -f5 * (f2 - f1) + (f7 - f6);
return Mth.lerp(f3, f6, f7) + f3 * (1.0F - f3) * Mth.lerp(f3, f8, f9);
}
}
private static int findIntervalStart(float[] p_216149_, float p_216150_) {
return Mth.binarySearch(0, p_216149_.length, (p_216142_) -> {
return p_216150_ < p_216149_[p_216142_];
}) - 1;
}
@VisibleForTesting
public String parityString() {
return "Spline{coordinate=" + this.coordinate + ", locations=" + this.toString(this.locations) + ", derivatives=" + this.toString(this.derivatives) + ", values=" + (String)this.values.stream().map(CubicSpline::parityString).collect(Collectors.joining(", ", "[", "]")) + "}";
}
private String toString(float[] p_184335_) {
return "[" + (String)IntStream.range(0, p_184335_.length).mapToDouble((p_184338_) -> {
return (double)p_184335_[p_184338_];
}).mapToObj((p_184330_) -> {
return String.format(Locale.ROOT, "%.3f", p_184330_);
}).collect(Collectors.joining(", ")) + "]";
}
public CubicSpline<C, I> mapAll(CubicSpline.CoordinateVisitor<I> p_211585_) {
return create(p_211585_.visit(this.coordinate), this.locations, this.values().stream().map((p_211588_) -> {
return p_211588_.mapAll(p_211585_);
}).toList(), this.derivatives);
}
public float minValue() {
return this.minValue;
}
public float maxValue() {
return this.maxValue;
}
}
}

View File

@@ -0,0 +1,44 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class DebugBuffer<T> {
private final AtomicReferenceArray<T> data;
private final AtomicInteger index;
public DebugBuffer(int p_144623_) {
this.data = new AtomicReferenceArray<>(p_144623_);
this.index = new AtomicInteger(0);
}
public void push(T p_144626_) {
int i = this.data.length();
int j;
int k;
do {
j = this.index.get();
k = (j + 1) % i;
} while(!this.index.compareAndSet(j, k));
this.data.set(k, p_144626_);
}
public List<T> dump() {
int i = this.index.get();
ImmutableList.Builder<T> builder = ImmutableList.builder();
for(int j = 0; j < this.data.length(); ++j) {
int k = Math.floorMod(i - j, this.data.length());
T t = this.data.get(k);
if (t != null) {
builder.add(t);
}
}
return builder.build();
}
}

View File

@@ -0,0 +1,71 @@
package net.minecraft.util;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class DependencySorter<K, V extends DependencySorter.Entry<K>> {
private final Map<K, V> contents = new HashMap<>();
public DependencySorter<K, V> addEntry(K p_285256_, V p_285334_) {
this.contents.put(p_285256_, p_285334_);
return this;
}
private void visitDependenciesAndElement(Multimap<K, K> p_285183_, Set<K> p_285506_, K p_285108_, BiConsumer<K, V> p_285007_) {
if (p_285506_.add(p_285108_)) {
p_285183_.get(p_285108_).forEach((p_285443_) -> {
this.visitDependenciesAndElement(p_285183_, p_285506_, p_285443_, p_285007_);
});
V v = this.contents.get(p_285108_);
if (v != null) {
p_285007_.accept(p_285108_, v);
}
}
}
private static <K> boolean isCyclic(Multimap<K, K> p_285132_, K p_285324_, K p_285326_) {
Collection<K> collection = p_285132_.get(p_285326_);
return collection.contains(p_285324_) ? true : collection.stream().anyMatch((p_284974_) -> {
return isCyclic(p_285132_, p_285324_, p_284974_);
});
}
private static <K> void addDependencyIfNotCyclic(Multimap<K, K> p_285047_, K p_285148_, K p_285193_) {
if (!isCyclic(p_285047_, p_285148_, p_285193_)) {
p_285047_.put(p_285148_, p_285193_);
}
}
public void orderByDependencies(BiConsumer<K, V> p_285438_) {
Multimap<K, K> multimap = HashMultimap.create();
this.contents.forEach((p_285415_, p_285018_) -> {
p_285018_.visitRequiredDependencies((p_285287_) -> {
addDependencyIfNotCyclic(multimap, p_285415_, p_285287_);
});
});
this.contents.forEach((p_285462_, p_285526_) -> {
p_285526_.visitOptionalDependencies((p_285513_) -> {
addDependencyIfNotCyclic(multimap, p_285462_, p_285513_);
});
});
Set<K> set = new HashSet<>();
this.contents.keySet().forEach((p_284996_) -> {
this.visitDependenciesAndElement(multimap, set, p_284996_, p_285438_);
});
}
public interface Entry<K> {
void visitRequiredDependencies(Consumer<K> p_285054_);
void visitOptionalDependencies(Consumer<K> p_285150_);
}
}

View File

@@ -0,0 +1,104 @@
package net.minecraft.util;
import com.google.common.base.Charsets;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import net.minecraft.FileUtil;
public class DirectoryLock implements AutoCloseable {
public static final String LOCK_FILE = "session.lock";
private final FileChannel lockFile;
private final FileLock lock;
private static final ByteBuffer DUMMY;
public static DirectoryLock create(Path p_13641_) throws IOException {
Path path = p_13641_.resolve("session.lock");
FileUtil.createDirectoriesSafe(p_13641_);
FileChannel filechannel = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
try {
filechannel.write(DUMMY.duplicate());
filechannel.force(true);
FileLock filelock = filechannel.tryLock();
if (filelock == null) {
throw DirectoryLock.LockException.alreadyLocked(path);
} else {
return new DirectoryLock(filechannel, filelock);
}
} catch (IOException ioexception1) {
try {
filechannel.close();
} catch (IOException ioexception) {
ioexception1.addSuppressed(ioexception);
}
throw ioexception1;
}
}
private DirectoryLock(FileChannel p_13637_, FileLock p_13638_) {
this.lockFile = p_13637_;
this.lock = p_13638_;
}
public void close() throws IOException {
try {
if (this.lock.isValid()) {
this.lock.release();
}
} finally {
if (this.lockFile.isOpen()) {
this.lockFile.close();
}
}
}
public boolean isValid() {
return this.lock.isValid();
}
public static boolean isLocked(Path p_13643_) throws IOException {
Path path = p_13643_.resolve("session.lock");
try {
boolean flag;
try (
FileChannel filechannel = FileChannel.open(path, StandardOpenOption.WRITE);
FileLock filelock = filechannel.tryLock();
) {
flag = filelock == null;
}
return flag;
} catch (AccessDeniedException accessdeniedexception) {
return true;
} catch (NoSuchFileException nosuchfileexception) {
return false;
}
}
static {
byte[] abyte = "\u2603".getBytes(Charsets.UTF_8);
DUMMY = ByteBuffer.allocateDirect(abyte.length);
DUMMY.put(abyte);
DUMMY.flip();
}
public static class LockException extends IOException {
private LockException(Path p_13646_, String p_13647_) {
super(p_13646_.toAbsolutePath() + ": " + p_13647_);
}
public static DirectoryLock.LockException alreadyLocked(Path p_13649_) {
return new DirectoryLock.LockException(p_13649_, "already locked (possibly by other Minecraft instance?)");
}
}
}

View File

@@ -0,0 +1,23 @@
package net.minecraft.util;
import javax.annotation.Nullable;
public class ExceptionCollector<T extends Throwable> {
@Nullable
private T result;
public void add(T p_13654_) {
if (this.result == null) {
this.result = p_13654_;
} else {
this.result.addSuppressed(p_13654_);
}
}
public void throwIfPresent() throws T {
if (this.result != null) {
throw this.result;
}
}
}

View File

@@ -0,0 +1,638 @@
package net.minecraft.util;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Decoder;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.Lifecycle;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.MapLike;
import com.mojang.serialization.RecordBuilder;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.floats.FloatList;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Base64;
import java.util.BitSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Stream;
import net.minecraft.Util;
import net.minecraft.core.HolderSet;
import net.minecraft.core.UUIDUtil;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.apache.commons.lang3.mutable.MutableObject;
import org.joml.AxisAngle4f;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public class ExtraCodecs {
public static final Codec<JsonElement> JSON = Codec.PASSTHROUGH.xmap((p_253507_) -> {
return p_253507_.convert(JsonOps.INSTANCE).getValue();
}, (p_253513_) -> {
return new Dynamic<>(JsonOps.INSTANCE, p_253513_);
});
public static final Codec<Component> COMPONENT = JSON.flatXmap((p_274861_) -> {
try {
return DataResult.success(Component.Serializer.fromJson(p_274861_));
} catch (JsonParseException jsonparseexception) {
return DataResult.error(jsonparseexception::getMessage);
}
}, (p_274859_) -> {
try {
return DataResult.success(Component.Serializer.toJsonTree(p_274859_));
} catch (IllegalArgumentException illegalargumentexception) {
return DataResult.error(illegalargumentexception::getMessage);
}
});
public static final Codec<Component> FLAT_COMPONENT = Codec.STRING.flatXmap((p_277276_) -> {
try {
return DataResult.success(Component.Serializer.fromJson(p_277276_));
} catch (JsonParseException jsonparseexception) {
return DataResult.error(jsonparseexception::getMessage);
}
}, (p_277277_) -> {
try {
return DataResult.success(Component.Serializer.toJson(p_277277_));
} catch (IllegalArgumentException illegalargumentexception) {
return DataResult.error(illegalargumentexception::getMessage);
}
});
public static final Codec<Vector3f> VECTOR3F = Codec.FLOAT.listOf().comapFlatMap((p_253502_) -> {
return Util.fixedSize(p_253502_, 3).map((p_253489_) -> {
return new Vector3f(p_253489_.get(0), p_253489_.get(1), p_253489_.get(2));
});
}, (p_269787_) -> {
return List.of(p_269787_.x(), p_269787_.y(), p_269787_.z());
});
public static final Codec<Quaternionf> QUATERNIONF_COMPONENTS = Codec.FLOAT.listOf().comapFlatMap((p_269773_) -> {
return Util.fixedSize(p_269773_, 4).map((p_269785_) -> {
return new Quaternionf(p_269785_.get(0), p_269785_.get(1), p_269785_.get(2), p_269785_.get(3));
});
}, (p_269780_) -> {
return List.of(p_269780_.x, p_269780_.y, p_269780_.z, p_269780_.w);
});
public static final Codec<AxisAngle4f> AXISANGLE4F = RecordCodecBuilder.create((p_269774_) -> {
return p_269774_.group(Codec.FLOAT.fieldOf("angle").forGetter((p_269776_) -> {
return p_269776_.angle;
}), VECTOR3F.fieldOf("axis").forGetter((p_269778_) -> {
return new Vector3f(p_269778_.x, p_269778_.y, p_269778_.z);
})).apply(p_269774_, AxisAngle4f::new);
});
public static final Codec<Quaternionf> QUATERNIONF = Codec.either(QUATERNIONF_COMPONENTS, AXISANGLE4F.xmap(Quaternionf::new, AxisAngle4f::new)).xmap((p_269779_) -> {
return p_269779_.map((p_269781_) -> {
return p_269781_;
}, (p_269786_) -> {
return p_269786_;
});
}, Either::left);
public static Codec<Matrix4f> MATRIX4F = Codec.FLOAT.listOf().comapFlatMap((p_269788_) -> {
return Util.fixedSize(p_269788_, 16).map((p_269777_) -> {
Matrix4f matrix4f = new Matrix4f();
for(int i = 0; i < p_269777_.size(); ++i) {
matrix4f.setRowColumn(i >> 2, i & 3, p_269777_.get(i));
}
return matrix4f.determineProperties();
});
}, (p_269775_) -> {
FloatList floatlist = new FloatArrayList(16);
for(int i = 0; i < 16; ++i) {
floatlist.add(p_269775_.getRowColumn(i >> 2, i & 3));
}
return floatlist;
});
public static final Codec<Integer> NON_NEGATIVE_INT = intRangeWithMessage(0, Integer.MAX_VALUE, (p_275703_) -> {
return "Value must be non-negative: " + p_275703_;
});
public static final Codec<Integer> POSITIVE_INT = intRangeWithMessage(1, Integer.MAX_VALUE, (p_274847_) -> {
return "Value must be positive: " + p_274847_;
});
public static final Codec<Float> POSITIVE_FLOAT = floatRangeMinExclusiveWithMessage(0.0F, Float.MAX_VALUE, (p_274876_) -> {
return "Value must be positive: " + p_274876_;
});
public static final Codec<Pattern> PATTERN = Codec.STRING.comapFlatMap((p_274857_) -> {
try {
return DataResult.success(Pattern.compile(p_274857_));
} catch (PatternSyntaxException patternsyntaxexception) {
return DataResult.error(() -> {
return "Invalid regex pattern '" + p_274857_ + "': " + patternsyntaxexception.getMessage();
});
}
}, Pattern::pattern);
public static final Codec<Instant> INSTANT_ISO8601 = instantCodec(DateTimeFormatter.ISO_INSTANT);
public static final Codec<byte[]> BASE64_STRING = Codec.STRING.comapFlatMap((p_274852_) -> {
try {
return DataResult.success(Base64.getDecoder().decode(p_274852_));
} catch (IllegalArgumentException illegalargumentexception) {
return DataResult.error(() -> {
return "Malformed base64 string";
});
}
}, (p_216180_) -> {
return Base64.getEncoder().encodeToString(p_216180_);
});
public static final Codec<ExtraCodecs.TagOrElementLocation> TAG_OR_ELEMENT_ID = Codec.STRING.comapFlatMap((p_216169_) -> {
return p_216169_.startsWith("#") ? ResourceLocation.read(p_216169_.substring(1)).map((p_216182_) -> {
return new ExtraCodecs.TagOrElementLocation(p_216182_, true);
}) : ResourceLocation.read(p_216169_).map((p_216165_) -> {
return new ExtraCodecs.TagOrElementLocation(p_216165_, false);
});
}, ExtraCodecs.TagOrElementLocation::decoratedId);
public static final Function<Optional<Long>, OptionalLong> toOptionalLong = (p_216176_) -> {
return p_216176_.map(OptionalLong::of).orElseGet(OptionalLong::empty);
};
public static final Function<OptionalLong, Optional<Long>> fromOptionalLong = (p_216178_) -> {
return p_216178_.isPresent() ? Optional.of(p_216178_.getAsLong()) : Optional.empty();
};
public static final Codec<BitSet> BIT_SET = Codec.LONG_STREAM.xmap((p_253514_) -> {
return BitSet.valueOf(p_253514_.toArray());
}, (p_253493_) -> {
return Arrays.stream(p_253493_.toLongArray());
});
private static final Codec<Property> PROPERTY = RecordCodecBuilder.create((p_253491_) -> {
return p_253491_.group(Codec.STRING.fieldOf("name").forGetter(Property::getName), Codec.STRING.fieldOf("value").forGetter(Property::getValue), Codec.STRING.optionalFieldOf("signature").forGetter((p_253490_) -> {
return Optional.ofNullable(p_253490_.getSignature());
})).apply(p_253491_, (p_253494_, p_253495_, p_253496_) -> {
return new Property(p_253494_, p_253495_, p_253496_.orElse((String)null));
});
});
@VisibleForTesting
public static final Codec<PropertyMap> PROPERTY_MAP = Codec.either(Codec.unboundedMap(Codec.STRING, Codec.STRING.listOf()), PROPERTY.listOf()).xmap((p_253515_) -> {
PropertyMap propertymap = new PropertyMap();
p_253515_.ifLeft((p_253506_) -> {
p_253506_.forEach((p_253500_, p_253501_) -> {
for(String s : p_253501_) {
propertymap.put(p_253500_, new Property(p_253500_, s));
}
});
}).ifRight((p_253509_) -> {
for(Property property : p_253509_) {
propertymap.put(property.getName(), property);
}
});
return propertymap;
}, (p_253504_) -> {
return Either.right(p_253504_.values().stream().toList());
});
public static final Codec<GameProfile> GAME_PROFILE = RecordCodecBuilder.create((p_253497_) -> {
return p_253497_.group(Codec.mapPair(UUIDUtil.AUTHLIB_CODEC.xmap(Optional::of, (p_253517_) -> {
return p_253517_.orElse((UUID)null);
}).optionalFieldOf("id", Optional.empty()), Codec.STRING.xmap(Optional::of, (p_253492_) -> {
return p_253492_.orElse((String)null);
}).optionalFieldOf("name", Optional.empty())).flatXmap(ExtraCodecs::mapIdNameToGameProfile, ExtraCodecs::mapGameProfileToIdName).forGetter(Function.identity()), PROPERTY_MAP.optionalFieldOf("properties", new PropertyMap()).forGetter(GameProfile::getProperties)).apply(p_253497_, (p_253518_, p_253519_) -> {
p_253519_.forEach((p_253511_, p_253512_) -> {
p_253518_.getProperties().put(p_253511_, p_253512_);
});
return p_253518_;
});
});
public static final Codec<String> NON_EMPTY_STRING = validate(Codec.STRING, (p_274858_) -> {
return p_274858_.isEmpty() ? DataResult.error(() -> {
return "Expected non-empty string";
}) : DataResult.success(p_274858_);
});
public static final Codec<Integer> CODEPOINT = Codec.STRING.comapFlatMap((p_284688_) -> {
int[] aint = p_284688_.codePoints().toArray();
return aint.length != 1 ? DataResult.error(() -> {
return "Expected one codepoint, got: " + p_284688_;
}) : DataResult.success(aint[0]);
}, Character::toString);
public static <F, S> Codec<Either<F, S>> xor(Codec<F> p_144640_, Codec<S> p_144641_) {
return new ExtraCodecs.XorCodec<>(p_144640_, p_144641_);
}
public static <P, I> Codec<I> intervalCodec(Codec<P> p_184362_, String p_184363_, String p_184364_, BiFunction<P, P, DataResult<I>> p_184365_, Function<I, P> p_184366_, Function<I, P> p_184367_) {
Codec<I> codec = Codec.list(p_184362_).comapFlatMap((p_184398_) -> {
return Util.fixedSize(p_184398_, 2).flatMap((p_184445_) -> {
P p = p_184445_.get(0);
P p1 = p_184445_.get(1);
return p_184365_.apply(p, p1);
});
}, (p_184459_) -> {
return ImmutableList.of(p_184366_.apply(p_184459_), p_184367_.apply(p_184459_));
});
Codec<I> codec1 = RecordCodecBuilder.<Pair<P,P>>create((p_184360_) -> {
return p_184360_.group(p_184362_.fieldOf(p_184363_).forGetter(Pair::getFirst), p_184362_.fieldOf(p_184364_).forGetter(Pair::getSecond)).apply(p_184360_, Pair::of);
}).comapFlatMap((p_184392_) -> {
return p_184365_.apply((P)p_184392_.getFirst(), (P)p_184392_.getSecond());
}, (p_184449_) -> {
return Pair.of(p_184366_.apply(p_184449_), p_184367_.apply(p_184449_));
});
Codec<I> codec2 = (new ExtraCodecs.EitherCodec<>(codec, codec1)).xmap((p_184355_) -> {
return p_184355_.map((p_184461_) -> {
return p_184461_;
}, (p_184455_) -> {
return p_184455_;
});
}, Either::left);
return Codec.either(p_184362_, codec2).comapFlatMap((p_184389_) -> {
return p_184389_.map((p_184395_) -> {
return p_184365_.apply(p_184395_, p_184395_);
}, DataResult::success);
}, (p_184411_) -> {
P p = p_184366_.apply(p_184411_);
P p1 = p_184367_.apply(p_184411_);
return Objects.equals(p, p1) ? Either.left(p) : Either.right(p_184411_);
});
}
public static <A> Codec.ResultFunction<A> orElsePartial(final A p_184382_) {
return new Codec.ResultFunction<A>() {
public <T> DataResult<Pair<A, T>> apply(DynamicOps<T> p_184466_, T p_184467_, DataResult<Pair<A, T>> p_184468_) {
MutableObject<String> mutableobject = new MutableObject<>();
Optional<Pair<A, T>> optional = p_184468_.resultOrPartial(mutableobject::setValue);
return optional.isPresent() ? p_184468_ : DataResult.error(() -> {
return "(" + (String)mutableobject.getValue() + " -> using default)";
}, Pair.of(p_184382_, p_184467_));
}
public <T> DataResult<T> coApply(DynamicOps<T> p_184470_, A p_184471_, DataResult<T> p_184472_) {
return p_184472_;
}
public String toString() {
return "OrElsePartial[" + p_184382_ + "]";
}
};
}
public static <E> Codec<E> idResolverCodec(ToIntFunction<E> p_184422_, IntFunction<E> p_184423_, int p_184424_) {
return Codec.INT.flatXmap((p_184414_) -> {
return Optional.ofNullable(p_184423_.apply(p_184414_)).map(DataResult::success).orElseGet(() -> {
return DataResult.error(() -> {
return "Unknown element id: " + p_184414_;
});
});
}, (p_274850_) -> {
int i = p_184422_.applyAsInt(p_274850_);
return i == p_184424_ ? DataResult.error(() -> {
return "Element with unknown id: " + p_274850_;
}) : DataResult.success(i);
});
}
public static <E> Codec<E> stringResolverCodec(Function<E, String> p_184406_, Function<String, E> p_184407_) {
return Codec.STRING.flatXmap((p_184404_) -> {
return Optional.ofNullable(p_184407_.apply(p_184404_)).map(DataResult::success).orElseGet(() -> {
return DataResult.error(() -> {
return "Unknown element name:" + p_184404_;
});
});
}, (p_184401_) -> {
return Optional.ofNullable(p_184406_.apply(p_184401_)).map(DataResult::success).orElseGet(() -> {
return DataResult.error(() -> {
return "Element with unknown name: " + p_184401_;
});
});
});
}
public static <E> Codec<E> orCompressed(final Codec<E> p_184426_, final Codec<E> p_184427_) {
return new Codec<E>() {
public <T> DataResult<T> encode(E p_184483_, DynamicOps<T> p_184484_, T p_184485_) {
return p_184484_.compressMaps() ? p_184427_.encode(p_184483_, p_184484_, p_184485_) : p_184426_.encode(p_184483_, p_184484_, p_184485_);
}
public <T> DataResult<Pair<E, T>> decode(DynamicOps<T> p_184480_, T p_184481_) {
return p_184480_.compressMaps() ? p_184427_.decode(p_184480_, p_184481_) : p_184426_.decode(p_184480_, p_184481_);
}
public String toString() {
return p_184426_ + " orCompressed " + p_184427_;
}
};
}
public static <E> Codec<E> overrideLifecycle(Codec<E> p_184369_, final Function<E, Lifecycle> p_184370_, final Function<E, Lifecycle> p_184371_) {
return p_184369_.mapResult(new Codec.ResultFunction<E>() {
public <T> DataResult<Pair<E, T>> apply(DynamicOps<T> p_184497_, T p_184498_, DataResult<Pair<E, T>> p_184499_) {
return p_184499_.result().map((p_184495_) -> {
return p_184499_.setLifecycle(p_184370_.apply(p_184495_.getFirst()));
}).orElse(p_184499_);
}
public <T> DataResult<T> coApply(DynamicOps<T> p_184501_, E p_184502_, DataResult<T> p_184503_) {
return p_184503_.setLifecycle(p_184371_.apply(p_184502_));
}
public String toString() {
return "WithLifecycle[" + p_184370_ + " " + p_184371_ + "]";
}
});
}
public static <T> Codec<T> validate(Codec<T> p_265690_, Function<T, DataResult<T>> p_265223_) {
return p_265690_.flatXmap(p_265223_, p_265223_);
}
public static <T> MapCodec<T> validate(MapCodec<T> p_286613_, Function<T, DataResult<T>> p_286875_) {
return p_286613_.flatXmap(p_286875_, p_286875_);
}
private static Codec<Integer> intRangeWithMessage(int p_144634_, int p_144635_, Function<Integer, String> p_144636_) {
return validate(Codec.INT, (p_274889_) -> {
return p_274889_.compareTo(p_144634_) >= 0 && p_274889_.compareTo(p_144635_) <= 0 ? DataResult.success(p_274889_) : DataResult.error(() -> {
return p_144636_.apply(p_274889_);
});
});
}
public static Codec<Integer> intRange(int p_270883_, int p_270323_) {
return intRangeWithMessage(p_270883_, p_270323_, (p_269784_) -> {
return "Value must be within range [" + p_270883_ + ";" + p_270323_ + "]: " + p_269784_;
});
}
private static Codec<Float> floatRangeMinExclusiveWithMessage(float p_184351_, float p_184352_, Function<Float, String> p_184353_) {
return validate(Codec.FLOAT, (p_274865_) -> {
return p_274865_.compareTo(p_184351_) > 0 && p_274865_.compareTo(p_184352_) <= 0 ? DataResult.success(p_274865_) : DataResult.error(() -> {
return p_184353_.apply(p_274865_);
});
});
}
public static <T> Codec<List<T>> nonEmptyList(Codec<List<T>> p_144638_) {
return validate(p_144638_, (p_274853_) -> {
return p_274853_.isEmpty() ? DataResult.error(() -> {
return "List must have contents";
}) : DataResult.success(p_274853_);
});
}
public static <T> Codec<HolderSet<T>> nonEmptyHolderSet(Codec<HolderSet<T>> p_203983_) {
return validate(p_203983_, (p_274860_) -> {
return p_274860_.unwrap().right().filter(List::isEmpty).isPresent() ? DataResult.error(() -> {
return "List must have contents";
}) : DataResult.success(p_274860_);
});
}
public static <A> Codec<A> lazyInitializedCodec(Supplier<Codec<A>> p_184416_) {
return new ExtraCodecs.LazyInitializedCodec<>(p_184416_);
}
public static <E> MapCodec<E> retrieveContext(final Function<DynamicOps<?>, DataResult<E>> p_203977_) {
class ContextRetrievalCodec extends MapCodec<E> {
public <T> RecordBuilder<T> encode(E p_203993_, DynamicOps<T> p_203994_, RecordBuilder<T> p_203995_) {
return p_203995_;
}
public <T> DataResult<E> decode(DynamicOps<T> p_203990_, MapLike<T> p_203991_) {
return p_203977_.apply(p_203990_);
}
public String toString() {
return "ContextRetrievalCodec[" + p_203977_ + "]";
}
public <T> Stream<T> keys(DynamicOps<T> p_203997_) {
return Stream.empty();
}
}
return new ContextRetrievalCodec();
}
public static <E, L extends Collection<E>, T> Function<L, DataResult<L>> ensureHomogenous(Function<E, T> p_203985_) {
return (p_203980_) -> {
Iterator<E> iterator = p_203980_.iterator();
if (iterator.hasNext()) {
T t = p_203985_.apply(iterator.next());
while(iterator.hasNext()) {
E e = iterator.next();
T t1 = p_203985_.apply(e);
if (t1 != t) {
return DataResult.error(() -> {
return "Mixed type list: element " + e + " had type " + t1 + ", but list is of type " + t;
});
}
}
}
return DataResult.success(p_203980_, Lifecycle.stable());
};
}
public static <A> Codec<A> catchDecoderException(final Codec<A> p_216186_) {
return Codec.of(p_216186_, new Decoder<A>() {
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> p_216193_, T p_216194_) {
try {
return p_216186_.decode(p_216193_, p_216194_);
} catch (Exception exception) {
return DataResult.error(() -> {
return "Caught exception decoding " + p_216194_ + ": " + exception.getMessage();
});
}
}
});
}
public static Codec<Instant> instantCodec(DateTimeFormatter p_216171_) {
return Codec.STRING.comapFlatMap((p_274881_) -> {
try {
return DataResult.success(Instant.from(p_216171_.parse(p_274881_)));
} catch (Exception exception) {
return DataResult.error(exception::getMessage);
}
}, p_216171_::format);
}
public static MapCodec<OptionalLong> asOptionalLong(MapCodec<Optional<Long>> p_216167_) {
return p_216167_.xmap(toOptionalLong, fromOptionalLong);
}
private static DataResult<GameProfile> mapIdNameToGameProfile(Pair<Optional<UUID>, Optional<String>> p_253764_) {
try {
return DataResult.success(new GameProfile(p_253764_.getFirst().orElse((UUID)null), p_253764_.getSecond().orElse((String)null)));
} catch (Throwable throwable) {
return DataResult.error(throwable::getMessage);
}
}
private static DataResult<Pair<Optional<UUID>, Optional<String>>> mapGameProfileToIdName(GameProfile p_254220_) {
return DataResult.success(Pair.of(Optional.ofNullable(p_254220_.getId()), Optional.ofNullable(p_254220_.getName())));
}
public static Codec<String> sizeLimitedString(int p_265773_, int p_265217_) {
return validate(Codec.STRING, (p_274879_) -> {
int i = p_274879_.length();
if (i < p_265773_) {
return DataResult.error(() -> {
return "String \"" + p_274879_ + "\" is too short: " + i + ", expected range [" + p_265773_ + "-" + p_265217_ + "]";
});
} else {
return i > p_265217_ ? DataResult.error(() -> {
return "String \"" + p_274879_ + "\" is too long: " + i + ", expected range [" + p_265773_ + "-" + p_265217_ + "]";
}) : DataResult.success(p_274879_);
}
});
}
public static final class EitherCodec<F, S> implements Codec<Either<F, S>> {
private final Codec<F> first;
private final Codec<S> second;
public EitherCodec(Codec<F> p_184508_, Codec<S> p_184509_) {
this.first = p_184508_;
this.second = p_184509_;
}
public <T> DataResult<Pair<Either<F, S>, T>> decode(DynamicOps<T> p_184530_, T p_184531_) {
DataResult<Pair<Either<F, S>, T>> dataresult = this.first.decode(p_184530_, p_184531_).map((p_184524_) -> {
return p_184524_.mapFirst(Either::left);
});
if (!dataresult.error().isPresent()) {
return dataresult;
} else {
DataResult<Pair<Either<F, S>, T>> dataresult1 = this.second.decode(p_184530_, p_184531_).map((p_184515_) -> {
return p_184515_.mapFirst(Either::right);
});
return !dataresult1.error().isPresent() ? dataresult1 : dataresult.apply2((p_184517_, p_184518_) -> {
return p_184518_;
}, dataresult1);
}
}
public <T> DataResult<T> encode(Either<F, S> p_184511_, DynamicOps<T> p_184512_, T p_184513_) {
return p_184511_.map((p_184528_) -> {
return this.first.encode(p_184528_, p_184512_, p_184513_);
}, (p_184522_) -> {
return this.second.encode(p_184522_, p_184512_, p_184513_);
});
}
public boolean equals(Object p_184537_) {
if (this == p_184537_) {
return true;
} else if (p_184537_ != null && this.getClass() == p_184537_.getClass()) {
ExtraCodecs.EitherCodec<?, ?> eithercodec = (ExtraCodecs.EitherCodec)p_184537_;
return Objects.equals(this.first, eithercodec.first) && Objects.equals(this.second, eithercodec.second);
} else {
return false;
}
}
public int hashCode() {
return Objects.hash(this.first, this.second);
}
public String toString() {
return "EitherCodec[" + this.first + ", " + this.second + "]";
}
}
static record LazyInitializedCodec<A>(Supplier<Codec<A>> delegate) implements Codec<A> {
LazyInitializedCodec {
delegate = Suppliers.memoize(delegate::get);
}
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> p_184545_, T p_184546_) {
return this.delegate.get().decode(p_184545_, p_184546_);
}
public <T> DataResult<T> encode(A p_184548_, DynamicOps<T> p_184549_, T p_184550_) {
return this.delegate.get().encode(p_184548_, p_184549_, p_184550_);
}
}
public static record TagOrElementLocation(ResourceLocation id, boolean tag) {
public String toString() {
return this.decoratedId();
}
private String decoratedId() {
return this.tag ? "#" + this.id : this.id.toString();
}
}
static final class XorCodec<F, S> implements Codec<Either<F, S>> {
private final Codec<F> first;
private final Codec<S> second;
public XorCodec(Codec<F> p_144660_, Codec<S> p_144661_) {
this.first = p_144660_;
this.second = p_144661_;
}
public <T> DataResult<Pair<Either<F, S>, T>> decode(DynamicOps<T> p_144679_, T p_144680_) {
DataResult<Pair<Either<F, S>, T>> dataresult = this.first.decode(p_144679_, p_144680_).map((p_144673_) -> {
return p_144673_.mapFirst(Either::left);
});
DataResult<Pair<Either<F, S>, T>> dataresult1 = this.second.decode(p_144679_, p_144680_).map((p_144667_) -> {
return p_144667_.mapFirst(Either::right);
});
Optional<Pair<Either<F, S>, T>> optional = dataresult.result();
Optional<Pair<Either<F, S>, T>> optional1 = dataresult1.result();
if (optional.isPresent() && optional1.isPresent()) {
return DataResult.error(() -> {
return "Both alternatives read successfully, can not pick the correct one; first: " + optional.get() + " second: " + optional1.get();
}, optional.get());
} else {
return optional.isPresent() ? dataresult : dataresult1;
}
}
public <T> DataResult<T> encode(Either<F, S> p_144663_, DynamicOps<T> p_144664_, T p_144665_) {
return p_144663_.map((p_144677_) -> {
return this.first.encode(p_144677_, p_144664_, p_144665_);
}, (p_144671_) -> {
return this.second.encode(p_144671_, p_144664_, p_144665_);
});
}
public boolean equals(Object p_144686_) {
if (this == p_144686_) {
return true;
} else if (p_144686_ != null && this.getClass() == p_144686_.getClass()) {
ExtraCodecs.XorCodec<?, ?> xorcodec = (ExtraCodecs.XorCodec)p_144686_;
return Objects.equals(this.first, xorcodec.first) && Objects.equals(this.second, xorcodec.second);
} else {
return false;
}
}
public int hashCode() {
return Objects.hash(this.first, this.second);
}
public String toString() {
return "XorCodec[" + this.first + ", " + this.second + "]";
}
}
}

View File

@@ -0,0 +1,95 @@
package net.minecraft.util;
import java.io.IOException;
import java.io.InputStream;
public class FastBufferedInputStream extends InputStream {
private static final int DEFAULT_BUFFER_SIZE = 8192;
private final InputStream in;
private final byte[] buffer;
private int limit;
private int position;
public FastBufferedInputStream(InputStream p_196566_) {
this(p_196566_, 8192);
}
public FastBufferedInputStream(InputStream p_196568_, int p_196569_) {
this.in = p_196568_;
this.buffer = new byte[p_196569_];
}
public int read() throws IOException {
if (this.position >= this.limit) {
this.fill();
if (this.position >= this.limit) {
return -1;
}
}
return Byte.toUnsignedInt(this.buffer[this.position++]);
}
public int read(byte[] p_196576_, int p_196577_, int p_196578_) throws IOException {
int i = this.bytesInBuffer();
if (i <= 0) {
if (p_196578_ >= this.buffer.length) {
return this.in.read(p_196576_, p_196577_, p_196578_);
}
this.fill();
i = this.bytesInBuffer();
if (i <= 0) {
return -1;
}
}
if (p_196578_ > i) {
p_196578_ = i;
}
System.arraycopy(this.buffer, this.position, p_196576_, p_196577_, p_196578_);
this.position += p_196578_;
return p_196578_;
}
public long skip(long p_196580_) throws IOException {
if (p_196580_ <= 0L) {
return 0L;
} else {
long i = (long)this.bytesInBuffer();
if (i <= 0L) {
return this.in.skip(p_196580_);
} else {
if (p_196580_ > i) {
p_196580_ = i;
}
this.position = (int)((long)this.position + p_196580_);
return p_196580_;
}
}
}
public int available() throws IOException {
return this.bytesInBuffer() + this.in.available();
}
public void close() throws IOException {
this.in.close();
}
private int bytesInBuffer() {
return this.limit - this.position;
}
private void fill() throws IOException {
this.limit = 0;
this.position = 0;
int i = this.in.read(this.buffer, 0, this.buffer.length);
if (i > 0) {
this.limit = i;
}
}
}

View File

@@ -0,0 +1,71 @@
package net.minecraft.util;
public class FastColor {
public static class ABGR32 {
public static int alpha(int p_267257_) {
return p_267257_ >>> 24;
}
public static int red(int p_267160_) {
return p_267160_ & 255;
}
public static int green(int p_266784_) {
return p_266784_ >> 8 & 255;
}
public static int blue(int p_267087_) {
return p_267087_ >> 16 & 255;
}
public static int transparent(int p_267248_) {
return p_267248_ & 16777215;
}
public static int opaque(int p_268288_) {
return p_268288_ | -16777216;
}
public static int color(int p_267196_, int p_266895_, int p_266779_, int p_267206_) {
return p_267196_ << 24 | p_266895_ << 16 | p_266779_ << 8 | p_267206_;
}
public static int color(int p_267230_, int p_266708_) {
return p_267230_ << 24 | p_266708_ & 16777215;
}
}
public static class ARGB32 {
public static int alpha(int p_13656_) {
return p_13656_ >>> 24;
}
public static int red(int p_13666_) {
return p_13666_ >> 16 & 255;
}
public static int green(int p_13668_) {
return p_13668_ >> 8 & 255;
}
public static int blue(int p_13670_) {
return p_13670_ & 255;
}
public static int color(int p_13661_, int p_13662_, int p_13663_, int p_13664_) {
return p_13661_ << 24 | p_13662_ << 16 | p_13663_ << 8 | p_13664_;
}
public static int multiply(int p_13658_, int p_13659_) {
return color(alpha(p_13658_) * alpha(p_13659_) / 255, red(p_13658_) * red(p_13659_) / 255, green(p_13658_) * green(p_13659_) / 255, blue(p_13658_) * blue(p_13659_) / 255);
}
public static int lerp(float p_270972_, int p_270081_, int p_270150_) {
int i = Mth.lerpInt(p_270972_, alpha(p_270081_), alpha(p_270150_));
int j = Mth.lerpInt(p_270972_, red(p_270081_), red(p_270150_));
int k = Mth.lerpInt(p_270972_, green(p_270081_), green(p_270150_));
int l = Mth.lerpInt(p_270972_, blue(p_270081_), blue(p_270150_));
return color(i, j, k, l);
}
}
}

View File

@@ -0,0 +1,89 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableMap;
import com.mojang.logging.LogUtils;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.Util;
import org.slf4j.Logger;
public class FileZipper implements Closeable {
private static final Logger LOGGER = LogUtils.getLogger();
private final Path outputFile;
private final Path tempFile;
private final FileSystem fs;
public FileZipper(Path p_144697_) {
this.outputFile = p_144697_;
this.tempFile = p_144697_.resolveSibling(p_144697_.getFileName().toString() + "_tmp");
try {
this.fs = Util.ZIP_FILE_SYSTEM_PROVIDER.newFileSystem(this.tempFile, ImmutableMap.of("create", "true"));
} catch (IOException ioexception) {
throw new UncheckedIOException(ioexception);
}
}
public void add(Path p_144704_, String p_144705_) {
try {
Path path = this.fs.getPath(File.separator);
Path path1 = path.resolve(p_144704_.toString());
Files.createDirectories(path1.getParent());
Files.write(path1, p_144705_.getBytes(StandardCharsets.UTF_8));
} catch (IOException ioexception) {
throw new UncheckedIOException(ioexception);
}
}
public void add(Path p_144701_, File p_144702_) {
try {
Path path = this.fs.getPath(File.separator);
Path path1 = path.resolve(p_144701_.toString());
Files.createDirectories(path1.getParent());
Files.copy(p_144702_.toPath(), path1);
} catch (IOException ioexception) {
throw new UncheckedIOException(ioexception);
}
}
public void add(Path p_144699_) {
try {
Path path = this.fs.getPath(File.separator);
if (Files.isRegularFile(p_144699_)) {
Path path3 = path.resolve(p_144699_.getParent().relativize(p_144699_).toString());
Files.copy(path3, p_144699_);
} else {
try (Stream<Path> stream = Files.find(p_144699_, Integer.MAX_VALUE, (p_144707_, p_144708_) -> {
return p_144708_.isRegularFile();
})) {
for(Path path1 : stream.collect(Collectors.toList())) {
Path path2 = path.resolve(p_144699_.relativize(path1).toString());
Files.createDirectories(path2.getParent());
Files.copy(path1, path2);
}
}
}
} catch (IOException ioexception) {
throw new UncheckedIOException(ioexception);
}
}
public void close() {
try {
this.fs.close();
Files.move(this.tempFile, this.outputFile);
LOGGER.info("Compressed to {}", (Object)this.outputFile);
} catch (IOException ioexception) {
throw new UncheckedIOException(ioexception);
}
}
}

View File

@@ -0,0 +1,99 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableList;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import java.util.List;
import net.minecraft.network.chat.Style;
@FunctionalInterface
public interface FormattedCharSequence {
FormattedCharSequence EMPTY = (p_13704_) -> {
return true;
};
boolean accept(FormattedCharSink p_13732_);
static FormattedCharSequence codepoint(int p_13694_, Style p_13695_) {
return (p_13730_) -> {
return p_13730_.accept(0, p_13695_, p_13694_);
};
}
static FormattedCharSequence forward(String p_13715_, Style p_13716_) {
return p_13715_.isEmpty() ? EMPTY : (p_13739_) -> {
return StringDecomposer.iterate(p_13715_, p_13716_, p_13739_);
};
}
static FormattedCharSequence forward(String p_144718_, Style p_144719_, Int2IntFunction p_144720_) {
return p_144718_.isEmpty() ? EMPTY : (p_144730_) -> {
return StringDecomposer.iterate(p_144718_, p_144719_, decorateOutput(p_144730_, p_144720_));
};
}
static FormattedCharSequence backward(String p_144724_, Style p_144725_) {
return p_144724_.isEmpty() ? EMPTY : (p_144716_) -> {
return StringDecomposer.iterateBackwards(p_144724_, p_144725_, p_144716_);
};
}
static FormattedCharSequence backward(String p_13741_, Style p_13742_, Int2IntFunction p_13743_) {
return p_13741_.isEmpty() ? EMPTY : (p_13721_) -> {
return StringDecomposer.iterateBackwards(p_13741_, p_13742_, decorateOutput(p_13721_, p_13743_));
};
}
static FormattedCharSink decorateOutput(FormattedCharSink p_13706_, Int2IntFunction p_13707_) {
return (p_13711_, p_13712_, p_13713_) -> {
return p_13706_.accept(p_13711_, p_13712_, p_13707_.apply(Integer.valueOf(p_13713_)));
};
}
static FormattedCharSequence composite() {
return EMPTY;
}
static FormattedCharSequence composite(FormattedCharSequence p_144712_) {
return p_144712_;
}
static FormattedCharSequence composite(FormattedCharSequence p_13697_, FormattedCharSequence p_13698_) {
return fromPair(p_13697_, p_13698_);
}
static FormattedCharSequence composite(FormattedCharSequence... p_144722_) {
return fromList(ImmutableList.copyOf(p_144722_));
}
static FormattedCharSequence composite(List<FormattedCharSequence> p_13723_) {
int i = p_13723_.size();
switch (i) {
case 0:
return EMPTY;
case 1:
return p_13723_.get(0);
case 2:
return fromPair(p_13723_.get(0), p_13723_.get(1));
default:
return fromList(ImmutableList.copyOf(p_13723_));
}
}
static FormattedCharSequence fromPair(FormattedCharSequence p_13734_, FormattedCharSequence p_13735_) {
return (p_13702_) -> {
return p_13734_.accept(p_13702_) && p_13735_.accept(p_13702_);
};
}
static FormattedCharSequence fromList(List<FormattedCharSequence> p_13745_) {
return (p_13726_) -> {
for(FormattedCharSequence formattedcharsequence : p_13745_) {
if (!formattedcharsequence.accept(p_13726_)) {
return false;
}
}
return true;
};
}
}

View File

@@ -0,0 +1,8 @@
package net.minecraft.util;
import net.minecraft.network.chat.Style;
@FunctionalInterface
public interface FormattedCharSink {
boolean accept(int p_13746_, Style p_13747_, int p_13748_);
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.util;
public class FrameTimer {
public static final int LOGGING_LENGTH = 240;
private final long[] loggedTimes = new long[240];
private int logStart;
private int logLength;
private int logEnd;
public void logFrameDuration(long p_13756_) {
this.loggedTimes[this.logEnd] = p_13756_;
++this.logEnd;
if (this.logEnd == 240) {
this.logEnd = 0;
}
if (this.logLength < 240) {
this.logStart = 0;
++this.logLength;
} else {
this.logStart = this.wrapIndex(this.logEnd + 1);
}
}
public long getAverageDuration(int p_144733_) {
int i = (this.logStart + p_144733_) % 240;
int j = this.logStart;
long k;
for(k = 0L; j != i; ++j) {
k += this.loggedTimes[j];
}
return k / (long)p_144733_;
}
public int scaleAverageDurationTo(int p_144735_, int p_144736_) {
return this.scaleSampleTo(this.getAverageDuration(p_144735_), p_144736_, 60);
}
public int scaleSampleTo(long p_13758_, int p_13759_, int p_13760_) {
double d0 = (double)p_13758_ / (double)(1000000000L / (long)p_13760_);
return (int)(d0 * (double)p_13759_);
}
public int getLogStart() {
return this.logStart;
}
public int getLogEnd() {
return this.logEnd;
}
public int wrapIndex(int p_13763_) {
return p_13763_ % 240;
}
public long[] getLog() {
return this.loggedTimes;
}
}

View File

@@ -0,0 +1,45 @@
package net.minecraft.util;
import com.mojang.logging.LogUtils;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;
import org.slf4j.Logger;
public class FutureChain implements TaskChainer, AutoCloseable {
private static final Logger LOGGER = LogUtils.getLogger();
private CompletableFuture<?> head = CompletableFuture.completedFuture((Object)null);
private final Executor checkedExecutor;
private volatile boolean closed;
public FutureChain(Executor p_242395_) {
this.checkedExecutor = (p_248283_) -> {
if (!this.closed) {
p_242395_.execute(p_248283_);
}
};
}
public void append(TaskChainer.DelayedTask p_242381_) {
this.head = this.head.thenComposeAsync((p_248281_) -> {
return p_242381_.submit(this.checkedExecutor);
}, this.checkedExecutor).exceptionally((p_242215_) -> {
if (p_242215_ instanceof CompletionException completionexception) {
p_242215_ = completionexception.getCause();
}
if (p_242215_ instanceof CancellationException cancellationexception) {
throw cancellationexception;
} else {
LOGGER.error("Chain link failed, continuing to next one", p_242215_);
return null;
}
});
}
public void close() {
this.closed = true;
}
}

View File

@@ -0,0 +1,32 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
public final class Graph {
private Graph() {
}
public static <T> boolean depthFirstSearch(Map<T, Set<T>> p_184557_, Set<T> p_184558_, Set<T> p_184559_, Consumer<T> p_184560_, T p_184561_) {
if (p_184558_.contains(p_184561_)) {
return false;
} else if (p_184559_.contains(p_184561_)) {
return true;
} else {
p_184559_.add(p_184561_);
for(T t : p_184557_.getOrDefault(p_184561_, ImmutableSet.of())) {
if (depthFirstSearch(p_184557_, p_184558_, p_184559_, p_184560_, t)) {
return true;
}
}
p_184559_.remove(p_184561_);
p_184558_.add(p_184561_);
p_184560_.accept(p_184561_);
return false;
}
}
}

View File

@@ -0,0 +1,585 @@
package net.minecraft.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Contract;
public class GsonHelper {
private static final Gson GSON = (new GsonBuilder()).create();
public static boolean isStringValue(JsonObject p_13814_, String p_13815_) {
return !isValidPrimitive(p_13814_, p_13815_) ? false : p_13814_.getAsJsonPrimitive(p_13815_).isString();
}
public static boolean isStringValue(JsonElement p_13804_) {
return !p_13804_.isJsonPrimitive() ? false : p_13804_.getAsJsonPrimitive().isString();
}
public static boolean isNumberValue(JsonObject p_144763_, String p_144764_) {
return !isValidPrimitive(p_144763_, p_144764_) ? false : p_144763_.getAsJsonPrimitive(p_144764_).isNumber();
}
public static boolean isNumberValue(JsonElement p_13873_) {
return !p_13873_.isJsonPrimitive() ? false : p_13873_.getAsJsonPrimitive().isNumber();
}
public static boolean isBooleanValue(JsonObject p_13881_, String p_13882_) {
return !isValidPrimitive(p_13881_, p_13882_) ? false : p_13881_.getAsJsonPrimitive(p_13882_).isBoolean();
}
public static boolean isBooleanValue(JsonElement p_144768_) {
return !p_144768_.isJsonPrimitive() ? false : p_144768_.getAsJsonPrimitive().isBoolean();
}
public static boolean isArrayNode(JsonObject p_13886_, String p_13887_) {
return !isValidNode(p_13886_, p_13887_) ? false : p_13886_.get(p_13887_).isJsonArray();
}
public static boolean isObjectNode(JsonObject p_144773_, String p_144774_) {
return !isValidNode(p_144773_, p_144774_) ? false : p_144773_.get(p_144774_).isJsonObject();
}
public static boolean isValidPrimitive(JsonObject p_13895_, String p_13896_) {
return !isValidNode(p_13895_, p_13896_) ? false : p_13895_.get(p_13896_).isJsonPrimitive();
}
public static boolean isValidNode(@Nullable JsonObject p_13901_, String p_13902_) {
if (p_13901_ == null) {
return false;
} else {
return p_13901_.get(p_13902_) != null;
}
}
public static JsonElement getNonNull(JsonObject p_289782_, String p_289789_) {
JsonElement jsonelement = p_289782_.get(p_289789_);
if (jsonelement != null && !jsonelement.isJsonNull()) {
return jsonelement;
} else {
throw new JsonSyntaxException("Missing field " + p_289789_);
}
}
public static String convertToString(JsonElement p_13806_, String p_13807_) {
if (p_13806_.isJsonPrimitive()) {
return p_13806_.getAsString();
} else {
throw new JsonSyntaxException("Expected " + p_13807_ + " to be a string, was " + getType(p_13806_));
}
}
public static String getAsString(JsonObject p_13907_, String p_13908_) {
if (p_13907_.has(p_13908_)) {
return convertToString(p_13907_.get(p_13908_), p_13908_);
} else {
throw new JsonSyntaxException("Missing " + p_13908_ + ", expected to find a string");
}
}
@Nullable
@Contract("_,_,!null->!null;_,_,null->_")
public static String getAsString(JsonObject p_13852_, String p_13853_, @Nullable String p_13854_) {
return p_13852_.has(p_13853_) ? convertToString(p_13852_.get(p_13853_), p_13853_) : p_13854_;
}
public static Item convertToItem(JsonElement p_13875_, String p_13876_) {
if (p_13875_.isJsonPrimitive()) {
String s = p_13875_.getAsString();
return BuiltInRegistries.ITEM.getOptional(new ResourceLocation(s)).orElseThrow(() -> {
return new JsonSyntaxException("Expected " + p_13876_ + " to be an item, was unknown string '" + s + "'");
});
} else {
throw new JsonSyntaxException("Expected " + p_13876_ + " to be an item, was " + getType(p_13875_));
}
}
public static Item getAsItem(JsonObject p_13910_, String p_13911_) {
if (p_13910_.has(p_13911_)) {
return convertToItem(p_13910_.get(p_13911_), p_13911_);
} else {
throw new JsonSyntaxException("Missing " + p_13911_ + ", expected to find an item");
}
}
@Nullable
@Contract("_,_,!null->!null;_,_,null->_")
public static Item getAsItem(JsonObject p_144747_, String p_144748_, @Nullable Item p_144749_) {
return p_144747_.has(p_144748_) ? convertToItem(p_144747_.get(p_144748_), p_144748_) : p_144749_;
}
public static boolean convertToBoolean(JsonElement p_13878_, String p_13879_) {
if (p_13878_.isJsonPrimitive()) {
return p_13878_.getAsBoolean();
} else {
throw new JsonSyntaxException("Expected " + p_13879_ + " to be a Boolean, was " + getType(p_13878_));
}
}
public static boolean getAsBoolean(JsonObject p_13913_, String p_13914_) {
if (p_13913_.has(p_13914_)) {
return convertToBoolean(p_13913_.get(p_13914_), p_13914_);
} else {
throw new JsonSyntaxException("Missing " + p_13914_ + ", expected to find a Boolean");
}
}
public static boolean getAsBoolean(JsonObject p_13856_, String p_13857_, boolean p_13858_) {
return p_13856_.has(p_13857_) ? convertToBoolean(p_13856_.get(p_13857_), p_13857_) : p_13858_;
}
public static double convertToDouble(JsonElement p_144770_, String p_144771_) {
if (p_144770_.isJsonPrimitive() && p_144770_.getAsJsonPrimitive().isNumber()) {
return p_144770_.getAsDouble();
} else {
throw new JsonSyntaxException("Expected " + p_144771_ + " to be a Double, was " + getType(p_144770_));
}
}
public static double getAsDouble(JsonObject p_144785_, String p_144786_) {
if (p_144785_.has(p_144786_)) {
return convertToDouble(p_144785_.get(p_144786_), p_144786_);
} else {
throw new JsonSyntaxException("Missing " + p_144786_ + ", expected to find a Double");
}
}
public static double getAsDouble(JsonObject p_144743_, String p_144744_, double p_144745_) {
return p_144743_.has(p_144744_) ? convertToDouble(p_144743_.get(p_144744_), p_144744_) : p_144745_;
}
public static float convertToFloat(JsonElement p_13889_, String p_13890_) {
if (p_13889_.isJsonPrimitive() && p_13889_.getAsJsonPrimitive().isNumber()) {
return p_13889_.getAsFloat();
} else {
throw new JsonSyntaxException("Expected " + p_13890_ + " to be a Float, was " + getType(p_13889_));
}
}
public static float getAsFloat(JsonObject p_13916_, String p_13917_) {
if (p_13916_.has(p_13917_)) {
return convertToFloat(p_13916_.get(p_13917_), p_13917_);
} else {
throw new JsonSyntaxException("Missing " + p_13917_ + ", expected to find a Float");
}
}
public static float getAsFloat(JsonObject p_13821_, String p_13822_, float p_13823_) {
return p_13821_.has(p_13822_) ? convertToFloat(p_13821_.get(p_13822_), p_13822_) : p_13823_;
}
public static long convertToLong(JsonElement p_13892_, String p_13893_) {
if (p_13892_.isJsonPrimitive() && p_13892_.getAsJsonPrimitive().isNumber()) {
return p_13892_.getAsLong();
} else {
throw new JsonSyntaxException("Expected " + p_13893_ + " to be a Long, was " + getType(p_13892_));
}
}
public static long getAsLong(JsonObject p_13922_, String p_13923_) {
if (p_13922_.has(p_13923_)) {
return convertToLong(p_13922_.get(p_13923_), p_13923_);
} else {
throw new JsonSyntaxException("Missing " + p_13923_ + ", expected to find a Long");
}
}
public static long getAsLong(JsonObject p_13829_, String p_13830_, long p_13831_) {
return p_13829_.has(p_13830_) ? convertToLong(p_13829_.get(p_13830_), p_13830_) : p_13831_;
}
public static int convertToInt(JsonElement p_13898_, String p_13899_) {
if (p_13898_.isJsonPrimitive() && p_13898_.getAsJsonPrimitive().isNumber()) {
return p_13898_.getAsInt();
} else {
throw new JsonSyntaxException("Expected " + p_13899_ + " to be a Int, was " + getType(p_13898_));
}
}
public static int getAsInt(JsonObject p_13928_, String p_13929_) {
if (p_13928_.has(p_13929_)) {
return convertToInt(p_13928_.get(p_13929_), p_13929_);
} else {
throw new JsonSyntaxException("Missing " + p_13929_ + ", expected to find a Int");
}
}
public static int getAsInt(JsonObject p_13825_, String p_13826_, int p_13827_) {
return p_13825_.has(p_13826_) ? convertToInt(p_13825_.get(p_13826_), p_13826_) : p_13827_;
}
public static byte convertToByte(JsonElement p_13904_, String p_13905_) {
if (p_13904_.isJsonPrimitive() && p_13904_.getAsJsonPrimitive().isNumber()) {
return p_13904_.getAsByte();
} else {
throw new JsonSyntaxException("Expected " + p_13905_ + " to be a Byte, was " + getType(p_13904_));
}
}
public static byte getAsByte(JsonObject p_144791_, String p_144792_) {
if (p_144791_.has(p_144792_)) {
return convertToByte(p_144791_.get(p_144792_), p_144792_);
} else {
throw new JsonSyntaxException("Missing " + p_144792_ + ", expected to find a Byte");
}
}
public static byte getAsByte(JsonObject p_13817_, String p_13818_, byte p_13819_) {
return p_13817_.has(p_13818_) ? convertToByte(p_13817_.get(p_13818_), p_13818_) : p_13819_;
}
public static char convertToCharacter(JsonElement p_144776_, String p_144777_) {
if (p_144776_.isJsonPrimitive() && p_144776_.getAsJsonPrimitive().isNumber()) {
return p_144776_.getAsCharacter();
} else {
throw new JsonSyntaxException("Expected " + p_144777_ + " to be a Character, was " + getType(p_144776_));
}
}
public static char getAsCharacter(JsonObject p_144794_, String p_144795_) {
if (p_144794_.has(p_144795_)) {
return convertToCharacter(p_144794_.get(p_144795_), p_144795_);
} else {
throw new JsonSyntaxException("Missing " + p_144795_ + ", expected to find a Character");
}
}
public static char getAsCharacter(JsonObject p_144739_, String p_144740_, char p_144741_) {
return p_144739_.has(p_144740_) ? convertToCharacter(p_144739_.get(p_144740_), p_144740_) : p_144741_;
}
public static BigDecimal convertToBigDecimal(JsonElement p_144779_, String p_144780_) {
if (p_144779_.isJsonPrimitive() && p_144779_.getAsJsonPrimitive().isNumber()) {
return p_144779_.getAsBigDecimal();
} else {
throw new JsonSyntaxException("Expected " + p_144780_ + " to be a BigDecimal, was " + getType(p_144779_));
}
}
public static BigDecimal getAsBigDecimal(JsonObject p_144797_, String p_144798_) {
if (p_144797_.has(p_144798_)) {
return convertToBigDecimal(p_144797_.get(p_144798_), p_144798_);
} else {
throw new JsonSyntaxException("Missing " + p_144798_ + ", expected to find a BigDecimal");
}
}
public static BigDecimal getAsBigDecimal(JsonObject p_144751_, String p_144752_, BigDecimal p_144753_) {
return p_144751_.has(p_144752_) ? convertToBigDecimal(p_144751_.get(p_144752_), p_144752_) : p_144753_;
}
public static BigInteger convertToBigInteger(JsonElement p_144782_, String p_144783_) {
if (p_144782_.isJsonPrimitive() && p_144782_.getAsJsonPrimitive().isNumber()) {
return p_144782_.getAsBigInteger();
} else {
throw new JsonSyntaxException("Expected " + p_144783_ + " to be a BigInteger, was " + getType(p_144782_));
}
}
public static BigInteger getAsBigInteger(JsonObject p_144800_, String p_144801_) {
if (p_144800_.has(p_144801_)) {
return convertToBigInteger(p_144800_.get(p_144801_), p_144801_);
} else {
throw new JsonSyntaxException("Missing " + p_144801_ + ", expected to find a BigInteger");
}
}
public static BigInteger getAsBigInteger(JsonObject p_144755_, String p_144756_, BigInteger p_144757_) {
return p_144755_.has(p_144756_) ? convertToBigInteger(p_144755_.get(p_144756_), p_144756_) : p_144757_;
}
public static short convertToShort(JsonElement p_144788_, String p_144789_) {
if (p_144788_.isJsonPrimitive() && p_144788_.getAsJsonPrimitive().isNumber()) {
return p_144788_.getAsShort();
} else {
throw new JsonSyntaxException("Expected " + p_144789_ + " to be a Short, was " + getType(p_144788_));
}
}
public static short getAsShort(JsonObject p_144803_, String p_144804_) {
if (p_144803_.has(p_144804_)) {
return convertToShort(p_144803_.get(p_144804_), p_144804_);
} else {
throw new JsonSyntaxException("Missing " + p_144804_ + ", expected to find a Short");
}
}
public static short getAsShort(JsonObject p_144759_, String p_144760_, short p_144761_) {
return p_144759_.has(p_144760_) ? convertToShort(p_144759_.get(p_144760_), p_144760_) : p_144761_;
}
public static JsonObject convertToJsonObject(JsonElement p_13919_, String p_13920_) {
if (p_13919_.isJsonObject()) {
return p_13919_.getAsJsonObject();
} else {
throw new JsonSyntaxException("Expected " + p_13920_ + " to be a JsonObject, was " + getType(p_13919_));
}
}
public static JsonObject getAsJsonObject(JsonObject p_13931_, String p_13932_) {
if (p_13931_.has(p_13932_)) {
return convertToJsonObject(p_13931_.get(p_13932_), p_13932_);
} else {
throw new JsonSyntaxException("Missing " + p_13932_ + ", expected to find a JsonObject");
}
}
@Nullable
@Contract("_,_,!null->!null;_,_,null->_")
public static JsonObject getAsJsonObject(JsonObject p_13842_, String p_13843_, @Nullable JsonObject p_13844_) {
return p_13842_.has(p_13843_) ? convertToJsonObject(p_13842_.get(p_13843_), p_13843_) : p_13844_;
}
public static JsonArray convertToJsonArray(JsonElement p_13925_, String p_13926_) {
if (p_13925_.isJsonArray()) {
return p_13925_.getAsJsonArray();
} else {
throw new JsonSyntaxException("Expected " + p_13926_ + " to be a JsonArray, was " + getType(p_13925_));
}
}
public static JsonArray getAsJsonArray(JsonObject p_13934_, String p_13935_) {
if (p_13934_.has(p_13935_)) {
return convertToJsonArray(p_13934_.get(p_13935_), p_13935_);
} else {
throw new JsonSyntaxException("Missing " + p_13935_ + ", expected to find a JsonArray");
}
}
@Nullable
@Contract("_,_,!null->!null;_,_,null->_")
public static JsonArray getAsJsonArray(JsonObject p_13833_, String p_13834_, @Nullable JsonArray p_13835_) {
return p_13833_.has(p_13834_) ? convertToJsonArray(p_13833_.get(p_13834_), p_13834_) : p_13835_;
}
public static <T> T convertToObject(@Nullable JsonElement p_13809_, String p_13810_, JsonDeserializationContext p_13811_, Class<? extends T> p_13812_) {
if (p_13809_ != null) {
return p_13811_.deserialize(p_13809_, p_13812_);
} else {
throw new JsonSyntaxException("Missing " + p_13810_);
}
}
public static <T> T getAsObject(JsonObject p_13837_, String p_13838_, JsonDeserializationContext p_13839_, Class<? extends T> p_13840_) {
if (p_13837_.has(p_13838_)) {
return convertToObject(p_13837_.get(p_13838_), p_13838_, p_13839_, p_13840_);
} else {
throw new JsonSyntaxException("Missing " + p_13838_);
}
}
@Nullable
@Contract("_,_,!null,_,_->!null;_,_,null,_,_->_")
public static <T> T getAsObject(JsonObject p_13846_, String p_13847_, @Nullable T p_13848_, JsonDeserializationContext p_13849_, Class<? extends T> p_13850_) {
return (T)(p_13846_.has(p_13847_) ? convertToObject(p_13846_.get(p_13847_), p_13847_, p_13849_, p_13850_) : p_13848_);
}
public static String getType(@Nullable JsonElement p_13884_) {
String s = StringUtils.abbreviateMiddle(String.valueOf((Object)p_13884_), "...", 10);
if (p_13884_ == null) {
return "null (missing)";
} else if (p_13884_.isJsonNull()) {
return "null (json)";
} else if (p_13884_.isJsonArray()) {
return "an array (" + s + ")";
} else if (p_13884_.isJsonObject()) {
return "an object (" + s + ")";
} else {
if (p_13884_.isJsonPrimitive()) {
JsonPrimitive jsonprimitive = p_13884_.getAsJsonPrimitive();
if (jsonprimitive.isNumber()) {
return "a number (" + s + ")";
}
if (jsonprimitive.isBoolean()) {
return "a boolean (" + s + ")";
}
}
return s;
}
}
@Nullable
public static <T> T fromNullableJson(Gson p_13781_, Reader p_13782_, Class<T> p_13783_, boolean p_13784_) {
try {
JsonReader jsonreader = new JsonReader(p_13782_);
jsonreader.setLenient(p_13784_);
return p_13781_.getAdapter(p_13783_).read(jsonreader);
} catch (IOException ioexception) {
throw new JsonParseException(ioexception);
}
}
public static <T> T fromJson(Gson p_263516_, Reader p_263522_, Class<T> p_263539_, boolean p_263489_) {
T t = fromNullableJson(p_263516_, p_263522_, p_263539_, p_263489_);
if (t == null) {
throw new JsonParseException("JSON data was null or empty");
} else {
return t;
}
}
@Nullable
public static <T> T fromNullableJson(Gson p_13772_, Reader p_13773_, TypeToken<T> p_13774_, boolean p_13775_) {
try {
JsonReader jsonreader = new JsonReader(p_13773_);
jsonreader.setLenient(p_13775_);
return p_13772_.getAdapter(p_13774_).read(jsonreader);
} catch (IOException ioexception) {
throw new JsonParseException(ioexception);
}
}
public static <T> T fromJson(Gson p_263499_, Reader p_263527_, TypeToken<T> p_263525_, boolean p_263507_) {
T t = fromNullableJson(p_263499_, p_263527_, p_263525_, p_263507_);
if (t == null) {
throw new JsonParseException("JSON data was null or empty");
} else {
return t;
}
}
@Nullable
public static <T> T fromNullableJson(Gson p_13790_, String p_13791_, TypeToken<T> p_13792_, boolean p_13793_) {
return fromNullableJson(p_13790_, new StringReader(p_13791_), p_13792_, p_13793_);
}
public static <T> T fromJson(Gson p_263492_, String p_263488_, Class<T> p_263503_, boolean p_263506_) {
return fromJson(p_263492_, new StringReader(p_263488_), p_263503_, p_263506_);
}
@Nullable
public static <T> T fromNullableJson(Gson p_13799_, String p_13800_, Class<T> p_13801_, boolean p_13802_) {
return fromNullableJson(p_13799_, new StringReader(p_13800_), p_13801_, p_13802_);
}
public static <T> T fromJson(Gson p_13768_, Reader p_13769_, TypeToken<T> p_13770_) {
return fromJson(p_13768_, p_13769_, p_13770_, false);
}
@Nullable
public static <T> T fromNullableJson(Gson p_13786_, String p_13787_, TypeToken<T> p_13788_) {
return fromNullableJson(p_13786_, p_13787_, p_13788_, false);
}
public static <T> T fromJson(Gson p_13777_, Reader p_13778_, Class<T> p_13779_) {
return fromJson(p_13777_, p_13778_, p_13779_, false);
}
public static <T> T fromJson(Gson p_13795_, String p_13796_, Class<T> p_13797_) {
return fromJson(p_13795_, p_13796_, p_13797_, false);
}
public static JsonObject parse(String p_13870_, boolean p_13871_) {
return parse(new StringReader(p_13870_), p_13871_);
}
public static JsonObject parse(Reader p_13862_, boolean p_13863_) {
return fromJson(GSON, p_13862_, JsonObject.class, p_13863_);
}
public static JsonObject parse(String p_13865_) {
return parse(p_13865_, false);
}
public static JsonObject parse(Reader p_13860_) {
return parse(p_13860_, false);
}
public static JsonArray parseArray(String p_216215_) {
return parseArray(new StringReader(p_216215_));
}
public static JsonArray parseArray(Reader p_144766_) {
return fromJson(GSON, p_144766_, JsonArray.class, false);
}
public static String toStableString(JsonElement p_216217_) {
StringWriter stringwriter = new StringWriter();
JsonWriter jsonwriter = new JsonWriter(stringwriter);
try {
writeValue(jsonwriter, p_216217_, Comparator.naturalOrder());
} catch (IOException ioexception) {
throw new AssertionError(ioexception);
}
return stringwriter.toString();
}
public static void writeValue(JsonWriter p_216208_, @Nullable JsonElement p_216209_, @Nullable Comparator<String> p_216210_) throws IOException {
if (p_216209_ != null && !p_216209_.isJsonNull()) {
if (p_216209_.isJsonPrimitive()) {
JsonPrimitive jsonprimitive = p_216209_.getAsJsonPrimitive();
if (jsonprimitive.isNumber()) {
p_216208_.value(jsonprimitive.getAsNumber());
} else if (jsonprimitive.isBoolean()) {
p_216208_.value(jsonprimitive.getAsBoolean());
} else {
p_216208_.value(jsonprimitive.getAsString());
}
} else if (p_216209_.isJsonArray()) {
p_216208_.beginArray();
for(JsonElement jsonelement : p_216209_.getAsJsonArray()) {
writeValue(p_216208_, jsonelement, p_216210_);
}
p_216208_.endArray();
} else {
if (!p_216209_.isJsonObject()) {
throw new IllegalArgumentException("Couldn't write " + p_216209_.getClass());
}
p_216208_.beginObject();
for(Map.Entry<String, JsonElement> entry : sortByKeyIfNeeded(p_216209_.getAsJsonObject().entrySet(), p_216210_)) {
p_216208_.name(entry.getKey());
writeValue(p_216208_, entry.getValue(), p_216210_);
}
p_216208_.endObject();
}
} else {
p_216208_.nullValue();
}
}
private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> p_216212_, @Nullable Comparator<String> p_216213_) {
if (p_216213_ == null) {
return p_216212_;
} else {
List<Map.Entry<String, JsonElement>> list = new ArrayList<>(p_216212_);
list.sort(Entry.comparingByKey(p_216213_));
return list;
}
}
}

View File

@@ -0,0 +1,174 @@
package net.minecraft.util;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.mojang.logging.LogUtils;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.ServerSocket;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
import net.minecraft.DefaultUncaughtExceptionHandler;
import net.minecraft.network.chat.Component;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
public class HttpUtil {
private static final Logger LOGGER = LogUtils.getLogger();
public static final ListeningExecutorService DOWNLOAD_EXECUTOR = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool((new ThreadFactoryBuilder()).setDaemon(true).setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).setNameFormat("Downloader %d").build()));
private HttpUtil() {
}
public static CompletableFuture<?> downloadTo(File p_216226_, URL p_216227_, Map<String, String> p_216228_, int p_216229_, @Nullable ProgressListener p_216230_, Proxy p_216231_) {
return CompletableFuture.supplyAsync(() -> {
HttpURLConnection httpurlconnection = null;
InputStream inputstream = null;
OutputStream outputstream = null;
if (p_216230_ != null) {
p_216230_.progressStart(Component.translatable("resourcepack.downloading"));
p_216230_.progressStage(Component.translatable("resourcepack.requesting"));
}
try {
try {
byte[] abyte = new byte[4096];
httpurlconnection = (HttpURLConnection)p_216227_.openConnection(p_216231_);
httpurlconnection.setInstanceFollowRedirects(true);
float f1 = 0.0F;
float f = (float)p_216228_.entrySet().size();
for(Map.Entry<String, String> entry : p_216228_.entrySet()) {
httpurlconnection.setRequestProperty(entry.getKey(), entry.getValue());
if (p_216230_ != null) {
p_216230_.progressStagePercentage((int)(++f1 / f * 100.0F));
}
}
inputstream = httpurlconnection.getInputStream();
f = (float)httpurlconnection.getContentLength();
int i = httpurlconnection.getContentLength();
if (p_216230_ != null) {
p_216230_.progressStage(Component.translatable("resourcepack.progress", String.format(Locale.ROOT, "%.2f", f / 1000.0F / 1000.0F)));
}
if (p_216226_.exists()) {
long j = p_216226_.length();
if (j == (long)i) {
if (p_216230_ != null) {
p_216230_.stop();
}
return null;
}
LOGGER.warn("Deleting {} as it does not match what we currently have ({} vs our {}).", p_216226_, i, j);
FileUtils.deleteQuietly(p_216226_);
} else if (p_216226_.getParentFile() != null) {
p_216226_.getParentFile().mkdirs();
}
outputstream = new DataOutputStream(new FileOutputStream(p_216226_));
if (p_216229_ > 0 && f > (float)p_216229_) {
if (p_216230_ != null) {
p_216230_.stop();
}
throw new IOException("Filesize is bigger than maximum allowed (file is " + f1 + ", limit is " + p_216229_ + ")");
}
int k;
while((k = inputstream.read(abyte)) >= 0) {
f1 += (float)k;
if (p_216230_ != null) {
p_216230_.progressStagePercentage((int)(f1 / f * 100.0F));
}
if (p_216229_ > 0 && f1 > (float)p_216229_) {
if (p_216230_ != null) {
p_216230_.stop();
}
throw new IOException("Filesize was bigger than maximum allowed (got >= " + f1 + ", limit was " + p_216229_ + ")");
}
if (Thread.interrupted()) {
LOGGER.error("INTERRUPTED");
if (p_216230_ != null) {
p_216230_.stop();
}
return null;
}
outputstream.write(abyte, 0, k);
}
if (p_216230_ != null) {
p_216230_.stop();
return null;
}
} catch (Throwable throwable) {
LOGGER.error("Failed to download file", throwable);
if (httpurlconnection != null) {
InputStream inputstream1 = httpurlconnection.getErrorStream();
try {
LOGGER.error("HTTP response error: {}", (Object)IOUtils.toString(inputstream1, StandardCharsets.UTF_8));
} catch (IOException ioexception) {
LOGGER.error("Failed to read response from server");
}
}
if (p_216230_ != null) {
p_216230_.stop();
return null;
}
}
return null;
} finally {
IOUtils.closeQuietly(inputstream);
IOUtils.closeQuietly(outputstream);
}
}, DOWNLOAD_EXECUTOR);
}
public static int getAvailablePort() {
try (ServerSocket serversocket = new ServerSocket(0)) {
return serversocket.getLocalPort();
} catch (IOException ioexception) {
return 25564;
}
}
public static boolean isPortAvailable(int p_259872_) {
if (p_259872_ >= 0 && p_259872_ <= 65535) {
try {
boolean flag;
try (ServerSocket serversocket = new ServerSocket(p_259872_)) {
flag = serversocket.getLocalPort() == p_259872_;
}
return flag;
} catch (IOException ioexception) {
return false;
}
} else {
return false;
}
}
}

View File

@@ -0,0 +1,50 @@
package net.minecraft.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
public record InclusiveRange<T extends Comparable<T>>(T minInclusive, T maxInclusive) {
public static final Codec<InclusiveRange<Integer>> INT = codec(Codec.INT);
public InclusiveRange {
if (minInclusive.compareTo(maxInclusive) > 0) {
throw new IllegalArgumentException("min_inclusive must be less than or equal to max_inclusive");
}
}
public static <T extends Comparable<T>> Codec<InclusiveRange<T>> codec(Codec<T> p_184573_) {
return ExtraCodecs.intervalCodec(p_184573_, "min_inclusive", "max_inclusive", InclusiveRange::create, InclusiveRange::minInclusive, InclusiveRange::maxInclusive);
}
public static <T extends Comparable<T>> Codec<InclusiveRange<T>> codec(Codec<T> p_184575_, T p_184576_, T p_184577_) {
return ExtraCodecs.validate(codec(p_184575_), (p_274898_) -> {
if (p_274898_.minInclusive().compareTo(p_184576_) < 0) {
return DataResult.error(() -> {
return "Range limit too low, expected at least " + p_184576_ + " [" + p_274898_.minInclusive() + "-" + p_274898_.maxInclusive() + "]";
});
} else {
return p_274898_.maxInclusive().compareTo(p_184577_) > 0 ? DataResult.error(() -> {
return "Range limit too high, expected at most " + p_184577_ + " [" + p_274898_.minInclusive() + "-" + p_274898_.maxInclusive() + "]";
}) : DataResult.success(p_274898_);
}
});
}
public static <T extends Comparable<T>> DataResult<InclusiveRange<T>> create(T p_184581_, T p_184582_) {
return p_184581_.compareTo(p_184582_) <= 0 ? DataResult.success(new InclusiveRange<>(p_184581_, p_184582_)) : DataResult.error(() -> {
return "min_inclusive must be less than or equal to max_inclusive";
});
}
public boolean isValueInRange(T p_184579_) {
return p_184579_.compareTo(this.minInclusive) >= 0 && p_184579_.compareTo(this.maxInclusive) <= 0;
}
public boolean contains(InclusiveRange<T> p_184571_) {
return p_184571_.minInclusive().compareTo(this.minInclusive) >= 0 && p_184571_.maxInclusive.compareTo(this.maxInclusive) <= 0;
}
public String toString() {
return "[" + this.minInclusive + ", " + this.maxInclusive + "]";
}
}

View File

@@ -0,0 +1,14 @@
package net.minecraft.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
public record KeyDispatchDataCodec<A>(Codec<A> codec) {
public static <A> KeyDispatchDataCodec<A> of(Codec<A> p_216237_) {
return new KeyDispatchDataCodec<>(p_216237_);
}
public static <A> KeyDispatchDataCodec<A> of(MapCodec<A> p_216239_) {
return new KeyDispatchDataCodec<>(p_216239_.codec());
}
}

View File

@@ -0,0 +1,18 @@
package net.minecraft.util;
import com.google.common.base.Suppliers;
import java.util.function.Supplier;
/** @deprecated */
@Deprecated
public class LazyLoadedValue<T> {
private final Supplier<T> factory;
public LazyLoadedValue(Supplier<T> p_13970_) {
this.factory = Suppliers.memoize(p_13970_::get);
}
public T get() {
return this.factory.get();
}
}

View File

@@ -0,0 +1,11 @@
package net.minecraft.util;
public class LinearCongruentialGenerator {
private static final long MULTIPLIER = 6364136223846793005L;
private static final long INCREMENT = 1442695040888963407L;
public static long next(long p_13973_, long p_13974_) {
p_13973_ *= p_13973_ * 6364136223846793005L + 1442695040888963407L;
return p_13973_ + p_13974_;
}
}

View File

@@ -0,0 +1,55 @@
package net.minecraft.util;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import javax.annotation.Nullable;
public class LowerCaseEnumTypeAdapterFactory implements TypeAdapterFactory {
@Nullable
public <T> TypeAdapter<T> create(Gson p_13982_, TypeToken<T> p_13983_) {
Class<T> oclass = (Class<T>)p_13983_.getRawType();
if (!oclass.isEnum()) {
return null;
} else {
final Map<String, T> map = Maps.newHashMap();
for(T t : oclass.getEnumConstants()) {
map.put(this.toLowercase(t), t);
}
return new TypeAdapter<T>() {
public void write(JsonWriter p_13992_, T p_13993_) throws IOException {
if (p_13993_ == null) {
p_13992_.nullValue();
} else {
p_13992_.value(LowerCaseEnumTypeAdapterFactory.this.toLowercase(p_13993_));
}
}
@Nullable
public T read(JsonReader p_13990_) throws IOException {
if (p_13990_.peek() == JsonToken.NULL) {
p_13990_.nextNull();
return (T)null;
} else {
return map.get(p_13990_.nextString());
}
}
};
}
}
String toLowercase(Object p_13980_) {
return p_13980_ instanceof Enum ? ((Enum)p_13980_).name().toLowerCase(Locale.ROOT) : p_13980_.toString().toLowerCase(Locale.ROOT);
}
}

View File

@@ -0,0 +1,16 @@
package net.minecraft.util;
import javax.annotation.Nullable;
public class MemoryReserve {
@Nullable
private static byte[] reserve = null;
public static void allocate() {
reserve = new byte[10485760];
}
public static void release() {
reserve = new byte[0];
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.util;
import java.util.function.Supplier;
import org.apache.commons.lang3.ObjectUtils;
public record ModCheck(ModCheck.Confidence confidence, String description) {
public static ModCheck identify(String p_184601_, Supplier<String> p_184602_, String p_184603_, Class<?> p_184604_) {
String s = p_184602_.get();
if (!p_184601_.equals(s)) {
return new ModCheck(ModCheck.Confidence.DEFINITELY, p_184603_ + " brand changed to '" + s + "'");
} else {
return p_184604_.getSigners() == null ? new ModCheck(ModCheck.Confidence.VERY_LIKELY, p_184603_ + " jar signature invalidated") : new ModCheck(ModCheck.Confidence.PROBABLY_NOT, p_184603_ + " jar signature and brand is untouched");
}
}
public boolean shouldReportAsModified() {
return this.confidence.shouldReportAsModified;
}
public ModCheck merge(ModCheck p_184599_) {
return new ModCheck(ObjectUtils.max(this.confidence, p_184599_.confidence), this.description + "; " + p_184599_.description);
}
public String fullDescription() {
return this.confidence.description + " " + this.description;
}
public static enum Confidence {
PROBABLY_NOT("Probably not.", false),
VERY_LIKELY("Very likely;", true),
DEFINITELY("Definitely;", true);
final String description;
final boolean shouldReportAsModified;
private Confidence(String p_184622_, boolean p_184623_) {
this.description = p_184622_;
this.shouldReportAsModified = p_184623_;
}
}
}

View File

@@ -0,0 +1,648 @@
package net.minecraft.util;
import java.util.Locale;
import java.util.UUID;
import java.util.function.IntPredicate;
import java.util.stream.IntStream;
import net.minecraft.Util;
import net.minecraft.core.Vec3i;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.math.NumberUtils;
public class Mth {
private static final long UUID_VERSION = 61440L;
private static final long UUID_VERSION_TYPE_4 = 16384L;
private static final long UUID_VARIANT = -4611686018427387904L;
private static final long UUID_VARIANT_2 = Long.MIN_VALUE;
public static final float PI = (float)Math.PI;
public static final float HALF_PI = ((float)Math.PI / 2F);
public static final float TWO_PI = ((float)Math.PI * 2F);
public static final float DEG_TO_RAD = ((float)Math.PI / 180F);
public static final float RAD_TO_DEG = (180F / (float)Math.PI);
public static final float EPSILON = 1.0E-5F;
public static final float SQRT_OF_TWO = sqrt(2.0F);
private static final float SIN_SCALE = 10430.378F;
private static final float[] SIN = Util.make(new float[65536], (p_14077_) -> {
for(int i = 0; i < p_14077_.length; ++i) {
p_14077_[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D);
}
});
private static final RandomSource RANDOM = RandomSource.createThreadSafe();
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
private static final double ONE_SIXTH = 0.16666666666666666D;
private static final int FRAC_EXP = 8;
private static final int LUT_SIZE = 257;
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
private static final double[] ASIN_TAB = new double[257];
private static final double[] COS_TAB = new double[257];
public static float sin(float p_14032_) {
return SIN[(int)(p_14032_ * 10430.378F) & '\uffff'];
}
public static float cos(float p_14090_) {
return SIN[(int)(p_14090_ * 10430.378F + 16384.0F) & '\uffff'];
}
public static float sqrt(float p_14117_) {
return (float)Math.sqrt((double)p_14117_);
}
public static int floor(float p_14144_) {
int i = (int)p_14144_;
return p_14144_ < (float)i ? i - 1 : i;
}
public static int floor(double p_14108_) {
int i = (int)p_14108_;
return p_14108_ < (double)i ? i - 1 : i;
}
public static long lfloor(double p_14135_) {
long i = (long)p_14135_;
return p_14135_ < (double)i ? i - 1L : i;
}
public static float abs(float p_14155_) {
return Math.abs(p_14155_);
}
public static int abs(int p_14041_) {
return Math.abs(p_14041_);
}
public static int ceil(float p_14168_) {
int i = (int)p_14168_;
return p_14168_ > (float)i ? i + 1 : i;
}
public static int ceil(double p_14166_) {
int i = (int)p_14166_;
return p_14166_ > (double)i ? i + 1 : i;
}
public static int clamp(int p_14046_, int p_14047_, int p_14048_) {
return Math.min(Math.max(p_14046_, p_14047_), p_14048_);
}
public static float clamp(float p_14037_, float p_14038_, float p_14039_) {
return p_14037_ < p_14038_ ? p_14038_ : Math.min(p_14037_, p_14039_);
}
public static double clamp(double p_14009_, double p_14010_, double p_14011_) {
return p_14009_ < p_14010_ ? p_14010_ : Math.min(p_14009_, p_14011_);
}
public static double clampedLerp(double p_14086_, double p_14087_, double p_14088_) {
if (p_14088_ < 0.0D) {
return p_14086_;
} else {
return p_14088_ > 1.0D ? p_14087_ : lerp(p_14088_, p_14086_, p_14087_);
}
}
public static float clampedLerp(float p_144921_, float p_144922_, float p_144923_) {
if (p_144923_ < 0.0F) {
return p_144921_;
} else {
return p_144923_ > 1.0F ? p_144922_ : lerp(p_144923_, p_144921_, p_144922_);
}
}
public static double absMax(double p_14006_, double p_14007_) {
if (p_14006_ < 0.0D) {
p_14006_ = -p_14006_;
}
if (p_14007_ < 0.0D) {
p_14007_ = -p_14007_;
}
return Math.max(p_14006_, p_14007_);
}
public static int floorDiv(int p_14043_, int p_14044_) {
return Math.floorDiv(p_14043_, p_14044_);
}
public static int nextInt(RandomSource p_216272_, int p_216273_, int p_216274_) {
return p_216273_ >= p_216274_ ? p_216273_ : p_216272_.nextInt(p_216274_ - p_216273_ + 1) + p_216273_;
}
public static float nextFloat(RandomSource p_216268_, float p_216269_, float p_216270_) {
return p_216269_ >= p_216270_ ? p_216269_ : p_216268_.nextFloat() * (p_216270_ - p_216269_) + p_216269_;
}
public static double nextDouble(RandomSource p_216264_, double p_216265_, double p_216266_) {
return p_216265_ >= p_216266_ ? p_216265_ : p_216264_.nextDouble() * (p_216266_ - p_216265_) + p_216265_;
}
public static boolean equal(float p_14034_, float p_14035_) {
return Math.abs(p_14035_ - p_14034_) < 1.0E-5F;
}
public static boolean equal(double p_14083_, double p_14084_) {
return Math.abs(p_14084_ - p_14083_) < (double)1.0E-5F;
}
public static int positiveModulo(int p_14101_, int p_14102_) {
return Math.floorMod(p_14101_, p_14102_);
}
public static float positiveModulo(float p_14092_, float p_14093_) {
return (p_14092_ % p_14093_ + p_14093_) % p_14093_;
}
public static double positiveModulo(double p_14110_, double p_14111_) {
return (p_14110_ % p_14111_ + p_14111_) % p_14111_;
}
public static boolean isMultipleOf(int p_265754_, int p_265543_) {
return p_265754_ % p_265543_ == 0;
}
public static int wrapDegrees(int p_14099_) {
int i = p_14099_ % 360;
if (i >= 180) {
i -= 360;
}
if (i < -180) {
i += 360;
}
return i;
}
public static float wrapDegrees(float p_14178_) {
float f = p_14178_ % 360.0F;
if (f >= 180.0F) {
f -= 360.0F;
}
if (f < -180.0F) {
f += 360.0F;
}
return f;
}
public static double wrapDegrees(double p_14176_) {
double d0 = p_14176_ % 360.0D;
if (d0 >= 180.0D) {
d0 -= 360.0D;
}
if (d0 < -180.0D) {
d0 += 360.0D;
}
return d0;
}
public static float degreesDifference(float p_14119_, float p_14120_) {
return wrapDegrees(p_14120_ - p_14119_);
}
public static float degreesDifferenceAbs(float p_14146_, float p_14147_) {
return abs(degreesDifference(p_14146_, p_14147_));
}
public static float rotateIfNecessary(float p_14095_, float p_14096_, float p_14097_) {
float f = degreesDifference(p_14095_, p_14096_);
float f1 = clamp(f, -p_14097_, p_14097_);
return p_14096_ - f1;
}
public static float approach(float p_14122_, float p_14123_, float p_14124_) {
p_14124_ = abs(p_14124_);
return p_14122_ < p_14123_ ? clamp(p_14122_ + p_14124_, p_14122_, p_14123_) : clamp(p_14122_ - p_14124_, p_14123_, p_14122_);
}
public static float approachDegrees(float p_14149_, float p_14150_, float p_14151_) {
float f = degreesDifference(p_14149_, p_14150_);
return approach(p_14149_, p_14149_ + f, p_14151_);
}
public static int getInt(String p_14060_, int p_14061_) {
return NumberUtils.toInt(p_14060_, p_14061_);
}
public static int smallestEncompassingPowerOfTwo(int p_14126_) {
int i = p_14126_ - 1;
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
return i + 1;
}
public static boolean isPowerOfTwo(int p_14153_) {
return p_14153_ != 0 && (p_14153_ & p_14153_ - 1) == 0;
}
public static int ceillog2(int p_14164_) {
p_14164_ = isPowerOfTwo(p_14164_) ? p_14164_ : smallestEncompassingPowerOfTwo(p_14164_);
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)p_14164_ * 125613361L >> 27) & 31];
}
public static int log2(int p_14174_) {
return ceillog2(p_14174_) - (isPowerOfTwo(p_14174_) ? 0 : 1);
}
public static int color(float p_14160_, float p_14161_, float p_14162_) {
return FastColor.ARGB32.color(0, floor(p_14160_ * 255.0F), floor(p_14161_ * 255.0F), floor(p_14162_ * 255.0F));
}
public static float frac(float p_14188_) {
return p_14188_ - (float)floor(p_14188_);
}
public static double frac(double p_14186_) {
return p_14186_ - (double)lfloor(p_14186_);
}
/** @deprecated */
@Deprecated
public static long getSeed(Vec3i p_14058_) {
return getSeed(p_14058_.getX(), p_14058_.getY(), p_14058_.getZ());
}
/** @deprecated */
@Deprecated
public static long getSeed(int p_14131_, int p_14132_, int p_14133_) {
long i = (long)(p_14131_ * 3129871) ^ (long)p_14133_ * 116129781L ^ (long)p_14132_;
i = i * i * 42317861L + i * 11L;
return i >> 16;
}
public static UUID createInsecureUUID(RandomSource p_216262_) {
long i = p_216262_.nextLong() & -61441L | 16384L;
long j = p_216262_.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
return new UUID(i, j);
}
public static UUID createInsecureUUID() {
return createInsecureUUID(RANDOM);
}
public static double inverseLerp(double p_14113_, double p_14114_, double p_14115_) {
return (p_14113_ - p_14114_) / (p_14115_ - p_14114_);
}
public static float inverseLerp(float p_184656_, float p_184657_, float p_184658_) {
return (p_184656_ - p_184657_) / (p_184658_ - p_184657_);
}
public static boolean rayIntersectsAABB(Vec3 p_144889_, Vec3 p_144890_, AABB p_144891_) {
double d0 = (p_144891_.minX + p_144891_.maxX) * 0.5D;
double d1 = (p_144891_.maxX - p_144891_.minX) * 0.5D;
double d2 = p_144889_.x - d0;
if (Math.abs(d2) > d1 && d2 * p_144890_.x >= 0.0D) {
return false;
} else {
double d3 = (p_144891_.minY + p_144891_.maxY) * 0.5D;
double d4 = (p_144891_.maxY - p_144891_.minY) * 0.5D;
double d5 = p_144889_.y - d3;
if (Math.abs(d5) > d4 && d5 * p_144890_.y >= 0.0D) {
return false;
} else {
double d6 = (p_144891_.minZ + p_144891_.maxZ) * 0.5D;
double d7 = (p_144891_.maxZ - p_144891_.minZ) * 0.5D;
double d8 = p_144889_.z - d6;
if (Math.abs(d8) > d7 && d8 * p_144890_.z >= 0.0D) {
return false;
} else {
double d9 = Math.abs(p_144890_.x);
double d10 = Math.abs(p_144890_.y);
double d11 = Math.abs(p_144890_.z);
double d12 = p_144890_.y * d8 - p_144890_.z * d5;
if (Math.abs(d12) > d4 * d11 + d7 * d10) {
return false;
} else {
d12 = p_144890_.z * d2 - p_144890_.x * d8;
if (Math.abs(d12) > d1 * d11 + d7 * d9) {
return false;
} else {
d12 = p_144890_.x * d5 - p_144890_.y * d2;
return Math.abs(d12) < d1 * d10 + d4 * d9;
}
}
}
}
}
}
public static double atan2(double p_14137_, double p_14138_) {
double d0 = p_14138_ * p_14138_ + p_14137_ * p_14137_;
if (Double.isNaN(d0)) {
return Double.NaN;
} else {
boolean flag = p_14137_ < 0.0D;
if (flag) {
p_14137_ = -p_14137_;
}
boolean flag1 = p_14138_ < 0.0D;
if (flag1) {
p_14138_ = -p_14138_;
}
boolean flag2 = p_14137_ > p_14138_;
if (flag2) {
double d1 = p_14138_;
p_14138_ = p_14137_;
p_14137_ = d1;
}
double d9 = fastInvSqrt(d0);
p_14138_ *= d9;
p_14137_ *= d9;
double d2 = FRAC_BIAS + p_14137_;
int i = (int)Double.doubleToRawLongBits(d2);
double d3 = ASIN_TAB[i];
double d4 = COS_TAB[i];
double d5 = d2 - FRAC_BIAS;
double d6 = p_14137_ * d4 - p_14138_ * d5;
double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D;
double d8 = d3 + d7;
if (flag2) {
d8 = (Math.PI / 2D) - d8;
}
if (flag1) {
d8 = Math.PI - d8;
}
if (flag) {
d8 = -d8;
}
return d8;
}
}
public static float invSqrt(float p_265060_) {
return org.joml.Math.invsqrt(p_265060_);
}
public static double invSqrt(double p_265088_) {
return org.joml.Math.invsqrt(p_265088_);
}
/** @deprecated */
@Deprecated
public static double fastInvSqrt(double p_14194_) {
double d0 = 0.5D * p_14194_;
long i = Double.doubleToRawLongBits(p_14194_);
i = 6910469410427058090L - (i >> 1);
p_14194_ = Double.longBitsToDouble(i);
return p_14194_ * (1.5D - d0 * p_14194_ * p_14194_);
}
public static float fastInvCubeRoot(float p_14200_) {
int i = Float.floatToIntBits(p_14200_);
i = 1419967116 - i / 3;
float f = Float.intBitsToFloat(i);
f = 0.6666667F * f + 1.0F / (3.0F * f * f * p_14200_);
return 0.6666667F * f + 1.0F / (3.0F * f * f * p_14200_);
}
public static int hsvToRgb(float p_14170_, float p_14171_, float p_14172_) {
int i = (int)(p_14170_ * 6.0F) % 6;
float f = p_14170_ * 6.0F - (float)i;
float f1 = p_14172_ * (1.0F - p_14171_);
float f2 = p_14172_ * (1.0F - f * p_14171_);
float f3 = p_14172_ * (1.0F - (1.0F - f) * p_14171_);
float f4;
float f5;
float f6;
switch (i) {
case 0:
f4 = p_14172_;
f5 = f3;
f6 = f1;
break;
case 1:
f4 = f2;
f5 = p_14172_;
f6 = f1;
break;
case 2:
f4 = f1;
f5 = p_14172_;
f6 = f3;
break;
case 3:
f4 = f1;
f5 = f2;
f6 = p_14172_;
break;
case 4:
f4 = f3;
f5 = f1;
f6 = p_14172_;
break;
case 5:
f4 = p_14172_;
f5 = f1;
f6 = f2;
break;
default:
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + p_14170_ + ", " + p_14171_ + ", " + p_14172_);
}
return FastColor.ARGB32.color(0, clamp((int)(f4 * 255.0F), 0, 255), clamp((int)(f5 * 255.0F), 0, 255), clamp((int)(f6 * 255.0F), 0, 255));
}
public static int murmurHash3Mixer(int p_14184_) {
p_14184_ ^= p_14184_ >>> 16;
p_14184_ *= -2048144789;
p_14184_ ^= p_14184_ >>> 13;
p_14184_ *= -1028477387;
return p_14184_ ^ p_14184_ >>> 16;
}
public static int binarySearch(int p_14050_, int p_14051_, IntPredicate p_14052_) {
int i = p_14051_ - p_14050_;
while(i > 0) {
int j = i / 2;
int k = p_14050_ + j;
if (p_14052_.test(k)) {
i = j;
} else {
p_14050_ = k + 1;
i -= j + 1;
}
}
return p_14050_;
}
public static int lerpInt(float p_270245_, int p_270597_, int p_270301_) {
return p_270597_ + floor(p_270245_ * (float)(p_270301_ - p_270597_));
}
public static float lerp(float p_14180_, float p_14181_, float p_14182_) {
return p_14181_ + p_14180_ * (p_14182_ - p_14181_);
}
public static double lerp(double p_14140_, double p_14141_, double p_14142_) {
return p_14141_ + p_14140_ * (p_14142_ - p_14141_);
}
public static double lerp2(double p_14013_, double p_14014_, double p_14015_, double p_14016_, double p_14017_, double p_14018_) {
return lerp(p_14014_, lerp(p_14013_, p_14015_, p_14016_), lerp(p_14013_, p_14017_, p_14018_));
}
public static double lerp3(double p_14020_, double p_14021_, double p_14022_, double p_14023_, double p_14024_, double p_14025_, double p_14026_, double p_14027_, double p_14028_, double p_14029_, double p_14030_) {
return lerp(p_14022_, lerp2(p_14020_, p_14021_, p_14023_, p_14024_, p_14025_, p_14026_), lerp2(p_14020_, p_14021_, p_14027_, p_14028_, p_14029_, p_14030_));
}
public static float catmullrom(float p_216245_, float p_216246_, float p_216247_, float p_216248_, float p_216249_) {
return 0.5F * (2.0F * p_216247_ + (p_216248_ - p_216246_) * p_216245_ + (2.0F * p_216246_ - 5.0F * p_216247_ + 4.0F * p_216248_ - p_216249_) * p_216245_ * p_216245_ + (3.0F * p_216247_ - p_216246_ - 3.0F * p_216248_ + p_216249_) * p_216245_ * p_216245_ * p_216245_);
}
public static double smoothstep(double p_14198_) {
return p_14198_ * p_14198_ * p_14198_ * (p_14198_ * (p_14198_ * 6.0D - 15.0D) + 10.0D);
}
public static double smoothstepDerivative(double p_144947_) {
return 30.0D * p_144947_ * p_144947_ * (p_144947_ - 1.0D) * (p_144947_ - 1.0D);
}
public static int sign(double p_14206_) {
if (p_14206_ == 0.0D) {
return 0;
} else {
return p_14206_ > 0.0D ? 1 : -1;
}
}
public static float rotLerp(float p_14190_, float p_14191_, float p_14192_) {
return p_14191_ + p_14190_ * wrapDegrees(p_14192_ - p_14191_);
}
public static float triangleWave(float p_14157_, float p_14158_) {
return (Math.abs(p_14157_ % p_14158_ - p_14158_ * 0.5F) - p_14158_ * 0.25F) / (p_14158_ * 0.25F);
}
public static float square(float p_14208_) {
return p_14208_ * p_14208_;
}
public static double square(double p_144953_) {
return p_144953_ * p_144953_;
}
public static int square(int p_144945_) {
return p_144945_ * p_144945_;
}
public static long square(long p_184644_) {
return p_184644_ * p_184644_;
}
public static double clampedMap(double p_144852_, double p_144853_, double p_144854_, double p_144855_, double p_144856_) {
return clampedLerp(p_144855_, p_144856_, inverseLerp(p_144852_, p_144853_, p_144854_));
}
public static float clampedMap(float p_184632_, float p_184633_, float p_184634_, float p_184635_, float p_184636_) {
return clampedLerp(p_184635_, p_184636_, inverseLerp(p_184632_, p_184633_, p_184634_));
}
public static double map(double p_144915_, double p_144916_, double p_144917_, double p_144918_, double p_144919_) {
return lerp(inverseLerp(p_144915_, p_144916_, p_144917_), p_144918_, p_144919_);
}
public static float map(float p_184638_, float p_184639_, float p_184640_, float p_184641_, float p_184642_) {
return lerp(inverseLerp(p_184638_, p_184639_, p_184640_), p_184641_, p_184642_);
}
public static double wobble(double p_144955_) {
return p_144955_ + (2.0D * RandomSource.create((long)floor(p_144955_ * 3000.0D)).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
}
public static int roundToward(int p_144942_, int p_144943_) {
return positiveCeilDiv(p_144942_, p_144943_) * p_144943_;
}
public static int positiveCeilDiv(int p_184653_, int p_184654_) {
return -Math.floorDiv(-p_184653_, p_184654_);
}
public static int randomBetweenInclusive(RandomSource p_216288_, int p_216289_, int p_216290_) {
return p_216288_.nextInt(p_216290_ - p_216289_ + 1) + p_216289_;
}
public static float randomBetween(RandomSource p_216284_, float p_216285_, float p_216286_) {
return p_216284_.nextFloat() * (p_216286_ - p_216285_) + p_216285_;
}
public static float normal(RandomSource p_216292_, float p_216293_, float p_216294_) {
return p_216293_ + (float)p_216292_.nextGaussian() * p_216294_;
}
public static double lengthSquared(double p_211590_, double p_211591_) {
return p_211590_ * p_211590_ + p_211591_ * p_211591_;
}
public static double length(double p_184646_, double p_184647_) {
return Math.sqrt(lengthSquared(p_184646_, p_184647_));
}
public static double lengthSquared(double p_211593_, double p_211594_, double p_211595_) {
return p_211593_ * p_211593_ + p_211594_ * p_211594_ + p_211595_ * p_211595_;
}
public static double length(double p_184649_, double p_184650_, double p_184651_) {
return Math.sqrt(lengthSquared(p_184649_, p_184650_, p_184651_));
}
public static int quantize(double p_184629_, int p_184630_) {
return floor(p_184629_ / (double)p_184630_) * p_184630_;
}
public static IntStream outFromOrigin(int p_216296_, int p_216297_, int p_216298_) {
return outFromOrigin(p_216296_, p_216297_, p_216298_, 1);
}
public static IntStream outFromOrigin(int p_216251_, int p_216252_, int p_216253_, int p_216254_) {
if (p_216252_ > p_216253_) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "upperbound %d expected to be > lowerBound %d", p_216253_, p_216252_));
} else if (p_216254_ < 1) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "steps expected to be >= 1, was %d", p_216254_));
} else {
return p_216251_ >= p_216252_ && p_216251_ <= p_216253_ ? IntStream.iterate(p_216251_, (p_216282_) -> {
int i = Math.abs(p_216251_ - p_216282_);
return p_216251_ - i >= p_216252_ || p_216251_ + i <= p_216253_;
}, (p_216260_) -> {
boolean flag = p_216260_ <= p_216251_;
int i = Math.abs(p_216251_ - p_216260_);
boolean flag1 = p_216251_ + i + p_216254_ <= p_216253_;
if (!flag || !flag1) {
int j = p_216251_ - i - (flag ? p_216254_ : 0);
if (j >= p_216252_) {
return j;
}
}
return p_216251_ + i + p_216254_;
}) : IntStream.empty();
}
}
static {
for(int i = 0; i < 257; ++i) {
double d0 = (double)i / 256.0D;
double d1 = Math.asin(d0);
COS_TAB[i] = Math.cos(d1);
ASIN_TAB[i] = d1;
}
}
}

View File

@@ -0,0 +1,167 @@
package net.minecraft.util;
import com.google.common.collect.ImmutableList;
import com.mojang.logging.LogUtils;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.Kernel32Util;
import com.sun.jna.platform.win32.Tlhelp32;
import com.sun.jna.platform.win32.Version;
import com.sun.jna.platform.win32.Win32Exception;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.Collectors;
import net.minecraft.CrashReportCategory;
import org.slf4j.Logger;
public class NativeModuleLister {
private static final Logger LOGGER = LogUtils.getLogger();
private static final int LANG_MASK = 65535;
private static final int DEFAULT_LANG = 1033;
private static final int CODEPAGE_MASK = -65536;
private static final int DEFAULT_CODEPAGE = 78643200;
public static List<NativeModuleLister.NativeModuleInfo> listModules() {
if (!Platform.isWindows()) {
return ImmutableList.of();
} else {
int i = Kernel32.INSTANCE.GetCurrentProcessId();
ImmutableList.Builder<NativeModuleLister.NativeModuleInfo> builder = ImmutableList.builder();
for(Tlhelp32.MODULEENTRY32W moduleentry32w : Kernel32Util.getModules(i)) {
String s = moduleentry32w.szModule();
Optional<NativeModuleLister.NativeModuleVersion> optional = tryGetVersion(moduleentry32w.szExePath());
builder.add(new NativeModuleLister.NativeModuleInfo(s, optional));
}
return builder.build();
}
}
private static Optional<NativeModuleLister.NativeModuleVersion> tryGetVersion(String p_184674_) {
try {
IntByReference intbyreference = new IntByReference();
int i = Version.INSTANCE.GetFileVersionInfoSize(p_184674_, intbyreference);
if (i == 0) {
int i1 = Native.getLastError();
if (i1 != 1813 && i1 != 1812) {
throw new Win32Exception(i1);
} else {
return Optional.empty();
}
} else {
Pointer pointer = new Memory((long)i);
if (!Version.INSTANCE.GetFileVersionInfo(p_184674_, 0, i, pointer)) {
throw new Win32Exception(Native.getLastError());
} else {
IntByReference intbyreference1 = new IntByReference();
Pointer pointer1 = queryVersionValue(pointer, "\\VarFileInfo\\Translation", intbyreference1);
int[] aint = pointer1.getIntArray(0L, intbyreference1.getValue() / 4);
OptionalInt optionalint = findLangAndCodepage(aint);
if (!optionalint.isPresent()) {
return Optional.empty();
} else {
int j = optionalint.getAsInt();
int k = j & '\uffff';
int l = (j & -65536) >> 16;
String s = queryVersionString(pointer, langTableKey("FileDescription", k, l), intbyreference1);
String s1 = queryVersionString(pointer, langTableKey("CompanyName", k, l), intbyreference1);
String s2 = queryVersionString(pointer, langTableKey("FileVersion", k, l), intbyreference1);
return Optional.of(new NativeModuleLister.NativeModuleVersion(s, s2, s1));
}
}
}
} catch (Exception exception) {
LOGGER.info("Failed to find module info for {}", p_184674_, exception);
return Optional.empty();
}
}
private static String langTableKey(String p_184676_, int p_184677_, int p_184678_) {
return String.format(Locale.ROOT, "\\StringFileInfo\\%04x%04x\\%s", p_184677_, p_184678_, p_184676_);
}
private static OptionalInt findLangAndCodepage(int[] p_184682_) {
OptionalInt optionalint = OptionalInt.empty();
for(int i : p_184682_) {
if ((i & -65536) == 78643200 && (i & '\uffff') == 1033) {
return OptionalInt.of(i);
}
optionalint = OptionalInt.of(i);
}
return optionalint;
}
private static Pointer queryVersionValue(Pointer p_184670_, String p_184671_, IntByReference p_184672_) {
PointerByReference pointerbyreference = new PointerByReference();
if (!Version.INSTANCE.VerQueryValue(p_184670_, p_184671_, pointerbyreference, p_184672_)) {
throw new UnsupportedOperationException("Can't get version value " + p_184671_);
} else {
return pointerbyreference.getValue();
}
}
private static String queryVersionString(Pointer p_184687_, String p_184688_, IntByReference p_184689_) {
try {
Pointer pointer = queryVersionValue(p_184687_, p_184688_, p_184689_);
byte[] abyte = pointer.getByteArray(0L, (p_184689_.getValue() - 1) * 2);
return new String(abyte, StandardCharsets.UTF_16LE);
} catch (Exception exception) {
return "";
}
}
public static void addCrashSection(CrashReportCategory p_184680_) {
p_184680_.setDetail("Modules", () -> {
return listModules().stream().sorted(Comparator.comparing((p_184685_) -> {
return p_184685_.name;
})).map((p_184668_) -> {
return "\n\t\t" + p_184668_;
}).collect(Collectors.joining());
});
}
public static class NativeModuleInfo {
public final String name;
public final Optional<NativeModuleLister.NativeModuleVersion> version;
public NativeModuleInfo(String p_184693_, Optional<NativeModuleLister.NativeModuleVersion> p_184694_) {
this.name = p_184693_;
this.version = p_184694_;
}
public String toString() {
return this.version.map((p_184696_) -> {
return this.name + ":" + p_184696_;
}).orElse(this.name);
}
}
public static class NativeModuleVersion {
public final String description;
public final String version;
public final String company;
public NativeModuleVersion(String p_184702_, String p_184703_, String p_184704_) {
this.description = p_184702_;
this.version = p_184703_;
this.company = p_184704_;
}
public String toString() {
return this.description + ":" + this.version + ":" + this.company;
}
}
}

View File

@@ -0,0 +1,13 @@
package net.minecraft.util;
import net.minecraft.network.chat.Component;
public interface OptionEnum {
int getId();
String getKey();
default Component getCaption() {
return Component.translatable(this.getKey());
}
}

View File

@@ -0,0 +1,74 @@
package net.minecraft.util;
import java.util.function.Supplier;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.util.valueproviders.IntProvider;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
public class ParticleUtils {
public static void spawnParticlesOnBlockFaces(Level p_216314_, BlockPos p_216315_, ParticleOptions p_216316_, IntProvider p_216317_) {
for(Direction direction : Direction.values()) {
spawnParticlesOnBlockFace(p_216314_, p_216315_, p_216316_, p_216317_, direction, () -> {
return getRandomSpeedRanges(p_216314_.random);
}, 0.55D);
}
}
public static void spawnParticlesOnBlockFace(Level p_216319_, BlockPos p_216320_, ParticleOptions p_216321_, IntProvider p_216322_, Direction p_216323_, Supplier<Vec3> p_216324_, double p_216325_) {
int i = p_216322_.sample(p_216319_.random);
for(int j = 0; j < i; ++j) {
spawnParticleOnFace(p_216319_, p_216320_, p_216323_, p_216321_, p_216324_.get(), p_216325_);
}
}
private static Vec3 getRandomSpeedRanges(RandomSource p_216303_) {
return new Vec3(Mth.nextDouble(p_216303_, -0.5D, 0.5D), Mth.nextDouble(p_216303_, -0.5D, 0.5D), Mth.nextDouble(p_216303_, -0.5D, 0.5D));
}
public static void spawnParticlesAlongAxis(Direction.Axis p_144968_, Level p_144969_, BlockPos p_144970_, double p_144971_, ParticleOptions p_144972_, UniformInt p_144973_) {
Vec3 vec3 = Vec3.atCenterOf(p_144970_);
boolean flag = p_144968_ == Direction.Axis.X;
boolean flag1 = p_144968_ == Direction.Axis.Y;
boolean flag2 = p_144968_ == Direction.Axis.Z;
int i = p_144973_.sample(p_144969_.random);
for(int j = 0; j < i; ++j) {
double d0 = vec3.x + Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) * (flag ? 0.5D : p_144971_);
double d1 = vec3.y + Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) * (flag1 ? 0.5D : p_144971_);
double d2 = vec3.z + Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) * (flag2 ? 0.5D : p_144971_);
double d3 = flag ? Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) : 0.0D;
double d4 = flag1 ? Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) : 0.0D;
double d5 = flag2 ? Mth.nextDouble(p_144969_.random, -1.0D, 1.0D) : 0.0D;
p_144969_.addParticle(p_144972_, d0, d1, d2, d3, d4, d5);
}
}
public static void spawnParticleOnFace(Level p_216307_, BlockPos p_216308_, Direction p_216309_, ParticleOptions p_216310_, Vec3 p_216311_, double p_216312_) {
Vec3 vec3 = Vec3.atCenterOf(p_216308_);
int i = p_216309_.getStepX();
int j = p_216309_.getStepY();
int k = p_216309_.getStepZ();
double d0 = vec3.x + (i == 0 ? Mth.nextDouble(p_216307_.random, -0.5D, 0.5D) : (double)i * p_216312_);
double d1 = vec3.y + (j == 0 ? Mth.nextDouble(p_216307_.random, -0.5D, 0.5D) : (double)j * p_216312_);
double d2 = vec3.z + (k == 0 ? Mth.nextDouble(p_216307_.random, -0.5D, 0.5D) : (double)k * p_216312_);
double d3 = i == 0 ? p_216311_.x() : 0.0D;
double d4 = j == 0 ? p_216311_.y() : 0.0D;
double d5 = k == 0 ? p_216311_.z() : 0.0D;
p_216307_.addParticle(p_216310_, d0, d1, d2, d3, d4, d5);
}
public static void spawnParticleBelow(Level p_273159_, BlockPos p_273452_, RandomSource p_273538_, ParticleOptions p_273419_) {
double d0 = (double)p_273452_.getX() + p_273538_.nextDouble();
double d1 = (double)p_273452_.getY() - 0.05D;
double d2 = (double)p_273452_.getZ() + p_273538_.nextDouble();
p_273159_.addParticle(p_273419_, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}

View File

@@ -0,0 +1,15 @@
package net.minecraft.util;
import net.minecraft.network.chat.Component;
public interface ProgressListener {
void progressStartNoAbort(Component p_14212_);
void progressStart(Component p_14213_);
void progressStage(Component p_14214_);
void progressStagePercentage(int p_14211_);
void stop();
}

View File

@@ -0,0 +1,75 @@
package net.minecraft.util;
import io.netty.util.internal.ThreadLocalRandom;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.PositionalRandomFactory;
import net.minecraft.world.level.levelgen.RandomSupport;
import net.minecraft.world.level.levelgen.SingleThreadedRandomSource;
import net.minecraft.world.level.levelgen.ThreadSafeLegacyRandomSource;
public interface RandomSource {
/** @deprecated */
@Deprecated
double GAUSSIAN_SPREAD_FACTOR = 2.297D;
static RandomSource create() {
return create(RandomSupport.generateUniqueSeed());
}
/** @deprecated */
@Deprecated
static RandomSource createThreadSafe() {
return new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
}
static RandomSource create(long p_216336_) {
return new LegacyRandomSource(p_216336_);
}
static RandomSource createNewThreadLocalInstance() {
return new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
}
RandomSource fork();
PositionalRandomFactory forkPositional();
void setSeed(long p_216342_);
int nextInt();
int nextInt(int p_216331_);
default int nextIntBetweenInclusive(int p_216333_, int p_216334_) {
return this.nextInt(p_216334_ - p_216333_ + 1) + p_216333_;
}
long nextLong();
boolean nextBoolean();
float nextFloat();
double nextDouble();
double nextGaussian();
default double triangle(double p_216329_, double p_216330_) {
return p_216329_ + p_216330_ * (this.nextDouble() - this.nextDouble());
}
default void consumeCount(int p_216338_) {
for(int i = 0; i < p_216338_; ++i) {
this.nextInt();
}
}
default int nextInt(int p_216340_, int p_216341_) {
if (p_216340_ >= p_216341_) {
throw new IllegalArgumentException("bound - origin is non positive");
} else {
return p_216340_ + this.nextInt(p_216341_ - p_216340_);
}
}
}

View File

@@ -0,0 +1,49 @@
package net.minecraft.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import net.minecraft.resources.ResourceLocation;
public class ResourceLocationPattern {
public static final Codec<ResourceLocationPattern> CODEC = RecordCodecBuilder.create((p_261684_) -> {
return p_261684_.group(ExtraCodecs.PATTERN.optionalFieldOf("namespace").forGetter((p_261529_) -> {
return p_261529_.namespacePattern;
}), ExtraCodecs.PATTERN.optionalFieldOf("path").forGetter((p_261660_) -> {
return p_261660_.pathPattern;
})).apply(p_261684_, ResourceLocationPattern::new);
});
private final Optional<Pattern> namespacePattern;
private final Predicate<String> namespacePredicate;
private final Optional<Pattern> pathPattern;
private final Predicate<String> pathPredicate;
private final Predicate<ResourceLocation> locationPredicate;
private ResourceLocationPattern(Optional<Pattern> p_261800_, Optional<Pattern> p_262131_) {
this.namespacePattern = p_261800_;
this.namespacePredicate = p_261800_.map(Pattern::asPredicate).orElse((p_261999_) -> {
return true;
});
this.pathPattern = p_262131_;
this.pathPredicate = p_262131_.map(Pattern::asPredicate).orElse((p_261815_) -> {
return true;
});
this.locationPredicate = (p_261854_) -> {
return this.namespacePredicate.test(p_261854_.getNamespace()) && this.pathPredicate.test(p_261854_.getPath());
};
}
public Predicate<String> namespacePredicate() {
return this.namespacePredicate;
}
public Predicate<String> pathPredicate() {
return this.pathPredicate;
}
public Predicate<ResourceLocation> locationPredicate() {
return this.locationPredicate;
}
}

View File

@@ -0,0 +1,63 @@
package net.minecraft.util;
import net.minecraft.core.Direction;
public class SegmentedAnglePrecision {
private final int mask;
private final int precision;
private final float degreeToAngle;
private final float angleToDegree;
public SegmentedAnglePrecision(int p_265275_) {
if (p_265275_ < 2) {
throw new IllegalArgumentException("Precision cannot be less than 2 bits");
} else if (p_265275_ > 30) {
throw new IllegalArgumentException("Precision cannot be greater than 30 bits");
} else {
int i = 1 << p_265275_;
this.mask = i - 1;
this.precision = p_265275_;
this.degreeToAngle = (float)i / 360.0F;
this.angleToDegree = 360.0F / (float)i;
}
}
public boolean isSameAxis(int p_265505_, int p_265708_) {
int i = this.getMask() >> 1;
return (p_265505_ & i) == (p_265708_ & i);
}
public int fromDirection(Direction p_265731_) {
if (p_265731_.getAxis().isVertical()) {
return 0;
} else {
int i = p_265731_.get2DDataValue();
return i << this.precision - 2;
}
}
public int fromDegreesWithTurns(float p_265346_) {
return Math.round(p_265346_ * this.degreeToAngle);
}
public int fromDegrees(float p_265688_) {
return this.normalize(this.fromDegreesWithTurns(p_265688_));
}
public float toDegreesWithTurns(int p_265278_) {
return (float)p_265278_ * this.angleToDegree;
}
public float toDegrees(int p_265623_) {
float f = this.toDegreesWithTurns(this.normalize(p_265623_));
return f >= 180.0F ? f - 360.0F : f;
}
public int normalize(int p_265542_) {
return p_265542_ & this.mask;
}
public int getMask() {
return this.mask;
}
}

View File

@@ -0,0 +1,13 @@
package net.minecraft.util;
import java.security.SignatureException;
@FunctionalInterface
public interface SignatureUpdater {
void update(SignatureUpdater.Output p_216345_) throws SignatureException;
@FunctionalInterface
public interface Output {
void update(byte[] p_216347_) throws SignatureException;
}
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.util;
import com.mojang.authlib.yggdrasil.ServicesKeyInfo;
import com.mojang.authlib.yggdrasil.ServicesKeySet;
import com.mojang.authlib.yggdrasil.ServicesKeyType;
import com.mojang.logging.LogUtils;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.util.Collection;
import javax.annotation.Nullable;
import org.slf4j.Logger;
public interface SignatureValidator {
SignatureValidator NO_VALIDATION = (p_216352_, p_216353_) -> {
return true;
};
Logger LOGGER = LogUtils.getLogger();
boolean validate(SignatureUpdater p_216379_, byte[] p_216380_);
default boolean validate(byte[] p_216376_, byte[] p_216377_) {
return this.validate((p_216374_) -> {
p_216374_.update(p_216376_);
}, p_216377_);
}
private static boolean verifySignature(SignatureUpdater p_216355_, byte[] p_216356_, Signature p_216357_) throws SignatureException {
p_216355_.update(p_216357_::update);
return p_216357_.verify(p_216356_);
}
static SignatureValidator from(PublicKey p_216370_, String p_216371_) {
return (p_216367_, p_216368_) -> {
try {
Signature signature = Signature.getInstance(p_216371_);
signature.initVerify(p_216370_);
return verifySignature(p_216367_, p_216368_, signature);
} catch (Exception exception) {
LOGGER.error("Failed to verify signature", (Throwable)exception);
return false;
}
};
}
@Nullable
static SignatureValidator from(ServicesKeySet p_285388_, ServicesKeyType p_285383_) {
Collection<ServicesKeyInfo> collection = p_285388_.keys(p_285383_);
return collection.isEmpty() ? null : (p_284690_, p_284691_) -> {
return collection.stream().anyMatch((p_216361_) -> {
Signature signature = p_216361_.signature();
try {
return verifySignature(p_284690_, p_284691_, signature);
} catch (SignatureException signatureexception) {
LOGGER.error("Failed to verify Services signature", (Throwable)signatureexception);
return false;
}
});
};
}
}

View File

@@ -0,0 +1,31 @@
package net.minecraft.util;
import com.mojang.logging.LogUtils;
import java.security.PrivateKey;
import java.security.Signature;
import org.slf4j.Logger;
public interface Signer {
Logger LOGGER = LogUtils.getLogger();
byte[] sign(SignatureUpdater p_216396_);
default byte[] sign(byte[] p_216391_) {
return this.sign((p_216394_) -> {
p_216394_.update(p_216391_);
});
}
static Signer from(PrivateKey p_216388_, String p_216389_) {
return (p_216386_) -> {
try {
Signature signature = Signature.getInstance(p_216389_);
signature.initSign(p_216388_);
p_216386_.update(signature::update);
return signature.sign();
} catch (Exception exception) {
throw new IllegalStateException("Failed to sign message", exception);
}
};
}
}

View File

@@ -0,0 +1,173 @@
package net.minecraft.util;
import java.util.function.IntConsumer;
import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
public class SimpleBitStorage implements BitStorage {
private static final int[] MAGIC = new int[]{-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE, 0, 5};
private final long[] data;
private final int bits;
private final long mask;
private final int size;
private final int valuesPerLong;
private final int divideMul;
private final int divideAdd;
private final int divideShift;
public SimpleBitStorage(int p_198164_, int p_198165_, int[] p_198166_) {
this(p_198164_, p_198165_);
int j = 0;
int i;
for(i = 0; i <= p_198165_ - this.valuesPerLong; i += this.valuesPerLong) {
long k = 0L;
for(int i1 = this.valuesPerLong - 1; i1 >= 0; --i1) {
k <<= p_198164_;
k |= (long)p_198166_[i + i1] & this.mask;
}
this.data[j++] = k;
}
int k1 = p_198165_ - i;
if (k1 > 0) {
long l = 0L;
for(int j1 = k1 - 1; j1 >= 0; --j1) {
l <<= p_198164_;
l |= (long)p_198166_[i + j1] & this.mask;
}
this.data[j] = l;
}
}
public SimpleBitStorage(int p_184717_, int p_184718_) {
this(p_184717_, p_184718_, (long[])null);
}
public SimpleBitStorage(int p_184724_, int p_184725_, @Nullable long[] p_184726_) {
Validate.inclusiveBetween(1L, 32L, (long)p_184724_);
this.size = p_184725_;
this.bits = p_184724_;
this.mask = (1L << p_184724_) - 1L;
this.valuesPerLong = (char)(64 / p_184724_);
int i = 3 * (this.valuesPerLong - 1);
this.divideMul = MAGIC[i + 0];
this.divideAdd = MAGIC[i + 1];
this.divideShift = MAGIC[i + 2];
int j = (p_184725_ + this.valuesPerLong - 1) / this.valuesPerLong;
if (p_184726_ != null) {
if (p_184726_.length != j) {
throw new SimpleBitStorage.InitializationException("Invalid length given for storage, got: " + p_184726_.length + " but expected: " + j);
}
this.data = p_184726_;
} else {
this.data = new long[j];
}
}
private int cellIndex(int p_184740_) {
long i = Integer.toUnsignedLong(this.divideMul);
long j = Integer.toUnsignedLong(this.divideAdd);
return (int)((long)p_184740_ * i + j >> 32 >> this.divideShift);
}
public int getAndSet(int p_184731_, int p_184732_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184731_);
Validate.inclusiveBetween(0L, this.mask, (long)p_184732_);
int i = this.cellIndex(p_184731_);
long j = this.data[i];
int k = (p_184731_ - i * this.valuesPerLong) * this.bits;
int l = (int)(j >> k & this.mask);
this.data[i] = j & ~(this.mask << k) | ((long)p_184732_ & this.mask) << k;
return l;
}
public void set(int p_184742_, int p_184743_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184742_);
Validate.inclusiveBetween(0L, this.mask, (long)p_184743_);
int i = this.cellIndex(p_184742_);
long j = this.data[i];
int k = (p_184742_ - i * this.valuesPerLong) * this.bits;
this.data[i] = j & ~(this.mask << k) | ((long)p_184743_ & this.mask) << k;
}
public int get(int p_184729_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184729_);
int i = this.cellIndex(p_184729_);
long j = this.data[i];
int k = (p_184729_ - i * this.valuesPerLong) * this.bits;
return (int)(j >> k & this.mask);
}
public long[] getRaw() {
return this.data;
}
public int getSize() {
return this.size;
}
public int getBits() {
return this.bits;
}
public void getAll(IntConsumer p_184734_) {
int i = 0;
for(long j : this.data) {
for(int k = 0; k < this.valuesPerLong; ++k) {
p_184734_.accept((int)(j & this.mask));
j >>= this.bits;
++i;
if (i >= this.size) {
return;
}
}
}
}
public void unpack(int[] p_198168_) {
int i = this.data.length;
int j = 0;
for(int k = 0; k < i - 1; ++k) {
long l = this.data[k];
for(int i1 = 0; i1 < this.valuesPerLong; ++i1) {
p_198168_[j + i1] = (int)(l & this.mask);
l >>= this.bits;
}
j += this.valuesPerLong;
}
int j1 = this.size - j;
if (j1 > 0) {
long k1 = this.data[i - 1];
for(int l1 = 0; l1 < j1; ++l1) {
p_198168_[j + l1] = (int)(k1 & this.mask);
k1 >>= this.bits;
}
}
}
public BitStorage copy() {
return new SimpleBitStorage(this.bits, this.size, (long[])this.data.clone());
}
public static class InitializationException extends RuntimeException {
InitializationException(String p_184746_) {
super(p_184746_);
}
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.util;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
public class SingleKeyCache<K, V> {
private final Function<K, V> computeValue;
@Nullable
private K cacheKey = (K)null;
@Nullable
private V cachedValue;
public SingleKeyCache(Function<K, V> p_270132_) {
this.computeValue = p_270132_;
}
public V getValue(K p_270953_) {
if (this.cachedValue == null || !Objects.equals(this.cacheKey, p_270953_)) {
this.cachedValue = this.computeValue.apply(p_270953_);
this.cacheKey = p_270953_;
}
return this.cachedValue;
}
}

View File

@@ -0,0 +1,27 @@
package net.minecraft.util;
public class SmoothDouble {
private double targetValue;
private double remainingValue;
private double lastAmount;
public double getNewDeltaValue(double p_14238_, double p_14239_) {
this.targetValue += p_14238_;
double d0 = this.targetValue - this.remainingValue;
double d1 = Mth.lerp(0.5D, this.lastAmount, d0);
double d2 = Math.signum(d0);
if (d2 * d0 > d2 * this.lastAmount) {
d0 = d1;
}
this.lastAmount = d1;
this.remainingValue += d0 * p_14239_;
return d0 * p_14239_;
}
public void reset() {
this.targetValue = 0.0D;
this.remainingValue = 0.0D;
this.lastAmount = 0.0D;
}
}

View File

@@ -0,0 +1,213 @@
package net.minecraft.util;
import it.unimi.dsi.fastutil.objects.ObjectArrays;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
public class SortedArraySet<T> extends AbstractSet<T> {
private static final int DEFAULT_INITIAL_CAPACITY = 10;
private final Comparator<T> comparator;
T[] contents;
int size;
private SortedArraySet(int p_14244_, Comparator<T> p_14245_) {
this.comparator = p_14245_;
if (p_14244_ < 0) {
throw new IllegalArgumentException("Initial capacity (" + p_14244_ + ") is negative");
} else {
this.contents = (T[])castRawArray(new Object[p_14244_]);
}
}
public static <T extends Comparable<T>> SortedArraySet<T> create() {
return create(10);
}
public static <T extends Comparable<T>> SortedArraySet<T> create(int p_14247_) {
return new SortedArraySet<>(p_14247_, Comparator.<T>naturalOrder());
}
public static <T> SortedArraySet<T> create(Comparator<T> p_144977_) {
return create(p_144977_, 10);
}
public static <T> SortedArraySet<T> create(Comparator<T> p_144979_, int p_144980_) {
return new SortedArraySet<>(p_144980_, p_144979_);
}
private static <T> T[] castRawArray(Object[] p_14259_) {
return (T[])p_14259_;
}
private int findIndex(T p_14270_) {
return Arrays.binarySearch(this.contents, 0, this.size, p_14270_, this.comparator);
}
private static int getInsertionPosition(int p_14264_) {
return -p_14264_ - 1;
}
public boolean add(T p_14261_) {
int i = this.findIndex(p_14261_);
if (i >= 0) {
return false;
} else {
int j = getInsertionPosition(i);
this.addInternal(p_14261_, j);
return true;
}
}
private void grow(int p_14268_) {
if (p_14268_ > this.contents.length) {
if (this.contents != ObjectArrays.DEFAULT_EMPTY_ARRAY) {
p_14268_ = (int)Math.max(Math.min((long)this.contents.length + (long)(this.contents.length >> 1), 2147483639L), (long)p_14268_);
} else if (p_14268_ < 10) {
p_14268_ = 10;
}
Object[] aobject = new Object[p_14268_];
System.arraycopy(this.contents, 0, aobject, 0, this.size);
this.contents = (T[])castRawArray(aobject);
}
}
private void addInternal(T p_14256_, int p_14257_) {
this.grow(this.size + 1);
if (p_14257_ != this.size) {
System.arraycopy(this.contents, p_14257_, this.contents, p_14257_ + 1, this.size - p_14257_);
}
this.contents[p_14257_] = p_14256_;
++this.size;
}
void removeInternal(int p_14275_) {
--this.size;
if (p_14275_ != this.size) {
System.arraycopy(this.contents, p_14275_ + 1, this.contents, p_14275_, this.size - p_14275_);
}
this.contents[this.size] = null;
}
private T getInternal(int p_14277_) {
return this.contents[p_14277_];
}
public T addOrGet(T p_14254_) {
int i = this.findIndex(p_14254_);
if (i >= 0) {
return this.getInternal(i);
} else {
this.addInternal(p_14254_, getInsertionPosition(i));
return p_14254_;
}
}
public boolean remove(Object p_14282_) {
int i = this.findIndex((T)p_14282_);
if (i >= 0) {
this.removeInternal(i);
return true;
} else {
return false;
}
}
@Nullable
public T get(T p_144982_) {
int i = this.findIndex(p_144982_);
return (T)(i >= 0 ? this.getInternal(i) : null);
}
public T first() {
return this.getInternal(0);
}
public T last() {
return this.getInternal(this.size - 1);
}
public boolean contains(Object p_14273_) {
int i = this.findIndex((T)p_14273_);
return i >= 0;
}
public Iterator<T> iterator() {
return new SortedArraySet.ArrayIterator();
}
public int size() {
return this.size;
}
public Object[] toArray() {
return Arrays.copyOf(this.contents, this.size, Object[].class);
}
public <U> U[] toArray(U[] p_14286_) {
if (p_14286_.length < this.size) {
return (U[])Arrays.copyOf(this.contents, this.size, p_14286_.getClass());
} else {
System.arraycopy(this.contents, 0, p_14286_, 0, this.size);
if (p_14286_.length > this.size) {
p_14286_[this.size] = null;
}
return p_14286_;
}
}
public void clear() {
Arrays.fill(this.contents, 0, this.size, (Object)null);
this.size = 0;
}
public boolean equals(Object p_14279_) {
if (this == p_14279_) {
return true;
} else {
if (p_14279_ instanceof SortedArraySet) {
SortedArraySet<?> sortedarrayset = (SortedArraySet)p_14279_;
if (this.comparator.equals(sortedarrayset.comparator)) {
return this.size == sortedarrayset.size && Arrays.equals(this.contents, sortedarrayset.contents);
}
}
return super.equals(p_14279_);
}
}
class ArrayIterator implements Iterator<T> {
private int index;
private int last = -1;
public boolean hasNext() {
return this.index < SortedArraySet.this.size;
}
public T next() {
if (this.index >= SortedArraySet.this.size) {
throw new NoSuchElementException();
} else {
this.last = this.index++;
return SortedArraySet.this.contents[this.last];
}
}
public void remove() {
if (this.last == -1) {
throw new IllegalStateException();
} else {
SortedArraySet.this.removeInternal(this.last);
--this.index;
this.last = -1;
}
}
}
}

View File

@@ -0,0 +1,78 @@
package net.minecraft.util;
import java.util.Optional;
import java.util.function.Consumer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.StainedGlassBlock;
import net.minecraft.world.level.block.StainedGlassPaneBlock;
import net.minecraft.world.level.block.state.BlockState;
public class SpawnUtil {
public static <T extends Mob> Optional<T> trySpawnMob(EntityType<T> p_216404_, MobSpawnType p_216405_, ServerLevel p_216406_, BlockPos p_216407_, int p_216408_, int p_216409_, int p_216410_, SpawnUtil.Strategy p_216411_) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = p_216407_.mutable();
for(int i = 0; i < p_216408_; ++i) {
int j = Mth.randomBetweenInclusive(p_216406_.random, -p_216409_, p_216409_);
int k = Mth.randomBetweenInclusive(p_216406_.random, -p_216409_, p_216409_);
blockpos$mutableblockpos.setWithOffset(p_216407_, j, p_216410_, k);
if (p_216406_.getWorldBorder().isWithinBounds(blockpos$mutableblockpos) && moveToPossibleSpawnPosition(p_216406_, p_216410_, blockpos$mutableblockpos, p_216411_)) {
T t = p_216404_.create(p_216406_, (CompoundTag)null, (Consumer<T>)null, blockpos$mutableblockpos, p_216405_, false, false);
if (t != null) {
if (net.minecraftforge.event.ForgeEventFactory.checkSpawnPosition(t, p_216406_, p_216405_)) {
p_216406_.addFreshEntityWithPassengers(t);
return Optional.of(t);
}
t.discard();
}
}
}
return Optional.empty();
}
private static boolean moveToPossibleSpawnPosition(ServerLevel p_216399_, int p_216400_, BlockPos.MutableBlockPos p_216401_, SpawnUtil.Strategy p_216402_) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = (new BlockPos.MutableBlockPos()).set(p_216401_);
BlockState blockstate = p_216399_.getBlockState(blockpos$mutableblockpos);
for(int i = p_216400_; i >= -p_216400_; --i) {
p_216401_.move(Direction.DOWN);
blockpos$mutableblockpos.setWithOffset(p_216401_, Direction.UP);
BlockState blockstate1 = p_216399_.getBlockState(p_216401_);
if (p_216402_.canSpawnOn(p_216399_, p_216401_, blockstate1, blockpos$mutableblockpos, blockstate)) {
p_216401_.move(Direction.UP);
return true;
}
blockstate = blockstate1;
}
return false;
}
public interface Strategy {
/** @deprecated */
@Deprecated
SpawnUtil.Strategy LEGACY_IRON_GOLEM = (p_289751_, p_289752_, p_289753_, p_289754_, p_289755_) -> {
if (!p_289753_.is(Blocks.COBWEB) && !p_289753_.is(Blocks.CACTUS) && !p_289753_.is(Blocks.GLASS_PANE) && !(p_289753_.getBlock() instanceof StainedGlassPaneBlock) && !(p_289753_.getBlock() instanceof StainedGlassBlock) && !(p_289753_.getBlock() instanceof LeavesBlock) && !p_289753_.is(Blocks.CONDUIT) && !p_289753_.is(Blocks.ICE) && !p_289753_.is(Blocks.TNT) && !p_289753_.is(Blocks.GLOWSTONE) && !p_289753_.is(Blocks.BEACON) && !p_289753_.is(Blocks.SEA_LANTERN) && !p_289753_.is(Blocks.FROSTED_ICE) && !p_289753_.is(Blocks.TINTED_GLASS) && !p_289753_.is(Blocks.GLASS)) {
return (p_289755_.isAir() || p_289755_.liquid()) && (p_289753_.isSolid() || p_289753_.is(Blocks.POWDER_SNOW));
} else {
return false;
}
};
SpawnUtil.Strategy ON_TOP_OF_COLLIDER = (p_216416_, p_216417_, p_216418_, p_216419_, p_216420_) -> {
return p_216420_.getCollisionShape(p_216416_, p_216419_).isEmpty() && Block.isFaceFull(p_216418_.getCollisionShape(p_216416_, p_216417_), Direction.UP);
};
boolean canSpawnOn(ServerLevel p_216428_, BlockPos p_216429_, BlockState p_216430_, BlockPos p_216431_, BlockState p_216432_);
}
}

View File

@@ -0,0 +1,152 @@
package net.minecraft.util;
import java.util.Optional;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.Style;
public class StringDecomposer {
private static final char REPLACEMENT_CHAR = '\ufffd';
private static final Optional<Object> STOP_ITERATION = Optional.of(Unit.INSTANCE);
private static boolean feedChar(Style p_14333_, FormattedCharSink p_14334_, int p_14335_, char p_14336_) {
return Character.isSurrogate(p_14336_) ? p_14334_.accept(p_14335_, p_14333_, 65533) : p_14334_.accept(p_14335_, p_14333_, p_14336_);
}
public static boolean iterate(String p_14318_, Style p_14319_, FormattedCharSink p_14320_) {
int i = p_14318_.length();
for(int j = 0; j < i; ++j) {
char c0 = p_14318_.charAt(j);
if (Character.isHighSurrogate(c0)) {
if (j + 1 >= i) {
if (!p_14320_.accept(j, p_14319_, 65533)) {
return false;
}
break;
}
char c1 = p_14318_.charAt(j + 1);
if (Character.isLowSurrogate(c1)) {
if (!p_14320_.accept(j, p_14319_, Character.toCodePoint(c0, c1))) {
return false;
}
++j;
} else if (!p_14320_.accept(j, p_14319_, 65533)) {
return false;
}
} else if (!feedChar(p_14319_, p_14320_, j, c0)) {
return false;
}
}
return true;
}
public static boolean iterateBackwards(String p_14338_, Style p_14339_, FormattedCharSink p_14340_) {
int i = p_14338_.length();
for(int j = i - 1; j >= 0; --j) {
char c0 = p_14338_.charAt(j);
if (Character.isLowSurrogate(c0)) {
if (j - 1 < 0) {
if (!p_14340_.accept(0, p_14339_, 65533)) {
return false;
}
break;
}
char c1 = p_14338_.charAt(j - 1);
if (Character.isHighSurrogate(c1)) {
--j;
if (!p_14340_.accept(j, p_14339_, Character.toCodePoint(c1, c0))) {
return false;
}
} else if (!p_14340_.accept(j, p_14339_, 65533)) {
return false;
}
} else if (!feedChar(p_14339_, p_14340_, j, c0)) {
return false;
}
}
return true;
}
public static boolean iterateFormatted(String p_14347_, Style p_14348_, FormattedCharSink p_14349_) {
return iterateFormatted(p_14347_, 0, p_14348_, p_14349_);
}
public static boolean iterateFormatted(String p_14307_, int p_14308_, Style p_14309_, FormattedCharSink p_14310_) {
return iterateFormatted(p_14307_, p_14308_, p_14309_, p_14309_, p_14310_);
}
public static boolean iterateFormatted(String p_14312_, int p_14313_, Style p_14314_, Style p_14315_, FormattedCharSink p_14316_) {
int i = p_14312_.length();
Style style = p_14314_;
for(int j = p_14313_; j < i; ++j) {
char c0 = p_14312_.charAt(j);
if (c0 == 167) {
if (j + 1 >= i) {
break;
}
char c1 = p_14312_.charAt(j + 1);
ChatFormatting chatformatting = ChatFormatting.getByCode(c1);
if (chatformatting != null) {
style = chatformatting == ChatFormatting.RESET ? p_14315_ : style.applyLegacyFormat(chatformatting);
}
++j;
} else if (Character.isHighSurrogate(c0)) {
if (j + 1 >= i) {
if (!p_14316_.accept(j, style, 65533)) {
return false;
}
break;
}
char c2 = p_14312_.charAt(j + 1);
if (Character.isLowSurrogate(c2)) {
if (!p_14316_.accept(j, style, Character.toCodePoint(c0, c2))) {
return false;
}
++j;
} else if (!p_14316_.accept(j, style, 65533)) {
return false;
}
} else if (!feedChar(style, p_14316_, j, c0)) {
return false;
}
}
return true;
}
public static boolean iterateFormatted(FormattedText p_14329_, Style p_14330_, FormattedCharSink p_14331_) {
return !p_14329_.visit((p_14302_, p_14303_) -> {
return iterateFormatted(p_14303_, 0, p_14302_, p_14331_) ? Optional.empty() : STOP_ITERATION;
}, p_14330_).isPresent();
}
public static String filterBrokenSurrogates(String p_14305_) {
StringBuilder stringbuilder = new StringBuilder();
iterate(p_14305_, Style.EMPTY, (p_14343_, p_14344_, p_14345_) -> {
stringbuilder.appendCodePoint(p_14345_);
return true;
});
return stringbuilder.toString();
}
public static String getPlainText(FormattedText p_14327_) {
StringBuilder stringbuilder = new StringBuilder();
iterateFormatted(p_14327_, Style.EMPTY, (p_14323_, p_14324_, p_14325_) -> {
stringbuilder.appendCodePoint(p_14325_);
return true;
});
return stringbuilder.toString();
}
}

View File

@@ -0,0 +1,94 @@
package net.minecraft.util;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Keyable;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
public interface StringRepresentable {
int PRE_BUILT_MAP_THRESHOLD = 16;
String getSerializedName();
static <E extends Enum<E> & StringRepresentable> StringRepresentable.EnumCodec<E> fromEnum(Supplier<E[]> p_216440_) {
return fromEnumWithMapping(p_216440_, (p_275327_) -> {
return p_275327_;
});
}
static <E extends Enum<E> & StringRepresentable> StringRepresentable.EnumCodec<E> fromEnumWithMapping(Supplier<E[]> p_275615_, Function<String, String> p_275259_) {
E[] ae = p_275615_.get();
if (ae.length > 16) {
Map<String, E> map = Arrays.stream(ae).collect(Collectors.toMap((p_274905_) -> {
return p_275259_.apply(p_274905_.getSerializedName());
}, (p_274903_) -> {
return p_274903_;
}));
return new StringRepresentable.EnumCodec<>(ae, (p_216438_) -> {
return (E)(p_216438_ == null ? null : map.get(p_216438_));
});
} else {
return new StringRepresentable.EnumCodec<>(ae, (p_274908_) -> {
for(E e : ae) {
if (p_275259_.apply(e.getSerializedName()).equals(p_274908_)) {
return e;
}
}
return (E)null;
});
}
}
static Keyable keys(final StringRepresentable[] p_14358_) {
return new Keyable() {
public <T> Stream<T> keys(DynamicOps<T> p_184758_) {
return Arrays.stream(p_14358_).map(StringRepresentable::getSerializedName).map(p_184758_::createString);
}
};
}
/** @deprecated */
@Deprecated
public static class EnumCodec<E extends Enum<E> & StringRepresentable> implements Codec<E> {
private final Codec<E> codec;
private final Function<String, E> resolver;
public EnumCodec(E[] p_216447_, Function<String, E> p_216448_) {
this.codec = ExtraCodecs.orCompressed(ExtraCodecs.stringResolverCodec((p_216461_) -> {
return p_216461_.getSerializedName();
}, p_216448_), ExtraCodecs.idResolverCodec((p_216454_) -> {
return p_216454_.ordinal();
}, (p_216459_) -> {
return (E)(p_216459_ >= 0 && p_216459_ < p_216447_.length ? p_216447_[p_216459_] : null);
}, -1));
this.resolver = p_216448_;
}
public <T> DataResult<Pair<E, T>> decode(DynamicOps<T> p_216463_, T p_216464_) {
return this.codec.decode(p_216463_, p_216464_);
}
public <T> DataResult<T> encode(E p_216450_, DynamicOps<T> p_216451_, T p_216452_) {
return this.codec.encode(p_216450_, p_216451_, p_216452_);
}
@Nullable
public E byName(@Nullable String p_216456_) {
return this.resolver.apply(p_216456_);
}
public E byName(@Nullable String p_263077_, E p_263115_) {
return Objects.requireNonNullElse(this.byName(p_263077_), p_263115_);
}
}
}

View File

@@ -0,0 +1,60 @@
package net.minecraft.util;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
public class StringUtil {
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)\\u00A7[0-9A-FK-OR]");
private static final Pattern LINE_PATTERN = Pattern.compile("\\r\\n|\\v");
private static final Pattern LINE_END_PATTERN = Pattern.compile("(?:\\r\\n|\\v)$");
public static String formatTickDuration(int p_14405_) {
int i = p_14405_ / 20;
int j = i / 60;
i %= 60;
int k = j / 60;
j %= 60;
return k > 0 ? String.format(Locale.ROOT, "%02d:%02d:%02d", k, j, i) : String.format(Locale.ROOT, "%02d:%02d", j, i);
}
public static String stripColor(String p_14407_) {
return STRIP_COLOR_PATTERN.matcher(p_14407_).replaceAll("");
}
public static boolean isNullOrEmpty(@Nullable String p_14409_) {
return StringUtils.isEmpty(p_14409_);
}
public static String truncateStringIfNecessary(String p_144999_, int p_145000_, boolean p_145001_) {
if (p_144999_.length() <= p_145000_) {
return p_144999_;
} else {
return p_145001_ && p_145000_ > 3 ? p_144999_.substring(0, p_145000_ - 3) + "..." : p_144999_.substring(0, p_145000_);
}
}
public static int lineCount(String p_145003_) {
if (p_145003_.isEmpty()) {
return 0;
} else {
Matcher matcher = LINE_PATTERN.matcher(p_145003_);
int i;
for(i = 1; matcher.find(); ++i) {
}
return i;
}
}
public static boolean endsWithNewLine(String p_145005_) {
return LINE_END_PATTERN.matcher(p_145005_).find();
}
public static String trimChatMessage(String p_216470_) {
return truncateStringIfNecessary(p_216470_, 256, false);
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.util;
import com.mojang.logging.LogUtils;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.slf4j.Logger;
@FunctionalInterface
public interface TaskChainer {
Logger LOGGER = LogUtils.getLogger();
static TaskChainer immediate(Executor p_251122_) {
return (p_248285_) -> {
p_248285_.submit(p_251122_).exceptionally((p_242314_) -> {
LOGGER.error("Task failed", p_242314_);
return null;
});
};
}
void append(TaskChainer.DelayedTask p_242206_);
public interface DelayedTask {
CompletableFuture<?> submit(Executor p_249412_);
}
}

View File

@@ -0,0 +1,89 @@
package net.minecraft.util;
import com.mojang.logging.LogUtils;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
import org.slf4j.Logger;
public class ThreadingDetector {
private static final Logger LOGGER = LogUtils.getLogger();
private final String name;
private final Semaphore lock = new Semaphore(1);
private final Lock stackTraceLock = new ReentrantLock();
@Nullable
private volatile Thread threadThatFailedToAcquire;
@Nullable
private volatile ReportedException fullException;
public ThreadingDetector(String p_199415_) {
this.name = p_199415_;
}
public void checkAndLock() {
boolean flag = false;
try {
this.stackTraceLock.lock();
if (!this.lock.tryAcquire()) {
this.threadThatFailedToAcquire = Thread.currentThread();
flag = true;
this.stackTraceLock.unlock();
try {
this.lock.acquire();
} catch (InterruptedException interruptedexception) {
Thread.currentThread().interrupt();
}
throw this.fullException;
}
} finally {
if (!flag) {
this.stackTraceLock.unlock();
}
}
}
public void checkAndUnlock() {
try {
this.stackTraceLock.lock();
Thread thread = this.threadThatFailedToAcquire;
if (thread != null) {
ReportedException reportedexception = makeThreadingException(this.name, thread);
this.fullException = reportedexception;
this.lock.release();
throw reportedexception;
}
this.lock.release();
} finally {
this.stackTraceLock.unlock();
}
}
public static ReportedException makeThreadingException(String p_199418_, @Nullable Thread p_199419_) {
String s = Stream.of(Thread.currentThread(), p_199419_).filter(Objects::nonNull).map(ThreadingDetector::stackTrace).collect(Collectors.joining("\n"));
String s1 = "Accessing " + p_199418_ + " from multiple threads";
CrashReport crashreport = new CrashReport(s1, new IllegalStateException(s1));
CrashReportCategory crashreportcategory = crashreport.addCategory("Thread dumps");
crashreportcategory.setDetail("Thread dumps", s);
LOGGER.error("Thread dumps: \n" + s);
return new ReportedException(crashreport);
}
private static String stackTrace(Thread p_199421_) {
return p_199421_.getName() + ": \n\tat " + (String)Arrays.stream(p_199421_.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n\tat "));
}
}

View File

@@ -0,0 +1,15 @@
package net.minecraft.util;
import java.util.concurrent.TimeUnit;
import java.util.function.LongSupplier;
@FunctionalInterface
public interface TimeSource {
long get(TimeUnit p_239337_);
public interface NanoTimeSource extends TimeSource, LongSupplier {
default long get(TimeUnit p_239379_) {
return p_239379_.convert(this.getAsLong(), TimeUnit.NANOSECONDS);
}
}
}

View File

@@ -0,0 +1,13 @@
package net.minecraft.util;
import java.util.concurrent.TimeUnit;
import net.minecraft.util.valueproviders.UniformInt;
public class TimeUtil {
public static final long NANOSECONDS_PER_SECOND = TimeUnit.SECONDS.toNanos(1L);
public static final long NANOSECONDS_PER_MILLISECOND = TimeUnit.MILLISECONDS.toNanos(1L);
public static UniformInt rangeOfSeconds(int p_145021_, int p_145022_) {
return UniformInt.of(p_145021_ * 20, p_145022_ * 20);
}
}

View File

@@ -0,0 +1,49 @@
package net.minecraft.util;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import java.util.function.Function;
public interface ToFloatFunction<C> {
ToFloatFunction<Float> IDENTITY = createUnlimited((p_216474_) -> {
return p_216474_;
});
float apply(C p_184786_);
float minValue();
float maxValue();
static ToFloatFunction<Float> createUnlimited(final Float2FloatFunction p_216476_) {
return new ToFloatFunction<Float>() {
public float apply(Float p_216483_) {
return p_216476_.apply(p_216483_);
}
public float minValue() {
return Float.NEGATIVE_INFINITY;
}
public float maxValue() {
return Float.POSITIVE_INFINITY;
}
};
}
default <C2> ToFloatFunction<C2> comap(final Function<C2, C> p_216478_) {
final ToFloatFunction<C> tofloatfunction = this;
return new ToFloatFunction<C2>() {
public float apply(C2 p_216496_) {
return tofloatfunction.apply(p_216478_.apply(p_216496_));
}
public float minValue() {
return tofloatfunction.minValue();
}
public float maxValue() {
return tofloatfunction.maxValue();
}
};
}
}

View File

@@ -0,0 +1,27 @@
package net.minecraft.util;
public class Tuple<A, B> {
private A a;
private B b;
public Tuple(A p_14416_, B p_14417_) {
this.a = p_14416_;
this.b = p_14417_;
}
public A getA() {
return this.a;
}
public void setA(A p_145024_) {
this.a = p_145024_;
}
public B getB() {
return this.b;
}
public void setB(B p_145026_) {
this.b = p_145026_;
}
}

View File

@@ -0,0 +1,5 @@
package net.minecraft.util;
public enum Unit {
INSTANCE;
}

View File

@@ -0,0 +1,4 @@
package net.minecraft.util;
public @interface VisibleForDebug {
}

View File

@@ -0,0 +1,57 @@
package net.minecraft.util;
import java.util.Arrays;
import java.util.function.IntConsumer;
import org.apache.commons.lang3.Validate;
public class ZeroBitStorage implements BitStorage {
public static final long[] RAW = new long[0];
private final int size;
public ZeroBitStorage(int p_184791_) {
this.size = p_184791_;
}
public int getAndSet(int p_184796_, int p_184797_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184796_);
Validate.inclusiveBetween(0L, 0L, (long)p_184797_);
return 0;
}
public void set(int p_184802_, int p_184803_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184802_);
Validate.inclusiveBetween(0L, 0L, (long)p_184803_);
}
public int get(int p_184794_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_184794_);
return 0;
}
public long[] getRaw() {
return RAW;
}
public int getSize() {
return this.size;
}
public int getBits() {
return 0;
}
public void getAll(IntConsumer p_184799_) {
for(int i = 0; i < this.size; ++i) {
p_184799_.accept(0);
}
}
public void unpack(int[] p_198170_) {
Arrays.fill(p_198170_, 0, this.size, 0);
}
public BitStorage copy() {
return this;
}
}

View File

@@ -0,0 +1,56 @@
package net.minecraft.util.datafix;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixer;
import com.mojang.serialization.Dynamic;
import java.util.Set;
import net.minecraft.SharedConstants;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.datafix.fixes.References;
public enum DataFixTypes {
LEVEL(References.LEVEL),
PLAYER(References.PLAYER),
CHUNK(References.CHUNK),
HOTBAR(References.HOTBAR),
OPTIONS(References.OPTIONS),
STRUCTURE(References.STRUCTURE),
STATS(References.STATS),
SAVED_DATA(References.SAVED_DATA),
ADVANCEMENTS(References.ADVANCEMENTS),
POI_CHUNK(References.POI_CHUNK),
WORLD_GEN_SETTINGS(References.WORLD_GEN_SETTINGS),
ENTITY_CHUNK(References.ENTITY_CHUNK);
public static final Set<DSL.TypeReference> TYPES_FOR_LEVEL_LIST;
private final DSL.TypeReference type;
private DataFixTypes(DSL.TypeReference p_14503_) {
this.type = p_14503_;
}
private static int currentVersion() {
return SharedConstants.getCurrentVersion().getDataVersion().getVersion();
}
public <T> Dynamic<T> update(DataFixer p_265388_, Dynamic<T> p_265179_, int p_265372_, int p_265168_) {
return p_265388_.update(this.type, p_265179_, p_265372_, p_265168_);
}
public <T> Dynamic<T> updateToCurrentVersion(DataFixer p_265085_, Dynamic<T> p_265237_, int p_265099_) {
return this.update(p_265085_, p_265237_, p_265099_, currentVersion());
}
public CompoundTag update(DataFixer p_265128_, CompoundTag p_265422_, int p_265549_, int p_265304_) {
return (CompoundTag)this.update(p_265128_, new Dynamic<>(NbtOps.INSTANCE, p_265422_), p_265549_, p_265304_).getValue();
}
public CompoundTag updateToCurrentVersion(DataFixer p_265583_, CompoundTag p_265401_, int p_265111_) {
return this.update(p_265583_, p_265401_, p_265111_, currentVersion());
}
static {
TYPES_FOR_LEVEL_LIST = Set.of(LEVEL.type);
}
}

View File

@@ -0,0 +1,805 @@
package net.minecraft.util.datafix;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.util.datafix.fixes.AbstractArrowPickupFix;
import net.minecraft.util.datafix.fixes.AddFlagIfNotPresentFix;
import net.minecraft.util.datafix.fixes.AddNewChoices;
import net.minecraft.util.datafix.fixes.AdvancementsFix;
import net.minecraft.util.datafix.fixes.AdvancementsRenameFix;
import net.minecraft.util.datafix.fixes.AttributesRename;
import net.minecraft.util.datafix.fixes.BedItemColorFix;
import net.minecraft.util.datafix.fixes.BiomeFix;
import net.minecraft.util.datafix.fixes.BitStorageAlignFix;
import net.minecraft.util.datafix.fixes.BlendingDataFix;
import net.minecraft.util.datafix.fixes.BlendingDataRemoveFromNetherEndFix;
import net.minecraft.util.datafix.fixes.BlockEntityBannerColorFix;
import net.minecraft.util.datafix.fixes.BlockEntityBlockStateFix;
import net.minecraft.util.datafix.fixes.BlockEntityCustomNameToComponentFix;
import net.minecraft.util.datafix.fixes.BlockEntityIdFix;
import net.minecraft.util.datafix.fixes.BlockEntityJukeboxFix;
import net.minecraft.util.datafix.fixes.BlockEntityKeepPacked;
import net.minecraft.util.datafix.fixes.BlockEntityRenameFix;
import net.minecraft.util.datafix.fixes.BlockEntityShulkerBoxColorFix;
import net.minecraft.util.datafix.fixes.BlockEntitySignDoubleSidedEditableTextFix;
import net.minecraft.util.datafix.fixes.BlockEntitySignTextStrictJsonFix;
import net.minecraft.util.datafix.fixes.BlockEntityUUIDFix;
import net.minecraft.util.datafix.fixes.BlockNameFlatteningFix;
import net.minecraft.util.datafix.fixes.BlockRenameFix;
import net.minecraft.util.datafix.fixes.BlockRenameFixWithJigsaw;
import net.minecraft.util.datafix.fixes.BlockStateStructureTemplateFix;
import net.minecraft.util.datafix.fixes.CatTypeFix;
import net.minecraft.util.datafix.fixes.CauldronRenameFix;
import net.minecraft.util.datafix.fixes.CavesAndCliffsRenames;
import net.minecraft.util.datafix.fixes.ChunkBedBlockEntityInjecterFix;
import net.minecraft.util.datafix.fixes.ChunkBiomeFix;
import net.minecraft.util.datafix.fixes.ChunkDeleteIgnoredLightDataFix;
import net.minecraft.util.datafix.fixes.ChunkDeleteLightFix;
import net.minecraft.util.datafix.fixes.ChunkHeightAndBiomeFix;
import net.minecraft.util.datafix.fixes.ChunkLightRemoveFix;
import net.minecraft.util.datafix.fixes.ChunkPalettedStorageFix;
import net.minecraft.util.datafix.fixes.ChunkProtoTickListFix;
import net.minecraft.util.datafix.fixes.ChunkRenamesFix;
import net.minecraft.util.datafix.fixes.ChunkStatusFix;
import net.minecraft.util.datafix.fixes.ChunkStatusFix2;
import net.minecraft.util.datafix.fixes.ChunkStructuresTemplateRenameFix;
import net.minecraft.util.datafix.fixes.ChunkToProtochunkFix;
import net.minecraft.util.datafix.fixes.ColorlessShulkerEntityFix;
import net.minecraft.util.datafix.fixes.CriteriaRenameFix;
import net.minecraft.util.datafix.fixes.DecoratedPotFieldRenameFix;
import net.minecraft.util.datafix.fixes.DyeItemRenameFix;
import net.minecraft.util.datafix.fixes.EffectDurationFix;
import net.minecraft.util.datafix.fixes.EntityArmorStandSilentFix;
import net.minecraft.util.datafix.fixes.EntityBlockStateFix;
import net.minecraft.util.datafix.fixes.EntityBrushableBlockFieldsRenameFix;
import net.minecraft.util.datafix.fixes.EntityCatSplitFix;
import net.minecraft.util.datafix.fixes.EntityCodSalmonFix;
import net.minecraft.util.datafix.fixes.EntityCustomNameToComponentFix;
import net.minecraft.util.datafix.fixes.EntityElderGuardianSplitFix;
import net.minecraft.util.datafix.fixes.EntityEquipmentToArmorAndHandFix;
import net.minecraft.util.datafix.fixes.EntityGoatMissingStateFix;
import net.minecraft.util.datafix.fixes.EntityHealthFix;
import net.minecraft.util.datafix.fixes.EntityHorseSaddleFix;
import net.minecraft.util.datafix.fixes.EntityHorseSplitFix;
import net.minecraft.util.datafix.fixes.EntityIdFix;
import net.minecraft.util.datafix.fixes.EntityItemFrameDirectionFix;
import net.minecraft.util.datafix.fixes.EntityMinecartIdentifiersFix;
import net.minecraft.util.datafix.fixes.EntityPaintingFieldsRenameFix;
import net.minecraft.util.datafix.fixes.EntityPaintingItemFrameDirectionFix;
import net.minecraft.util.datafix.fixes.EntityPaintingMotiveFix;
import net.minecraft.util.datafix.fixes.EntityProjectileOwnerFix;
import net.minecraft.util.datafix.fixes.EntityPufferfishRenameFix;
import net.minecraft.util.datafix.fixes.EntityRavagerRenameFix;
import net.minecraft.util.datafix.fixes.EntityRedundantChanceTagsFix;
import net.minecraft.util.datafix.fixes.EntityRidingToPassengersFix;
import net.minecraft.util.datafix.fixes.EntityShulkerColorFix;
import net.minecraft.util.datafix.fixes.EntityShulkerRotationFix;
import net.minecraft.util.datafix.fixes.EntitySkeletonSplitFix;
import net.minecraft.util.datafix.fixes.EntityStringUuidFix;
import net.minecraft.util.datafix.fixes.EntityTheRenameningFix;
import net.minecraft.util.datafix.fixes.EntityTippedArrowFix;
import net.minecraft.util.datafix.fixes.EntityUUIDFix;
import net.minecraft.util.datafix.fixes.EntityVariantFix;
import net.minecraft.util.datafix.fixes.EntityWolfColorFix;
import net.minecraft.util.datafix.fixes.EntityZombieSplitFix;
import net.minecraft.util.datafix.fixes.EntityZombieVillagerTypeFix;
import net.minecraft.util.datafix.fixes.EntityZombifiedPiglinRenameFix;
import net.minecraft.util.datafix.fixes.FeatureFlagRemoveFix;
import net.minecraft.util.datafix.fixes.FilteredBooksFix;
import net.minecraft.util.datafix.fixes.FilteredSignsFix;
import net.minecraft.util.datafix.fixes.ForcePoiRebuild;
import net.minecraft.util.datafix.fixes.FurnaceRecipeFix;
import net.minecraft.util.datafix.fixes.GoatHornIdFix;
import net.minecraft.util.datafix.fixes.GossipUUIDFix;
import net.minecraft.util.datafix.fixes.HeightmapRenamingFix;
import net.minecraft.util.datafix.fixes.IglooMetadataRemovalFix;
import net.minecraft.util.datafix.fixes.ItemBannerColorFix;
import net.minecraft.util.datafix.fixes.ItemCustomNameToComponentFix;
import net.minecraft.util.datafix.fixes.ItemIdFix;
import net.minecraft.util.datafix.fixes.ItemLoreFix;
import net.minecraft.util.datafix.fixes.ItemPotionFix;
import net.minecraft.util.datafix.fixes.ItemRemoveBlockEntityTagFix;
import net.minecraft.util.datafix.fixes.ItemRenameFix;
import net.minecraft.util.datafix.fixes.ItemShulkerBoxColorFix;
import net.minecraft.util.datafix.fixes.ItemSpawnEggFix;
import net.minecraft.util.datafix.fixes.ItemStackEnchantmentNamesFix;
import net.minecraft.util.datafix.fixes.ItemStackMapIdFix;
import net.minecraft.util.datafix.fixes.ItemStackSpawnEggFix;
import net.minecraft.util.datafix.fixes.ItemStackTheFlatteningFix;
import net.minecraft.util.datafix.fixes.ItemStackUUIDFix;
import net.minecraft.util.datafix.fixes.ItemWaterPotionFix;
import net.minecraft.util.datafix.fixes.ItemWrittenBookPagesStrictJsonFix;
import net.minecraft.util.datafix.fixes.JigsawPropertiesFix;
import net.minecraft.util.datafix.fixes.JigsawRotationFix;
import net.minecraft.util.datafix.fixes.LeavesFix;
import net.minecraft.util.datafix.fixes.LegacyDragonFightFix;
import net.minecraft.util.datafix.fixes.LevelDataGeneratorOptionsFix;
import net.minecraft.util.datafix.fixes.LevelFlatGeneratorInfoFix;
import net.minecraft.util.datafix.fixes.LevelUUIDFix;
import net.minecraft.util.datafix.fixes.MapIdFix;
import net.minecraft.util.datafix.fixes.MemoryExpiryDataFix;
import net.minecraft.util.datafix.fixes.MissingDimensionFix;
import net.minecraft.util.datafix.fixes.MobSpawnerEntityIdentifiersFix;
import net.minecraft.util.datafix.fixes.NamedEntityFix;
import net.minecraft.util.datafix.fixes.NamespacedTypeRenameFix;
import net.minecraft.util.datafix.fixes.NewVillageFix;
import net.minecraft.util.datafix.fixes.ObjectiveDisplayNameFix;
import net.minecraft.util.datafix.fixes.ObjectiveRenderTypeFix;
import net.minecraft.util.datafix.fixes.OminousBannerBlockEntityRenameFix;
import net.minecraft.util.datafix.fixes.OminousBannerRenameFix;
import net.minecraft.util.datafix.fixes.OptionsAccessibilityOnboardFix;
import net.minecraft.util.datafix.fixes.OptionsAddTextBackgroundFix;
import net.minecraft.util.datafix.fixes.OptionsAmbientOcclusionFix;
import net.minecraft.util.datafix.fixes.OptionsForceVBOFix;
import net.minecraft.util.datafix.fixes.OptionsKeyLwjgl3Fix;
import net.minecraft.util.datafix.fixes.OptionsKeyTranslationFix;
import net.minecraft.util.datafix.fixes.OptionsLowerCaseLanguageFix;
import net.minecraft.util.datafix.fixes.OptionsProgrammerArtFix;
import net.minecraft.util.datafix.fixes.OptionsRenameFieldFix;
import net.minecraft.util.datafix.fixes.OverreachingTickFix;
import net.minecraft.util.datafix.fixes.PlayerUUIDFix;
import net.minecraft.util.datafix.fixes.PoiTypeRemoveFix;
import net.minecraft.util.datafix.fixes.PoiTypeRenameFix;
import net.minecraft.util.datafix.fixes.RecipesFix;
import net.minecraft.util.datafix.fixes.RecipesRenameningFix;
import net.minecraft.util.datafix.fixes.RedstoneWireConnectionsFix;
import net.minecraft.util.datafix.fixes.References;
import net.minecraft.util.datafix.fixes.RemapChunkStatusFix;
import net.minecraft.util.datafix.fixes.RemoveGolemGossipFix;
import net.minecraft.util.datafix.fixes.RenamedCoralFansFix;
import net.minecraft.util.datafix.fixes.RenamedCoralFix;
import net.minecraft.util.datafix.fixes.ReorganizePoi;
import net.minecraft.util.datafix.fixes.SavedDataFeaturePoolElementFix;
import net.minecraft.util.datafix.fixes.SavedDataUUIDFix;
import net.minecraft.util.datafix.fixes.SpawnerDataFix;
import net.minecraft.util.datafix.fixes.StatsCounterFix;
import net.minecraft.util.datafix.fixes.StatsRenameFix;
import net.minecraft.util.datafix.fixes.StriderGravityFix;
import net.minecraft.util.datafix.fixes.StructureReferenceCountFix;
import net.minecraft.util.datafix.fixes.StructureSettingsFlattenFix;
import net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix;
import net.minecraft.util.datafix.fixes.TeamDisplayNameFix;
import net.minecraft.util.datafix.fixes.TrappedChestBlockEntityFix;
import net.minecraft.util.datafix.fixes.VariantRenameFix;
import net.minecraft.util.datafix.fixes.VillagerDataFix;
import net.minecraft.util.datafix.fixes.VillagerFollowRangeFix;
import net.minecraft.util.datafix.fixes.VillagerRebuildLevelAndXpFix;
import net.minecraft.util.datafix.fixes.VillagerTradeFix;
import net.minecraft.util.datafix.fixes.WallPropertyFix;
import net.minecraft.util.datafix.fixes.WeaponSmithChestLootTableFix;
import net.minecraft.util.datafix.fixes.WorldGenSettingsDisallowOldCustomWorldsFix;
import net.minecraft.util.datafix.fixes.WorldGenSettingsFix;
import net.minecraft.util.datafix.fixes.WorldGenSettingsHeightAndBiomeFix;
import net.minecraft.util.datafix.fixes.WriteAndReadFix;
import net.minecraft.util.datafix.fixes.ZombieVillagerRebuildXpFix;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
import net.minecraft.util.datafix.schemas.V100;
import net.minecraft.util.datafix.schemas.V102;
import net.minecraft.util.datafix.schemas.V1022;
import net.minecraft.util.datafix.schemas.V106;
import net.minecraft.util.datafix.schemas.V107;
import net.minecraft.util.datafix.schemas.V1125;
import net.minecraft.util.datafix.schemas.V135;
import net.minecraft.util.datafix.schemas.V143;
import net.minecraft.util.datafix.schemas.V1451;
import net.minecraft.util.datafix.schemas.V1451_1;
import net.minecraft.util.datafix.schemas.V1451_2;
import net.minecraft.util.datafix.schemas.V1451_3;
import net.minecraft.util.datafix.schemas.V1451_4;
import net.minecraft.util.datafix.schemas.V1451_5;
import net.minecraft.util.datafix.schemas.V1451_6;
import net.minecraft.util.datafix.schemas.V1460;
import net.minecraft.util.datafix.schemas.V1466;
import net.minecraft.util.datafix.schemas.V1470;
import net.minecraft.util.datafix.schemas.V1481;
import net.minecraft.util.datafix.schemas.V1483;
import net.minecraft.util.datafix.schemas.V1486;
import net.minecraft.util.datafix.schemas.V1510;
import net.minecraft.util.datafix.schemas.V1800;
import net.minecraft.util.datafix.schemas.V1801;
import net.minecraft.util.datafix.schemas.V1904;
import net.minecraft.util.datafix.schemas.V1906;
import net.minecraft.util.datafix.schemas.V1909;
import net.minecraft.util.datafix.schemas.V1920;
import net.minecraft.util.datafix.schemas.V1928;
import net.minecraft.util.datafix.schemas.V1929;
import net.minecraft.util.datafix.schemas.V1931;
import net.minecraft.util.datafix.schemas.V2100;
import net.minecraft.util.datafix.schemas.V2501;
import net.minecraft.util.datafix.schemas.V2502;
import net.minecraft.util.datafix.schemas.V2505;
import net.minecraft.util.datafix.schemas.V2509;
import net.minecraft.util.datafix.schemas.V2519;
import net.minecraft.util.datafix.schemas.V2522;
import net.minecraft.util.datafix.schemas.V2551;
import net.minecraft.util.datafix.schemas.V2568;
import net.minecraft.util.datafix.schemas.V2571;
import net.minecraft.util.datafix.schemas.V2684;
import net.minecraft.util.datafix.schemas.V2686;
import net.minecraft.util.datafix.schemas.V2688;
import net.minecraft.util.datafix.schemas.V2704;
import net.minecraft.util.datafix.schemas.V2707;
import net.minecraft.util.datafix.schemas.V2831;
import net.minecraft.util.datafix.schemas.V2832;
import net.minecraft.util.datafix.schemas.V2842;
import net.minecraft.util.datafix.schemas.V3076;
import net.minecraft.util.datafix.schemas.V3078;
import net.minecraft.util.datafix.schemas.V3081;
import net.minecraft.util.datafix.schemas.V3082;
import net.minecraft.util.datafix.schemas.V3083;
import net.minecraft.util.datafix.schemas.V3202;
import net.minecraft.util.datafix.schemas.V3203;
import net.minecraft.util.datafix.schemas.V3204;
import net.minecraft.util.datafix.schemas.V3325;
import net.minecraft.util.datafix.schemas.V3326;
import net.minecraft.util.datafix.schemas.V3327;
import net.minecraft.util.datafix.schemas.V3328;
import net.minecraft.util.datafix.schemas.V3438;
import net.minecraft.util.datafix.schemas.V3448;
import net.minecraft.util.datafix.schemas.V501;
import net.minecraft.util.datafix.schemas.V700;
import net.minecraft.util.datafix.schemas.V701;
import net.minecraft.util.datafix.schemas.V702;
import net.minecraft.util.datafix.schemas.V703;
import net.minecraft.util.datafix.schemas.V704;
import net.minecraft.util.datafix.schemas.V705;
import net.minecraft.util.datafix.schemas.V808;
import net.minecraft.util.datafix.schemas.V99;
public class DataFixers {
private static final BiFunction<Integer, Schema, Schema> SAME = Schema::new;
private static final BiFunction<Integer, Schema, Schema> SAME_NAMESPACED = NamespacedSchema::new;
private static final DataFixer dataFixer = createFixerUpper(SharedConstants.DATA_FIX_TYPES_TO_OPTIMIZE);
public static final int BLENDING_VERSION = 3441;
private DataFixers() {
}
public static DataFixer getDataFixer() {
return dataFixer;
}
private static synchronized DataFixer createFixerUpper(Set<DSL.TypeReference> p_275618_) {
DataFixerBuilder datafixerbuilder = new DataFixerBuilder(SharedConstants.getCurrentVersion().getDataVersion().getVersion());
addFixers(datafixerbuilder);
if (p_275618_.isEmpty()) {
return datafixerbuilder.buildUnoptimized();
} else {
Executor executor = Executors.newSingleThreadExecutor((new ThreadFactoryBuilder()).setNameFormat("Datafixer Bootstrap").setDaemon(true).setPriority(1).build());
return datafixerbuilder.buildOptimized(p_275618_, executor);
}
}
private static void addFixers(DataFixerBuilder p_14514_) {
p_14514_.addSchema(99, V99::new);
Schema schema = p_14514_.addSchema(100, V100::new);
p_14514_.addFixer(new EntityEquipmentToArmorAndHandFix(schema, true));
Schema schema1 = p_14514_.addSchema(101, SAME);
p_14514_.addFixer(new BlockEntitySignTextStrictJsonFix(schema1, false));
Schema schema2 = p_14514_.addSchema(102, V102::new);
p_14514_.addFixer(new ItemIdFix(schema2, true));
p_14514_.addFixer(new ItemPotionFix(schema2, false));
Schema schema3 = p_14514_.addSchema(105, SAME);
p_14514_.addFixer(new ItemSpawnEggFix(schema3, true));
Schema schema4 = p_14514_.addSchema(106, V106::new);
p_14514_.addFixer(new MobSpawnerEntityIdentifiersFix(schema4, true));
Schema schema5 = p_14514_.addSchema(107, V107::new);
p_14514_.addFixer(new EntityMinecartIdentifiersFix(schema5, true));
Schema schema6 = p_14514_.addSchema(108, SAME);
p_14514_.addFixer(new EntityStringUuidFix(schema6, true));
Schema schema7 = p_14514_.addSchema(109, SAME);
p_14514_.addFixer(new EntityHealthFix(schema7, true));
Schema schema8 = p_14514_.addSchema(110, SAME);
p_14514_.addFixer(new EntityHorseSaddleFix(schema8, true));
Schema schema9 = p_14514_.addSchema(111, SAME);
p_14514_.addFixer(new EntityPaintingItemFrameDirectionFix(schema9, true));
Schema schema10 = p_14514_.addSchema(113, SAME);
p_14514_.addFixer(new EntityRedundantChanceTagsFix(schema10, true));
Schema schema11 = p_14514_.addSchema(135, V135::new);
p_14514_.addFixer(new EntityRidingToPassengersFix(schema11, true));
Schema schema12 = p_14514_.addSchema(143, V143::new);
p_14514_.addFixer(new EntityTippedArrowFix(schema12, true));
Schema schema13 = p_14514_.addSchema(147, SAME);
p_14514_.addFixer(new EntityArmorStandSilentFix(schema13, true));
Schema schema14 = p_14514_.addSchema(165, SAME);
p_14514_.addFixer(new ItemWrittenBookPagesStrictJsonFix(schema14, true));
Schema schema15 = p_14514_.addSchema(501, V501::new);
p_14514_.addFixer(new AddNewChoices(schema15, "Add 1.10 entities fix", References.ENTITY));
Schema schema16 = p_14514_.addSchema(502, SAME);
p_14514_.addFixer(ItemRenameFix.create(schema16, "cooked_fished item renamer", (p_14533_) -> {
return Objects.equals(NamespacedSchema.ensureNamespaced(p_14533_), "minecraft:cooked_fished") ? "minecraft:cooked_fish" : p_14533_;
}));
p_14514_.addFixer(new EntityZombieVillagerTypeFix(schema16, false));
Schema schema17 = p_14514_.addSchema(505, SAME);
p_14514_.addFixer(new OptionsForceVBOFix(schema17, false));
Schema schema18 = p_14514_.addSchema(700, V700::new);
p_14514_.addFixer(new EntityElderGuardianSplitFix(schema18, true));
Schema schema19 = p_14514_.addSchema(701, V701::new);
p_14514_.addFixer(new EntitySkeletonSplitFix(schema19, true));
Schema schema20 = p_14514_.addSchema(702, V702::new);
p_14514_.addFixer(new EntityZombieSplitFix(schema20, true));
Schema schema21 = p_14514_.addSchema(703, V703::new);
p_14514_.addFixer(new EntityHorseSplitFix(schema21, true));
Schema schema22 = p_14514_.addSchema(704, V704::new);
p_14514_.addFixer(new BlockEntityIdFix(schema22, true));
Schema schema23 = p_14514_.addSchema(705, V705::new);
p_14514_.addFixer(new EntityIdFix(schema23, true));
Schema schema24 = p_14514_.addSchema(804, SAME_NAMESPACED);
p_14514_.addFixer(new ItemBannerColorFix(schema24, true));
Schema schema25 = p_14514_.addSchema(806, SAME_NAMESPACED);
p_14514_.addFixer(new ItemWaterPotionFix(schema25, false));
Schema schema26 = p_14514_.addSchema(808, V808::new);
p_14514_.addFixer(new AddNewChoices(schema26, "added shulker box", References.BLOCK_ENTITY));
Schema schema27 = p_14514_.addSchema(808, 1, SAME_NAMESPACED);
p_14514_.addFixer(new EntityShulkerColorFix(schema27, false));
Schema schema28 = p_14514_.addSchema(813, SAME_NAMESPACED);
p_14514_.addFixer(new ItemShulkerBoxColorFix(schema28, false));
p_14514_.addFixer(new BlockEntityShulkerBoxColorFix(schema28, false));
Schema schema29 = p_14514_.addSchema(816, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsLowerCaseLanguageFix(schema29, false));
Schema schema30 = p_14514_.addSchema(820, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema30, "totem item renamer", createRenamer("minecraft:totem", "minecraft:totem_of_undying")));
Schema schema31 = p_14514_.addSchema(1022, V1022::new);
p_14514_.addFixer(new WriteAndReadFix(schema31, "added shoulder entities to players", References.PLAYER));
Schema schema32 = p_14514_.addSchema(1125, V1125::new);
p_14514_.addFixer(new ChunkBedBlockEntityInjecterFix(schema32, true));
p_14514_.addFixer(new BedItemColorFix(schema32, false));
Schema schema33 = p_14514_.addSchema(1344, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsKeyLwjgl3Fix(schema33, false));
Schema schema34 = p_14514_.addSchema(1446, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsKeyTranslationFix(schema34, false));
Schema schema35 = p_14514_.addSchema(1450, SAME_NAMESPACED);
p_14514_.addFixer(new BlockStateStructureTemplateFix(schema35, false));
Schema schema36 = p_14514_.addSchema(1451, V1451::new);
p_14514_.addFixer(new AddNewChoices(schema36, "AddTrappedChestFix", References.BLOCK_ENTITY));
Schema schema37 = p_14514_.addSchema(1451, 1, V1451_1::new);
p_14514_.addFixer(new ChunkPalettedStorageFix(schema37, true));
Schema schema38 = p_14514_.addSchema(1451, 2, V1451_2::new);
p_14514_.addFixer(new BlockEntityBlockStateFix(schema38, true));
Schema schema39 = p_14514_.addSchema(1451, 3, V1451_3::new);
p_14514_.addFixer(new EntityBlockStateFix(schema39, true));
p_14514_.addFixer(new ItemStackMapIdFix(schema39, false));
Schema schema40 = p_14514_.addSchema(1451, 4, V1451_4::new);
p_14514_.addFixer(new BlockNameFlatteningFix(schema40, true));
p_14514_.addFixer(new ItemStackTheFlatteningFix(schema40, false));
Schema schema41 = p_14514_.addSchema(1451, 5, V1451_5::new);
p_14514_.addFixer(new ItemRemoveBlockEntityTagFix(schema41, false, Set.of("minecraft:note_block", "minecraft:flower_pot", "minecraft:dandelion", "minecraft:poppy", "minecraft:blue_orchid", "minecraft:allium", "minecraft:azure_bluet", "minecraft:red_tulip", "minecraft:orange_tulip", "minecraft:white_tulip", "minecraft:pink_tulip", "minecraft:oxeye_daisy", "minecraft:cactus", "minecraft:brown_mushroom", "minecraft:red_mushroom", "minecraft:oak_sapling", "minecraft:spruce_sapling", "minecraft:birch_sapling", "minecraft:jungle_sapling", "minecraft:acacia_sapling", "minecraft:dark_oak_sapling", "minecraft:dead_bush", "minecraft:fern")));
p_14514_.addFixer(new AddNewChoices(schema41, "RemoveNoteBlockFlowerPotFix", References.BLOCK_ENTITY));
p_14514_.addFixer(new ItemStackSpawnEggFix(schema41, false, "minecraft:spawn_egg"));
p_14514_.addFixer(new EntityWolfColorFix(schema41, false));
p_14514_.addFixer(new BlockEntityBannerColorFix(schema41, false));
p_14514_.addFixer(new LevelFlatGeneratorInfoFix(schema41, false));
Schema schema42 = p_14514_.addSchema(1451, 6, V1451_6::new);
p_14514_.addFixer(new StatsCounterFix(schema42, true));
p_14514_.addFixer(new WriteAndReadFix(schema42, "Rewrite objectives", References.OBJECTIVE));
p_14514_.addFixer(new BlockEntityJukeboxFix(schema42, false));
Schema schema43 = p_14514_.addSchema(1451, 7, SAME_NAMESPACED);
p_14514_.addFixer(new VillagerTradeFix(schema43, false));
Schema schema44 = p_14514_.addSchema(1456, SAME_NAMESPACED);
p_14514_.addFixer(new EntityItemFrameDirectionFix(schema44, false));
Schema schema45 = p_14514_.addSchema(1458, SAME_NAMESPACED);
p_14514_.addFixer(new EntityCustomNameToComponentFix(schema45, false));
p_14514_.addFixer(new ItemCustomNameToComponentFix(schema45, false));
p_14514_.addFixer(new BlockEntityCustomNameToComponentFix(schema45, false));
Schema schema46 = p_14514_.addSchema(1460, V1460::new);
p_14514_.addFixer(new EntityPaintingMotiveFix(schema46, false));
Schema schema47 = p_14514_.addSchema(1466, V1466::new);
p_14514_.addFixer(new ChunkToProtochunkFix(schema47, true));
Schema schema48 = p_14514_.addSchema(1470, V1470::new);
p_14514_.addFixer(new AddNewChoices(schema48, "Add 1.13 entities fix", References.ENTITY));
Schema schema49 = p_14514_.addSchema(1474, SAME_NAMESPACED);
p_14514_.addFixer(new ColorlessShulkerEntityFix(schema49, false));
p_14514_.addFixer(BlockRenameFix.create(schema49, "Colorless shulker block fixer", (p_14531_) -> {
return Objects.equals(NamespacedSchema.ensureNamespaced(p_14531_), "minecraft:purple_shulker_box") ? "minecraft:shulker_box" : p_14531_;
}));
p_14514_.addFixer(ItemRenameFix.create(schema49, "Colorless shulker item fixer", (p_14516_) -> {
return Objects.equals(NamespacedSchema.ensureNamespaced(p_14516_), "minecraft:purple_shulker_box") ? "minecraft:shulker_box" : p_14516_;
}));
Schema schema50 = p_14514_.addSchema(1475, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema50, "Flowing fixer", createRenamer(ImmutableMap.of("minecraft:flowing_water", "minecraft:water", "minecraft:flowing_lava", "minecraft:lava"))));
Schema schema51 = p_14514_.addSchema(1480, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema51, "Rename coral blocks", createRenamer(RenamedCoralFix.RENAMED_IDS)));
p_14514_.addFixer(ItemRenameFix.create(schema51, "Rename coral items", createRenamer(RenamedCoralFix.RENAMED_IDS)));
Schema schema52 = p_14514_.addSchema(1481, V1481::new);
p_14514_.addFixer(new AddNewChoices(schema52, "Add conduit", References.BLOCK_ENTITY));
Schema schema53 = p_14514_.addSchema(1483, V1483::new);
p_14514_.addFixer(new EntityPufferfishRenameFix(schema53, true));
p_14514_.addFixer(ItemRenameFix.create(schema53, "Rename pufferfish egg item", createRenamer(EntityPufferfishRenameFix.RENAMED_IDS)));
Schema schema54 = p_14514_.addSchema(1484, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema54, "Rename seagrass items", createRenamer(ImmutableMap.of("minecraft:sea_grass", "minecraft:seagrass", "minecraft:tall_sea_grass", "minecraft:tall_seagrass"))));
p_14514_.addFixer(BlockRenameFix.create(schema54, "Rename seagrass blocks", createRenamer(ImmutableMap.of("minecraft:sea_grass", "minecraft:seagrass", "minecraft:tall_sea_grass", "minecraft:tall_seagrass"))));
p_14514_.addFixer(new HeightmapRenamingFix(schema54, false));
Schema schema55 = p_14514_.addSchema(1486, V1486::new);
p_14514_.addFixer(new EntityCodSalmonFix(schema55, true));
p_14514_.addFixer(ItemRenameFix.create(schema55, "Rename cod/salmon egg items", createRenamer(EntityCodSalmonFix.RENAMED_EGG_IDS)));
Schema schema56 = p_14514_.addSchema(1487, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema56, "Rename prismarine_brick(s)_* blocks", createRenamer(ImmutableMap.of("minecraft:prismarine_bricks_slab", "minecraft:prismarine_brick_slab", "minecraft:prismarine_bricks_stairs", "minecraft:prismarine_brick_stairs"))));
p_14514_.addFixer(BlockRenameFix.create(schema56, "Rename prismarine_brick(s)_* items", createRenamer(ImmutableMap.of("minecraft:prismarine_bricks_slab", "minecraft:prismarine_brick_slab", "minecraft:prismarine_bricks_stairs", "minecraft:prismarine_brick_stairs"))));
Schema schema57 = p_14514_.addSchema(1488, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema57, "Rename kelp/kelptop", createRenamer(ImmutableMap.of("minecraft:kelp_top", "minecraft:kelp", "minecraft:kelp", "minecraft:kelp_plant"))));
p_14514_.addFixer(ItemRenameFix.create(schema57, "Rename kelptop", createRenamer("minecraft:kelp_top", "minecraft:kelp")));
p_14514_.addFixer(new NamedEntityFix(schema57, false, "Command block block entity custom name fix", References.BLOCK_ENTITY, "minecraft:command_block") {
protected Typed<?> fix(Typed<?> p_14541_) {
return p_14541_.update(DSL.remainderFinder(), EntityCustomNameToComponentFix::fixTagCustomName);
}
});
p_14514_.addFixer(new NamedEntityFix(schema57, false, "Command block minecart custom name fix", References.ENTITY, "minecraft:commandblock_minecart") {
protected Typed<?> fix(Typed<?> p_14549_) {
return p_14549_.update(DSL.remainderFinder(), EntityCustomNameToComponentFix::fixTagCustomName);
}
});
p_14514_.addFixer(new IglooMetadataRemovalFix(schema57, false));
Schema schema58 = p_14514_.addSchema(1490, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema58, "Rename melon_block", createRenamer("minecraft:melon_block", "minecraft:melon")));
p_14514_.addFixer(ItemRenameFix.create(schema58, "Rename melon_block/melon/speckled_melon", createRenamer(ImmutableMap.of("minecraft:melon_block", "minecraft:melon", "minecraft:melon", "minecraft:melon_slice", "minecraft:speckled_melon", "minecraft:glistering_melon_slice"))));
Schema schema59 = p_14514_.addSchema(1492, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkStructuresTemplateRenameFix(schema59, false));
Schema schema60 = p_14514_.addSchema(1494, SAME_NAMESPACED);
p_14514_.addFixer(new ItemStackEnchantmentNamesFix(schema60, false));
Schema schema61 = p_14514_.addSchema(1496, SAME_NAMESPACED);
p_14514_.addFixer(new LeavesFix(schema61, false));
Schema schema62 = p_14514_.addSchema(1500, SAME_NAMESPACED);
p_14514_.addFixer(new BlockEntityKeepPacked(schema62, false));
Schema schema63 = p_14514_.addSchema(1501, SAME_NAMESPACED);
p_14514_.addFixer(new AdvancementsFix(schema63, false));
Schema schema64 = p_14514_.addSchema(1502, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema64, "Recipes fix", References.RECIPE, createRenamer(RecipesFix.RECIPES)));
Schema schema65 = p_14514_.addSchema(1506, SAME_NAMESPACED);
p_14514_.addFixer(new LevelDataGeneratorOptionsFix(schema65, false));
Schema schema66 = p_14514_.addSchema(1510, V1510::new);
p_14514_.addFixer(BlockRenameFix.create(schema66, "Block renamening fix", createRenamer(EntityTheRenameningFix.RENAMED_BLOCKS)));
p_14514_.addFixer(ItemRenameFix.create(schema66, "Item renamening fix", createRenamer(EntityTheRenameningFix.RENAMED_ITEMS)));
p_14514_.addFixer(new NamespacedTypeRenameFix(schema66, "Recipes renamening fix", References.RECIPE, createRenamer(RecipesRenameningFix.RECIPES)));
p_14514_.addFixer(new EntityTheRenameningFix(schema66, true));
p_14514_.addFixer(new StatsRenameFix(schema66, "SwimStatsRenameFix", ImmutableMap.of("minecraft:swim_one_cm", "minecraft:walk_on_water_one_cm", "minecraft:dive_one_cm", "minecraft:walk_under_water_one_cm")));
Schema schema67 = p_14514_.addSchema(1514, SAME_NAMESPACED);
p_14514_.addFixer(new ObjectiveDisplayNameFix(schema67, false));
p_14514_.addFixer(new TeamDisplayNameFix(schema67, false));
p_14514_.addFixer(new ObjectiveRenderTypeFix(schema67, false));
Schema schema68 = p_14514_.addSchema(1515, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema68, "Rename coral fan blocks", createRenamer(RenamedCoralFansFix.RENAMED_IDS)));
Schema schema69 = p_14514_.addSchema(1624, SAME_NAMESPACED);
p_14514_.addFixer(new TrappedChestBlockEntityFix(schema69, false));
Schema schema70 = p_14514_.addSchema(1800, V1800::new);
p_14514_.addFixer(new AddNewChoices(schema70, "Added 1.14 mobs fix", References.ENTITY));
p_14514_.addFixer(ItemRenameFix.create(schema70, "Rename dye items", createRenamer(DyeItemRenameFix.RENAMED_IDS)));
Schema schema71 = p_14514_.addSchema(1801, V1801::new);
p_14514_.addFixer(new AddNewChoices(schema71, "Added Illager Beast", References.ENTITY));
Schema schema72 = p_14514_.addSchema(1802, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFix.create(schema72, "Rename sign blocks & stone slabs", createRenamer(ImmutableMap.of("minecraft:stone_slab", "minecraft:smooth_stone_slab", "minecraft:sign", "minecraft:oak_sign", "minecraft:wall_sign", "minecraft:oak_wall_sign"))));
p_14514_.addFixer(ItemRenameFix.create(schema72, "Rename sign item & stone slabs", createRenamer(ImmutableMap.of("minecraft:stone_slab", "minecraft:smooth_stone_slab", "minecraft:sign", "minecraft:oak_sign"))));
Schema schema73 = p_14514_.addSchema(1803, SAME_NAMESPACED);
p_14514_.addFixer(new ItemLoreFix(schema73, false));
Schema schema74 = p_14514_.addSchema(1904, V1904::new);
p_14514_.addFixer(new AddNewChoices(schema74, "Added Cats", References.ENTITY));
p_14514_.addFixer(new EntityCatSplitFix(schema74, false));
Schema schema75 = p_14514_.addSchema(1905, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkStatusFix(schema75, false));
Schema schema76 = p_14514_.addSchema(1906, V1906::new);
p_14514_.addFixer(new AddNewChoices(schema76, "Add POI Blocks", References.BLOCK_ENTITY));
Schema schema77 = p_14514_.addSchema(1909, V1909::new);
p_14514_.addFixer(new AddNewChoices(schema77, "Add jigsaw", References.BLOCK_ENTITY));
Schema schema78 = p_14514_.addSchema(1911, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkStatusFix2(schema78, false));
Schema schema79 = p_14514_.addSchema(1914, SAME_NAMESPACED);
p_14514_.addFixer(new WeaponSmithChestLootTableFix(schema79, false));
Schema schema80 = p_14514_.addSchema(1917, SAME_NAMESPACED);
p_14514_.addFixer(new CatTypeFix(schema80, false));
Schema schema81 = p_14514_.addSchema(1918, SAME_NAMESPACED);
p_14514_.addFixer(new VillagerDataFix(schema81, "minecraft:villager"));
p_14514_.addFixer(new VillagerDataFix(schema81, "minecraft:zombie_villager"));
Schema schema82 = p_14514_.addSchema(1920, V1920::new);
p_14514_.addFixer(new NewVillageFix(schema82, false));
p_14514_.addFixer(new AddNewChoices(schema82, "Add campfire", References.BLOCK_ENTITY));
Schema schema83 = p_14514_.addSchema(1925, SAME_NAMESPACED);
p_14514_.addFixer(new MapIdFix(schema83, false));
Schema schema84 = p_14514_.addSchema(1928, V1928::new);
p_14514_.addFixer(new EntityRavagerRenameFix(schema84, true));
p_14514_.addFixer(ItemRenameFix.create(schema84, "Rename ravager egg item", createRenamer(EntityRavagerRenameFix.RENAMED_IDS)));
Schema schema85 = p_14514_.addSchema(1929, V1929::new);
p_14514_.addFixer(new AddNewChoices(schema85, "Add Wandering Trader and Trader Llama", References.ENTITY));
Schema schema86 = p_14514_.addSchema(1931, V1931::new);
p_14514_.addFixer(new AddNewChoices(schema86, "Added Fox", References.ENTITY));
Schema schema87 = p_14514_.addSchema(1936, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsAddTextBackgroundFix(schema87, false));
Schema schema88 = p_14514_.addSchema(1946, SAME_NAMESPACED);
p_14514_.addFixer(new ReorganizePoi(schema88, false));
Schema schema89 = p_14514_.addSchema(1948, SAME_NAMESPACED);
p_14514_.addFixer(new OminousBannerRenameFix(schema89));
Schema schema90 = p_14514_.addSchema(1953, SAME_NAMESPACED);
p_14514_.addFixer(new OminousBannerBlockEntityRenameFix(schema90, false));
Schema schema91 = p_14514_.addSchema(1955, SAME_NAMESPACED);
p_14514_.addFixer(new VillagerRebuildLevelAndXpFix(schema91, false));
p_14514_.addFixer(new ZombieVillagerRebuildXpFix(schema91, false));
Schema schema92 = p_14514_.addSchema(1961, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkLightRemoveFix(schema92, false));
Schema schema93 = p_14514_.addSchema(1963, SAME_NAMESPACED);
p_14514_.addFixer(new RemoveGolemGossipFix(schema93, false));
Schema schema94 = p_14514_.addSchema(2100, V2100::new);
p_14514_.addFixer(new AddNewChoices(schema94, "Added Bee and Bee Stinger", References.ENTITY));
p_14514_.addFixer(new AddNewChoices(schema94, "Add beehive", References.BLOCK_ENTITY));
p_14514_.addFixer(new NamespacedTypeRenameFix(schema94, "Rename sugar recipe", References.RECIPE, createRenamer("minecraft:sugar", "sugar_from_sugar_cane")));
p_14514_.addFixer(new AdvancementsRenameFix(schema94, false, "Rename sugar recipe advancement", createRenamer("minecraft:recipes/misc/sugar", "minecraft:recipes/misc/sugar_from_sugar_cane")));
Schema schema95 = p_14514_.addSchema(2202, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkBiomeFix(schema95, false));
Schema schema96 = p_14514_.addSchema(2209, SAME_NAMESPACED);
UnaryOperator<String> unaryoperator = createRenamer("minecraft:bee_hive", "minecraft:beehive");
p_14514_.addFixer(ItemRenameFix.create(schema96, "Rename bee_hive item to beehive", unaryoperator));
p_14514_.addFixer(new PoiTypeRenameFix(schema96, "Rename bee_hive poi to beehive", unaryoperator));
p_14514_.addFixer(BlockRenameFix.create(schema96, "Rename bee_hive block to beehive", unaryoperator));
Schema schema97 = p_14514_.addSchema(2211, SAME_NAMESPACED);
p_14514_.addFixer(new StructureReferenceCountFix(schema97, false));
Schema schema98 = p_14514_.addSchema(2218, SAME_NAMESPACED);
p_14514_.addFixer(new ForcePoiRebuild(schema98, false));
Schema schema99 = p_14514_.addSchema(2501, V2501::new);
p_14514_.addFixer(new FurnaceRecipeFix(schema99, true));
Schema schema100 = p_14514_.addSchema(2502, V2502::new);
p_14514_.addFixer(new AddNewChoices(schema100, "Added Hoglin", References.ENTITY));
Schema schema101 = p_14514_.addSchema(2503, SAME_NAMESPACED);
p_14514_.addFixer(new WallPropertyFix(schema101, false));
p_14514_.addFixer(new AdvancementsRenameFix(schema101, false, "Composter category change", createRenamer("minecraft:recipes/misc/composter", "minecraft:recipes/decorations/composter")));
Schema schema102 = p_14514_.addSchema(2505, V2505::new);
p_14514_.addFixer(new AddNewChoices(schema102, "Added Piglin", References.ENTITY));
p_14514_.addFixer(new MemoryExpiryDataFix(schema102, "minecraft:villager"));
Schema schema103 = p_14514_.addSchema(2508, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema103, "Renamed fungi items to fungus", createRenamer(ImmutableMap.of("minecraft:warped_fungi", "minecraft:warped_fungus", "minecraft:crimson_fungi", "minecraft:crimson_fungus"))));
p_14514_.addFixer(BlockRenameFix.create(schema103, "Renamed fungi blocks to fungus", createRenamer(ImmutableMap.of("minecraft:warped_fungi", "minecraft:warped_fungus", "minecraft:crimson_fungi", "minecraft:crimson_fungus"))));
Schema schema104 = p_14514_.addSchema(2509, V2509::new);
p_14514_.addFixer(new EntityZombifiedPiglinRenameFix(schema104));
p_14514_.addFixer(ItemRenameFix.create(schema104, "Rename zombie pigman egg item", createRenamer(EntityZombifiedPiglinRenameFix.RENAMED_IDS)));
Schema schema105 = p_14514_.addSchema(2511, SAME_NAMESPACED);
p_14514_.addFixer(new EntityProjectileOwnerFix(schema105));
Schema schema106 = p_14514_.addSchema(2514, SAME_NAMESPACED);
p_14514_.addFixer(new EntityUUIDFix(schema106));
p_14514_.addFixer(new BlockEntityUUIDFix(schema106));
p_14514_.addFixer(new PlayerUUIDFix(schema106));
p_14514_.addFixer(new LevelUUIDFix(schema106));
p_14514_.addFixer(new SavedDataUUIDFix(schema106));
p_14514_.addFixer(new ItemStackUUIDFix(schema106));
Schema schema107 = p_14514_.addSchema(2516, SAME_NAMESPACED);
p_14514_.addFixer(new GossipUUIDFix(schema107, "minecraft:villager"));
p_14514_.addFixer(new GossipUUIDFix(schema107, "minecraft:zombie_villager"));
Schema schema108 = p_14514_.addSchema(2518, SAME_NAMESPACED);
p_14514_.addFixer(new JigsawPropertiesFix(schema108, false));
p_14514_.addFixer(new JigsawRotationFix(schema108, false));
Schema schema109 = p_14514_.addSchema(2519, V2519::new);
p_14514_.addFixer(new AddNewChoices(schema109, "Added Strider", References.ENTITY));
Schema schema110 = p_14514_.addSchema(2522, V2522::new);
p_14514_.addFixer(new AddNewChoices(schema110, "Added Zoglin", References.ENTITY));
Schema schema111 = p_14514_.addSchema(2523, SAME_NAMESPACED);
p_14514_.addFixer(new AttributesRename(schema111));
Schema schema112 = p_14514_.addSchema(2527, SAME_NAMESPACED);
p_14514_.addFixer(new BitStorageAlignFix(schema112));
Schema schema113 = p_14514_.addSchema(2528, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema113, "Rename soul fire torch and soul fire lantern", createRenamer(ImmutableMap.of("minecraft:soul_fire_torch", "minecraft:soul_torch", "minecraft:soul_fire_lantern", "minecraft:soul_lantern"))));
p_14514_.addFixer(BlockRenameFix.create(schema113, "Rename soul fire torch and soul fire lantern", createRenamer(ImmutableMap.of("minecraft:soul_fire_torch", "minecraft:soul_torch", "minecraft:soul_fire_wall_torch", "minecraft:soul_wall_torch", "minecraft:soul_fire_lantern", "minecraft:soul_lantern"))));
Schema schema114 = p_14514_.addSchema(2529, SAME_NAMESPACED);
p_14514_.addFixer(new StriderGravityFix(schema114, false));
Schema schema115 = p_14514_.addSchema(2531, SAME_NAMESPACED);
p_14514_.addFixer(new RedstoneWireConnectionsFix(schema115));
Schema schema116 = p_14514_.addSchema(2533, SAME_NAMESPACED);
p_14514_.addFixer(new VillagerFollowRangeFix(schema116));
Schema schema117 = p_14514_.addSchema(2535, SAME_NAMESPACED);
p_14514_.addFixer(new EntityShulkerRotationFix(schema117));
Schema schema118 = p_14514_.addSchema(2550, SAME_NAMESPACED);
p_14514_.addFixer(new WorldGenSettingsFix(schema118));
Schema schema119 = p_14514_.addSchema(2551, V2551::new);
p_14514_.addFixer(new WriteAndReadFix(schema119, "add types to WorldGenData", References.WORLD_GEN_SETTINGS));
Schema schema120 = p_14514_.addSchema(2552, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema120, "Nether biome rename", References.BIOME, createRenamer("minecraft:nether", "minecraft:nether_wastes")));
Schema schema121 = p_14514_.addSchema(2553, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema121, "Biomes fix", References.BIOME, createRenamer(BiomeFix.BIOMES)));
Schema schema122 = p_14514_.addSchema(2558, SAME_NAMESPACED);
p_14514_.addFixer(new MissingDimensionFix(schema122, false));
p_14514_.addFixer(new OptionsRenameFieldFix(schema122, false, "Rename swapHands setting", "key_key.swapHands", "key_key.swapOffhand"));
Schema schema123 = p_14514_.addSchema(2568, V2568::new);
p_14514_.addFixer(new AddNewChoices(schema123, "Added Piglin Brute", References.ENTITY));
Schema schema124 = p_14514_.addSchema(2571, V2571::new);
p_14514_.addFixer(new AddNewChoices(schema124, "Added Goat", References.ENTITY));
Schema schema125 = p_14514_.addSchema(2679, SAME_NAMESPACED);
p_14514_.addFixer(new CauldronRenameFix(schema125, false));
Schema schema126 = p_14514_.addSchema(2680, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema126, "Renamed grass path item to dirt path", createRenamer("minecraft:grass_path", "minecraft:dirt_path")));
p_14514_.addFixer(BlockRenameFixWithJigsaw.create(schema126, "Renamed grass path block to dirt path", createRenamer("minecraft:grass_path", "minecraft:dirt_path")));
Schema schema127 = p_14514_.addSchema(2684, V2684::new);
p_14514_.addFixer(new AddNewChoices(schema127, "Added Sculk Sensor", References.BLOCK_ENTITY));
Schema schema128 = p_14514_.addSchema(2686, V2686::new);
p_14514_.addFixer(new AddNewChoices(schema128, "Added Axolotl", References.ENTITY));
Schema schema129 = p_14514_.addSchema(2688, V2688::new);
p_14514_.addFixer(new AddNewChoices(schema129, "Added Glow Squid", References.ENTITY));
p_14514_.addFixer(new AddNewChoices(schema129, "Added Glow Item Frame", References.ENTITY));
Schema schema130 = p_14514_.addSchema(2690, SAME_NAMESPACED);
ImmutableMap<String, String> immutablemap = ImmutableMap.<String, String>builder().put("minecraft:weathered_copper_block", "minecraft:oxidized_copper_block").put("minecraft:semi_weathered_copper_block", "minecraft:weathered_copper_block").put("minecraft:lightly_weathered_copper_block", "minecraft:exposed_copper_block").put("minecraft:weathered_cut_copper", "minecraft:oxidized_cut_copper").put("minecraft:semi_weathered_cut_copper", "minecraft:weathered_cut_copper").put("minecraft:lightly_weathered_cut_copper", "minecraft:exposed_cut_copper").put("minecraft:weathered_cut_copper_stairs", "minecraft:oxidized_cut_copper_stairs").put("minecraft:semi_weathered_cut_copper_stairs", "minecraft:weathered_cut_copper_stairs").put("minecraft:lightly_weathered_cut_copper_stairs", "minecraft:exposed_cut_copper_stairs").put("minecraft:weathered_cut_copper_slab", "minecraft:oxidized_cut_copper_slab").put("minecraft:semi_weathered_cut_copper_slab", "minecraft:weathered_cut_copper_slab").put("minecraft:lightly_weathered_cut_copper_slab", "minecraft:exposed_cut_copper_slab").put("minecraft:waxed_semi_weathered_copper", "minecraft:waxed_weathered_copper").put("minecraft:waxed_lightly_weathered_copper", "minecraft:waxed_exposed_copper").put("minecraft:waxed_semi_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper").put("minecraft:waxed_lightly_weathered_cut_copper", "minecraft:waxed_exposed_cut_copper").put("minecraft:waxed_semi_weathered_cut_copper_stairs", "minecraft:waxed_weathered_cut_copper_stairs").put("minecraft:waxed_lightly_weathered_cut_copper_stairs", "minecraft:waxed_exposed_cut_copper_stairs").put("minecraft:waxed_semi_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_slab").put("minecraft:waxed_lightly_weathered_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_slab").build();
p_14514_.addFixer(ItemRenameFix.create(schema130, "Renamed copper block items to new oxidized terms", createRenamer(immutablemap)));
p_14514_.addFixer(BlockRenameFixWithJigsaw.create(schema130, "Renamed copper blocks to new oxidized terms", createRenamer(immutablemap)));
Schema schema131 = p_14514_.addSchema(2691, SAME_NAMESPACED);
ImmutableMap<String, String> immutablemap1 = ImmutableMap.<String, String>builder().put("minecraft:waxed_copper", "minecraft:waxed_copper_block").put("minecraft:oxidized_copper_block", "minecraft:oxidized_copper").put("minecraft:weathered_copper_block", "minecraft:weathered_copper").put("minecraft:exposed_copper_block", "minecraft:exposed_copper").build();
p_14514_.addFixer(ItemRenameFix.create(schema131, "Rename copper item suffixes", createRenamer(immutablemap1)));
p_14514_.addFixer(BlockRenameFixWithJigsaw.create(schema131, "Rename copper blocks suffixes", createRenamer(immutablemap1)));
Schema schema132 = p_14514_.addSchema(2693, SAME_NAMESPACED);
p_14514_.addFixer(new AddFlagIfNotPresentFix(schema132, References.WORLD_GEN_SETTINGS, "has_increased_height_already", false));
Schema schema133 = p_14514_.addSchema(2696, SAME_NAMESPACED);
ImmutableMap<String, String> immutablemap2 = ImmutableMap.<String, String>builder().put("minecraft:grimstone", "minecraft:deepslate").put("minecraft:grimstone_slab", "minecraft:cobbled_deepslate_slab").put("minecraft:grimstone_stairs", "minecraft:cobbled_deepslate_stairs").put("minecraft:grimstone_wall", "minecraft:cobbled_deepslate_wall").put("minecraft:polished_grimstone", "minecraft:polished_deepslate").put("minecraft:polished_grimstone_slab", "minecraft:polished_deepslate_slab").put("minecraft:polished_grimstone_stairs", "minecraft:polished_deepslate_stairs").put("minecraft:polished_grimstone_wall", "minecraft:polished_deepslate_wall").put("minecraft:grimstone_tiles", "minecraft:deepslate_tiles").put("minecraft:grimstone_tile_slab", "minecraft:deepslate_tile_slab").put("minecraft:grimstone_tile_stairs", "minecraft:deepslate_tile_stairs").put("minecraft:grimstone_tile_wall", "minecraft:deepslate_tile_wall").put("minecraft:grimstone_bricks", "minecraft:deepslate_bricks").put("minecraft:grimstone_brick_slab", "minecraft:deepslate_brick_slab").put("minecraft:grimstone_brick_stairs", "minecraft:deepslate_brick_stairs").put("minecraft:grimstone_brick_wall", "minecraft:deepslate_brick_wall").put("minecraft:chiseled_grimstone", "minecraft:chiseled_deepslate").build();
p_14514_.addFixer(ItemRenameFix.create(schema133, "Renamed grimstone block items to deepslate", createRenamer(immutablemap2)));
p_14514_.addFixer(BlockRenameFixWithJigsaw.create(schema133, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2)));
Schema schema134 = p_14514_.addSchema(2700, SAME_NAMESPACED);
p_14514_.addFixer(BlockRenameFixWithJigsaw.create(schema134, "Renamed cave vines blocks", createRenamer(ImmutableMap.of("minecraft:cave_vines_head", "minecraft:cave_vines", "minecraft:cave_vines_body", "minecraft:cave_vines_plant"))));
Schema schema135 = p_14514_.addSchema(2701, SAME_NAMESPACED);
p_14514_.addFixer(new SavedDataFeaturePoolElementFix(schema135));
Schema schema136 = p_14514_.addSchema(2702, SAME_NAMESPACED);
p_14514_.addFixer(new AbstractArrowPickupFix(schema136));
Schema schema137 = p_14514_.addSchema(2704, V2704::new);
p_14514_.addFixer(new AddNewChoices(schema137, "Added Goat", References.ENTITY));
Schema schema138 = p_14514_.addSchema(2707, V2707::new);
p_14514_.addFixer(new AddNewChoices(schema138, "Added Marker", References.ENTITY));
p_14514_.addFixer(new AddFlagIfNotPresentFix(schema138, References.WORLD_GEN_SETTINGS, "has_increased_height_already", true));
Schema schema139 = p_14514_.addSchema(2710, SAME_NAMESPACED);
p_14514_.addFixer(new StatsRenameFix(schema139, "Renamed play_one_minute stat to play_time", ImmutableMap.of("minecraft:play_one_minute", "minecraft:play_time")));
Schema schema140 = p_14514_.addSchema(2717, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema140, "Rename azalea_leaves_flowers", createRenamer(ImmutableMap.of("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves"))));
p_14514_.addFixer(BlockRenameFix.create(schema140, "Rename azalea_leaves_flowers items", createRenamer(ImmutableMap.of("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves"))));
Schema schema141 = p_14514_.addSchema(2825, SAME_NAMESPACED);
p_14514_.addFixer(new AddFlagIfNotPresentFix(schema141, References.WORLD_GEN_SETTINGS, "has_increased_height_already", false));
Schema schema142 = p_14514_.addSchema(2831, V2831::new);
p_14514_.addFixer(new SpawnerDataFix(schema142));
Schema schema143 = p_14514_.addSchema(2832, V2832::new);
p_14514_.addFixer(new WorldGenSettingsHeightAndBiomeFix(schema143));
p_14514_.addFixer(new ChunkHeightAndBiomeFix(schema143));
Schema schema144 = p_14514_.addSchema(2833, SAME_NAMESPACED);
p_14514_.addFixer(new WorldGenSettingsDisallowOldCustomWorldsFix(schema144));
Schema schema145 = p_14514_.addSchema(2838, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema145, "Caves and Cliffs biome renames", References.BIOME, createRenamer(CavesAndCliffsRenames.RENAMES)));
Schema schema146 = p_14514_.addSchema(2841, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkProtoTickListFix(schema146));
Schema schema147 = p_14514_.addSchema(2842, V2842::new);
p_14514_.addFixer(new ChunkRenamesFix(schema147));
Schema schema148 = p_14514_.addSchema(2843, SAME_NAMESPACED);
p_14514_.addFixer(new OverreachingTickFix(schema148));
p_14514_.addFixer(new NamespacedTypeRenameFix(schema148, "Remove Deep Warm Ocean", References.BIOME, createRenamer("minecraft:deep_warm_ocean", "minecraft:warm_ocean")));
Schema schema149 = p_14514_.addSchema(2846, SAME_NAMESPACED);
p_14514_.addFixer(new AdvancementsRenameFix(schema149, false, "Rename some C&C part 2 advancements", createRenamer(ImmutableMap.of("minecraft:husbandry/play_jukebox_in_meadows", "minecraft:adventure/play_jukebox_in_meadows", "minecraft:adventure/caves_and_cliff", "minecraft:adventure/fall_from_world_height", "minecraft:adventure/ride_strider_in_overworld_lava", "minecraft:nether/ride_strider_in_overworld_lava"))));
Schema schema150 = p_14514_.addSchema(2852, SAME_NAMESPACED);
p_14514_.addFixer(new WorldGenSettingsDisallowOldCustomWorldsFix(schema150));
Schema schema151 = p_14514_.addSchema(2967, SAME_NAMESPACED);
p_14514_.addFixer(new StructureSettingsFlattenFix(schema151));
Schema schema152 = p_14514_.addSchema(2970, SAME_NAMESPACED);
p_14514_.addFixer(new StructuresBecomeConfiguredFix(schema152));
Schema schema153 = p_14514_.addSchema(3076, V3076::new);
p_14514_.addFixer(new AddNewChoices(schema153, "Added Sculk Catalyst", References.BLOCK_ENTITY));
Schema schema154 = p_14514_.addSchema(3077, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkDeleteIgnoredLightDataFix(schema154));
Schema schema155 = p_14514_.addSchema(3078, V3078::new);
p_14514_.addFixer(new AddNewChoices(schema155, "Added Frog", References.ENTITY));
p_14514_.addFixer(new AddNewChoices(schema155, "Added Tadpole", References.ENTITY));
p_14514_.addFixer(new AddNewChoices(schema155, "Added Sculk Shrieker", References.BLOCK_ENTITY));
Schema schema156 = p_14514_.addSchema(3081, V3081::new);
p_14514_.addFixer(new AddNewChoices(schema156, "Added Warden", References.ENTITY));
Schema schema157 = p_14514_.addSchema(3082, V3082::new);
p_14514_.addFixer(new AddNewChoices(schema157, "Added Chest Boat", References.ENTITY));
Schema schema158 = p_14514_.addSchema(3083, V3083::new);
p_14514_.addFixer(new AddNewChoices(schema158, "Added Allay", References.ENTITY));
Schema schema159 = p_14514_.addSchema(3084, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema159, "game_event_renames_3084", References.GAME_EVENT_NAME, createRenamer(ImmutableMap.<String, String>builder().put("minecraft:block_press", "minecraft:block_activate").put("minecraft:block_switch", "minecraft:block_activate").put("minecraft:block_unpress", "minecraft:block_deactivate").put("minecraft:block_unswitch", "minecraft:block_deactivate").put("minecraft:drinking_finish", "minecraft:drink").put("minecraft:elytra_free_fall", "minecraft:elytra_glide").put("minecraft:entity_damaged", "minecraft:entity_damage").put("minecraft:entity_dying", "minecraft:entity_die").put("minecraft:entity_killed", "minecraft:entity_die").put("minecraft:mob_interact", "minecraft:entity_interact").put("minecraft:ravager_roar", "minecraft:entity_roar").put("minecraft:ring_bell", "minecraft:block_change").put("minecraft:shulker_close", "minecraft:container_close").put("minecraft:shulker_open", "minecraft:container_open").put("minecraft:wolf_shaking", "minecraft:entity_shake").build())));
Schema schema160 = p_14514_.addSchema(3086, SAME_NAMESPACED);
p_14514_.addFixer(new EntityVariantFix(schema160, "Change cat variant type", References.ENTITY, "minecraft:cat", "CatType", Util.make(new Int2ObjectOpenHashMap<String>(), (p_216528_) -> {
p_216528_.defaultReturnValue("minecraft:tabby");
p_216528_.put(0, "minecraft:tabby");
p_216528_.put(1, "minecraft:black");
p_216528_.put(2, "minecraft:red");
p_216528_.put(3, "minecraft:siamese");
p_216528_.put(4, "minecraft:british");
p_216528_.put(5, "minecraft:calico");
p_216528_.put(6, "minecraft:persian");
p_216528_.put(7, "minecraft:ragdoll");
p_216528_.put(8, "minecraft:white");
p_216528_.put(9, "minecraft:jellie");
p_216528_.put(10, "minecraft:all_black");
})::get));
ImmutableMap<String, String> immutablemap3 = ImmutableMap.<String, String>builder().put("textures/entity/cat/tabby.png", "minecraft:tabby").put("textures/entity/cat/black.png", "minecraft:black").put("textures/entity/cat/red.png", "minecraft:red").put("textures/entity/cat/siamese.png", "minecraft:siamese").put("textures/entity/cat/british_shorthair.png", "minecraft:british").put("textures/entity/cat/calico.png", "minecraft:calico").put("textures/entity/cat/persian.png", "minecraft:persian").put("textures/entity/cat/ragdoll.png", "minecraft:ragdoll").put("textures/entity/cat/white.png", "minecraft:white").put("textures/entity/cat/jellie.png", "minecraft:jellie").put("textures/entity/cat/all_black.png", "minecraft:all_black").build();
p_14514_.addFixer(new CriteriaRenameFix(schema160, "Migrate cat variant advancement", "minecraft:husbandry/complete_catalogue", (p_216517_) -> {
return immutablemap3.getOrDefault(p_216517_, p_216517_);
}));
Schema schema161 = p_14514_.addSchema(3087, SAME_NAMESPACED);
p_14514_.addFixer(new EntityVariantFix(schema161, "Change frog variant type", References.ENTITY, "minecraft:frog", "Variant", Util.make(new Int2ObjectOpenHashMap<String>(), (p_216519_) -> {
p_216519_.put(0, "minecraft:temperate");
p_216519_.put(1, "minecraft:warm");
p_216519_.put(2, "minecraft:cold");
})::get));
Schema schema162 = p_14514_.addSchema(3090, SAME_NAMESPACED);
p_14514_.addFixer(new EntityPaintingFieldsRenameFix(schema162));
Schema schema163 = p_14514_.addSchema(3093, SAME_NAMESPACED);
p_14514_.addFixer(new EntityGoatMissingStateFix(schema163));
Schema schema164 = p_14514_.addSchema(3094, SAME_NAMESPACED);
p_14514_.addFixer(new GoatHornIdFix(schema164));
Schema schema165 = p_14514_.addSchema(3097, SAME_NAMESPACED);
p_14514_.addFixer(new FilteredBooksFix(schema165));
p_14514_.addFixer(new FilteredSignsFix(schema165));
Map<String, String> map = Map.of("minecraft:british", "minecraft:british_shorthair");
p_14514_.addFixer(new VariantRenameFix(schema165, "Rename british shorthair", References.ENTITY, "minecraft:cat", map));
p_14514_.addFixer(new CriteriaRenameFix(schema165, "Migrate cat variant advancement for british shorthair", "minecraft:husbandry/complete_catalogue", (p_216531_) -> {
return map.getOrDefault(p_216531_, p_216531_);
}));
p_14514_.addFixer(new PoiTypeRemoveFix(schema165, "Remove unpopulated villager PoI types", Set.of("minecraft:unemployed", "minecraft:nitwit")::contains));
Schema schema166 = p_14514_.addSchema(3108, SAME_NAMESPACED);
p_14514_.addFixer(new BlendingDataRemoveFromNetherEndFix(schema166));
Schema schema167 = p_14514_.addSchema(3201, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsProgrammerArtFix(schema167));
Schema schema168 = p_14514_.addSchema(3202, V3202::new);
p_14514_.addFixer(new AddNewChoices(schema168, "Added Hanging Sign", References.BLOCK_ENTITY));
Schema schema169 = p_14514_.addSchema(3203, V3203::new);
p_14514_.addFixer(new AddNewChoices(schema169, "Added Camel", References.ENTITY));
Schema schema170 = p_14514_.addSchema(3204, V3204::new);
p_14514_.addFixer(new AddNewChoices(schema170, "Added Chiseled Bookshelf", References.BLOCK_ENTITY));
Schema schema171 = p_14514_.addSchema(3209, SAME_NAMESPACED);
p_14514_.addFixer(new ItemStackSpawnEggFix(schema171, false, "minecraft:pig_spawn_egg"));
Schema schema172 = p_14514_.addSchema(3214, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsAmbientOcclusionFix(schema172));
Schema schema173 = p_14514_.addSchema(3319, SAME_NAMESPACED);
p_14514_.addFixer(new OptionsAccessibilityOnboardFix(schema173));
Schema schema174 = p_14514_.addSchema(3322, SAME_NAMESPACED);
p_14514_.addFixer(new EffectDurationFix(schema174));
Schema schema175 = p_14514_.addSchema(3325, V3325::new);
p_14514_.addFixer(new AddNewChoices(schema175, "Added displays", References.ENTITY));
Schema schema176 = p_14514_.addSchema(3326, V3326::new);
p_14514_.addFixer(new AddNewChoices(schema176, "Added Sniffer", References.ENTITY));
Schema schema177 = p_14514_.addSchema(3327, V3327::new);
p_14514_.addFixer(new AddNewChoices(schema177, "Archaeology", References.BLOCK_ENTITY));
Schema schema178 = p_14514_.addSchema(3328, V3328::new);
p_14514_.addFixer(new AddNewChoices(schema178, "Added interaction", References.ENTITY));
Schema schema179 = p_14514_.addSchema(3438, V3438::new);
p_14514_.addFixer(BlockEntityRenameFix.create(schema179, "Rename Suspicious Sand to Brushable Block", createRenamer("minecraft:suspicious_sand", "minecraft:brushable_block")));
p_14514_.addFixer(new EntityBrushableBlockFieldsRenameFix(schema179));
p_14514_.addFixer(ItemRenameFix.create(schema179, "Pottery shard renaming", createRenamer(ImmutableMap.of("minecraft:pottery_shard_archer", "minecraft:archer_pottery_shard", "minecraft:pottery_shard_prize", "minecraft:prize_pottery_shard", "minecraft:pottery_shard_arms_up", "minecraft:arms_up_pottery_shard", "minecraft:pottery_shard_skull", "minecraft:skull_pottery_shard"))));
p_14514_.addFixer(new AddNewChoices(schema179, "Added calibrated sculk sensor", References.BLOCK_ENTITY));
Schema schema180 = p_14514_.addSchema(3439, SAME_NAMESPACED);
p_14514_.addFixer(new BlockEntitySignDoubleSidedEditableTextFix(schema180, "Updated sign text format for Signs", "minecraft:sign"));
p_14514_.addFixer(new BlockEntitySignDoubleSidedEditableTextFix(schema180, "Updated sign text format for Hanging Signs", "minecraft:hanging_sign"));
Schema schema181 = p_14514_.addSchema(3440, SAME_NAMESPACED);
p_14514_.addFixer(new NamespacedTypeRenameFix(schema181, "Replace experimental 1.20 overworld", References.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST, createRenamer("minecraft:overworld_update_1_20", "minecraft:overworld")));
p_14514_.addFixer(new FeatureFlagRemoveFix(schema181, "Remove 1.20 feature toggle", Set.of("minecraft:update_1_20")));
Schema schema182 = p_14514_.addSchema(3441, SAME_NAMESPACED);
p_14514_.addFixer(new BlendingDataFix(schema182));
Schema schema183 = p_14514_.addSchema(3447, SAME_NAMESPACED);
p_14514_.addFixer(ItemRenameFix.create(schema183, "Pottery shard item renaming to Pottery sherd", createRenamer(Stream.of("minecraft:angler_pottery_shard", "minecraft:archer_pottery_shard", "minecraft:arms_up_pottery_shard", "minecraft:blade_pottery_shard", "minecraft:brewer_pottery_shard", "minecraft:burn_pottery_shard", "minecraft:danger_pottery_shard", "minecraft:explorer_pottery_shard", "minecraft:friend_pottery_shard", "minecraft:heart_pottery_shard", "minecraft:heartbreak_pottery_shard", "minecraft:howl_pottery_shard", "minecraft:miner_pottery_shard", "minecraft:mourner_pottery_shard", "minecraft:plenty_pottery_shard", "minecraft:prize_pottery_shard", "minecraft:sheaf_pottery_shard", "minecraft:shelter_pottery_shard", "minecraft:skull_pottery_shard", "minecraft:snort_pottery_shard").collect(Collectors.toMap(Function.identity(), (p_280993_) -> {
return p_280993_.replace("_pottery_shard", "_pottery_sherd");
})))));
Schema schema184 = p_14514_.addSchema(3448, V3448::new);
p_14514_.addFixer(new DecoratedPotFieldRenameFix(schema184));
Schema schema185 = p_14514_.addSchema(3450, SAME_NAMESPACED);
p_14514_.addFixer(new RemapChunkStatusFix(schema185, "Remove liquid_carvers and heightmap chunk statuses", createRenamer(Map.of("minecraft:liquid_carvers", "minecraft:carvers", "minecraft:heightmaps", "minecraft:spawn"))));
Schema schema186 = p_14514_.addSchema(3451, SAME_NAMESPACED);
p_14514_.addFixer(new ChunkDeleteLightFix(schema186));
Schema schema187 = p_14514_.addSchema(3459, SAME_NAMESPACED);
p_14514_.addFixer(new LegacyDragonFightFix(schema187));
}
private static UnaryOperator<String> createRenamer(Map<String, String> p_14525_) {
return (p_216526_) -> {
return p_14525_.getOrDefault(p_216526_, p_216526_);
};
}
private static UnaryOperator<String> createRenamer(String p_14518_, String p_14519_) {
return (p_216523_) -> {
return Objects.equals(p_216523_, p_14518_) ? p_14519_ : p_216523_;
};
}
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.util.datafix;
import net.minecraft.util.Mth;
import org.apache.commons.lang3.Validate;
public class PackedBitStorage {
private static final int BIT_TO_LONG_SHIFT = 6;
private final long[] data;
private final int bits;
private final long mask;
private final int size;
public PackedBitStorage(int p_14555_, int p_14556_) {
this(p_14555_, p_14556_, new long[Mth.roundToward(p_14556_ * p_14555_, 64) / 64]);
}
public PackedBitStorage(int p_14558_, int p_14559_, long[] p_14560_) {
Validate.inclusiveBetween(1L, 32L, (long)p_14558_);
this.size = p_14559_;
this.bits = p_14558_;
this.data = p_14560_;
this.mask = (1L << p_14558_) - 1L;
int i = Mth.roundToward(p_14559_ * p_14558_, 64) / 64;
if (p_14560_.length != i) {
throw new IllegalArgumentException("Invalid length given for storage, got: " + p_14560_.length + " but expected: " + i);
}
}
public void set(int p_14565_, int p_14566_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_14565_);
Validate.inclusiveBetween(0L, this.mask, (long)p_14566_);
int i = p_14565_ * this.bits;
int j = i >> 6;
int k = (p_14565_ + 1) * this.bits - 1 >> 6;
int l = i ^ j << 6;
this.data[j] = this.data[j] & ~(this.mask << l) | ((long)p_14566_ & this.mask) << l;
if (j != k) {
int i1 = 64 - l;
int j1 = this.bits - i1;
this.data[k] = this.data[k] >>> j1 << j1 | ((long)p_14566_ & this.mask) >> i1;
}
}
public int get(int p_14563_) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)p_14563_);
int i = p_14563_ * this.bits;
int j = i >> 6;
int k = (p_14563_ + 1) * this.bits - 1 >> 6;
int l = i ^ j << 6;
if (j == k) {
return (int)(this.data[j] >>> l & this.mask);
} else {
int i1 = 64 - l;
return (int)((this.data[j] >>> l | this.data[k] << i1) & this.mask);
}
}
public long[] getRaw() {
return this.data;
}
public int getBits() {
return this.bits;
}
}

View File

@@ -0,0 +1,44 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
import java.util.function.Function;
public class AbstractArrowPickupFix extends DataFix {
public AbstractArrowPickupFix(Schema p_145046_) {
super(p_145046_, false);
}
protected TypeRewriteRule makeRule() {
Schema schema = this.getInputSchema();
return this.fixTypeEverywhereTyped("AbstractArrowPickupFix", schema.getType(References.ENTITY), this::updateProjectiles);
}
private Typed<?> updateProjectiles(Typed<?> p_145048_) {
p_145048_ = this.updateEntity(p_145048_, "minecraft:arrow", AbstractArrowPickupFix::updatePickup);
p_145048_ = this.updateEntity(p_145048_, "minecraft:spectral_arrow", AbstractArrowPickupFix::updatePickup);
return this.updateEntity(p_145048_, "minecraft:trident", AbstractArrowPickupFix::updatePickup);
}
private static Dynamic<?> updatePickup(Dynamic<?> p_145054_) {
if (p_145054_.get("pickup").result().isPresent()) {
return p_145054_;
} else {
boolean flag = p_145054_.get("player").asBoolean(true);
return p_145054_.set("pickup", p_145054_.createByte((byte)(flag ? 1 : 0))).remove("player");
}
}
private Typed<?> updateEntity(Typed<?> p_145050_, String p_145051_, Function<Dynamic<?>, Dynamic<?>> p_145052_) {
Type<?> type = this.getInputSchema().getChoiceType(References.ENTITY, p_145051_);
Type<?> type1 = this.getOutputSchema().getChoiceType(References.ENTITY, p_145051_);
return p_145050_.updateTyped(DSL.namedChoice(p_145051_, type), type1, (p_145057_) -> {
return p_145057_.update(DSL.remainderFinder(), p_145052_);
});
}
}

View File

@@ -0,0 +1,54 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Dynamic;
import java.util.Objects;
import java.util.stream.Stream;
public abstract class AbstractPoiSectionFix extends DataFix {
private final String name;
public AbstractPoiSectionFix(Schema p_216536_, String p_216537_) {
super(p_216536_, false);
this.name = p_216537_;
}
protected TypeRewriteRule makeRule() {
Type<Pair<String, Dynamic<?>>> type = DSL.named(References.POI_CHUNK.typeName(), DSL.remainderType());
if (!Objects.equals(type, this.getInputSchema().getType(References.POI_CHUNK))) {
throw new IllegalStateException("Poi type is not what was expected.");
} else {
return this.fixTypeEverywhere(this.name, type, (p_216546_) -> {
return (p_216549_) -> {
return p_216549_.mapSecond(this::cap);
};
});
}
}
private <T> Dynamic<T> cap(Dynamic<T> p_216541_) {
return p_216541_.update("Sections", (p_216555_) -> {
return p_216555_.updateMapValues((p_216539_) -> {
return p_216539_.mapSecond(this::processSection);
});
});
}
private Dynamic<?> processSection(Dynamic<?> p_216551_) {
return p_216551_.update("Records", this::processSectionRecords);
}
private <T> Dynamic<T> processSectionRecords(Dynamic<T> p_216553_) {
return DataFixUtils.orElse(p_216553_.asStreamOpt().result().map((p_216544_) -> {
return p_216553_.createList(this.processRecords(p_216544_));
}), p_216553_);
}
protected abstract <T> Stream<Dynamic<T>> processRecords(Stream<Dynamic<T>> p_216547_);
}

View File

@@ -0,0 +1,78 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
import java.util.Arrays;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
public abstract class AbstractUUIDFix extends DataFix {
protected DSL.TypeReference typeReference;
public AbstractUUIDFix(Schema p_14572_, DSL.TypeReference p_14573_) {
super(p_14572_, false);
this.typeReference = p_14573_;
}
protected Typed<?> updateNamedChoice(Typed<?> p_14575_, String p_14576_, Function<Dynamic<?>, Dynamic<?>> p_14577_) {
Type<?> type = this.getInputSchema().getChoiceType(this.typeReference, p_14576_);
Type<?> type1 = this.getOutputSchema().getChoiceType(this.typeReference, p_14576_);
return p_14575_.updateTyped(DSL.namedChoice(p_14576_, type), type1, (p_14607_) -> {
return p_14607_.update(DSL.remainderFinder(), p_14577_);
});
}
protected static Optional<Dynamic<?>> replaceUUIDString(Dynamic<?> p_14591_, String p_14592_, String p_14593_) {
return createUUIDFromString(p_14591_, p_14592_).map((p_14616_) -> {
return p_14591_.remove(p_14592_).set(p_14593_, p_14616_);
});
}
protected static Optional<Dynamic<?>> replaceUUIDMLTag(Dynamic<?> p_14609_, String p_14610_, String p_14611_) {
return p_14609_.get(p_14610_).result().flatMap(AbstractUUIDFix::createUUIDFromML).map((p_14598_) -> {
return p_14609_.remove(p_14610_).set(p_14611_, p_14598_);
});
}
protected static Optional<Dynamic<?>> replaceUUIDLeastMost(Dynamic<?> p_14618_, String p_14619_, String p_14620_) {
String s = p_14619_ + "Most";
String s1 = p_14619_ + "Least";
return createUUIDFromLongs(p_14618_, s, s1).map((p_14604_) -> {
return p_14618_.remove(s).remove(s1).set(p_14620_, p_14604_);
});
}
protected static Optional<Dynamic<?>> createUUIDFromString(Dynamic<?> p_14588_, String p_14589_) {
return p_14588_.get(p_14589_).result().flatMap((p_14586_) -> {
String s = p_14586_.asString((String)null);
if (s != null) {
try {
UUID uuid = UUID.fromString(s);
return createUUIDTag(p_14588_, uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
} catch (IllegalArgumentException illegalargumentexception) {
}
}
return Optional.empty();
});
}
protected static Optional<Dynamic<?>> createUUIDFromML(Dynamic<?> p_14579_) {
return createUUIDFromLongs(p_14579_, "M", "L");
}
protected static Optional<Dynamic<?>> createUUIDFromLongs(Dynamic<?> p_14622_, String p_14623_, String p_14624_) {
long i = p_14622_.get(p_14623_).asLong(0L);
long j = p_14622_.get(p_14624_).asLong(0L);
return i != 0L && j != 0L ? createUUIDTag(p_14622_, i, j) : Optional.empty();
}
protected static Optional<Dynamic<?>> createUUIDTag(Dynamic<?> p_14581_, long p_14582_, long p_14583_) {
return Optional.of(p_14581_.createIntList(Arrays.stream(new int[]{(int)(p_14582_ >> 32), (int)p_14582_, (int)(p_14583_ >> 32), (int)p_14583_})));
}
}

View File

@@ -0,0 +1,34 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
public class AddFlagIfNotPresentFix extends DataFix {
private final String name;
private final boolean flagValue;
private final String flagKey;
private final DSL.TypeReference typeReference;
public AddFlagIfNotPresentFix(Schema p_184810_, DSL.TypeReference p_184811_, String p_184812_, boolean p_184813_) {
super(p_184810_, true);
this.flagValue = p_184813_;
this.flagKey = p_184812_;
this.name = "AddFlagIfNotPresentFix_" + this.flagKey + "=" + this.flagValue + " for " + p_184810_.getVersionKey();
this.typeReference = p_184811_;
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(this.typeReference);
return this.fixTypeEverywhereTyped(this.name, type, (p_184815_) -> {
return p_184815_.update(DSL.remainderFinder(), (p_184817_) -> {
return p_184817_.set(this.flagKey, DataFixUtils.orElseGet(p_184817_.get(this.flagKey).result(), () -> {
return p_184817_.createBoolean(this.flagValue);
}));
});
});
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.templates.TaggedChoice;
import java.util.Locale;
public class AddNewChoices extends DataFix {
private final String name;
private final DSL.TypeReference type;
public AddNewChoices(Schema p_14628_, String p_14629_, DSL.TypeReference p_14630_) {
super(p_14628_, true);
this.name = p_14629_;
this.type = p_14630_;
}
public TypeRewriteRule makeRule() {
TaggedChoice.TaggedChoiceType<?> taggedchoicetype = this.getInputSchema().findChoiceType(this.type);
TaggedChoice.TaggedChoiceType<?> taggedchoicetype1 = this.getOutputSchema().findChoiceType(this.type);
return this.cap(this.name, taggedchoicetype, taggedchoicetype1);
}
protected final <K> TypeRewriteRule cap(String p_14638_, TaggedChoice.TaggedChoiceType<K> p_14639_, TaggedChoice.TaggedChoiceType<?> p_14640_) {
if (p_14639_.getKeyType() != p_14640_.getKeyType()) {
throw new IllegalStateException("Could not inject: key type is not the same");
} else {
return this.fixTypeEverywhere(p_14638_, p_14639_, (TaggedChoice.TaggedChoiceType<K>)p_14640_, (p_14636_) -> {
return (p_145061_) -> {
if (!((TaggedChoice.TaggedChoiceType<K>)p_14640_).hasType(p_145061_.getFirst())) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "Unknown type %s in %s ", p_145061_.getFirst(), this.type));
} else {
return p_145061_;
}
};
});
}
}
}

View File

@@ -0,0 +1,31 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import java.util.function.Function;
public class AdvancementsRenameFix extends DataFix {
private final String name;
private final Function<String, String> renamer;
public AdvancementsRenameFix(Schema p_14652_, boolean p_14653_, String p_14654_, Function<String, String> p_14655_) {
super(p_14652_, p_14653_);
this.name = p_14654_;
this.renamer = p_14655_;
}
protected TypeRewriteRule makeRule() {
return this.fixTypeEverywhereTyped(this.name, this.getInputSchema().getType(References.ADVANCEMENTS), (p_14657_) -> {
return p_14657_.update(DSL.remainderFinder(), (p_145063_) -> {
return p_145063_.updateMapValues((p_145066_) -> {
String s = p_145066_.getFirst().asString("");
return p_145066_.mapFirst((p_145070_) -> {
return p_145063_.createString(this.renamer.apply(s));
});
});
});
});
}
}

View File

@@ -0,0 +1,59 @@
package net.minecraft.util.datafix.fixes;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
import java.util.Map;
public class AttributesRename extends DataFix {
private static final Map<String, String> RENAMES = ImmutableMap.<String, String>builder().put("generic.maxHealth", "generic.max_health").put("Max Health", "generic.max_health").put("zombie.spawnReinforcements", "zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "zombie.spawn_reinforcements").put("horse.jumpStrength", "horse.jump_strength").put("Jump Strength", "horse.jump_strength").put("generic.followRange", "generic.follow_range").put("Follow Range", "generic.follow_range").put("generic.knockbackResistance", "generic.knockback_resistance").put("Knockback Resistance", "generic.knockback_resistance").put("generic.movementSpeed", "generic.movement_speed").put("Movement Speed", "generic.movement_speed").put("generic.flyingSpeed", "generic.flying_speed").put("Flying Speed", "generic.flying_speed").put("generic.attackDamage", "generic.attack_damage").put("generic.attackKnockback", "generic.attack_knockback").put("generic.attackSpeed", "generic.attack_speed").put("generic.armorToughness", "generic.armor_toughness").build();
public AttributesRename(Schema p_14671_) {
super(p_14671_, false);
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.ITEM_STACK);
OpticFinder<?> opticfinder = type.findField("tag");
return TypeRewriteRule.seq(this.fixTypeEverywhereTyped("Rename ItemStack Attributes", type, (p_14674_) -> {
return p_14674_.updateTyped(opticfinder, AttributesRename::fixItemStackTag);
}), this.fixTypeEverywhereTyped("Rename Entity Attributes", this.getInputSchema().getType(References.ENTITY), AttributesRename::fixEntity), this.fixTypeEverywhereTyped("Rename Player Attributes", this.getInputSchema().getType(References.PLAYER), AttributesRename::fixEntity));
}
private static Dynamic<?> fixName(Dynamic<?> p_14678_) {
return DataFixUtils.orElse(p_14678_.asString().result().map((p_14680_) -> {
return RENAMES.getOrDefault(p_14680_, p_14680_);
}).map(p_14678_::createString), p_14678_);
}
private static Typed<?> fixItemStackTag(Typed<?> p_14676_) {
return p_14676_.update(DSL.remainderFinder(), (p_14694_) -> {
return p_14694_.update("AttributeModifiers", (p_145080_) -> {
return DataFixUtils.orElse(p_145080_.asStreamOpt().result().map((p_145074_) -> {
return p_145074_.map((p_145082_) -> {
return p_145082_.update("AttributeName", AttributesRename::fixName);
});
}).map(p_145080_::createList), p_145080_);
});
});
}
private static Typed<?> fixEntity(Typed<?> p_14684_) {
return p_14684_.update(DSL.remainderFinder(), (p_14686_) -> {
return p_14686_.update("Attributes", (p_145076_) -> {
return DataFixUtils.orElse(p_145076_.asStreamOpt().result().map((p_145072_) -> {
return p_145072_.map((p_145078_) -> {
return p_145078_.update("Name", AttributesRename::fixName);
});
}).map(p_145076_::createList), p_145076_);
});
});
}
}

View File

@@ -0,0 +1,33 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Dynamic;
import java.util.Objects;
import java.util.Optional;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
public class BedItemColorFix extends DataFix {
public BedItemColorFix(Schema p_14720_, boolean p_14721_) {
super(p_14720_, p_14721_);
}
public TypeRewriteRule makeRule() {
OpticFinder<Pair<String, String>> opticfinder = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
return this.fixTypeEverywhereTyped("BedItemColorFix", this.getInputSchema().getType(References.ITEM_STACK), (p_14724_) -> {
Optional<Pair<String, String>> optional = p_14724_.getOptional(opticfinder);
if (optional.isPresent() && Objects.equals(optional.get().getSecond(), "minecraft:bed")) {
Dynamic<?> dynamic = p_14724_.get(DSL.remainderFinder());
if (dynamic.get("Damage").asInt(0) == 0) {
return p_14724_.set(DSL.remainderFinder(), dynamic.set("Damage", dynamic.createShort((short)14)));
}
}
return p_14724_;
});
}
}

View File

@@ -0,0 +1,8 @@
package net.minecraft.util.datafix.fixes;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
public class BiomeFix {
public static final Map<String, String> BIOMES = ImmutableMap.<String, String>builder().put("minecraft:extreme_hills", "minecraft:mountains").put("minecraft:swampland", "minecraft:swamp").put("minecraft:hell", "minecraft:nether_wastes").put("minecraft:sky", "minecraft:the_end").put("minecraft:ice_flats", "minecraft:snowy_tundra").put("minecraft:ice_mountains", "minecraft:snowy_mountains").put("minecraft:mushroom_island", "minecraft:mushroom_fields").put("minecraft:mushroom_island_shore", "minecraft:mushroom_field_shore").put("minecraft:beaches", "minecraft:beach").put("minecraft:forest_hills", "minecraft:wooded_hills").put("minecraft:smaller_extreme_hills", "minecraft:mountain_edge").put("minecraft:stone_beach", "minecraft:stone_shore").put("minecraft:cold_beach", "minecraft:snowy_beach").put("minecraft:roofed_forest", "minecraft:dark_forest").put("minecraft:taiga_cold", "minecraft:snowy_taiga").put("minecraft:taiga_cold_hills", "minecraft:snowy_taiga_hills").put("minecraft:redwood_taiga", "minecraft:giant_tree_taiga").put("minecraft:redwood_taiga_hills", "minecraft:giant_tree_taiga_hills").put("minecraft:extreme_hills_with_trees", "minecraft:wooded_mountains").put("minecraft:savanna_rock", "minecraft:savanna_plateau").put("minecraft:mesa", "minecraft:badlands").put("minecraft:mesa_rock", "minecraft:wooded_badlands_plateau").put("minecraft:mesa_clear_rock", "minecraft:badlands_plateau").put("minecraft:sky_island_low", "minecraft:small_end_islands").put("minecraft:sky_island_medium", "minecraft:end_midlands").put("minecraft:sky_island_high", "minecraft:end_highlands").put("minecraft:sky_island_barren", "minecraft:end_barrens").put("minecraft:void", "minecraft:the_void").put("minecraft:mutated_plains", "minecraft:sunflower_plains").put("minecraft:mutated_desert", "minecraft:desert_lakes").put("minecraft:mutated_extreme_hills", "minecraft:gravelly_mountains").put("minecraft:mutated_forest", "minecraft:flower_forest").put("minecraft:mutated_taiga", "minecraft:taiga_mountains").put("minecraft:mutated_swampland", "minecraft:swamp_hills").put("minecraft:mutated_ice_flats", "minecraft:ice_spikes").put("minecraft:mutated_jungle", "minecraft:modified_jungle").put("minecraft:mutated_jungle_edge", "minecraft:modified_jungle_edge").put("minecraft:mutated_birch_forest", "minecraft:tall_birch_forest").put("minecraft:mutated_birch_forest_hills", "minecraft:tall_birch_hills").put("minecraft:mutated_roofed_forest", "minecraft:dark_forest_hills").put("minecraft:mutated_taiga_cold", "minecraft:snowy_taiga_mountains").put("minecraft:mutated_redwood_taiga", "minecraft:giant_spruce_taiga").put("minecraft:mutated_redwood_taiga_hills", "minecraft:giant_spruce_taiga_hills").put("minecraft:mutated_extreme_hills_with_trees", "minecraft:modified_gravelly_mountains").put("minecraft:mutated_savanna", "minecraft:shattered_savanna").put("minecraft:mutated_savanna_rock", "minecraft:shattered_savanna_plateau").put("minecraft:mutated_mesa", "minecraft:eroded_badlands").put("minecraft:mutated_mesa_rock", "minecraft:modified_wooded_badlands_plateau").put("minecraft:mutated_mesa_clear_rock", "minecraft:modified_badlands_plateau").put("minecraft:warm_deep_ocean", "minecraft:deep_warm_ocean").put("minecraft:lukewarm_deep_ocean", "minecraft:deep_lukewarm_ocean").put("minecraft:cold_deep_ocean", "minecraft:deep_cold_ocean").put("minecraft:frozen_deep_ocean", "minecraft:deep_frozen_ocean").build();
}

View File

@@ -0,0 +1,131 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Dynamic;
import java.util.List;
import java.util.stream.LongStream;
import net.minecraft.util.Mth;
public class BitStorageAlignFix extends DataFix {
private static final int BIT_TO_LONG_SHIFT = 6;
private static final int SECTION_WIDTH = 16;
private static final int SECTION_HEIGHT = 16;
private static final int SECTION_SIZE = 4096;
private static final int HEIGHTMAP_BITS = 9;
private static final int HEIGHTMAP_SIZE = 256;
public BitStorageAlignFix(Schema p_14736_) {
super(p_14736_, false);
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.CHUNK);
Type<?> type1 = type.findFieldType("Level");
OpticFinder<?> opticfinder = DSL.fieldFinder("Level", type1);
OpticFinder<?> opticfinder1 = opticfinder.type().findField("Sections");
Type<?> type2 = ((com.mojang.datafixers.types.templates.List.ListType)opticfinder1.type()).getElement();
OpticFinder<?> opticfinder2 = DSL.typeFinder(type2);
Type<Pair<String, Dynamic<?>>> type3 = DSL.named(References.BLOCK_STATE.typeName(), DSL.remainderType());
OpticFinder<List<Pair<String, Dynamic<?>>>> opticfinder3 = DSL.fieldFinder("Palette", DSL.list(type3));
return this.fixTypeEverywhereTyped("BitStorageAlignFix", type, this.getOutputSchema().getType(References.CHUNK), (p_14749_) -> {
return p_14749_.updateTyped(opticfinder, (p_145120_) -> {
return this.updateHeightmaps(updateSections(opticfinder1, opticfinder2, opticfinder3, p_145120_));
});
});
}
private Typed<?> updateHeightmaps(Typed<?> p_14763_) {
return p_14763_.update(DSL.remainderFinder(), (p_14765_) -> {
return p_14765_.update("Heightmaps", (p_145113_) -> {
return p_145113_.updateMapValues((p_145110_) -> {
return p_145110_.mapSecond((p_145123_) -> {
return updateBitStorage(p_14765_, p_145123_, 256, 9);
});
});
});
});
}
private static Typed<?> updateSections(OpticFinder<?> p_14751_, OpticFinder<?> p_14752_, OpticFinder<List<Pair<String, Dynamic<?>>>> p_14753_, Typed<?> p_14754_) {
return p_14754_.updateTyped(p_14751_, (p_14758_) -> {
return p_14758_.updateTyped(p_14752_, (p_145103_) -> {
int i = p_145103_.getOptional(p_14753_).map((p_145115_) -> {
return Math.max(4, DataFixUtils.ceillog2(p_145115_.size()));
}).orElse(0);
return i != 0 && !Mth.isPowerOfTwo(i) ? p_145103_.update(DSL.remainderFinder(), (p_145100_) -> {
return p_145100_.update("BlockStates", (p_145107_) -> {
return updateBitStorage(p_145100_, p_145107_, 4096, i);
});
}) : p_145103_;
});
});
}
private static Dynamic<?> updateBitStorage(Dynamic<?> p_14777_, Dynamic<?> p_14778_, int p_14779_, int p_14780_) {
long[] along = p_14778_.asLongStream().toArray();
long[] along1 = addPadding(p_14779_, p_14780_, along);
return p_14777_.createLongList(LongStream.of(along1));
}
public static long[] addPadding(int p_14738_, int p_14739_, long[] p_14740_) {
int i = p_14740_.length;
if (i == 0) {
return p_14740_;
} else {
long j = (1L << p_14739_) - 1L;
int k = 64 / p_14739_;
int l = (p_14738_ + k - 1) / k;
long[] along = new long[l];
int i1 = 0;
int j1 = 0;
long k1 = 0L;
int l1 = 0;
long i2 = p_14740_[0];
long j2 = i > 1 ? p_14740_[1] : 0L;
for(int k2 = 0; k2 < p_14738_; ++k2) {
int l2 = k2 * p_14739_;
int i3 = l2 >> 6;
int j3 = (k2 + 1) * p_14739_ - 1 >> 6;
int k3 = l2 ^ i3 << 6;
if (i3 != l1) {
i2 = j2;
j2 = i3 + 1 < i ? p_14740_[i3 + 1] : 0L;
l1 = i3;
}
long l3;
if (i3 == j3) {
l3 = i2 >>> k3 & j;
} else {
int i4 = 64 - k3;
l3 = (i2 >>> k3 | j2 << i4) & j;
}
int j4 = j1 + p_14739_;
if (j4 >= 64) {
along[i1++] = k1;
k1 = l3;
j1 = p_14739_;
} else {
k1 |= l3 << j1;
j1 = j4;
}
}
if (k1 != 0L) {
along[i1] = k1;
}
return along;
}
}
}

View File

@@ -0,0 +1,58 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.OptionalDynamic;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import net.minecraft.core.SectionPos;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
public class BlendingDataFix extends DataFix {
private final String name;
private static final Set<String> STATUSES_TO_SKIP_BLENDING = Set.of("minecraft:empty", "minecraft:structure_starts", "minecraft:structure_references", "minecraft:biomes");
public BlendingDataFix(Schema p_216561_) {
super(p_216561_, false);
this.name = "Blending Data Fix v" + p_216561_.getVersionKey();
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getOutputSchema().getType(References.CHUNK);
return this.fixTypeEverywhereTyped(this.name, type, (p_216563_) -> {
return p_216563_.update(DSL.remainderFinder(), (p_240248_) -> {
return updateChunkTag(p_240248_, p_240248_.get("__context"));
});
});
}
private static Dynamic<?> updateChunkTag(Dynamic<?> p_240279_, OptionalDynamic<?> p_240280_) {
p_240279_ = p_240279_.remove("blending_data");
boolean flag = "minecraft:overworld".equals(p_240280_.get("dimension").asString().result().orElse(""));
Optional<? extends Dynamic<?>> optional = p_240279_.get("Status").result();
if (flag && optional.isPresent()) {
String s = NamespacedSchema.ensureNamespaced(optional.get().asString("empty"));
Optional<? extends Dynamic<?>> optional1 = p_240279_.get("below_zero_retrogen").result();
if (!STATUSES_TO_SKIP_BLENDING.contains(s)) {
p_240279_ = updateBlendingData(p_240279_, 384, -64);
} else if (optional1.isPresent()) {
Dynamic<?> dynamic = optional1.get();
String s1 = NamespacedSchema.ensureNamespaced(dynamic.get("target_status").asString("empty"));
if (!STATUSES_TO_SKIP_BLENDING.contains(s1)) {
p_240279_ = updateBlendingData(p_240279_, 256, 0);
}
}
}
return p_240279_;
}
private static Dynamic<?> updateBlendingData(Dynamic<?> p_216567_, int p_216568_, int p_216569_) {
return p_216567_.set("blending_data", p_216567_.createMap(Map.of(p_216567_.createString("min_section"), p_216567_.createInt(SectionPos.blockToSectionCoord(p_216569_)), p_216567_.createString("max_section"), p_216567_.createInt(SectionPos.blockToSectionCoord(p_216569_ + p_216568_)))));
}
}

View File

@@ -0,0 +1,29 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.OptionalDynamic;
public class BlendingDataRemoveFromNetherEndFix extends DataFix {
public BlendingDataRemoveFromNetherEndFix(Schema p_240321_) {
super(p_240321_, false);
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getOutputSchema().getType(References.CHUNK);
return this.fixTypeEverywhereTyped("BlendingDataRemoveFromNetherEndFix", type, (p_240286_) -> {
return p_240286_.update(DSL.remainderFinder(), (p_240254_) -> {
return updateChunkTag(p_240254_, p_240254_.get("__context"));
});
});
}
private static Dynamic<?> updateChunkTag(Dynamic<?> p_240318_, OptionalDynamic<?> p_240319_) {
boolean flag = "minecraft:overworld".equals(p_240319_.get("dimension").asString().result().orElse(""));
return flag ? p_240318_ : p_240318_.remove("blending_data");
}
}

View File

@@ -0,0 +1,32 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
public class BlockEntityBannerColorFix extends NamedEntityFix {
public BlockEntityBannerColorFix(Schema p_14793_, boolean p_14794_) {
super(p_14793_, p_14794_, "BlockEntityBannerColorFix", References.BLOCK_ENTITY, "minecraft:banner");
}
public Dynamic<?> fixTag(Dynamic<?> p_14798_) {
p_14798_ = p_14798_.update("Base", (p_14808_) -> {
return p_14808_.createInt(15 - p_14808_.asInt(0));
});
return p_14798_.update("Patterns", (p_14802_) -> {
return DataFixUtils.orElse(p_14802_.asStreamOpt().map((p_145125_) -> {
return p_145125_.map((p_145127_) -> {
return p_145127_.update("Color", (p_145129_) -> {
return p_145129_.createInt(15 - p_145129_.asInt(0));
});
});
}).map(p_14802_::createList).result(), p_14802_);
});
}
protected Typed<?> fix(Typed<?> p_14796_) {
return p_14796_.update(DSL.remainderFinder(), this::fixTag);
}
}

View File

@@ -0,0 +1,32 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
public class BlockEntityBlockStateFix extends NamedEntityFix {
public BlockEntityBlockStateFix(Schema p_14810_, boolean p_14811_) {
super(p_14810_, p_14811_, "BlockEntityBlockStateFix", References.BLOCK_ENTITY, "minecraft:piston");
}
protected Typed<?> fix(Typed<?> p_14814_) {
Type<?> type = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:piston");
Type<?> type1 = type.findFieldType("blockState");
OpticFinder<?> opticfinder = DSL.fieldFinder("blockState", type1);
Dynamic<?> dynamic = p_14814_.get(DSL.remainderFinder());
int i = dynamic.get("blockId").asInt(0);
dynamic = dynamic.remove("blockId");
int j = dynamic.get("blockData").asInt(0) & 15;
dynamic = dynamic.remove("blockData");
Dynamic<?> dynamic1 = BlockStateData.getTag(i << 4 | j);
Typed<?> typed = type.pointTyped(p_14814_.getOps()).orElseThrow(() -> {
return new IllegalStateException("Could not create new piston block entity.");
});
return typed.set(DSL.remainderFinder(), dynamic).set(opticfinder, type1.readTyped(dynamic1).result().orElseThrow(() -> {
return new IllegalStateException("Could not parse newly created block state tag.");
}).getFirst());
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import java.util.Objects;
import java.util.Optional;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
public class BlockEntityCustomNameToComponentFix extends DataFix {
public BlockEntityCustomNameToComponentFix(Schema p_14817_, boolean p_14818_) {
super(p_14817_, p_14818_);
}
public TypeRewriteRule makeRule() {
OpticFinder<String> opticfinder = DSL.fieldFinder("id", NamespacedSchema.namespacedString());
return this.fixTypeEverywhereTyped("BlockEntityCustomNameToComponentFix", this.getInputSchema().getType(References.BLOCK_ENTITY), (p_14821_) -> {
return p_14821_.update(DSL.remainderFinder(), (p_145133_) -> {
Optional<String> optional = p_14821_.getOptional(opticfinder);
return optional.isPresent() && Objects.equals(optional.get(), "minecraft:command_block") ? p_145133_ : EntityCustomNameToComponentFix.fixTagCustomName(p_145133_);
});
});
}
}

View File

@@ -0,0 +1,56 @@
package net.minecraft.util.datafix.fixes;
import com.google.common.collect.Maps;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.types.templates.TaggedChoice;
import java.util.Map;
public class BlockEntityIdFix extends DataFix {
private static final Map<String, String> ID_MAP = DataFixUtils.make(Maps.newHashMap(), (p_14839_) -> {
p_14839_.put("Airportal", "minecraft:end_portal");
p_14839_.put("Banner", "minecraft:banner");
p_14839_.put("Beacon", "minecraft:beacon");
p_14839_.put("Cauldron", "minecraft:brewing_stand");
p_14839_.put("Chest", "minecraft:chest");
p_14839_.put("Comparator", "minecraft:comparator");
p_14839_.put("Control", "minecraft:command_block");
p_14839_.put("DLDetector", "minecraft:daylight_detector");
p_14839_.put("Dropper", "minecraft:dropper");
p_14839_.put("EnchantTable", "minecraft:enchanting_table");
p_14839_.put("EndGateway", "minecraft:end_gateway");
p_14839_.put("EnderChest", "minecraft:ender_chest");
p_14839_.put("FlowerPot", "minecraft:flower_pot");
p_14839_.put("Furnace", "minecraft:furnace");
p_14839_.put("Hopper", "minecraft:hopper");
p_14839_.put("MobSpawner", "minecraft:mob_spawner");
p_14839_.put("Music", "minecraft:noteblock");
p_14839_.put("Piston", "minecraft:piston");
p_14839_.put("RecordPlayer", "minecraft:jukebox");
p_14839_.put("Sign", "minecraft:sign");
p_14839_.put("Skull", "minecraft:skull");
p_14839_.put("Structure", "minecraft:structure_block");
p_14839_.put("Trap", "minecraft:dispenser");
});
public BlockEntityIdFix(Schema p_14830_, boolean p_14831_) {
super(p_14830_, p_14831_);
}
public TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.ITEM_STACK);
Type<?> type1 = this.getOutputSchema().getType(References.ITEM_STACK);
TaggedChoice.TaggedChoiceType<String> taggedchoicetype = (TaggedChoice.TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY);
TaggedChoice.TaggedChoiceType<String> taggedchoicetype1 = (TaggedChoice.TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY);
return TypeRewriteRule.seq(this.convertUnchecked("item stack block entity name hook converter", type, type1), this.fixTypeEverywhere("BlockEntityIdFix", taggedchoicetype, taggedchoicetype1, (p_14835_) -> {
return (p_145135_) -> {
return p_145135_.mapFirst((p_145137_) -> {
return ID_MAP.getOrDefault(p_145137_, p_145137_);
});
};
}));
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.serialization.Dynamic;
public class BlockEntityJukeboxFix extends NamedEntityFix {
public BlockEntityJukeboxFix(Schema p_14842_, boolean p_14843_) {
super(p_14842_, p_14843_, "BlockEntityJukeboxFix", References.BLOCK_ENTITY, "minecraft:jukebox");
}
protected Typed<?> fix(Typed<?> p_14846_) {
Type<?> type = this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:jukebox");
Type<?> type1 = type.findFieldType("RecordItem");
OpticFinder<?> opticfinder = DSL.fieldFinder("RecordItem", type1);
Dynamic<?> dynamic = p_14846_.get(DSL.remainderFinder());
int i = dynamic.get("Record").asInt(0);
if (i > 0) {
dynamic.remove("Record");
String s = ItemStackTheFlatteningFix.updateItem(ItemIdFix.getItem(i), 0);
if (s != null) {
Dynamic<?> dynamic1 = dynamic.emptyMap();
dynamic1 = dynamic1.set("id", dynamic1.createString(s));
dynamic1 = dynamic1.set("Count", dynamic1.createByte((byte)1));
return p_14846_.set(opticfinder, type1.readTyped(dynamic1).result().orElseThrow(() -> {
return new IllegalStateException("Could not create record item stack.");
}).getFirst()).set(DSL.remainderFinder(), dynamic);
}
}
return p_14846_;
}
}

View File

@@ -0,0 +1,20 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
public class BlockEntityKeepPacked extends NamedEntityFix {
public BlockEntityKeepPacked(Schema p_14848_, boolean p_14849_) {
super(p_14848_, p_14849_, "BlockEntityKeepPacked", References.BLOCK_ENTITY, "DUMMY");
}
private static Dynamic<?> fixTag(Dynamic<?> p_14853_) {
return p_14853_.set("keepPacked", p_14853_.createBoolean(true));
}
protected Typed<?> fix(Typed<?> p_14851_) {
return p_14851_.update(DSL.remainderFinder(), BlockEntityKeepPacked::fixTag);
}
}

View File

@@ -0,0 +1,32 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.templates.TaggedChoice;
import java.util.function.UnaryOperator;
public class BlockEntityRenameFix extends DataFix {
private final String name;
private final UnaryOperator<String> nameChangeLookup;
private BlockEntityRenameFix(Schema p_277450_, String p_278025_, UnaryOperator<String> p_277596_) {
super(p_277450_, true);
this.name = p_278025_;
this.nameChangeLookup = p_277596_;
}
public TypeRewriteRule makeRule() {
TaggedChoice.TaggedChoiceType<String> taggedchoicetype = (TaggedChoice.TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY);
TaggedChoice.TaggedChoiceType<String> taggedchoicetype1 = (TaggedChoice.TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY);
return this.fixTypeEverywhere(this.name, taggedchoicetype, taggedchoicetype1, (p_277946_) -> {
return (p_277512_) -> {
return p_277512_.mapFirst(this.nameChangeLookup);
};
});
}
public static DataFix create(Schema p_278009_, String p_277879_, UnaryOperator<String> p_277753_) {
return new BlockEntityRenameFix(p_278009_, p_277879_, p_277753_);
}
}

View File

@@ -0,0 +1,17 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
public class BlockEntityShulkerBoxColorFix extends NamedEntityFix {
public BlockEntityShulkerBoxColorFix(Schema p_14855_, boolean p_14856_) {
super(p_14855_, p_14856_, "BlockEntityShulkerBoxColorFix", References.BLOCK_ENTITY, "minecraft:shulker_box");
}
protected Typed<?> fix(Typed<?> p_14858_) {
return p_14858_.update(DSL.remainderFinder(), (p_14860_) -> {
return p_14860_.remove("Color");
});
}
}

View File

@@ -0,0 +1,53 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import java.util.Optional;
import java.util.stream.Stream;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
public class BlockEntitySignDoubleSidedEditableTextFix extends NamedEntityFix {
public BlockEntitySignDoubleSidedEditableTextFix(Schema p_277789_, String p_278061_, String p_277403_) {
super(p_277789_, false, p_278061_, References.BLOCK_ENTITY, p_277403_);
}
private static Dynamic<?> fixTag(Dynamic<?> p_278110_) {
String s = "black";
Dynamic<?> dynamic = p_278110_.emptyMap();
dynamic = dynamic.set("messages", getTextList(p_278110_, "Text"));
dynamic = dynamic.set("filtered_messages", getTextList(p_278110_, "FilteredText"));
Optional<? extends Dynamic<?>> optional = p_278110_.get("Color").result();
dynamic = dynamic.set("color", optional.isPresent() ? optional.get() : dynamic.createString("black"));
Optional<? extends Dynamic<?>> optional1 = p_278110_.get("GlowingText").result();
dynamic = dynamic.set("has_glowing_text", optional1.isPresent() ? optional1.get() : dynamic.createBoolean(false));
Dynamic<?> dynamic1 = p_278110_.emptyMap();
Dynamic<?> dynamic2 = getEmptyTextList(p_278110_);
dynamic1 = dynamic1.set("messages", dynamic2);
dynamic1 = dynamic1.set("filtered_messages", dynamic2);
dynamic1 = dynamic1.set("color", dynamic1.createString("black"));
dynamic1 = dynamic1.set("has_glowing_text", dynamic1.createBoolean(false));
p_278110_ = p_278110_.set("front_text", dynamic);
return p_278110_.set("back_text", dynamic1);
}
private static <T> Dynamic<T> getTextList(Dynamic<T> p_277452_, String p_277422_) {
Dynamic<T> dynamic = p_277452_.createString(getEmptyComponent());
return p_277452_.createList(Stream.of(p_277452_.get(p_277422_ + "1").result().orElse(dynamic), p_277452_.get(p_277422_ + "2").result().orElse(dynamic), p_277452_.get(p_277422_ + "3").result().orElse(dynamic), p_277452_.get(p_277422_ + "4").result().orElse(dynamic)));
}
private static <T> Dynamic<T> getEmptyTextList(Dynamic<T> p_277949_) {
Dynamic<T> dynamic = p_277949_.createString(getEmptyComponent());
return p_277949_.createList(Stream.of(dynamic, dynamic, dynamic, dynamic));
}
private static String getEmptyComponent() {
return Component.Serializer.toJson(CommonComponents.EMPTY);
}
protected Typed<?> fix(Typed<?> p_277962_) {
return p_277962_.update(DSL.remainderFinder(), BlockEntitySignDoubleSidedEditableTextFix::fixTag);
}
}

View File

@@ -0,0 +1,98 @@
package net.minecraft.util.datafix.fixes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import java.lang.reflect.Type;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.GsonHelper;
import org.apache.commons.lang3.StringUtils;
public class BlockEntitySignTextStrictJsonFix extends NamedEntityFix {
public static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(Component.class, new JsonDeserializer<Component>() {
public MutableComponent deserialize(JsonElement p_14875_, Type p_14876_, JsonDeserializationContext p_14877_) throws JsonParseException {
if (p_14875_.isJsonPrimitive()) {
return Component.literal(p_14875_.getAsString());
} else if (p_14875_.isJsonArray()) {
JsonArray jsonarray = p_14875_.getAsJsonArray();
MutableComponent mutablecomponent = null;
for(JsonElement jsonelement : jsonarray) {
MutableComponent mutablecomponent1 = this.deserialize(jsonelement, jsonelement.getClass(), p_14877_);
if (mutablecomponent == null) {
mutablecomponent = mutablecomponent1;
} else {
mutablecomponent.append(mutablecomponent1);
}
}
return mutablecomponent;
} else {
throw new JsonParseException("Don't know how to turn " + p_14875_ + " into a Component");
}
}
}).create();
public BlockEntitySignTextStrictJsonFix(Schema p_14864_, boolean p_14865_) {
super(p_14864_, p_14865_, "BlockEntitySignTextStrictJsonFix", References.BLOCK_ENTITY, "Sign");
}
private Dynamic<?> updateLine(Dynamic<?> p_14871_, String p_14872_) {
String s = p_14871_.get(p_14872_).asString("");
Component component = null;
if (!"null".equals(s) && !StringUtils.isEmpty(s)) {
if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"' || s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}') {
try {
component = GsonHelper.fromNullableJson(GSON, s, Component.class, true);
if (component == null) {
component = CommonComponents.EMPTY;
}
} catch (Exception exception2) {
}
if (component == null) {
try {
component = Component.Serializer.fromJson(s);
} catch (Exception exception1) {
}
}
if (component == null) {
try {
component = Component.Serializer.fromJsonLenient(s);
} catch (Exception exception) {
}
}
if (component == null) {
component = Component.literal(s);
}
} else {
component = Component.literal(s);
}
} else {
component = CommonComponents.EMPTY;
}
return p_14871_.set(p_14872_, p_14871_.createString(Component.Serializer.toJson(component)));
}
protected Typed<?> fix(Typed<?> p_14867_) {
return p_14867_.update(DSL.remainderFinder(), (p_14869_) -> {
p_14869_ = this.updateLine(p_14869_, "Text1");
p_14869_ = this.updateLine(p_14869_, "Text2");
p_14869_ = this.updateLine(p_14869_, "Text3");
return this.updateLine(p_14869_, "Text4");
});
}
}

View File

@@ -0,0 +1,30 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
public class BlockEntityUUIDFix extends AbstractUUIDFix {
public BlockEntityUUIDFix(Schema p_14883_) {
super(p_14883_, References.BLOCK_ENTITY);
}
protected TypeRewriteRule makeRule() {
return this.fixTypeEverywhereTyped("BlockEntityUUIDFix", this.getInputSchema().getType(this.typeReference), (p_14885_) -> {
p_14885_ = this.updateNamedChoice(p_14885_, "minecraft:conduit", this::updateConduit);
return this.updateNamedChoice(p_14885_, "minecraft:skull", this::updateSkull);
});
}
private Dynamic<?> updateSkull(Dynamic<?> p_14890_) {
return p_14890_.get("Owner").get().map((p_14894_) -> {
return replaceUUIDString(p_14894_, "Id", "Id").orElse(p_14894_);
}).<Dynamic<?>>map((p_14888_) -> {
return p_14890_.remove("Owner").set("SkullOwner", p_14888_);
}).result().orElse(p_14890_);
}
private Dynamic<?> updateConduit(Dynamic<?> p_14892_) {
return replaceUUIDMLTag(p_14892_, "target_uuid", "Target").orElse(p_14892_);
}
}

View File

@@ -0,0 +1,37 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
import java.util.Objects;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
public class BlockNameFlatteningFix extends DataFix {
public BlockNameFlatteningFix(Schema p_14897_, boolean p_14898_) {
super(p_14897_, p_14898_);
}
public TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.BLOCK_NAME);
Type<?> type1 = this.getOutputSchema().getType(References.BLOCK_NAME);
Type<Pair<String, Either<Integer, String>>> type2 = DSL.named(References.BLOCK_NAME.typeName(), DSL.or(DSL.intType(), NamespacedSchema.namespacedString()));
Type<Pair<String, String>> type3 = DSL.named(References.BLOCK_NAME.typeName(), NamespacedSchema.namespacedString());
if (Objects.equals(type, type2) && Objects.equals(type1, type3)) {
return this.fixTypeEverywhere("BlockNameFlatteningFix", type2, type3, (p_14904_) -> {
return (p_145141_) -> {
return p_145141_.mapSecond((p_145139_) -> {
return p_145139_.map(BlockStateData::upgradeBlock, (p_145143_) -> {
return BlockStateData.upgradeBlock(NamespacedSchema.ensureNamespaced(p_145143_));
});
});
};
});
} else {
throw new IllegalStateException("Expected and actual types don't match.");
}
}
}

View File

@@ -0,0 +1,52 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.util.Pair;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import net.minecraft.util.datafix.schemas.NamespacedSchema;
public abstract class BlockRenameFix extends DataFix {
private final String name;
public BlockRenameFix(Schema p_14910_, String p_14911_) {
super(p_14910_, false);
this.name = p_14911_;
}
public TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.BLOCK_NAME);
Type<Pair<String, String>> type1 = DSL.named(References.BLOCK_NAME.typeName(), NamespacedSchema.namespacedString());
if (!Objects.equals(type, type1)) {
throw new IllegalStateException("block type is not what was expected.");
} else {
TypeRewriteRule typerewriterule = this.fixTypeEverywhere(this.name + " for block", type1, (p_14923_) -> {
return (p_145145_) -> {
return p_145145_.mapSecond(this::fixBlock);
};
});
TypeRewriteRule typerewriterule1 = this.fixTypeEverywhereTyped(this.name + " for block_state", this.getInputSchema().getType(References.BLOCK_STATE), (p_14913_) -> {
return p_14913_.update(DSL.remainderFinder(), (p_145147_) -> {
Optional<String> optional = p_145147_.get("Name").asString().result();
return optional.isPresent() ? p_145147_.set("Name", p_145147_.createString(this.fixBlock(optional.get()))) : p_145147_;
});
});
return TypeRewriteRule.seq(typerewriterule, typerewriterule1);
}
}
protected abstract String fixBlock(String p_14924_);
public static DataFix create(Schema p_14915_, String p_14916_, final Function<String, String> p_14917_) {
return new BlockRenameFix(p_14915_, p_14916_) {
protected String fixBlock(String p_14932_) {
return p_14917_.apply(p_14932_);
}
};
}
}

View File

@@ -0,0 +1,57 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import java.util.function.Function;
public abstract class BlockRenameFixWithJigsaw extends BlockRenameFix {
private final String name;
public BlockRenameFixWithJigsaw(Schema p_145150_, String p_145151_) {
super(p_145150_, p_145151_);
this.name = p_145151_;
}
public TypeRewriteRule makeRule() {
DSL.TypeReference typereference = References.BLOCK_ENTITY;
String s = "minecraft:jigsaw";
OpticFinder<?> opticfinder = DSL.namedChoice("minecraft:jigsaw", this.getInputSchema().getChoiceType(typereference, "minecraft:jigsaw"));
TypeRewriteRule typerewriterule = this.fixTypeEverywhereTyped(this.name + " for jigsaw state", this.getInputSchema().getType(typereference), this.getOutputSchema().getType(typereference), (p_145155_) -> {
return p_145155_.updateTyped(opticfinder, this.getOutputSchema().getChoiceType(typereference, "minecraft:jigsaw"), (p_145157_) -> {
return p_145157_.update(DSL.remainderFinder(), (p_145159_) -> {
return p_145159_.update("final_state", (p_145162_) -> {
return DataFixUtils.orElse(p_145162_.asString().result().map((p_145168_) -> {
int i = p_145168_.indexOf(91);
int j = p_145168_.indexOf(123);
int k = p_145168_.length();
if (i > 0) {
k = Math.min(k, i);
}
if (j > 0) {
k = Math.min(k, j);
}
String s1 = p_145168_.substring(0, k);
String s2 = this.fixBlock(s1);
return s2 + p_145168_.substring(k);
}).map(p_145159_::createString), p_145162_);
});
});
});
});
return TypeRewriteRule.seq(super.makeRule(), typerewriterule);
}
public static DataFix create(Schema p_145164_, String p_145165_, final Function<String, String> p_145166_) {
return new BlockRenameFixWithJigsaw(p_145164_, p_145165_) {
protected String fixBlock(String p_145176_) {
return p_145166_.apply(p_145176_);
}
};
}
}

View File

@@ -0,0 +1,18 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
public class BlockStateStructureTemplateFix extends DataFix {
public BlockStateStructureTemplateFix(Schema p_15001_, boolean p_15002_) {
super(p_15001_, p_15002_);
}
public TypeRewriteRule makeRule() {
return this.fixTypeEverywhereTyped("BlockStateStructureTemplateFix", this.getInputSchema().getType(References.BLOCK_STATE), (p_15004_) -> {
return p_15004_.update(DSL.remainderFinder(), BlockStateData::upgradeBlockStateTag);
});
}
}

View File

@@ -0,0 +1,20 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
public class CatTypeFix extends NamedEntityFix {
public CatTypeFix(Schema p_15007_, boolean p_15008_) {
super(p_15007_, p_15008_, "CatTypeFix", References.ENTITY, "minecraft:cat");
}
public Dynamic<?> fixTag(Dynamic<?> p_15012_) {
return p_15012_.get("CatType").asInt(0) == 9 ? p_15012_.set("CatType", p_15012_.createInt(10)) : p_15012_;
}
protected Typed<?> fix(Typed<?> p_15010_) {
return p_15010_.update(DSL.remainderFinder(), this::fixTag);
}
}

View File

@@ -0,0 +1,30 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import java.util.Optional;
public class CauldronRenameFix extends DataFix {
public CauldronRenameFix(Schema p_145196_, boolean p_145197_) {
super(p_145196_, p_145197_);
}
private static Dynamic<?> fix(Dynamic<?> p_145201_) {
Optional<String> optional = p_145201_.get("Name").asString().result();
if (optional.equals(Optional.of("minecraft:cauldron"))) {
Dynamic<?> dynamic = p_145201_.get("Properties").orElseEmptyMap();
return dynamic.get("level").asString("0").equals("0") ? p_145201_.remove("Properties") : p_145201_.set("Name", p_145201_.createString("minecraft:water_cauldron"));
} else {
return p_145201_;
}
}
protected TypeRewriteRule makeRule() {
return this.fixTypeEverywhereTyped("cauldron_rename_fix", this.getInputSchema().getType(References.BLOCK_STATE), (p_145199_) -> {
return p_145199_.update(DSL.remainderFinder(), CauldronRenameFix::fix);
});
}
}

View File

@@ -0,0 +1,10 @@
package net.minecraft.util.datafix.fixes;
import com.google.common.collect.ImmutableMap;
public final class CavesAndCliffsRenames {
public static final ImmutableMap<String, String> RENAMES = ImmutableMap.<String, String>builder().put("minecraft:badlands_plateau", "minecraft:badlands").put("minecraft:bamboo_jungle_hills", "minecraft:bamboo_jungle").put("minecraft:birch_forest_hills", "minecraft:birch_forest").put("minecraft:dark_forest_hills", "minecraft:dark_forest").put("minecraft:desert_hills", "minecraft:desert").put("minecraft:desert_lakes", "minecraft:desert").put("minecraft:giant_spruce_taiga_hills", "minecraft:old_growth_spruce_taiga").put("minecraft:giant_spruce_taiga", "minecraft:old_growth_spruce_taiga").put("minecraft:giant_tree_taiga_hills", "minecraft:old_growth_pine_taiga").put("minecraft:giant_tree_taiga", "minecraft:old_growth_pine_taiga").put("minecraft:gravelly_mountains", "minecraft:windswept_gravelly_hills").put("minecraft:jungle_edge", "minecraft:sparse_jungle").put("minecraft:jungle_hills", "minecraft:jungle").put("minecraft:modified_badlands_plateau", "minecraft:badlands").put("minecraft:modified_gravelly_mountains", "minecraft:windswept_gravelly_hills").put("minecraft:modified_jungle_edge", "minecraft:sparse_jungle").put("minecraft:modified_jungle", "minecraft:jungle").put("minecraft:modified_wooded_badlands_plateau", "minecraft:wooded_badlands").put("minecraft:mountain_edge", "minecraft:windswept_hills").put("minecraft:mountains", "minecraft:windswept_hills").put("minecraft:mushroom_field_shore", "minecraft:mushroom_fields").put("minecraft:shattered_savanna", "minecraft:windswept_savanna").put("minecraft:shattered_savanna_plateau", "minecraft:windswept_savanna").put("minecraft:snowy_mountains", "minecraft:snowy_plains").put("minecraft:snowy_taiga_hills", "minecraft:snowy_taiga").put("minecraft:snowy_taiga_mountains", "minecraft:snowy_taiga").put("minecraft:snowy_tundra", "minecraft:snowy_plains").put("minecraft:stone_shore", "minecraft:stony_shore").put("minecraft:swamp_hills", "minecraft:swamp").put("minecraft:taiga_hills", "minecraft:taiga").put("minecraft:taiga_mountains", "minecraft:taiga").put("minecraft:tall_birch_forest", "minecraft:old_growth_birch_forest").put("minecraft:tall_birch_hills", "minecraft:old_growth_birch_forest").put("minecraft:wooded_badlands_plateau", "minecraft:wooded_badlands").put("minecraft:wooded_hills", "minecraft:forest").put("minecraft:wooded_mountains", "minecraft:windswept_forest").put("minecraft:lofty_peaks", "minecraft:jagged_peaks").put("minecraft:snowcapped_peaks", "minecraft:frozen_peaks").build();
private CavesAndCliffsRenames() {
}
}

View File

@@ -0,0 +1,83 @@
package net.minecraft.util.datafix.fixes;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Streams;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.types.templates.List;
import com.mojang.serialization.Dynamic;
import java.util.Map;
import java.util.function.Function;
public class ChunkBedBlockEntityInjecterFix extends DataFix {
public ChunkBedBlockEntityInjecterFix(Schema p_184825_, boolean p_184826_) {
super(p_184825_, p_184826_);
}
public TypeRewriteRule makeRule() {
Type<?> type = this.getOutputSchema().getType(References.CHUNK);
Type<?> type1 = type.findFieldType("Level");
Type<?> type2 = type1.findFieldType("TileEntities");
if (!(type2 instanceof List.ListType<?> listtype)) {
throw new IllegalStateException("Tile entity type is not a list type.");
} else {
return this.cap(type1, listtype);
}
}
private <TE> TypeRewriteRule cap(Type<?> p_184834_, List.ListType<TE> p_184835_) {
Type<TE> type = p_184835_.getElement();
OpticFinder<?> opticfinder = DSL.fieldFinder("Level", p_184834_);
OpticFinder<java.util.List<TE>> opticfinder1 = DSL.fieldFinder("TileEntities", p_184835_);
int i = 416;
return TypeRewriteRule.seq(this.fixTypeEverywhere("InjectBedBlockEntityType", (com.mojang.datafixers.types.templates.TaggedChoice.TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY), (com.mojang.datafixers.types.templates.TaggedChoice.TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY), (p_184841_) -> {
return (p_184837_) -> {
return p_184837_;
};
}), this.fixTypeEverywhereTyped("BedBlockEntityInjecter", this.getOutputSchema().getType(References.CHUNK), (p_274912_) -> {
Typed<?> typed = p_274912_.getTyped(opticfinder);
Dynamic<?> dynamic = typed.get(DSL.remainderFinder());
int j = dynamic.get("xPos").asInt(0);
int k = dynamic.get("zPos").asInt(0);
java.util.List<TE> list = Lists.newArrayList(typed.getOrCreate(opticfinder1));
java.util.List<? extends Dynamic<?>> list1 = dynamic.get("Sections").asList(Function.identity());
for(int l = 0; l < list1.size(); ++l) {
Dynamic<?> dynamic1 = list1.get(l);
int i1 = dynamic1.get("Y").asInt(0);
Streams.mapWithIndex(dynamic1.get("Blocks").asIntStream(), (p_274917_, p_274918_) -> {
if (416 == (p_274917_ & 255) << 4) {
int j1 = (int)p_274918_;
int k1 = j1 & 15;
int l1 = j1 >> 8 & 15;
int i2 = j1 >> 4 & 15;
Map<Dynamic<?>, Dynamic<?>> map = Maps.newHashMap();
map.put(dynamic1.createString("id"), dynamic1.createString("minecraft:bed"));
map.put(dynamic1.createString("x"), dynamic1.createInt(k1 + (j << 4)));
map.put(dynamic1.createString("y"), dynamic1.createInt(l1 + (i1 << 4)));
map.put(dynamic1.createString("z"), dynamic1.createInt(i2 + (k << 4)));
map.put(dynamic1.createString("color"), dynamic1.createShort((short)14));
return map;
} else {
return null;
}
}).forEachOrdered((p_274922_) -> {
if (p_274922_ != null) {
list.add(type.read(dynamic1.createMap(p_274922_)).result().orElseThrow(() -> {
return new IllegalStateException("Could not parse newly created bed block entity.");
}).getFirst());
}
});
}
return !list.isEmpty() ? p_274912_.set(opticfinder, typed.set(opticfinder1, list)) : p_274912_;
}));
}
}

View File

@@ -0,0 +1,54 @@
package net.minecraft.util.datafix.fixes;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.OpticFinder;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.IntStream;
public class ChunkBiomeFix extends DataFix {
public ChunkBiomeFix(Schema p_15014_, boolean p_15015_) {
super(p_15014_, p_15015_);
}
protected TypeRewriteRule makeRule() {
Type<?> type = this.getInputSchema().getType(References.CHUNK);
OpticFinder<?> opticfinder = type.findField("Level");
return this.fixTypeEverywhereTyped("Leaves fix", type, (p_15018_) -> {
return p_15018_.updateTyped(opticfinder, (p_145204_) -> {
return p_145204_.update(DSL.remainderFinder(), (p_145206_) -> {
Optional<IntStream> optional = p_145206_.get("Biomes").asIntStreamOpt().result();
if (optional.isEmpty()) {
return p_145206_;
} else {
int[] aint = optional.get().toArray();
if (aint.length != 256) {
return p_145206_;
} else {
int[] aint1 = new int[1024];
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 4; ++j) {
int k = (j << 2) + 2;
int l = (i << 2) + 2;
int i1 = l << 4 | k;
aint1[i << 2 | j] = aint[i1];
}
}
for(int j1 = 1; j1 < 64; ++j1) {
System.arraycopy(aint1, 0, aint1, j1 * 16, 16);
}
return p_145206_.set("Biomes", p_145206_.createIntList(Arrays.stream(aint1)));
}
}
});
});
});
}
}

Some files were not shown because too many files have changed in this diff Show More