Initial Commit
This commit is contained in:
1 parent
377b32db6e
commit
2d9a5eecba
14134 files changed
+1160982
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AbortableIterationConsumer<T> {
|
||||
AbortableIterationConsumer.Continuation accept(T pValue);
|
||||
|
||||
static <T> AbortableIterationConsumer<T> forConsumer(Consumer<T> pConsumer) {
|
||||
return (p_261916_) -> {
|
||||
pConsumer.accept(p_261916_);
|
||||
return AbortableIterationConsumer.Continuation.CONTINUE;
|
||||
};
|
||||
}
|
||||
|
||||
public static enum Continuation {
|
||||
CONTINUE,
|
||||
ABORT;
|
||||
|
||||
public boolean shouldAbort() {
|
||||
return this == ABORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public interface BitStorage {
|
||||
int getAndSet(int pIndex, int pValue);
|
||||
|
||||
/**
|
||||
* Sets the entry at the given location to the given value
|
||||
*/
|
||||
void set(int pIndex, int pValue);
|
||||
|
||||
/**
|
||||
* Gets the entry at the given index
|
||||
*/
|
||||
int get(int pIndex);
|
||||
|
||||
/**
|
||||
* Gets the long array that is used to store the data in this BitArray. This is useful for sending packet data.
|
||||
*/
|
||||
long[] getRaw();
|
||||
|
||||
int getSize();
|
||||
|
||||
int getBits();
|
||||
|
||||
void getAll(IntConsumer pConsumer);
|
||||
|
||||
void unpack(int[] p_198162_);
|
||||
|
||||
BitStorage copy();
|
||||
}
|
||||
+22
@@ -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 pPackedBrightness) {
|
||||
int i = pPackedBrightness >> 4 & '\uffff';
|
||||
int j = pPackedBrightness >> 20 & '\uffff';
|
||||
return new Brightness(i, j);
|
||||
}
|
||||
}
|
||||
+101
@@ -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> pKeyExtractor, T[] pValues) {
|
||||
if (pValues.length == 0) {
|
||||
throw new IllegalArgumentException("Empty value list");
|
||||
} else {
|
||||
Int2ObjectMap<T> int2objectmap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
for(T t : pValues) {
|
||||
int i = pKeyExtractor.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> pKeyExtractor, T[] pValues, T pFallback) {
|
||||
IntFunction<T> intfunction = createMap(pKeyExtractor, pValues);
|
||||
return (p_262932_) -> {
|
||||
return Objects.requireNonNullElse(intfunction.apply(p_262932_), pFallback);
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> T[] createSortedArray(ToIntFunction<T> pKeyExtractor, T[] pValues) {
|
||||
int i = pValues.length;
|
||||
if (i == 0) {
|
||||
throw new IllegalArgumentException("Empty value list");
|
||||
} else {
|
||||
T[] at = (T[])((Object[])pValues.clone());
|
||||
Arrays.fill(at, (Object)null);
|
||||
|
||||
for(T t : pValues) {
|
||||
int j = pKeyExtractor.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> pKeyExtractor, T[] pValues, ByIdMap.OutOfBoundsStrategy pOutOfBoundsStrategy) {
|
||||
T[] at = createSortedArray(pKeyExtractor, pValues);
|
||||
int i = at.length;
|
||||
IntFunction intfunction;
|
||||
switch (pOutOfBoundsStrategy) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
+76
@@ -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> pBaseClass) {
|
||||
this.baseClass = pBaseClass;
|
||||
this.byClass.put(pBaseClass, this.allInstances);
|
||||
}
|
||||
|
||||
public boolean add(T pValue) {
|
||||
boolean flag = false;
|
||||
|
||||
for(Map.Entry<Class<?>, List<T>> entry : this.byClass.entrySet()) {
|
||||
if (entry.getKey().isInstance(pValue)) {
|
||||
flag |= entry.getValue().add(pValue);
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
public boolean remove(Object pKey) {
|
||||
boolean flag = false;
|
||||
|
||||
for(Map.Entry<Class<?>, List<T>> entry : this.byClass.entrySet()) {
|
||||
if (entry.getKey().isInstance(pKey)) {
|
||||
List<T> list = entry.getValue();
|
||||
flag |= list.remove(pKey);
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
public boolean contains(Object pKey) {
|
||||
return this.find(pKey.getClass()).contains(pKey);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
+8
@@ -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;
|
||||
}
|
||||
+31
@@ -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 pSubscriptionId, String pProfieId, boolean pIsTrial) {
|
||||
return extendRealms(pSubscriptionId, pProfieId) + "&ref=" + (pIsTrial ? "expiredTrial" : "expiredRealm");
|
||||
}
|
||||
|
||||
public static String extendRealms(String pSubscriptionId, String pProfileId) {
|
||||
return "https://aka.ms/ExtendJavaRealms?subscriptionId=" + pSubscriptionId + "&profileId=" + pProfileId;
|
||||
}
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
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 pSize) {
|
||||
this.keys = (K[])(new Object[pSize]);
|
||||
this.values = new int[pSize];
|
||||
this.byId = (K[])(new Object[pSize]);
|
||||
}
|
||||
|
||||
private CrudeIncrementalIntIdentityHashBiMap(K[] pKeys, int[] pValues, K[] pById, int pNextId, int pSize) {
|
||||
this.keys = pKeys;
|
||||
this.values = pValues;
|
||||
this.byId = pById;
|
||||
this.nextId = pNextId;
|
||||
this.size = pSize;
|
||||
}
|
||||
|
||||
public static <A> CrudeIncrementalIntIdentityHashBiMap<A> create(int pSize) {
|
||||
return new CrudeIncrementalIntIdentityHashBiMap<>((int)((float)pSize / 0.8F));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the integer ID used to identify the given object
|
||||
*/
|
||||
public int getId(@Nullable K pValue) {
|
||||
return this.getValue(this.indexOf(pValue, this.hash(pValue)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public K byId(int pValue) {
|
||||
return (K)(pValue >= 0 && pValue < this.byId.length ? this.byId[pValue] : null);
|
||||
}
|
||||
|
||||
private int getValue(int pKey) {
|
||||
return pKey == -1 ? -1 : this.values[pKey];
|
||||
}
|
||||
|
||||
public boolean contains(K p_144610_) {
|
||||
return this.getId(p_144610_) != -1;
|
||||
}
|
||||
|
||||
public boolean contains(int pValue) {
|
||||
return this.byId(pValue) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given object while expanding this map
|
||||
*/
|
||||
public int add(K pObject) {
|
||||
int i = this.nextId();
|
||||
this.addMapping(pObject, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
private int nextId() {
|
||||
while(this.nextId < this.byId.length && this.byId[this.nextId] != null) {
|
||||
++this.nextId;
|
||||
}
|
||||
|
||||
return this.nextId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rehashes the map to the new capacity
|
||||
*/
|
||||
private void grow(int pCapacity) {
|
||||
K[] ak = this.keys;
|
||||
int[] aint = this.values;
|
||||
CrudeIncrementalIntIdentityHashBiMap<K> crudeincrementalintidentityhashbimap = new CrudeIncrementalIntIdentityHashBiMap<>(pCapacity);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the provided object value with the integer key.
|
||||
*/
|
||||
public void addMapping(K pObject, int pIntKey) {
|
||||
int i = Math.max(pIntKey, this.size + 1);
|
||||
if ((float)i >= (float)this.keys.length * 0.8F) {
|
||||
int j;
|
||||
for(j = this.keys.length << 1; j < pIntKey; j <<= 1) {
|
||||
}
|
||||
|
||||
this.grow(j);
|
||||
}
|
||||
|
||||
int k = this.findEmpty(this.hash(pObject));
|
||||
this.keys[k] = pObject;
|
||||
this.values[k] = pIntKey;
|
||||
this.byId[pIntKey] = pObject;
|
||||
++this.size;
|
||||
if (pIntKey == this.nextId) {
|
||||
++this.nextId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int hash(@Nullable K pObject) {
|
||||
return (Mth.murmurHash3Mixer(System.identityHashCode(pObject)) & Integer.MAX_VALUE) % this.keys.length;
|
||||
}
|
||||
|
||||
private int indexOf(@Nullable K pObject, int pStartIndex) {
|
||||
for(int i = pStartIndex; i < this.keys.length; ++i) {
|
||||
if (this.keys[i] == pObject) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if (this.keys[i] == EMPTY_SLOT) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < pStartIndex; ++j) {
|
||||
if (this.keys[j] == pObject) {
|
||||
return j;
|
||||
}
|
||||
|
||||
if (this.keys[j] == EMPTY_SLOT) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findEmpty(int pStartIndex) {
|
||||
for(int i = pStartIndex; i < this.keys.length; ++i) {
|
||||
if (this.keys[i] == EMPTY_SLOT) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < pStartIndex; ++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);
|
||||
}
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
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);
|
||||
|
||||
/**
|
||||
* Generate a new shared secret AES key from a secure random source
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates RSA KeyPair
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a serverId hash for use by sendSessionRequest()
|
||||
*/
|
||||
public static byte[] digestData(String pServerId, PublicKey pPublicKey, SecretKey pSecretKey) throws CryptException {
|
||||
try {
|
||||
return digestData(pServerId.getBytes("ISO_8859_1"), pSecretKey.getEncoded(), pPublicKey.getEncoded());
|
||||
} catch (Exception exception) {
|
||||
throw new CryptException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] digestData(byte[]... pData) throws Exception {
|
||||
MessageDigest messagedigest = MessageDigest.getInstance("SHA-1");
|
||||
|
||||
for(byte[] abyte : pData) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PublicKey from encoded X.509 data
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt shared secret AES key using RSA private key
|
||||
*/
|
||||
public static SecretKey decryptByteToSecretKey(PrivateKey pKey, byte[] pSecretKeyEncrypted) throws CryptException {
|
||||
byte[] abyte = decryptUsingKey(pKey, pSecretKeyEncrypted);
|
||||
|
||||
try {
|
||||
return new SecretKeySpec(abyte, "AES");
|
||||
} catch (Exception exception) {
|
||||
throw new CryptException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt byte[] data with RSA public key
|
||||
*/
|
||||
public static byte[] encryptUsingKey(Key pKey, byte[] pData) throws CryptException {
|
||||
return cipherData(1, pKey, pData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt byte[] data with RSA private key
|
||||
*/
|
||||
public static byte[] decryptUsingKey(Key pKey, byte[] pData) throws CryptException {
|
||||
return cipherData(2, pKey, pData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt or decrypt byte[] data using the specified key
|
||||
*/
|
||||
private static byte[] cipherData(int pOpMode, Key pKey, byte[] pData) throws CryptException {
|
||||
try {
|
||||
return setupCipher(pOpMode, pKey.getAlgorithm(), pKey).doFinal(pData);
|
||||
} catch (Exception exception) {
|
||||
throw new CryptException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Cipher Instance.
|
||||
*/
|
||||
private static Cipher setupCipher(int pOpMode, String pTransformation, Key pKey) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance(pTransformation);
|
||||
cipher.init(pOpMode, pKey);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cipher instance using the AES/CFB8/NoPadding algorithm. Used for protocol encryption.
|
||||
*/
|
||||
public static Cipher getCipher(int pOpMode, Key pKey) throws CryptException {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding");
|
||||
cipher.init(pOpMode, pKey, new IvParameterSpec(pKey.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public class CryptException extends Exception {
|
||||
public CryptException(Throwable pCause) {
|
||||
super(pCause);
|
||||
}
|
||||
}
|
||||
+56
@@ -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 pOutput, List<String> pFirstRow) throws IOException {
|
||||
this.output = pOutput;
|
||||
this.columnCount = pFirstRow.size();
|
||||
this.writeLine(pFirstRow.stream());
|
||||
}
|
||||
|
||||
public static CsvOutput.Builder builder() {
|
||||
return new CsvOutput.Builder();
|
||||
}
|
||||
|
||||
public void writeRow(Object... pData) throws IOException {
|
||||
if (pData.length != this.columnCount) {
|
||||
throw new IllegalArgumentException("Invalid number of columns, expected " + this.columnCount + ", but got " + pData.length);
|
||||
} else {
|
||||
this.writeLine(Stream.of(pData));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLine(Stream<?> pData) throws IOException {
|
||||
this.output.write((String)pData.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 pOutput) throws IOException {
|
||||
return new CsvOutput(pOutput, this.headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -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_);
|
||||
}
|
||||
}
|
||||
+292
@@ -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 pValue) {
|
||||
return new CubicSpline.Constant<>(pValue);
|
||||
}
|
||||
|
||||
static <C, I extends ToFloatFunction<C>> CubicSpline.Builder<C, I> builder(I pCoordinate) {
|
||||
return new CubicSpline.Builder<>(pCoordinate);
|
||||
}
|
||||
|
||||
static <C, I extends ToFloatFunction<C>> CubicSpline.Builder<C, I> builder(I pCoordinate, ToFloatFunction<Float> pValueTransformer) {
|
||||
return new CubicSpline.Builder<>(pCoordinate, pValueTransformer);
|
||||
}
|
||||
|
||||
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 pCoordinate) {
|
||||
this(pCoordinate, ToFloatFunction.IDENTITY);
|
||||
}
|
||||
|
||||
protected Builder(I pCoordinate, ToFloatFunction<Float> pValueTransformer) {
|
||||
this.coordinate = pCoordinate;
|
||||
this.valueTransformer = pValueTransformer;
|
||||
}
|
||||
|
||||
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 pLocation, float pValue, float pDerivative) {
|
||||
return this.addPoint(pLocation, new CubicSpline.Constant<>(this.valueTransformer.apply(pValue)), pDerivative);
|
||||
}
|
||||
|
||||
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 pLocation, CubicSpline<C, I> pValue, float pDerivative) {
|
||||
if (!this.locations.isEmpty() && pLocation <= this.locations.getFloat(this.locations.size() - 1)) {
|
||||
throw new IllegalArgumentException("Please register points in ascending order");
|
||||
} else {
|
||||
this.locations.add(pLocation);
|
||||
this.values.add(pValue);
|
||||
this.derivatives.add(pDerivative);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -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 pLength) {
|
||||
this.data = new AtomicReferenceArray<>(pLength);
|
||||
this.index = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
public void push(T pValue) {
|
||||
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, pValue);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
+71
@@ -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 pKey, V pValue) {
|
||||
this.contents.put(pKey, pValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void visitDependenciesAndElement(Multimap<K, K> pDependencies, Set<K> pVisited, K pElement, BiConsumer<K, V> pAction) {
|
||||
if (pVisited.add(pElement)) {
|
||||
pDependencies.get(pElement).forEach((p_285443_) -> {
|
||||
this.visitDependenciesAndElement(pDependencies, pVisited, p_285443_, pAction);
|
||||
});
|
||||
V v = this.contents.get(pElement);
|
||||
if (v != null) {
|
||||
pAction.accept(pElement, v);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static <K> boolean isCyclic(Multimap<K, K> pDependencies, K pSource, K pTarget) {
|
||||
Collection<K> collection = pDependencies.get(pTarget);
|
||||
return collection.contains(pSource) ? true : collection.stream().anyMatch((p_284974_) -> {
|
||||
return isCyclic(pDependencies, pSource, p_284974_);
|
||||
});
|
||||
}
|
||||
|
||||
private static <K> void addDependencyIfNotCyclic(Multimap<K, K> pDependencies, K pSource, K pTarget) {
|
||||
if (!isCyclic(pDependencies, pSource, pTarget)) {
|
||||
pDependencies.put(pSource, pTarget);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void orderByDependencies(BiConsumer<K, V> pAction) {
|
||||
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_, pAction);
|
||||
});
|
||||
}
|
||||
|
||||
public interface Entry<K> {
|
||||
void visitRequiredDependencies(Consumer<K> pVisitor);
|
||||
|
||||
void visitOptionalDependencies(Consumer<K> pVisitor);
|
||||
}
|
||||
}
|
||||
+104
@@ -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 pPath) throws IOException {
|
||||
Path path = pPath.resolve("session.lock");
|
||||
FileUtil.createDirectoriesSafe(pPath);
|
||||
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 pLockFile, FileLock pLock) {
|
||||
this.lockFile = pLockFile;
|
||||
this.lock = pLock;
|
||||
}
|
||||
|
||||
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 pPath) throws IOException {
|
||||
Path path = pPath.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 pPath, String pMessage) {
|
||||
super(pPath.toAbsolutePath() + ": " + pMessage);
|
||||
}
|
||||
|
||||
public static DirectoryLock.LockException alreadyLocked(Path pPath) {
|
||||
return new DirectoryLock.LockException(pPath, "already locked (possibly by other Minecraft instance?)");
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -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 pException) {
|
||||
if (this.result == null) {
|
||||
this.result = pException;
|
||||
} else {
|
||||
this.result.addSuppressed(pException);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void throwIfPresent() throws T {
|
||||
if (this.result != null) {
|
||||
throw this.result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+638
@@ -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> pFirst, Codec<S> pSecond) {
|
||||
return new ExtraCodecs.XorCodec<>(pFirst, pSecond);
|
||||
}
|
||||
|
||||
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> pFirst, final Codec<E> pSecond) {
|
||||
return new Codec<E>() {
|
||||
public <T> DataResult<T> encode(E p_184483_, DynamicOps<T> p_184484_, T p_184485_) {
|
||||
return p_184484_.compressMaps() ? pSecond.encode(p_184483_, p_184484_, p_184485_) : pFirst.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() ? pSecond.decode(p_184480_, p_184481_) : pFirst.decode(p_184480_, p_184481_);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return pFirst + " orCompressed " + pSecond;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <E> Codec<E> overrideLifecycle(Codec<E> pCodec, final Function<E, Lifecycle> p_184370_, final Function<E, Lifecycle> p_184371_) {
|
||||
return pCodec.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> pCodec, Function<T, DataResult<T>> p_265223_) {
|
||||
return pCodec.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 pMin, int pMax, Function<Integer, String> pErrorMessage) {
|
||||
return validate(Codec.INT, (p_274889_) -> {
|
||||
return p_274889_.compareTo(pMin) >= 0 && p_274889_.compareTo(pMax) <= 0 ? DataResult.success(p_274889_) : DataResult.error(() -> {
|
||||
return pErrorMessage.apply(p_274889_);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static Codec<Integer> intRange(int pMin, int pMax) {
|
||||
return intRangeWithMessage(pMin, pMax, (p_269784_) -> {
|
||||
return "Value must be within range [" + pMin + ";" + pMax + "]: " + p_269784_;
|
||||
});
|
||||
}
|
||||
|
||||
private static Codec<Float> floatRangeMinExclusiveWithMessage(float pMin, float pMax, Function<Float, String> pErrorMessage) {
|
||||
return validate(Codec.FLOAT, (p_274865_) -> {
|
||||
return p_274865_.compareTo(pMin) > 0 && p_274865_.compareTo(pMax) <= 0 ? DataResult.success(p_274865_) : DataResult.error(() -> {
|
||||
return pErrorMessage.apply(p_274865_);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> Codec<List<T>> nonEmptyList(Codec<List<T>> pCodec) {
|
||||
return validate(pCodec, (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>> pCodec) {
|
||||
return validate(pCodec, (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>> pDelegate) {
|
||||
return new ExtraCodecs.LazyInitializedCodec<>(pDelegate);
|
||||
}
|
||||
|
||||
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> pCodec) {
|
||||
return Codec.of(pCodec, new Decoder<A>() {
|
||||
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> p_216193_, T p_216194_) {
|
||||
try {
|
||||
return pCodec.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 pDateTimeFormatter) {
|
||||
return Codec.STRING.comapFlatMap((p_274881_) -> {
|
||||
try {
|
||||
return DataResult.success(Instant.from(pDateTimeFormatter.parse(p_274881_)));
|
||||
} catch (Exception exception) {
|
||||
return DataResult.error(exception::getMessage);
|
||||
}
|
||||
}, pDateTimeFormatter::format);
|
||||
}
|
||||
|
||||
public static MapCodec<OptionalLong> asOptionalLong(MapCodec<Optional<Long>> pCodec) {
|
||||
return pCodec.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 pMinSize, int pMaxSize) {
|
||||
return validate(Codec.STRING, (p_274879_) -> {
|
||||
int i = p_274879_.length();
|
||||
if (i < pMinSize) {
|
||||
return DataResult.error(() -> {
|
||||
return "String \"" + p_274879_ + "\" is too short: " + i + ", expected range [" + pMinSize + "-" + pMaxSize + "]";
|
||||
});
|
||||
} else {
|
||||
return i > pMaxSize ? DataResult.error(() -> {
|
||||
return "String \"" + p_274879_ + "\" is too long: " + i + ", expected range [" + pMinSize + "-" + pMaxSize + "]";
|
||||
}) : 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> pFirst, Codec<S> pSecond) {
|
||||
this.first = pFirst;
|
||||
this.second = pSecond;
|
||||
}
|
||||
|
||||
public <T> DataResult<Pair<Either<F, S>, T>> decode(DynamicOps<T> pOps, T pInput) {
|
||||
DataResult<Pair<Either<F, S>, T>> dataresult = this.first.decode(pOps, pInput).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(pOps, pInput).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> pInput, DynamicOps<T> pOps, T pPrefix) {
|
||||
return pInput.map((p_184528_) -> {
|
||||
return this.first.encode(p_184528_, pOps, pPrefix);
|
||||
}, (p_184522_) -> {
|
||||
return this.second.encode(p_184522_, pOps, pPrefix);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean equals(Object pOther) {
|
||||
if (this == pOther) {
|
||||
return true;
|
||||
} else if (pOther != null && this.getClass() == pOther.getClass()) {
|
||||
ExtraCodecs.EitherCodec<?, ?> eithercodec = (ExtraCodecs.EitherCodec)pOther;
|
||||
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> pOps, T pInput) {
|
||||
return this.delegate.get().decode(pOps, pInput);
|
||||
}
|
||||
|
||||
public <T> DataResult<T> encode(A pInput, DynamicOps<T> pOps, T pPrefix) {
|
||||
return this.delegate.get().encode(pInput, pOps, pPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
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> pFirst, Codec<S> pSecond) {
|
||||
this.first = pFirst;
|
||||
this.second = pSecond;
|
||||
}
|
||||
|
||||
public <T> DataResult<Pair<Either<F, S>, T>> decode(DynamicOps<T> pOps, T pInput) {
|
||||
DataResult<Pair<Either<F, S>, T>> dataresult = this.first.decode(pOps, pInput).map((p_144673_) -> {
|
||||
return p_144673_.mapFirst(Either::left);
|
||||
});
|
||||
DataResult<Pair<Either<F, S>, T>> dataresult1 = this.second.decode(pOps, pInput).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> pInput, DynamicOps<T> pOps, T pPrefix) {
|
||||
return pInput.map((p_144677_) -> {
|
||||
return this.first.encode(p_144677_, pOps, pPrefix);
|
||||
}, (p_144671_) -> {
|
||||
return this.second.encode(p_144671_, pOps, pPrefix);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean equals(Object pOther) {
|
||||
if (this == pOther) {
|
||||
return true;
|
||||
} else if (pOther != null && this.getClass() == pOther.getClass()) {
|
||||
ExtraCodecs.XorCodec<?, ?> xorcodec = (ExtraCodecs.XorCodec)pOther;
|
||||
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 + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
@@ -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 pIn) {
|
||||
this(pIn, 8192);
|
||||
}
|
||||
|
||||
public FastBufferedInputStream(InputStream pIn, int pBufferSize) {
|
||||
this.in = pIn;
|
||||
this.buffer = new byte[pBufferSize];
|
||||
}
|
||||
|
||||
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[] pBuffer, int pOffset, int pLength) throws IOException {
|
||||
int i = this.bytesInBuffer();
|
||||
if (i <= 0) {
|
||||
if (pLength >= this.buffer.length) {
|
||||
return this.in.read(pBuffer, pOffset, pLength);
|
||||
}
|
||||
|
||||
this.fill();
|
||||
i = this.bytesInBuffer();
|
||||
if (i <= 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pLength > i) {
|
||||
pLength = i;
|
||||
}
|
||||
|
||||
System.arraycopy(this.buffer, this.position, pBuffer, pOffset, pLength);
|
||||
this.position += pLength;
|
||||
return pLength;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public class FastColor {
|
||||
public static class ABGR32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
}
|
||||
|
||||
public static int red(int pPackedColor) {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
|
||||
public static int green(int pPackedColor) {
|
||||
return pPackedColor >> 8 & 255;
|
||||
}
|
||||
|
||||
public static int blue(int pPackedColor) {
|
||||
return pPackedColor >> 16 & 255;
|
||||
}
|
||||
|
||||
public static int transparent(int pPackedColor) {
|
||||
return pPackedColor & 16777215;
|
||||
}
|
||||
|
||||
public static int opaque(int pPackedColor) {
|
||||
return pPackedColor | -16777216;
|
||||
}
|
||||
|
||||
public static int color(int pAlpha, int pBlue, int pGreen, int pRed) {
|
||||
return pAlpha << 24 | pBlue << 16 | pGreen << 8 | pRed;
|
||||
}
|
||||
|
||||
public static int color(int pAlpha, int pPackedColor) {
|
||||
return pAlpha << 24 | pPackedColor & 16777215;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ARGB32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
}
|
||||
|
||||
public static int red(int pPackedColor) {
|
||||
return pPackedColor >> 16 & 255;
|
||||
}
|
||||
|
||||
public static int green(int pPackedColor) {
|
||||
return pPackedColor >> 8 & 255;
|
||||
}
|
||||
|
||||
public static int blue(int pPackedColor) {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
|
||||
public static int color(int pAlpha, int pRed, int pGreen, int pBlue) {
|
||||
return pAlpha << 24 | pRed << 16 | pGreen << 8 | pBlue;
|
||||
}
|
||||
|
||||
public static int multiply(int pPackedColourOne, int pPackedColorTwo) {
|
||||
return color(alpha(pPackedColourOne) * alpha(pPackedColorTwo) / 255, red(pPackedColourOne) * red(pPackedColorTwo) / 255, green(pPackedColourOne) * green(pPackedColorTwo) / 255, blue(pPackedColourOne) * blue(pPackedColorTwo) / 255);
|
||||
}
|
||||
|
||||
public static int lerp(float pDelta, int pMin, int pMax) {
|
||||
int i = Mth.lerpInt(pDelta, alpha(pMin), alpha(pMax));
|
||||
int j = Mth.lerpInt(pDelta, red(pMin), red(pMax));
|
||||
int k = Mth.lerpInt(pDelta, green(pMin), green(pMax));
|
||||
int l = Mth.lerpInt(pDelta, blue(pMin), blue(pMax));
|
||||
return color(i, j, k, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
+89
@@ -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 pOutputFile) {
|
||||
this.outputFile = pOutputFile;
|
||||
this.tempFile = pOutputFile.resolveSibling(pOutputFile.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 pPath, String pFilename) {
|
||||
try {
|
||||
Path path = this.fs.getPath(File.separator);
|
||||
Path path1 = path.resolve(pPath.toString());
|
||||
Files.createDirectories(path1.getParent());
|
||||
Files.write(path1, pFilename.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (IOException ioexception) {
|
||||
throw new UncheckedIOException(ioexception);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Path pPath, File pFilename) {
|
||||
try {
|
||||
Path path = this.fs.getPath(File.separator);
|
||||
Path path1 = path.resolve(pPath.toString());
|
||||
Files.createDirectories(path1.getParent());
|
||||
Files.copy(pFilename.toPath(), path1);
|
||||
} catch (IOException ioexception) {
|
||||
throw new UncheckedIOException(ioexception);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Path pPath) {
|
||||
try {
|
||||
Path path = this.fs.getPath(File.separator);
|
||||
if (Files.isRegularFile(pPath)) {
|
||||
Path path3 = path.resolve(pPath.getParent().relativize(pPath).toString());
|
||||
Files.copy(path3, pPath);
|
||||
} else {
|
||||
try (Stream<Path> stream = Files.find(pPath, Integer.MAX_VALUE, (p_144707_, p_144708_) -> {
|
||||
return p_144708_.isRegularFile();
|
||||
})) {
|
||||
for(Path path1 : stream.collect(Collectors.toList())) {
|
||||
Path path2 = path.resolve(pPath.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
@@ -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 pSink);
|
||||
|
||||
static FormattedCharSequence codepoint(int pCodePoint, Style pStyle) {
|
||||
return (p_13730_) -> {
|
||||
return p_13730_.accept(0, pStyle, pCodePoint);
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence forward(String pText, Style pStyle) {
|
||||
return pText.isEmpty() ? EMPTY : (p_13739_) -> {
|
||||
return StringDecomposer.iterate(pText, pStyle, p_13739_);
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence forward(String pText, Style pStyle, Int2IntFunction pCodePointMapper) {
|
||||
return pText.isEmpty() ? EMPTY : (p_144730_) -> {
|
||||
return StringDecomposer.iterate(pText, pStyle, decorateOutput(p_144730_, pCodePointMapper));
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence backward(String pText, Style pStyle) {
|
||||
return pText.isEmpty() ? EMPTY : (p_144716_) -> {
|
||||
return StringDecomposer.iterateBackwards(pText, pStyle, p_144716_);
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence backward(String pText, Style pStyle, Int2IntFunction pCodePointMapper) {
|
||||
return pText.isEmpty() ? EMPTY : (p_13721_) -> {
|
||||
return StringDecomposer.iterateBackwards(pText, pStyle, decorateOutput(p_13721_, pCodePointMapper));
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSink decorateOutput(FormattedCharSink pSink, Int2IntFunction pCodePointMapper) {
|
||||
return (p_13711_, p_13712_, p_13713_) -> {
|
||||
return pSink.accept(p_13711_, p_13712_, pCodePointMapper.apply(Integer.valueOf(p_13713_)));
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence composite() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
static FormattedCharSequence composite(FormattedCharSequence pSequence) {
|
||||
return pSequence;
|
||||
}
|
||||
|
||||
static FormattedCharSequence composite(FormattedCharSequence pFirst, FormattedCharSequence pSecond) {
|
||||
return fromPair(pFirst, pSecond);
|
||||
}
|
||||
|
||||
static FormattedCharSequence composite(FormattedCharSequence... pParts) {
|
||||
return fromList(ImmutableList.copyOf(pParts));
|
||||
}
|
||||
|
||||
static FormattedCharSequence composite(List<FormattedCharSequence> pParts) {
|
||||
int i = pParts.size();
|
||||
switch (i) {
|
||||
case 0:
|
||||
return EMPTY;
|
||||
case 1:
|
||||
return pParts.get(0);
|
||||
case 2:
|
||||
return fromPair(pParts.get(0), pParts.get(1));
|
||||
default:
|
||||
return fromList(ImmutableList.copyOf(pParts));
|
||||
}
|
||||
}
|
||||
|
||||
static FormattedCharSequence fromPair(FormattedCharSequence pFirst, FormattedCharSequence pSecond) {
|
||||
return (p_13702_) -> {
|
||||
return pFirst.accept(p_13702_) && pSecond.accept(p_13702_);
|
||||
};
|
||||
}
|
||||
|
||||
static FormattedCharSequence fromList(List<FormattedCharSequence> pParts) {
|
||||
return (p_13726_) -> {
|
||||
for(FormattedCharSequence formattedcharsequence : pParts) {
|
||||
if (!formattedcharsequence.accept(p_13726_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FormattedCharSink {
|
||||
/**
|
||||
* Accepts a single code point from a {@link net.minecraft.util.FormattedCharSequence}.
|
||||
* @return {@code true} to accept more characters, {@code false} to stop traversing the sequence.
|
||||
* @param pPositionInCurrentSequence Contains the relative position of the character in the current sub-sequence. If
|
||||
* multiple formatted char sequences have been combined, this value will reset to {@code 0} after each sequence has
|
||||
* been fully consumed.
|
||||
*/
|
||||
boolean accept(int pPositionInCurrentSequence, Style pStyle, int pCodePoint);
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public class FrameTimer {
|
||||
public static final int LOGGING_LENGTH = 240;
|
||||
/** An array with the last 240 frames */
|
||||
private final long[] loggedTimes = new long[240];
|
||||
/** The last index used when 240 frames have been set */
|
||||
private int logStart;
|
||||
/** A counter */
|
||||
private int logLength;
|
||||
/** The next index to use in the array */
|
||||
private int logEnd;
|
||||
|
||||
/**
|
||||
* Add a frame at the next index in the array frames
|
||||
*/
|
||||
public void logFrameDuration(long pRunningTime) {
|
||||
this.loggedTimes[this.logEnd] = pRunningTime;
|
||||
++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 pValue, int pScale, int pDivisor) {
|
||||
double d0 = (double)pValue / (double)(1000000000L / (long)pDivisor);
|
||||
return (int)(d0 * (double)pScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last index used when 240 frames have been set
|
||||
*/
|
||||
public int getLogStart() {
|
||||
return this.logStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index of the next frame in the array
|
||||
*/
|
||||
public int getLogEnd() {
|
||||
return this.logEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change 240 to 0
|
||||
*/
|
||||
public int wrapIndex(int pRawIndex) {
|
||||
return pRawIndex % 240;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the array of frames
|
||||
*/
|
||||
public long[] getLog() {
|
||||
return this.loggedTimes;
|
||||
}
|
||||
}
|
||||
+45
@@ -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 pExecutor) {
|
||||
this.checkedExecutor = (p_248283_) -> {
|
||||
if (!this.closed) {
|
||||
pExecutor.execute(p_248283_);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public void append(TaskChainer.DelayedTask pDelayedTask) {
|
||||
this.head = this.head.thenComposeAsync((p_248281_) -> {
|
||||
return pDelayedTask.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;
|
||||
}
|
||||
}
|
||||
+32
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+673
@@ -0,0 +1,673 @@
|
||||
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();
|
||||
|
||||
/**
|
||||
* Does the given JsonObject contain a string field with the given name?
|
||||
*/
|
||||
public static boolean isStringValue(JsonObject pJson, String pMemberName) {
|
||||
return !isValidPrimitive(pJson, pMemberName) ? false : pJson.getAsJsonPrimitive(pMemberName).isString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given JsonElement a string?
|
||||
*/
|
||||
public static boolean isStringValue(JsonElement pJson) {
|
||||
return !pJson.isJsonPrimitive() ? false : pJson.getAsJsonPrimitive().isString();
|
||||
}
|
||||
|
||||
public static boolean isNumberValue(JsonObject pJson, String pMemberName) {
|
||||
return !isValidPrimitive(pJson, pMemberName) ? false : pJson.getAsJsonPrimitive(pMemberName).isNumber();
|
||||
}
|
||||
|
||||
public static boolean isNumberValue(JsonElement pJson) {
|
||||
return !pJson.isJsonPrimitive() ? false : pJson.getAsJsonPrimitive().isNumber();
|
||||
}
|
||||
|
||||
public static boolean isBooleanValue(JsonObject pJson, String pMemberName) {
|
||||
return !isValidPrimitive(pJson, pMemberName) ? false : pJson.getAsJsonPrimitive(pMemberName).isBoolean();
|
||||
}
|
||||
|
||||
public static boolean isBooleanValue(JsonElement pJson) {
|
||||
return !pJson.isJsonPrimitive() ? false : pJson.getAsJsonPrimitive().isBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given JsonObject contain an array field with the given name?
|
||||
*/
|
||||
public static boolean isArrayNode(JsonObject pJson, String pMemberName) {
|
||||
return !isValidNode(pJson, pMemberName) ? false : pJson.get(pMemberName).isJsonArray();
|
||||
}
|
||||
|
||||
public static boolean isObjectNode(JsonObject pJson, String pMemberName) {
|
||||
return !isValidNode(pJson, pMemberName) ? false : pJson.get(pMemberName).isJsonObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or
|
||||
* Java primitive wrapper)?
|
||||
*/
|
||||
public static boolean isValidPrimitive(JsonObject pJson, String pMemberName) {
|
||||
return !isValidNode(pJson, pMemberName) ? false : pJson.get(pMemberName).isJsonPrimitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given JsonObject contain a field with the given name?
|
||||
*/
|
||||
public static boolean isValidNode(@Nullable JsonObject pJson, String pMemberName) {
|
||||
if (pJson == null) {
|
||||
return false;
|
||||
} else {
|
||||
return pJson.get(pMemberName) != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonElement getNonNull(JsonObject pJson, String pMemberName) {
|
||||
JsonElement jsonelement = pJson.get(pMemberName);
|
||||
if (jsonelement != null && !jsonelement.isJsonNull()) {
|
||||
return jsonelement;
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing field " + pMemberName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string value of the given JsonElement. Expects the second parameter to be the name of the element's
|
||||
* field if an error message needs to be thrown.
|
||||
*/
|
||||
public static String convertToString(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive()) {
|
||||
return pJson.getAsString();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a string, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string value of the field on the JsonObject with the given name.
|
||||
*/
|
||||
public static String getAsString(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToString(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a string");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string value of the field on the JsonObject with the given name, or the given default value if the field
|
||||
* is missing.
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("_,_,!null->!null;_,_,null->_")
|
||||
public static String getAsString(JsonObject pJson, String pMemberName, @Nullable String pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToString(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static Item convertToItem(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive()) {
|
||||
String s = pJson.getAsString();
|
||||
return BuiltInRegistries.ITEM.getOptional(new ResourceLocation(s)).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Expected " + pMemberName + " to be an item, was unknown string '" + s + "'");
|
||||
});
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be an item, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static Item getAsItem(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToItem(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find an item");
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("_,_,!null->!null;_,_,null->_")
|
||||
public static Item getAsItem(JsonObject pJson, String pMemberName, @Nullable Item pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToItem(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's
|
||||
* field if an error message needs to be thrown.
|
||||
*/
|
||||
public static boolean convertToBoolean(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive()) {
|
||||
return pJson.getAsBoolean();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Boolean, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean value of the field on the JsonObject with the given name.
|
||||
*/
|
||||
public static boolean getAsBoolean(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToBoolean(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Boolean");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean value of the field on the JsonObject with the given name, or the given default value if the field
|
||||
* is missing.
|
||||
*/
|
||||
public static boolean getAsBoolean(JsonObject pJson, String pMemberName, boolean pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToBoolean(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static double convertToDouble(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsDouble();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Double, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static double getAsDouble(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToDouble(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Double");
|
||||
}
|
||||
}
|
||||
|
||||
public static double getAsDouble(JsonObject pJson, String pMemberName, double pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToDouble(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's field
|
||||
* if an error message needs to be thrown.
|
||||
*/
|
||||
public static float convertToFloat(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsFloat();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Float, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the float value of the field on the JsonObject with the given name.
|
||||
*/
|
||||
public static float getAsFloat(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToFloat(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Float");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the float value of the field on the JsonObject with the given name, or the given default value if the field
|
||||
* is missing.
|
||||
*/
|
||||
public static float getAsFloat(JsonObject pJson, String pMemberName, float pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToFloat(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a long from a JSON element and validates that the value is actually a number.
|
||||
*/
|
||||
public static long convertToLong(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsLong();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Long, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a long from a JSON element, throws an error if the member does not exist.
|
||||
*/
|
||||
public static long getAsLong(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToLong(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Long");
|
||||
}
|
||||
}
|
||||
|
||||
public static long getAsLong(JsonObject pJson, String pMemberName, long pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToLong(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the integer value of the given JsonElement. Expects the second parameter to be the name of the element's
|
||||
* field if an error message needs to be thrown.
|
||||
*/
|
||||
public static int convertToInt(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsInt();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Int, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the integer value of the field on the JsonObject with the given name.
|
||||
*/
|
||||
public static int getAsInt(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToInt(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Int");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the integer value of the field on the JsonObject with the given name, or the given default value if the field
|
||||
* is missing.
|
||||
*/
|
||||
public static int getAsInt(JsonObject pJson, String pMemberName, int pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToInt(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static byte convertToByte(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsByte();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Byte, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static byte getAsByte(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToByte(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Byte");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte getAsByte(JsonObject pJson, String pMemberName, byte pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToByte(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static char convertToCharacter(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsCharacter();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Character, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static char getAsCharacter(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToCharacter(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Character");
|
||||
}
|
||||
}
|
||||
|
||||
public static char getAsCharacter(JsonObject pJson, String pMemberName, char pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToCharacter(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static BigDecimal convertToBigDecimal(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsBigDecimal();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a BigDecimal, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static BigDecimal getAsBigDecimal(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToBigDecimal(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a BigDecimal");
|
||||
}
|
||||
}
|
||||
|
||||
public static BigDecimal getAsBigDecimal(JsonObject pJson, String pMemberName, BigDecimal pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToBigDecimal(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static BigInteger convertToBigInteger(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsBigInteger();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a BigInteger, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static BigInteger getAsBigInteger(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToBigInteger(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a BigInteger");
|
||||
}
|
||||
}
|
||||
|
||||
public static BigInteger getAsBigInteger(JsonObject pJson, String pMemberName, BigInteger pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToBigInteger(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static short convertToShort(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonPrimitive() && pJson.getAsJsonPrimitive().isNumber()) {
|
||||
return pJson.getAsShort();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a Short, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static short getAsShort(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToShort(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a Short");
|
||||
}
|
||||
}
|
||||
|
||||
public static short getAsShort(JsonObject pJson, String pMemberName, short pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToShort(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given JsonElement as a JsonObject. Expects the second parameter to be the name of the element's field if
|
||||
* an error message needs to be thrown.
|
||||
*/
|
||||
public static JsonObject convertToJsonObject(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonObject()) {
|
||||
return pJson.getAsJsonObject();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a JsonObject, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject getAsJsonObject(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToJsonObject(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a JsonObject");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is
|
||||
* missing.
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("_,_,!null->!null;_,_,null->_")
|
||||
public static JsonObject getAsJsonObject(JsonObject pJson, String pMemberName, @Nullable JsonObject pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToJsonObject(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given JsonElement as a JsonArray. Expects the second parameter to be the name of the element's field if
|
||||
* an error message needs to be thrown.
|
||||
*/
|
||||
public static JsonArray convertToJsonArray(JsonElement pJson, String pMemberName) {
|
||||
if (pJson.isJsonArray()) {
|
||||
return pJson.getAsJsonArray();
|
||||
} else {
|
||||
throw new JsonSyntaxException("Expected " + pMemberName + " to be a JsonArray, was " + getType(pJson));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JsonArray field on the JsonObject with the given name.
|
||||
*/
|
||||
public static JsonArray getAsJsonArray(JsonObject pJson, String pMemberName) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToJsonArray(pJson.get(pMemberName), pMemberName);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName + ", expected to find a JsonArray");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is
|
||||
* missing.
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("_,_,!null->!null;_,_,null->_")
|
||||
public static JsonArray getAsJsonArray(JsonObject pJson, String pMemberName, @Nullable JsonArray pFallback) {
|
||||
return pJson.has(pMemberName) ? convertToJsonArray(pJson.get(pMemberName), pMemberName) : pFallback;
|
||||
}
|
||||
|
||||
public static <T> T convertToObject(@Nullable JsonElement pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) {
|
||||
if (pJson != null) {
|
||||
return pContext.deserialize(pJson, pAdapter);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getAsObject(JsonObject pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) {
|
||||
if (pJson.has(pMemberName)) {
|
||||
return convertToObject(pJson.get(pMemberName), pMemberName, pContext, pAdapter);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Missing " + pMemberName);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("_,_,!null,_,_->!null;_,_,null,_,_->_")
|
||||
public static <T> T getAsObject(JsonObject pJson, String pMemberName, @Nullable T pFallback, JsonDeserializationContext pContext, Class<? extends T> pAdapter) {
|
||||
return (T)(pJson.has(pMemberName) ? convertToObject(pJson.get(pMemberName), pMemberName, pContext, pAdapter) : pFallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a human-readable description of the given JsonElement's type. For example: "a number (4)"
|
||||
*/
|
||||
public static String getType(@Nullable JsonElement pJson) {
|
||||
String s = StringUtils.abbreviateMiddle(String.valueOf((Object)pJson), "...", 10);
|
||||
if (pJson == null) {
|
||||
return "null (missing)";
|
||||
} else if (pJson.isJsonNull()) {
|
||||
return "null (json)";
|
||||
} else if (pJson.isJsonArray()) {
|
||||
return "an array (" + s + ")";
|
||||
} else if (pJson.isJsonObject()) {
|
||||
return "an object (" + s + ")";
|
||||
} else {
|
||||
if (pJson.isJsonPrimitive()) {
|
||||
JsonPrimitive jsonprimitive = pJson.getAsJsonPrimitive();
|
||||
if (jsonprimitive.isNumber()) {
|
||||
return "a number (" + s + ")";
|
||||
}
|
||||
|
||||
if (jsonprimitive.isBoolean()) {
|
||||
return "a boolean (" + s + ")";
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T fromNullableJson(Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient) {
|
||||
try {
|
||||
JsonReader jsonreader = new JsonReader(pReader);
|
||||
jsonreader.setLenient(pLenient);
|
||||
return pGson.getAdapter(pAdapter).read(jsonreader);
|
||||
} catch (IOException ioexception) {
|
||||
throw new JsonParseException(ioexception);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient) {
|
||||
T t = fromNullableJson(pGson, pReader, pAdapter, pLenient);
|
||||
if (t == null) {
|
||||
throw new JsonParseException("JSON data was null or empty");
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T fromNullableJson(Gson pGson, Reader pReader, TypeToken<T> pType, boolean pLenient) {
|
||||
try {
|
||||
JsonReader jsonreader = new JsonReader(pReader);
|
||||
jsonreader.setLenient(pLenient);
|
||||
return pGson.getAdapter(pType).read(jsonreader);
|
||||
} catch (IOException ioexception) {
|
||||
throw new JsonParseException(ioexception);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, Reader pReader, TypeToken<T> pType, boolean pLenient) {
|
||||
T t = fromNullableJson(pGson, pReader, pType, pLenient);
|
||||
if (t == null) {
|
||||
throw new JsonParseException("JSON data was null or empty");
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T fromNullableJson(Gson pGson, String pJson, TypeToken<T> pType, boolean pLenient) {
|
||||
return fromNullableJson(pGson, new StringReader(pJson), pType, pLenient);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient) {
|
||||
return fromJson(pGson, new StringReader(pJson), pAdapter, pLenient);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T fromNullableJson(Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient) {
|
||||
return fromNullableJson(pGson, new StringReader(pJson), pAdapter, pLenient);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, Reader pReader, TypeToken<T> pType) {
|
||||
return fromJson(pGson, pReader, pType, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T fromNullableJson(Gson pGson, String pJson, TypeToken<T> pType) {
|
||||
return fromNullableJson(pGson, pJson, pType, false);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, Reader pReader, Class<T> pJsonClass) {
|
||||
return fromJson(pGson, pReader, pJsonClass, false);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(Gson pGson, String pJson, Class<T> pAdapter) {
|
||||
return fromJson(pGson, pJson, pAdapter, false);
|
||||
}
|
||||
|
||||
public static JsonObject parse(String pJson, boolean pLenient) {
|
||||
return parse(new StringReader(pJson), pLenient);
|
||||
}
|
||||
|
||||
public static JsonObject parse(Reader pReader, boolean pLenient) {
|
||||
return fromJson(GSON, pReader, JsonObject.class, pLenient);
|
||||
}
|
||||
|
||||
public static JsonObject parse(String pJson) {
|
||||
return parse(pJson, false);
|
||||
}
|
||||
|
||||
public static JsonObject parse(Reader pReader) {
|
||||
return parse(pReader, false);
|
||||
}
|
||||
|
||||
public static JsonArray parseArray(String pString) {
|
||||
return parseArray(new StringReader(pString));
|
||||
}
|
||||
|
||||
public static JsonArray parseArray(Reader pReader) {
|
||||
return fromJson(GSON, pReader, JsonArray.class, false);
|
||||
}
|
||||
|
||||
public static String toStableString(JsonElement pJson) {
|
||||
StringWriter stringwriter = new StringWriter();
|
||||
JsonWriter jsonwriter = new JsonWriter(stringwriter);
|
||||
|
||||
try {
|
||||
writeValue(jsonwriter, pJson, Comparator.naturalOrder());
|
||||
} catch (IOException ioexception) {
|
||||
throw new AssertionError(ioexception);
|
||||
}
|
||||
|
||||
return stringwriter.toString();
|
||||
}
|
||||
|
||||
public static void writeValue(JsonWriter pWriter, @Nullable JsonElement pJsonElement, @Nullable Comparator<String> pSorter) throws IOException {
|
||||
if (pJsonElement != null && !pJsonElement.isJsonNull()) {
|
||||
if (pJsonElement.isJsonPrimitive()) {
|
||||
JsonPrimitive jsonprimitive = pJsonElement.getAsJsonPrimitive();
|
||||
if (jsonprimitive.isNumber()) {
|
||||
pWriter.value(jsonprimitive.getAsNumber());
|
||||
} else if (jsonprimitive.isBoolean()) {
|
||||
pWriter.value(jsonprimitive.getAsBoolean());
|
||||
} else {
|
||||
pWriter.value(jsonprimitive.getAsString());
|
||||
}
|
||||
} else if (pJsonElement.isJsonArray()) {
|
||||
pWriter.beginArray();
|
||||
|
||||
for(JsonElement jsonelement : pJsonElement.getAsJsonArray()) {
|
||||
writeValue(pWriter, jsonelement, pSorter);
|
||||
}
|
||||
|
||||
pWriter.endArray();
|
||||
} else {
|
||||
if (!pJsonElement.isJsonObject()) {
|
||||
throw new IllegalArgumentException("Couldn't write " + pJsonElement.getClass());
|
||||
}
|
||||
|
||||
pWriter.beginObject();
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : sortByKeyIfNeeded(pJsonElement.getAsJsonObject().entrySet(), pSorter)) {
|
||||
pWriter.name(entry.getKey());
|
||||
writeValue(pWriter, entry.getValue(), pSorter);
|
||||
}
|
||||
|
||||
pWriter.endObject();
|
||||
}
|
||||
} else {
|
||||
pWriter.nullValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> pEntries, @Nullable Comparator<String> pSorter) {
|
||||
if (pSorter == null) {
|
||||
return pEntries;
|
||||
} else {
|
||||
List<Map.Entry<String, JsonElement>> list = new ArrayList<>(pEntries);
|
||||
list.sort(Entry.comparingByKey(pSorter));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
+174
@@ -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 pSaveFile, URL pPackUrl, Map<String, String> pRequestProperties, int pMaxSize, @Nullable ProgressListener pProgressCallback, Proxy pProxy) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
HttpURLConnection httpurlconnection = null;
|
||||
InputStream inputstream = null;
|
||||
OutputStream outputstream = null;
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.progressStart(Component.translatable("resourcepack.downloading"));
|
||||
pProgressCallback.progressStage(Component.translatable("resourcepack.requesting"));
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
byte[] abyte = new byte[4096];
|
||||
httpurlconnection = (HttpURLConnection)pPackUrl.openConnection(pProxy);
|
||||
httpurlconnection.setInstanceFollowRedirects(true);
|
||||
float f1 = 0.0F;
|
||||
float f = (float)pRequestProperties.entrySet().size();
|
||||
|
||||
for(Map.Entry<String, String> entry : pRequestProperties.entrySet()) {
|
||||
httpurlconnection.setRequestProperty(entry.getKey(), entry.getValue());
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.progressStagePercentage((int)(++f1 / f * 100.0F));
|
||||
}
|
||||
}
|
||||
|
||||
inputstream = httpurlconnection.getInputStream();
|
||||
f = (float)httpurlconnection.getContentLength();
|
||||
int i = httpurlconnection.getContentLength();
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.progressStage(Component.translatable("resourcepack.progress", String.format(Locale.ROOT, "%.2f", f / 1000.0F / 1000.0F)));
|
||||
}
|
||||
|
||||
if (pSaveFile.exists()) {
|
||||
long j = pSaveFile.length();
|
||||
if (j == (long)i) {
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.stop();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
LOGGER.warn("Deleting {} as it does not match what we currently have ({} vs our {}).", pSaveFile, i, j);
|
||||
FileUtils.deleteQuietly(pSaveFile);
|
||||
} else if (pSaveFile.getParentFile() != null) {
|
||||
pSaveFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
outputstream = new DataOutputStream(new FileOutputStream(pSaveFile));
|
||||
if (pMaxSize > 0 && f > (float)pMaxSize) {
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.stop();
|
||||
}
|
||||
|
||||
throw new IOException("Filesize is bigger than maximum allowed (file is " + f1 + ", limit is " + pMaxSize + ")");
|
||||
}
|
||||
|
||||
int k;
|
||||
while((k = inputstream.read(abyte)) >= 0) {
|
||||
f1 += (float)k;
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.progressStagePercentage((int)(f1 / f * 100.0F));
|
||||
}
|
||||
|
||||
if (pMaxSize > 0 && f1 > (float)pMaxSize) {
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.stop();
|
||||
}
|
||||
|
||||
throw new IOException("Filesize was bigger than maximum allowed (got >= " + f1 + ", limit was " + pMaxSize + ")");
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) {
|
||||
LOGGER.error("INTERRUPTED");
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.stop();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
outputstream.write(abyte, 0, k);
|
||||
}
|
||||
|
||||
if (pProgressCallback != null) {
|
||||
pProgressCallback.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 (pProgressCallback != null) {
|
||||
pProgressCallback.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -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> pCodec) {
|
||||
return ExtraCodecs.intervalCodec(pCodec, "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 pValue) {
|
||||
return pValue.compareTo(this.minInclusive) >= 0 && pValue.compareTo(this.maxInclusive) <= 0;
|
||||
}
|
||||
|
||||
public boolean contains(InclusiveRange<T> pValue) {
|
||||
return pValue.minInclusive().compareTo(this.minInclusive) >= 0 && pValue.maxInclusive.compareTo(this.maxInclusive) <= 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + this.minInclusive + ", " + this.maxInclusive + "]";
|
||||
}
|
||||
}
|
||||
+14
@@ -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> pCodec) {
|
||||
return new KeyDispatchDataCodec<>(pCodec);
|
||||
}
|
||||
|
||||
public static <A> KeyDispatchDataCodec<A> of(MapCodec<A> pCodec) {
|
||||
return new KeyDispatchDataCodec<>(pCodec.codec());
|
||||
}
|
||||
}
|
||||
+18
@@ -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();
|
||||
}
|
||||
}
|
||||
+11
@@ -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 pLeft, long pRight) {
|
||||
pLeft *= pLeft * 6364136223846793005L + 1442695040888963407L;
|
||||
return pLeft + pRight;
|
||||
}
|
||||
}
|
||||
+55
@@ -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 pGson, TypeToken<T> pTypeToken) {
|
||||
Class<T> oclass = (Class<T>)pTypeToken.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 pObject) {
|
||||
return pObject instanceof Enum ? ((Enum)pObject).name().toLowerCase(Locale.ROOT) : pObject.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+16
@@ -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];
|
||||
}
|
||||
}
|
||||
+41
@@ -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 pOther) {
|
||||
return new ModCheck(ObjectUtils.max(this.confidence, pOther.confidence), this.description + "; " + pOther.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 pDescription, boolean pShouldReportAsModified) {
|
||||
this.description = pDescription;
|
||||
this.shouldReportAsModified = pShouldReportAsModified;
|
||||
}
|
||||
}
|
||||
}
|
||||
+805
@@ -0,0 +1,805 @@
|
||||
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();
|
||||
/**
|
||||
* Though it looks like an array, this is really more like a mapping. Key (index of this array) is the upper 5 bits
|
||||
* of the result of multiplying a 32-bit unsigned integer by the B(2, 5) De Bruijn sequence 0x077CB531. Value (value
|
||||
* stored in the array) is the unique index (from the right) of the leftmo
|
||||
*/
|
||||
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];
|
||||
|
||||
/**
|
||||
* sin looked up in a table
|
||||
*/
|
||||
public static float sin(float pValue) {
|
||||
return SIN[(int)(pValue * 10430.378F) & '\uffff'];
|
||||
}
|
||||
|
||||
/**
|
||||
* cos looked up in the sin table with the appropriate offset
|
||||
*/
|
||||
public static float cos(float pValue) {
|
||||
return SIN[(int)(pValue * 10430.378F + 16384.0F) & '\uffff'];
|
||||
}
|
||||
|
||||
public static float sqrt(float pValue) {
|
||||
return (float)Math.sqrt((double)pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greatest integer less than or equal to the float argument
|
||||
*/
|
||||
public static int floor(float pValue) {
|
||||
int i = (int)pValue;
|
||||
return pValue < (float)i ? i - 1 : i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greatest integer less than or equal to the double argument
|
||||
*/
|
||||
public static int floor(double pValue) {
|
||||
int i = (int)pValue;
|
||||
return pValue < (double)i ? i - 1 : i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Long version of floor()
|
||||
*/
|
||||
public static long lfloor(double pValue) {
|
||||
long i = (long)pValue;
|
||||
return pValue < (double)i ? i - 1L : i;
|
||||
}
|
||||
|
||||
public static float abs(float pValue) {
|
||||
return Math.abs(pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unsigned value of an int.
|
||||
*/
|
||||
public static int abs(int pValue) {
|
||||
return Math.abs(pValue);
|
||||
}
|
||||
|
||||
public static int ceil(float pValue) {
|
||||
int i = (int)pValue;
|
||||
return pValue > (float)i ? i + 1 : i;
|
||||
}
|
||||
|
||||
public static int ceil(double pValue) {
|
||||
int i = (int)pValue;
|
||||
return pValue > (double)i ? i + 1 : i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given value if between the lower and the upper bound. If the value is less than the lower bound,
|
||||
* returns the lower bound. If the value is greater than the upper bound, returns the upper bound.
|
||||
* @param pValue The value that is clamped.
|
||||
* @param pMin The lower bound for the clamp.
|
||||
* @param pMax The upper bound for the clamp.
|
||||
*/
|
||||
public static int clamp(int pValue, int pMin, int pMax) {
|
||||
return Math.min(Math.max(pValue, pMin), pMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given value if between the lower and the upper bound. If the value is less than the lower bound,
|
||||
* returns the lower bound. If the value is greater than the upper bound, returns the upper bound.
|
||||
* @param pValue The value that is clamped.
|
||||
* @param pMin The lower bound for the clamp.
|
||||
* @param pMax The upper bound for the clamp.
|
||||
*/
|
||||
public static float clamp(float pValue, float pMin, float pMax) {
|
||||
return pValue < pMin ? pMin : Math.min(pValue, pMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given value if between the lower and the upper bound. If the value is less than the lower bound,
|
||||
* returns the lower bound. If the value is greater than the upper bound, returns the upper bound.
|
||||
* @param pValue The value that is clamped.
|
||||
* @param pMin The lower bound for the clamp.
|
||||
* @param pMax The upper bound for the clamp.
|
||||
*/
|
||||
public static double clamp(double pValue, double pMin, double pMax) {
|
||||
return pValue < pMin ? pMin : Math.min(pValue, pMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for linear interpolation of doubles.
|
||||
* @param pStart Start value for the lerp.
|
||||
* @param pEnd End value for the lerp.
|
||||
* @param pDelta A value between 0 and 1 that indicates the percentage of the lerp. (0 will give the start value and
|
||||
* 1 will give the end value) If the value is not between 0 and 1, it is clamped.
|
||||
*/
|
||||
public static double clampedLerp(double pStart, double pEnd, double pDelta) {
|
||||
if (pDelta < 0.0D) {
|
||||
return pStart;
|
||||
} else {
|
||||
return pDelta > 1.0D ? pEnd : lerp(pDelta, pStart, pEnd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for linear interpolation of floats.
|
||||
* @param pStart Start value for the lerp.
|
||||
* @param pEnd End value for the lerp.
|
||||
* @param pDelta A value between 0 and 1 that indicates the percentage of the lerp. (0 will give the start value and
|
||||
* 1 will give the end value) If the value is not between 0 and 1, it is clamped.
|
||||
*/
|
||||
public static float clampedLerp(float pStart, float pEnd, float pDelta) {
|
||||
if (pDelta < 0.0F) {
|
||||
return pStart;
|
||||
} else {
|
||||
return pDelta > 1.0F ? pEnd : lerp(pDelta, pStart, pEnd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum of the absolute value of two numbers.
|
||||
*/
|
||||
public static double absMax(double pX, double pY) {
|
||||
if (pX < 0.0D) {
|
||||
pX = -pX;
|
||||
}
|
||||
|
||||
if (pY < 0.0D) {
|
||||
pY = -pY;
|
||||
}
|
||||
|
||||
return Math.max(pX, pY);
|
||||
}
|
||||
|
||||
public static int floorDiv(int pDividend, int pDivisor) {
|
||||
return Math.floorDiv(pDividend, pDivisor);
|
||||
}
|
||||
|
||||
public static int nextInt(RandomSource pRandom, int pMinimum, int pMaximum) {
|
||||
return pMinimum >= pMaximum ? pMinimum : pRandom.nextInt(pMaximum - pMinimum + 1) + pMinimum;
|
||||
}
|
||||
|
||||
public static float nextFloat(RandomSource pRandom, float pMinimum, float pMaximum) {
|
||||
return pMinimum >= pMaximum ? pMinimum : pRandom.nextFloat() * (pMaximum - pMinimum) + pMinimum;
|
||||
}
|
||||
|
||||
public static double nextDouble(RandomSource pRandom, double pMinimum, double pMaximum) {
|
||||
return pMinimum >= pMaximum ? pMinimum : pRandom.nextDouble() * (pMaximum - pMinimum) + pMinimum;
|
||||
}
|
||||
|
||||
public static boolean equal(float pX, float pY) {
|
||||
return Math.abs(pY - pX) < 1.0E-5F;
|
||||
}
|
||||
|
||||
public static boolean equal(double pX, double pY) {
|
||||
return Math.abs(pY - pX) < (double)1.0E-5F;
|
||||
}
|
||||
|
||||
public static int positiveModulo(int pX, int pY) {
|
||||
return Math.floorMod(pX, pY);
|
||||
}
|
||||
|
||||
public static float positiveModulo(float pNumerator, float pDenominator) {
|
||||
return (pNumerator % pDenominator + pDenominator) % pDenominator;
|
||||
}
|
||||
|
||||
public static double positiveModulo(double pNumerator, double pDenominator) {
|
||||
return (pNumerator % pDenominator + pDenominator) % pDenominator;
|
||||
}
|
||||
|
||||
public static boolean isMultipleOf(int pNumber, int pMultiple) {
|
||||
return pNumber % pMultiple == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the angle so that its value is in the range [-180;180)
|
||||
*/
|
||||
public static int wrapDegrees(int pAngle) {
|
||||
int i = pAngle % 360;
|
||||
if (i >= 180) {
|
||||
i -= 360;
|
||||
}
|
||||
|
||||
if (i < -180) {
|
||||
i += 360;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* The angle is reduced to an angle between -180 and +180 by mod, and a 360 check.
|
||||
*/
|
||||
public static float wrapDegrees(float pValue) {
|
||||
float f = pValue % 360.0F;
|
||||
if (f >= 180.0F) {
|
||||
f -= 360.0F;
|
||||
}
|
||||
|
||||
if (f < -180.0F) {
|
||||
f += 360.0F;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* The angle is reduced to an angle between -180 and +180 by mod, and a 360 check.
|
||||
*/
|
||||
public static double wrapDegrees(double pValue) {
|
||||
double d0 = pValue % 360.0D;
|
||||
if (d0 >= 180.0D) {
|
||||
d0 -= 360.0D;
|
||||
}
|
||||
|
||||
if (d0 < -180.0D) {
|
||||
d0 += 360.0D;
|
||||
}
|
||||
|
||||
return d0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the difference between two angles in degrees.
|
||||
*/
|
||||
public static float degreesDifference(float pStart, float pEnd) {
|
||||
return wrapDegrees(pEnd - pStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the absolute of the difference between two angles in degrees.
|
||||
*/
|
||||
public static float degreesDifferenceAbs(float pStart, float pEnd) {
|
||||
return abs(degreesDifference(pStart, pEnd));
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a rotation and compares it to another rotation.
|
||||
* If the difference is greater than a given maximum, clamps the original rotation between to have at most the given
|
||||
* difference to the actual rotation.
|
||||
* This is used to match the body rotation of entities to their head rotation.
|
||||
* @return The new value for the rotation that was adjusted
|
||||
*/
|
||||
public static float rotateIfNecessary(float pRotationToAdjust, float pActualRotation, float pMaxDifference) {
|
||||
float f = degreesDifference(pRotationToAdjust, pActualRotation);
|
||||
float f1 = clamp(f, -pMaxDifference, pMaxDifference);
|
||||
return pActualRotation - f1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes value by stepSize towards the limit and returns the result.
|
||||
* If value is smaller than limit, the result will never be bigger than limit.
|
||||
* If value is bigger than limit, the result will never be smaller than limit.
|
||||
*/
|
||||
public static float approach(float pValue, float pLimit, float pStepSize) {
|
||||
pStepSize = abs(pStepSize);
|
||||
return pValue < pLimit ? clamp(pValue + pStepSize, pValue, pLimit) : clamp(pValue - pStepSize, pLimit, pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the angle by stepSize towards the limit in the direction where the distance is smaller.
|
||||
* {@see #approach(float, float, float)}
|
||||
*/
|
||||
public static float approachDegrees(float pAngle, float pLimit, float pStepSize) {
|
||||
float f = degreesDifference(pAngle, pLimit);
|
||||
return approach(pAngle, pAngle + f, pStepSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the string as an integer or returns the second parameter if it fails.
|
||||
*/
|
||||
public static int getInt(String pValue, int pDefaultValue) {
|
||||
return NumberUtils.toInt(pValue, pDefaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input value rounded up to the next highest power of two.
|
||||
*/
|
||||
public static int smallestEncompassingPowerOfTwo(int pValue) {
|
||||
int i = pValue - 1;
|
||||
i |= i >> 1;
|
||||
i |= i >> 2;
|
||||
i |= i >> 4;
|
||||
i |= i >> 8;
|
||||
i |= i >> 16;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given value a power of two? (1, 2, 4, 8, 16, ...)
|
||||
*/
|
||||
public static boolean isPowerOfTwo(int pValue) {
|
||||
return pValue != 0 && (pValue & pValue - 1) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a B(2, 5) De Bruijn sequence and a lookup table to efficiently calculate the log-base-two of the given value.
|
||||
* Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-two, then
|
||||
* subtract 1 from the return value.
|
||||
*/
|
||||
public static int ceillog2(int pValue) {
|
||||
pValue = isPowerOfTwo(pValue) ? pValue : smallestEncompassingPowerOfTwo(pValue);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)pValue * 125613361L >> 27) & 31];
|
||||
}
|
||||
|
||||
/**
|
||||
* Efficiently calculates the floor of the base-2 log of an integer value. This is effectively the index of the
|
||||
* highest bit that is set. For example, if the number in binary is 0...100101, this will return 5.
|
||||
*/
|
||||
public static int log2(int pValue) {
|
||||
return ceillog2(pValue) - (isPowerOfTwo(pValue) ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an integer color from the given red, green, and blue float values
|
||||
*/
|
||||
public static int color(float pR, float pG, float pB) {
|
||||
return FastColor.ARGB32.color(0, floor(pR * 255.0F), floor(pG * 255.0F), floor(pB * 255.0F));
|
||||
}
|
||||
|
||||
public static float frac(float pNumber) {
|
||||
return pNumber - (float)floor(pNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the decimal portion of the given double. For instance, {@code frac(5.5)} returns {@code .5}.
|
||||
*/
|
||||
public static double frac(double pNumber) {
|
||||
return pNumber - (double)lfloor(pNumber);
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static long getSeed(Vec3i pPos) {
|
||||
return getSeed(pPos.getX(), pPos.getY(), pPos.getZ());
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static long getSeed(int pX, int pY, int pZ) {
|
||||
long i = (long)(pX * 3129871) ^ (long)pZ * 116129781L ^ (long)pY;
|
||||
i = i * i * 42317861L + i * 11L;
|
||||
return i >> 16;
|
||||
}
|
||||
|
||||
public static UUID createInsecureUUID(RandomSource pRandom) {
|
||||
long i = pRandom.nextLong() & -61441L | 16384L;
|
||||
long j = pRandom.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
|
||||
return new UUID(i, j);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random UUID using the shared random
|
||||
*/
|
||||
public static UUID createInsecureUUID() {
|
||||
return createInsecureUUID(RANDOM);
|
||||
}
|
||||
|
||||
public static double inverseLerp(double pDelta, double pStart, double pEnd) {
|
||||
return (pDelta - pStart) / (pEnd - pStart);
|
||||
}
|
||||
|
||||
public static float inverseLerp(float pDelta, float pStart, float pEnd) {
|
||||
return (pDelta - pStart) / (pEnd - pStart);
|
||||
}
|
||||
|
||||
public static boolean rayIntersectsAABB(Vec3 pStart, Vec3 pEnd, AABB pBoundingBox) {
|
||||
double d0 = (pBoundingBox.minX + pBoundingBox.maxX) * 0.5D;
|
||||
double d1 = (pBoundingBox.maxX - pBoundingBox.minX) * 0.5D;
|
||||
double d2 = pStart.x - d0;
|
||||
if (Math.abs(d2) > d1 && d2 * pEnd.x >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double d3 = (pBoundingBox.minY + pBoundingBox.maxY) * 0.5D;
|
||||
double d4 = (pBoundingBox.maxY - pBoundingBox.minY) * 0.5D;
|
||||
double d5 = pStart.y - d3;
|
||||
if (Math.abs(d5) > d4 && d5 * pEnd.y >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double d6 = (pBoundingBox.minZ + pBoundingBox.maxZ) * 0.5D;
|
||||
double d7 = (pBoundingBox.maxZ - pBoundingBox.minZ) * 0.5D;
|
||||
double d8 = pStart.z - d6;
|
||||
if (Math.abs(d8) > d7 && d8 * pEnd.z >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double d9 = Math.abs(pEnd.x);
|
||||
double d10 = Math.abs(pEnd.y);
|
||||
double d11 = Math.abs(pEnd.z);
|
||||
double d12 = pEnd.y * d8 - pEnd.z * d5;
|
||||
if (Math.abs(d12) > d4 * d11 + d7 * d10) {
|
||||
return false;
|
||||
} else {
|
||||
d12 = pEnd.z * d2 - pEnd.x * d8;
|
||||
if (Math.abs(d12) > d1 * d11 + d7 * d9) {
|
||||
return false;
|
||||
} else {
|
||||
d12 = pEnd.x * d5 - pEnd.y * d2;
|
||||
return Math.abs(d12) < d1 * d10 + d4 * d9;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static double atan2(double pY, double pX) {
|
||||
double d0 = pX * pX + pY * pY;
|
||||
if (Double.isNaN(d0)) {
|
||||
return Double.NaN;
|
||||
} else {
|
||||
boolean flag = pY < 0.0D;
|
||||
if (flag) {
|
||||
pY = -pY;
|
||||
}
|
||||
|
||||
boolean flag1 = pX < 0.0D;
|
||||
if (flag1) {
|
||||
pX = -pX;
|
||||
}
|
||||
|
||||
boolean flag2 = pY > pX;
|
||||
if (flag2) {
|
||||
double d1 = pX;
|
||||
pX = pY;
|
||||
pY = d1;
|
||||
}
|
||||
|
||||
double d9 = fastInvSqrt(d0);
|
||||
pX *= d9;
|
||||
pY *= d9;
|
||||
double d2 = FRAC_BIAS + pY;
|
||||
int i = (int)Double.doubleToRawLongBits(d2);
|
||||
double d3 = ASIN_TAB[i];
|
||||
double d4 = COS_TAB[i];
|
||||
double d5 = d2 - FRAC_BIAS;
|
||||
double d6 = pY * d4 - pX * 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 pNumber) {
|
||||
return org.joml.Math.invsqrt(pNumber);
|
||||
}
|
||||
|
||||
public static double invSqrt(double pNumber) {
|
||||
return org.joml.Math.invsqrt(pNumber);
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
/**
|
||||
* Computes 1/sqrt(n) using <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">the fast inverse square
|
||||
* root</a> with a constant of 0x5FE6EB50C7B537AA.
|
||||
*/
|
||||
@Deprecated
|
||||
public static double fastInvSqrt(double pNumber) {
|
||||
double d0 = 0.5D * pNumber;
|
||||
long i = Double.doubleToRawLongBits(pNumber);
|
||||
i = 6910469410427058090L - (i >> 1);
|
||||
pNumber = Double.longBitsToDouble(i);
|
||||
return pNumber * (1.5D - d0 * pNumber * pNumber);
|
||||
}
|
||||
|
||||
public static float fastInvCubeRoot(float pNumber) {
|
||||
int i = Float.floatToIntBits(pNumber);
|
||||
i = 1419967116 - i / 3;
|
||||
float f = Float.intBitsToFloat(i);
|
||||
f = 0.6666667F * f + 1.0F / (3.0F * f * f * pNumber);
|
||||
return 0.6666667F * f + 1.0F / (3.0F * f * f * pNumber);
|
||||
}
|
||||
|
||||
public static int hsvToRgb(float pHue, float pSaturation, float pValue) {
|
||||
int i = (int)(pHue * 6.0F) % 6;
|
||||
float f = pHue * 6.0F - (float)i;
|
||||
float f1 = pValue * (1.0F - pSaturation);
|
||||
float f2 = pValue * (1.0F - f * pSaturation);
|
||||
float f3 = pValue * (1.0F - (1.0F - f) * pSaturation);
|
||||
float f4;
|
||||
float f5;
|
||||
float f6;
|
||||
switch (i) {
|
||||
case 0:
|
||||
f4 = pValue;
|
||||
f5 = f3;
|
||||
f6 = f1;
|
||||
break;
|
||||
case 1:
|
||||
f4 = f2;
|
||||
f5 = pValue;
|
||||
f6 = f1;
|
||||
break;
|
||||
case 2:
|
||||
f4 = f1;
|
||||
f5 = pValue;
|
||||
f6 = f3;
|
||||
break;
|
||||
case 3:
|
||||
f4 = f1;
|
||||
f5 = f2;
|
||||
f6 = pValue;
|
||||
break;
|
||||
case 4:
|
||||
f4 = f3;
|
||||
f5 = f1;
|
||||
f6 = pValue;
|
||||
break;
|
||||
case 5:
|
||||
f4 = pValue;
|
||||
f5 = f1;
|
||||
f6 = f2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + pHue + ", " + pSaturation + ", " + pValue);
|
||||
}
|
||||
|
||||
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 pInput) {
|
||||
pInput ^= pInput >>> 16;
|
||||
pInput *= -2048144789;
|
||||
pInput ^= pInput >>> 13;
|
||||
pInput *= -1028477387;
|
||||
return pInput ^ pInput >>> 16;
|
||||
}
|
||||
|
||||
public static int binarySearch(int pMin, int pMax, IntPredicate pIsTargetBeforeOrAt) {
|
||||
int i = pMax - pMin;
|
||||
|
||||
while(i > 0) {
|
||||
int j = i / 2;
|
||||
int k = pMin + j;
|
||||
if (pIsTargetBeforeOrAt.test(k)) {
|
||||
i = j;
|
||||
} else {
|
||||
pMin = k + 1;
|
||||
i -= j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return pMin;
|
||||
}
|
||||
|
||||
public static int lerpInt(float p_270245_, int p_270597_, int p_270301_) {
|
||||
return p_270597_ + floor(p_270245_ * (float)(p_270301_ - p_270597_));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for linear interpolation of floats
|
||||
* @param pDelta A value usually between 0 and 1 that indicates the percentage of the lerp. (0 will give the start
|
||||
* value and 1 will give the end value)
|
||||
* @param pStart Start value for the lerp
|
||||
* @param pEnd End value for the lerp
|
||||
*/
|
||||
public static float lerp(float pDelta, float pStart, float pEnd) {
|
||||
return pStart + pDelta * (pEnd - pStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for linear interpolation of doubles
|
||||
* @param pDelta A value usually between 0 and 1 that indicates the percentage of the lerp. (0 will give the start
|
||||
* value and 1 will give the end value)
|
||||
* @param pStart Start value for the lerp
|
||||
* @param pEnd End value for the lerp
|
||||
*/
|
||||
public static double lerp(double pDelta, double pStart, double pEnd) {
|
||||
return pStart + pDelta * (pEnd - pStart);
|
||||
}
|
||||
|
||||
public static double lerp2(double pDelta1, double pDelta2, double pStart1, double pEnd1, double pStart2, double pEnd2) {
|
||||
return lerp(pDelta2, lerp(pDelta1, pStart1, pEnd1), lerp(pDelta1, pStart2, pEnd2));
|
||||
}
|
||||
|
||||
public static double lerp3(double pDelta1, double pDelta2, double pDelta3, double pStart1, double pEnd1, double pStart2, double pEnd2, double pStart3, double pEnd3, double pStart4, double pEnd4) {
|
||||
return lerp(pDelta3, lerp2(pDelta1, pDelta2, pStart1, pEnd1, pStart2, pEnd2), lerp2(pDelta1, pDelta2, pStart3, pEnd3, pStart4, pEnd4));
|
||||
}
|
||||
|
||||
public static float catmullrom(float pDelta, float pControlPoint1, float pControlPoint2, float pControlPoint3, float pControlPoint4) {
|
||||
return 0.5F * (2.0F * pControlPoint2 + (pControlPoint3 - pControlPoint1) * pDelta + (2.0F * pControlPoint1 - 5.0F * pControlPoint2 + 4.0F * pControlPoint3 - pControlPoint4) * pDelta * pDelta + (3.0F * pControlPoint2 - pControlPoint1 - 3.0F * pControlPoint3 + pControlPoint4) * pDelta * pDelta * pDelta);
|
||||
}
|
||||
|
||||
public static double smoothstep(double pInput) {
|
||||
return pInput * pInput * pInput * (pInput * (pInput * 6.0D - 15.0D) + 10.0D);
|
||||
}
|
||||
|
||||
public static double smoothstepDerivative(double pInput) {
|
||||
return 30.0D * pInput * pInput * (pInput - 1.0D) * (pInput - 1.0D);
|
||||
}
|
||||
|
||||
public static int sign(double pX) {
|
||||
if (pX == 0.0D) {
|
||||
return 0;
|
||||
} else {
|
||||
return pX > 0.0D ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolates an angle between the start between the start and end values given as degrees.
|
||||
* @param pDelta A value between 0 and 1 that indicates the percentage of the lerp. (0 will give the start value and
|
||||
* 1 will give the end value)
|
||||
*/
|
||||
public static float rotLerp(float pDelta, float pStart, float pEnd) {
|
||||
return pStart + pDelta * wrapDegrees(pEnd - pStart);
|
||||
}
|
||||
|
||||
public static float triangleWave(float pInput, float pPeriod) {
|
||||
return (Math.abs(pInput % pPeriod - pPeriod * 0.5F) - pPeriod * 0.25F) / (pPeriod * 0.25F);
|
||||
}
|
||||
|
||||
public static float square(float pValue) {
|
||||
return pValue * pValue;
|
||||
}
|
||||
|
||||
public static double square(double pValue) {
|
||||
return pValue * pValue;
|
||||
}
|
||||
|
||||
public static int square(int pValue) {
|
||||
return pValue * pValue;
|
||||
}
|
||||
|
||||
public static long square(long pValue) {
|
||||
return pValue * pValue;
|
||||
}
|
||||
|
||||
public static double clampedMap(double pInput, double pInputMin, double pInputMax, double pOuputMin, double pOutputMax) {
|
||||
return clampedLerp(pOuputMin, pOutputMax, inverseLerp(pInput, pInputMin, pInputMax));
|
||||
}
|
||||
|
||||
public static float clampedMap(float pInput, float pInputMin, float pInputMax, float pOutputMin, float pOutputMax) {
|
||||
return clampedLerp(pOutputMin, pOutputMax, inverseLerp(pInput, pInputMin, pInputMax));
|
||||
}
|
||||
|
||||
public static double map(double pInput, double pInputMin, double pInputMax, double pOutputMin, double pOutputMax) {
|
||||
return lerp(inverseLerp(pInput, pInputMin, pInputMax), pOutputMin, pOutputMax);
|
||||
}
|
||||
|
||||
public static float map(float pInput, float pInputMin, float pInputMax, float pOutputMin, float pOutputMax) {
|
||||
return lerp(inverseLerp(pInput, pInputMin, pInputMax), pOutputMin, pOutputMax);
|
||||
}
|
||||
|
||||
public static double wobble(double pInput) {
|
||||
return pInput + (2.0D * RandomSource.create((long)floor(pInput * 3000.0D)).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the given value up to a multiple of factor.
|
||||
* @return The smallest integer multiple of factor that is greater than or equal to the value
|
||||
*/
|
||||
public static int roundToward(int pValue, int pFactor) {
|
||||
return positiveCeilDiv(pValue, pFactor) * pFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest (closest to negative infinity) int value that is greater than or equal to the algebraic
|
||||
* quotient.
|
||||
* @see java.lang.Math#floorDiv(int, int)
|
||||
*/
|
||||
public static int positiveCeilDiv(int pX, int pY) {
|
||||
return -Math.floorDiv(-pX, pY);
|
||||
}
|
||||
|
||||
public static int randomBetweenInclusive(RandomSource pRandom, int pMinInclusive, int pMaxInclusive) {
|
||||
return pRandom.nextInt(pMaxInclusive - pMinInclusive + 1) + pMinInclusive;
|
||||
}
|
||||
|
||||
public static float randomBetween(RandomSource pRandom, float pMinInclusive, float pMaxExclusive) {
|
||||
return pRandom.nextFloat() * (pMaxExclusive - pMinInclusive) + pMinInclusive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a value from a normal distribution with the given mean and deviation.
|
||||
*/
|
||||
public static float normal(RandomSource pRandom, float pMean, float pDeviation) {
|
||||
return pMean + (float)pRandom.nextGaussian() * pDeviation;
|
||||
}
|
||||
|
||||
public static double lengthSquared(double pXDistance, double pYDistance) {
|
||||
return pXDistance * pXDistance + pYDistance * pYDistance;
|
||||
}
|
||||
|
||||
public static double length(double pXDistance, double pYDistance) {
|
||||
return Math.sqrt(lengthSquared(pXDistance, pYDistance));
|
||||
}
|
||||
|
||||
public static double lengthSquared(double pXDistance, double pYDistance, double pZDistance) {
|
||||
return pXDistance * pXDistance + pYDistance * pYDistance + pZDistance * pZDistance;
|
||||
}
|
||||
|
||||
public static double length(double pXDistance, double pYDistance, double pZDistance) {
|
||||
return Math.sqrt(lengthSquared(pXDistance, pYDistance, pZDistance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value closest to zero that is not closer to zero than the given value and is a multiple of the factor.
|
||||
*/
|
||||
public static int quantize(double pValue, int pFactor) {
|
||||
return floor(pValue / (double)pFactor) * pFactor;
|
||||
}
|
||||
|
||||
public static IntStream outFromOrigin(int pInput, int pLowerBound, int pUpperBound) {
|
||||
return outFromOrigin(pInput, pLowerBound, pUpperBound, 1);
|
||||
}
|
||||
|
||||
public static IntStream outFromOrigin(int pInput, int pLowerBound, int pUpperBound, int pSteps) {
|
||||
if (pLowerBound > pUpperBound) {
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "upperbound %d expected to be > lowerBound %d", pUpperBound, pLowerBound));
|
||||
} else if (pSteps < 1) {
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "steps expected to be >= 1, was %d", pSteps));
|
||||
} else {
|
||||
return pInput >= pLowerBound && pInput <= pUpperBound ? IntStream.iterate(pInput, (p_216282_) -> {
|
||||
int i = Math.abs(pInput - p_216282_);
|
||||
return pInput - i >= pLowerBound || pInput + i <= pUpperBound;
|
||||
}, (p_216260_) -> {
|
||||
boolean flag = p_216260_ <= pInput;
|
||||
int i = Math.abs(pInput - p_216260_);
|
||||
boolean flag1 = pInput + i + pSteps <= pUpperBound;
|
||||
if (!flag || !flag1) {
|
||||
int j = pInput - i - (flag ? pSteps : 0);
|
||||
if (j >= pLowerBound) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
return pInput + i + pSteps;
|
||||
}) : 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+167
@@ -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 pCrashSection) {
|
||||
pCrashSection.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 pName, Optional<NativeModuleLister.NativeModuleVersion> pVersion) {
|
||||
this.name = pName;
|
||||
this.version = pVersion;
|
||||
}
|
||||
|
||||
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 pDescription, String pVersion, String pCompany) {
|
||||
this.description = pDescription;
|
||||
this.version = pVersion;
|
||||
this.company = pCompany;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.description + ":" + this.version + ":" + this.company;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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());
|
||||
}
|
||||
}
|
||||
+74
@@ -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 pLevel, BlockPos pPos, ParticleOptions pParticle, IntProvider pCount) {
|
||||
for(Direction direction : Direction.values()) {
|
||||
spawnParticlesOnBlockFace(pLevel, pPos, pParticle, pCount, direction, () -> {
|
||||
return getRandomSpeedRanges(pLevel.random);
|
||||
}, 0.55D);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void spawnParticlesOnBlockFace(Level pLevel, BlockPos pPos, ParticleOptions pParticle, IntProvider pCount, Direction pDirection, Supplier<Vec3> p_216324_, double p_216325_) {
|
||||
int i = pCount.sample(pLevel.random);
|
||||
|
||||
for(int j = 0; j < i; ++j) {
|
||||
spawnParticleOnFace(pLevel, pPos, pDirection, pParticle, p_216324_.get(), p_216325_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Vec3 getRandomSpeedRanges(RandomSource pRandom) {
|
||||
return new Vec3(Mth.nextDouble(pRandom, -0.5D, 0.5D), Mth.nextDouble(pRandom, -0.5D, 0.5D), Mth.nextDouble(pRandom, -0.5D, 0.5D));
|
||||
}
|
||||
|
||||
public static void spawnParticlesAlongAxis(Direction.Axis pAxis, Level pLevel, BlockPos pPos, double p_144971_, ParticleOptions pParticle, UniformInt pCount) {
|
||||
Vec3 vec3 = Vec3.atCenterOf(pPos);
|
||||
boolean flag = pAxis == Direction.Axis.X;
|
||||
boolean flag1 = pAxis == Direction.Axis.Y;
|
||||
boolean flag2 = pAxis == Direction.Axis.Z;
|
||||
int i = pCount.sample(pLevel.random);
|
||||
|
||||
for(int j = 0; j < i; ++j) {
|
||||
double d0 = vec3.x + Mth.nextDouble(pLevel.random, -1.0D, 1.0D) * (flag ? 0.5D : p_144971_);
|
||||
double d1 = vec3.y + Mth.nextDouble(pLevel.random, -1.0D, 1.0D) * (flag1 ? 0.5D : p_144971_);
|
||||
double d2 = vec3.z + Mth.nextDouble(pLevel.random, -1.0D, 1.0D) * (flag2 ? 0.5D : p_144971_);
|
||||
double d3 = flag ? Mth.nextDouble(pLevel.random, -1.0D, 1.0D) : 0.0D;
|
||||
double d4 = flag1 ? Mth.nextDouble(pLevel.random, -1.0D, 1.0D) : 0.0D;
|
||||
double d5 = flag2 ? Mth.nextDouble(pLevel.random, -1.0D, 1.0D) : 0.0D;
|
||||
pLevel.addParticle(pParticle, d0, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void spawnParticleOnFace(Level pLevel, BlockPos pPos, Direction pDirection, ParticleOptions pParticle, Vec3 p_216311_, double p_216312_) {
|
||||
Vec3 vec3 = Vec3.atCenterOf(pPos);
|
||||
int i = pDirection.getStepX();
|
||||
int j = pDirection.getStepY();
|
||||
int k = pDirection.getStepZ();
|
||||
double d0 = vec3.x + (i == 0 ? Mth.nextDouble(pLevel.random, -0.5D, 0.5D) : (double)i * p_216312_);
|
||||
double d1 = vec3.y + (j == 0 ? Mth.nextDouble(pLevel.random, -0.5D, 0.5D) : (double)j * p_216312_);
|
||||
double d2 = vec3.z + (k == 0 ? Mth.nextDouble(pLevel.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;
|
||||
pLevel.addParticle(pParticle, d0, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
public static void spawnParticleBelow(Level pLevel, BlockPos pPos, RandomSource pRandom, ParticleOptions pParticle) {
|
||||
double d0 = (double)pPos.getX() + pRandom.nextDouble();
|
||||
double d1 = (double)pPos.getY() - 0.05D;
|
||||
double d2 = (double)pPos.getZ() + pRandom.nextDouble();
|
||||
pLevel.addParticle(pParticle, d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public interface ProgressListener {
|
||||
void progressStartNoAbort(Component pComponent);
|
||||
|
||||
void progressStart(Component pHeader);
|
||||
|
||||
void progressStage(Component pStage);
|
||||
|
||||
/**
|
||||
* Updates the progress bar on the loading screen to the specified amount.
|
||||
*/
|
||||
void progressStagePercentage(int pProgress);
|
||||
|
||||
void stop();
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* A basic interface for random number generation. This mirrors the same methods in {@link java.util.Random}, however it
|
||||
* does not make any guarantee that these are thread-safe, unlike {@code Random}.
|
||||
* The notable difference is that {@link #setSeed(long)} is not {@code synchronized} and should not be accessed from
|
||||
* multiple threads.
|
||||
* The documentation for each individual method can be assumed to be otherwise the same as the identically named method
|
||||
* in {@link java.util.Random}.
|
||||
* @see java.util.Random
|
||||
* @see net.minecraft.world.level.levelgen.SimpleRandomSource
|
||||
*/
|
||||
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 pSeed) {
|
||||
return new LegacyRandomSource(pSeed);
|
||||
}
|
||||
|
||||
static RandomSource createNewThreadLocalInstance() {
|
||||
return new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
|
||||
}
|
||||
|
||||
RandomSource fork();
|
||||
|
||||
PositionalRandomFactory forkPositional();
|
||||
|
||||
void setSeed(long pSeed);
|
||||
|
||||
int nextInt();
|
||||
|
||||
int nextInt(int pBound);
|
||||
|
||||
default int nextIntBetweenInclusive(int pMin, int pMax) {
|
||||
return this.nextInt(pMax - pMin + 1) + pMin;
|
||||
}
|
||||
|
||||
long nextLong();
|
||||
|
||||
boolean nextBoolean();
|
||||
|
||||
float nextFloat();
|
||||
|
||||
double nextDouble();
|
||||
|
||||
double nextGaussian();
|
||||
|
||||
default double triangle(double pMin, double pMax) {
|
||||
return pMin + pMax * (this.nextDouble() - this.nextDouble());
|
||||
}
|
||||
|
||||
default void consumeCount(int pCount) {
|
||||
for(int i = 0; i < pCount; ++i) {
|
||||
this.nextInt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
default int nextInt(int pOrigin, int pBound) {
|
||||
if (pOrigin >= pBound) {
|
||||
throw new IllegalArgumentException("bound - origin is non positive");
|
||||
} else {
|
||||
return pOrigin + this.nextInt(pBound - pOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -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;
|
||||
}
|
||||
}
|
||||
+63
@@ -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 pPrecision) {
|
||||
if (pPrecision < 2) {
|
||||
throw new IllegalArgumentException("Precision cannot be less than 2 bits");
|
||||
} else if (pPrecision > 30) {
|
||||
throw new IllegalArgumentException("Precision cannot be greater than 30 bits");
|
||||
} else {
|
||||
int i = 1 << pPrecision;
|
||||
this.mask = i - 1;
|
||||
this.precision = pPrecision;
|
||||
this.degreeToAngle = (float)i / 360.0F;
|
||||
this.angleToDegree = 360.0F / (float)i;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSameAxis(int pFirst, int pSecond) {
|
||||
int i = this.getMask() >> 1;
|
||||
return (pFirst & i) == (pSecond & i);
|
||||
}
|
||||
|
||||
public int fromDirection(Direction pDirection) {
|
||||
if (pDirection.getAxis().isVertical()) {
|
||||
return 0;
|
||||
} else {
|
||||
int i = pDirection.get2DDataValue();
|
||||
return i << this.precision - 2;
|
||||
}
|
||||
}
|
||||
|
||||
public int fromDegreesWithTurns(float pDegreesWithTurns) {
|
||||
return Math.round(pDegreesWithTurns * this.degreeToAngle);
|
||||
}
|
||||
|
||||
public int fromDegrees(float pDegrees) {
|
||||
return this.normalize(this.fromDegreesWithTurns(pDegrees));
|
||||
}
|
||||
|
||||
public float toDegreesWithTurns(int pDegrees) {
|
||||
return (float)pDegrees * this.angleToDegree;
|
||||
}
|
||||
|
||||
public float toDegrees(int pDegreesWithTurns) {
|
||||
float f = this.toDegreesWithTurns(this.normalize(pDegreesWithTurns));
|
||||
return f >= 180.0F ? f - 360.0F : f;
|
||||
}
|
||||
|
||||
public int normalize(int pDegrees) {
|
||||
return pDegrees & this.mask;
|
||||
}
|
||||
|
||||
public int getMask() {
|
||||
return this.mask;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import java.security.SignatureException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SignatureUpdater {
|
||||
void update(SignatureUpdater.Output pOutput) throws SignatureException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Output {
|
||||
void update(byte[] pBodyDigest) throws SignatureException;
|
||||
}
|
||||
}
|
||||
+62
@@ -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 pUpdater, byte[] pSignature);
|
||||
|
||||
default boolean validate(byte[] p_216376_, byte[] pSignature) {
|
||||
return this.validate((p_216374_) -> {
|
||||
p_216374_.update(p_216376_);
|
||||
}, pSignature);
|
||||
}
|
||||
|
||||
private static boolean verifySignature(SignatureUpdater pUpdater, byte[] pSignatureBytes, Signature pSignature) throws SignatureException {
|
||||
pUpdater.update(pSignature::update);
|
||||
return pSignature.verify(pSignatureBytes);
|
||||
}
|
||||
|
||||
static SignatureValidator from(PublicKey pPublicKey, String pAlgorithm) {
|
||||
return (p_216367_, p_216368_) -> {
|
||||
try {
|
||||
Signature signature = Signature.getInstance(pAlgorithm);
|
||||
signature.initVerify(pPublicKey);
|
||||
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 pServiceKeySet, ServicesKeyType pServiceKeyType) {
|
||||
Collection<ServicesKeyInfo> collection = pServiceKeySet.keys(pServiceKeyType);
|
||||
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;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
+31
@@ -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 pUpdater);
|
||||
|
||||
default byte[] sign(byte[] pSignature) {
|
||||
return this.sign((p_216394_) -> {
|
||||
p_216394_.update(pSignature);
|
||||
});
|
||||
}
|
||||
|
||||
static Signer from(PrivateKey pPrivateKey, String pAlgorithm) {
|
||||
return (p_216386_) -> {
|
||||
try {
|
||||
Signature signature = Signature.getInstance(pAlgorithm);
|
||||
signature.initSign(pPrivateKey);
|
||||
p_216386_.update(signature::update);
|
||||
return signature.sign();
|
||||
} catch (Exception exception) {
|
||||
throw new IllegalStateException("Failed to sign message", exception);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
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 pBits, int pSize, int[] p_198166_) {
|
||||
this(pBits, pSize);
|
||||
int j = 0;
|
||||
|
||||
int i;
|
||||
for(i = 0; i <= pSize - this.valuesPerLong; i += this.valuesPerLong) {
|
||||
long k = 0L;
|
||||
|
||||
for(int i1 = this.valuesPerLong - 1; i1 >= 0; --i1) {
|
||||
k <<= pBits;
|
||||
k |= (long)p_198166_[i + i1] & this.mask;
|
||||
}
|
||||
|
||||
this.data[j++] = k;
|
||||
}
|
||||
|
||||
int k1 = pSize - i;
|
||||
if (k1 > 0) {
|
||||
long l = 0L;
|
||||
|
||||
for(int j1 = k1 - 1; j1 >= 0; --j1) {
|
||||
l <<= pBits;
|
||||
l |= (long)p_198166_[i + j1] & this.mask;
|
||||
}
|
||||
|
||||
this.data[j] = l;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SimpleBitStorage(int pBits, int pSize) {
|
||||
this(pBits, pSize, (long[])null);
|
||||
}
|
||||
|
||||
public SimpleBitStorage(int pBits, int pSize, @Nullable long[] pData) {
|
||||
Validate.inclusiveBetween(1L, 32L, (long)pBits);
|
||||
this.size = pSize;
|
||||
this.bits = pBits;
|
||||
this.mask = (1L << pBits) - 1L;
|
||||
this.valuesPerLong = (char)(64 / pBits);
|
||||
int i = 3 * (this.valuesPerLong - 1);
|
||||
this.divideMul = MAGIC[i + 0];
|
||||
this.divideAdd = MAGIC[i + 1];
|
||||
this.divideShift = MAGIC[i + 2];
|
||||
int j = (pSize + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (pData != null) {
|
||||
if (pData.length != j) {
|
||||
throw new SimpleBitStorage.InitializationException("Invalid length given for storage, got: " + pData.length + " but expected: " + j);
|
||||
}
|
||||
|
||||
this.data = pData;
|
||||
} 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 pIndex, int pValue) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
Validate.inclusiveBetween(0L, this.mask, (long)pValue);
|
||||
int i = this.cellIndex(pIndex);
|
||||
long j = this.data[i];
|
||||
int k = (pIndex - i * this.valuesPerLong) * this.bits;
|
||||
int l = (int)(j >> k & this.mask);
|
||||
this.data[i] = j & ~(this.mask << k) | ((long)pValue & this.mask) << k;
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry at the given location to the given value
|
||||
*/
|
||||
public void set(int pIndex, int pValue) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
Validate.inclusiveBetween(0L, this.mask, (long)pValue);
|
||||
int i = this.cellIndex(pIndex);
|
||||
long j = this.data[i];
|
||||
int k = (pIndex - i * this.valuesPerLong) * this.bits;
|
||||
this.data[i] = j & ~(this.mask << k) | ((long)pValue & this.mask) << k;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entry at the given index
|
||||
*/
|
||||
public int get(int pIndex) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
int i = this.cellIndex(pIndex);
|
||||
long j = this.data[i];
|
||||
int k = (pIndex - i * this.valuesPerLong) * this.bits;
|
||||
return (int)(j >> k & this.mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the long array that is used to store the data in this BitArray. This is useful for sending packet data.
|
||||
*/
|
||||
public long[] getRaw() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public int getBits() {
|
||||
return this.bits;
|
||||
}
|
||||
|
||||
public void getAll(IntConsumer pConsumer) {
|
||||
int i = 0;
|
||||
|
||||
for(long j : this.data) {
|
||||
for(int k = 0; k < this.valuesPerLong; ++k) {
|
||||
pConsumer.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_);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -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> pComputeValue) {
|
||||
this.computeValue = pComputeValue;
|
||||
}
|
||||
|
||||
public V getValue(K pCacheKey) {
|
||||
if (this.cachedValue == null || !Objects.equals(this.cacheKey, pCacheKey)) {
|
||||
this.cachedValue = this.computeValue.apply(pCacheKey);
|
||||
this.cacheKey = pCacheKey;
|
||||
}
|
||||
|
||||
return this.cachedValue;
|
||||
}
|
||||
}
|
||||
+27
@@ -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;
|
||||
}
|
||||
}
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
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 pInitialCapacity, Comparator<T> pComparator) {
|
||||
this.comparator = pComparator;
|
||||
if (pInitialCapacity < 0) {
|
||||
throw new IllegalArgumentException("Initial capacity (" + pInitialCapacity + ") is negative");
|
||||
} else {
|
||||
this.contents = (T[])castRawArray(new Object[pInitialCapacity]);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> SortedArraySet<T> create() {
|
||||
return create(10);
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> SortedArraySet<T> create(int pInitialCapacity) {
|
||||
return new SortedArraySet<>(pInitialCapacity, Comparator.<T>naturalOrder());
|
||||
}
|
||||
|
||||
public static <T> SortedArraySet<T> create(Comparator<T> pComparator) {
|
||||
return create(pComparator, 10);
|
||||
}
|
||||
|
||||
public static <T> SortedArraySet<T> create(Comparator<T> pComparator, int pInitialCapacity) {
|
||||
return new SortedArraySet<>(pInitialCapacity, pComparator);
|
||||
}
|
||||
|
||||
private static <T> T[] castRawArray(Object[] pArray) {
|
||||
return (T[])pArray;
|
||||
}
|
||||
|
||||
private int findIndex(T pObject) {
|
||||
return Arrays.binarySearch(this.contents, 0, this.size, pObject, this.comparator);
|
||||
}
|
||||
|
||||
private static int getInsertionPosition(int p_14264_) {
|
||||
return -p_14264_ - 1;
|
||||
}
|
||||
|
||||
public boolean add(T pElement) {
|
||||
int i = this.findIndex(pElement);
|
||||
if (i >= 0) {
|
||||
return false;
|
||||
} else {
|
||||
int j = getInsertionPosition(i);
|
||||
this.addInternal(pElement, 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 pElement, int pIndex) {
|
||||
this.grow(this.size + 1);
|
||||
if (pIndex != this.size) {
|
||||
System.arraycopy(this.contents, pIndex, this.contents, pIndex + 1, this.size - pIndex);
|
||||
}
|
||||
|
||||
this.contents[pIndex] = pElement;
|
||||
++this.size;
|
||||
}
|
||||
|
||||
void removeInternal(int pIndex) {
|
||||
--this.size;
|
||||
if (pIndex != this.size) {
|
||||
System.arraycopy(this.contents, pIndex + 1, this.contents, pIndex, this.size - pIndex);
|
||||
}
|
||||
|
||||
this.contents[this.size] = null;
|
||||
}
|
||||
|
||||
private T getInternal(int pIndex) {
|
||||
return this.contents[pIndex];
|
||||
}
|
||||
|
||||
public T addOrGet(T pElement) {
|
||||
int i = this.findIndex(pElement);
|
||||
if (i >= 0) {
|
||||
return this.getInternal(i);
|
||||
} else {
|
||||
this.addInternal(pElement, getInsertionPosition(i));
|
||||
return pElement;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(Object pElement) {
|
||||
int i = this.findIndex((T)pElement);
|
||||
if (i >= 0) {
|
||||
this.removeInternal(i);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T get(T pElement) {
|
||||
int i = this.findIndex(pElement);
|
||||
return (T)(i >= 0 ? this.getInternal(i) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the smallest element in the set
|
||||
*/
|
||||
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 pOther) {
|
||||
if (this == pOther) {
|
||||
return true;
|
||||
} else {
|
||||
if (pOther instanceof SortedArraySet) {
|
||||
SortedArraySet<?> sortedarrayset = (SortedArraySet)pOther;
|
||||
if (this.comparator.equals(sortedarrayset.comparator)) {
|
||||
return this.size == sortedarrayset.size && Arrays.equals(this.contents, sortedarrayset.contents);
|
||||
}
|
||||
}
|
||||
|
||||
return super.equals(pOther);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -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> pEntityType, MobSpawnType pSpawnType, ServerLevel pLevel, BlockPos pPos, int pAttempts, int p_216409_, int p_216410_, SpawnUtil.Strategy pStrategy) {
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = pPos.mutable();
|
||||
|
||||
for(int i = 0; i < pAttempts; ++i) {
|
||||
int j = Mth.randomBetweenInclusive(pLevel.random, -p_216409_, p_216409_);
|
||||
int k = Mth.randomBetweenInclusive(pLevel.random, -p_216409_, p_216409_);
|
||||
blockpos$mutableblockpos.setWithOffset(pPos, j, p_216410_, k);
|
||||
if (pLevel.getWorldBorder().isWithinBounds(blockpos$mutableblockpos) && moveToPossibleSpawnPosition(pLevel, p_216410_, blockpos$mutableblockpos, pStrategy)) {
|
||||
T t = pEntityType.create(pLevel, (CompoundTag)null, (Consumer<T>)null, blockpos$mutableblockpos, pSpawnType, false, false);
|
||||
if (t != null) {
|
||||
if (net.minecraftforge.event.ForgeEventFactory.checkSpawnPosition(t, pLevel, pSpawnType)) {
|
||||
pLevel.addFreshEntityWithPassengers(t);
|
||||
return Optional.of(t);
|
||||
}
|
||||
|
||||
t.discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static boolean moveToPossibleSpawnPosition(ServerLevel pLevel, int p_216400_, BlockPos.MutableBlockPos p_216401_, SpawnUtil.Strategy pStrategy) {
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = (new BlockPos.MutableBlockPos()).set(p_216401_);
|
||||
BlockState blockstate = pLevel.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 = pLevel.getBlockState(p_216401_);
|
||||
if (pStrategy.canSpawnOn(pLevel, 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_);
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
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 pStyle, FormattedCharSink pSink, int pPosition, char pCharacter) {
|
||||
return Character.isSurrogate(pCharacter) ? pSink.accept(pPosition, pStyle, 65533) : pSink.accept(pPosition, pStyle, pCharacter);
|
||||
}
|
||||
|
||||
public static boolean iterate(String pText, Style pStyle, FormattedCharSink pSink) {
|
||||
int i = pText.length();
|
||||
|
||||
for(int j = 0; j < i; ++j) {
|
||||
char c0 = pText.charAt(j);
|
||||
if (Character.isHighSurrogate(c0)) {
|
||||
if (j + 1 >= i) {
|
||||
if (!pSink.accept(j, pStyle, 65533)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
char c1 = pText.charAt(j + 1);
|
||||
if (Character.isLowSurrogate(c1)) {
|
||||
if (!pSink.accept(j, pStyle, Character.toCodePoint(c0, c1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++j;
|
||||
} else if (!pSink.accept(j, pStyle, 65533)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!feedChar(pStyle, pSink, j, c0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean iterateBackwards(String pText, Style pStyle, FormattedCharSink pSink) {
|
||||
int i = pText.length();
|
||||
|
||||
for(int j = i - 1; j >= 0; --j) {
|
||||
char c0 = pText.charAt(j);
|
||||
if (Character.isLowSurrogate(c0)) {
|
||||
if (j - 1 < 0) {
|
||||
if (!pSink.accept(0, pStyle, 65533)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
char c1 = pText.charAt(j - 1);
|
||||
if (Character.isHighSurrogate(c1)) {
|
||||
--j;
|
||||
if (!pSink.accept(j, pStyle, Character.toCodePoint(c1, c0))) {
|
||||
return false;
|
||||
}
|
||||
} else if (!pSink.accept(j, pStyle, 65533)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!feedChar(pStyle, pSink, j, c0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate a String while applying legacy formatting codes starting with a {@code §} sign.
|
||||
*/
|
||||
public static boolean iterateFormatted(String pText, Style pStyle, FormattedCharSink pSink) {
|
||||
return iterateFormatted(pText, 0, pStyle, pSink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate a String while applying legacy formatting codes starting with a {@code §} sign.
|
||||
* @param pSkip The amount of characters to skip from the beginning.
|
||||
*/
|
||||
public static boolean iterateFormatted(String pText, int pSkip, Style pStyle, FormattedCharSink pSink) {
|
||||
return iterateFormatted(pText, pSkip, pStyle, pStyle, pSink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate a String while applying legacy formatting codes starting with a {@code §} sign.
|
||||
* @param pSkip The amount of character to skip from the beginning.
|
||||
* @param pCurrentStyle The current style at the starting position after the skip.
|
||||
* @param pDefaultStyle The default style for the sequence that should be applied after a reset format code ({@code
|
||||
* §r})
|
||||
*/
|
||||
public static boolean iterateFormatted(String pText, int pSkip, Style pCurrentStyle, Style pDefaultStyle, FormattedCharSink pSink) {
|
||||
int i = pText.length();
|
||||
Style style = pCurrentStyle;
|
||||
|
||||
for(int j = pSkip; j < i; ++j) {
|
||||
char c0 = pText.charAt(j);
|
||||
if (c0 == 167) {
|
||||
if (j + 1 >= i) {
|
||||
break;
|
||||
}
|
||||
|
||||
char c1 = pText.charAt(j + 1);
|
||||
ChatFormatting chatformatting = ChatFormatting.getByCode(c1);
|
||||
if (chatformatting != null) {
|
||||
style = chatformatting == ChatFormatting.RESET ? pDefaultStyle : style.applyLegacyFormat(chatformatting);
|
||||
}
|
||||
|
||||
++j;
|
||||
} else if (Character.isHighSurrogate(c0)) {
|
||||
if (j + 1 >= i) {
|
||||
if (!pSink.accept(j, style, 65533)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
char c2 = pText.charAt(j + 1);
|
||||
if (Character.isLowSurrogate(c2)) {
|
||||
if (!pSink.accept(j, style, Character.toCodePoint(c0, c2))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++j;
|
||||
} else if (!pSink.accept(j, style, 65533)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!feedChar(style, pSink, j, c0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean iterateFormatted(FormattedText pText, Style pStyle, FormattedCharSink pSink) {
|
||||
return !pText.visit((p_14302_, p_14303_) -> {
|
||||
return iterateFormatted(p_14303_, 0, p_14302_, pSink) ? Optional.empty() : STOP_ITERATION;
|
||||
}, pStyle).isPresent();
|
||||
}
|
||||
|
||||
public static String filterBrokenSurrogates(String pText) {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
iterate(pText, Style.EMPTY, (p_14343_, p_14344_, p_14345_) -> {
|
||||
stringbuilder.appendCodePoint(p_14345_);
|
||||
return true;
|
||||
});
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public static String getPlainText(FormattedText pText) {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
iterateFormatted(pText, Style.EMPTY, (p_14323_, p_14324_, p_14325_) -> {
|
||||
stringbuilder.appendCodePoint(p_14325_);
|
||||
return true;
|
||||
});
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
}
|
||||
+94
@@ -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[]> pElementsSupplier) {
|
||||
return fromEnumWithMapping(pElementsSupplier, (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[] pSerializables) {
|
||||
return new Keyable() {
|
||||
public <T> Stream<T> keys(DynamicOps<T> p_184758_) {
|
||||
return Arrays.stream(pSerializables).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[] pValues, Function<String, E> pResolver) {
|
||||
this.codec = ExtraCodecs.orCompressed(ExtraCodecs.stringResolverCodec((p_216461_) -> {
|
||||
return p_216461_.getSerializedName();
|
||||
}, pResolver), ExtraCodecs.idResolverCodec((p_216454_) -> {
|
||||
return p_216454_.ordinal();
|
||||
}, (p_216459_) -> {
|
||||
return (E)(p_216459_ >= 0 && p_216459_ < pValues.length ? pValues[p_216459_] : null);
|
||||
}, -1));
|
||||
this.resolver = pResolver;
|
||||
}
|
||||
|
||||
public <T> DataResult<Pair<E, T>> decode(DynamicOps<T> pOps, T pInput) {
|
||||
return this.codec.decode(pOps, pInput);
|
||||
}
|
||||
|
||||
public <T> DataResult<T> encode(E pInput, DynamicOps<T> pOps, T pPrefix) {
|
||||
return this.codec.encode(pInput, pOps, pPrefix);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public E byName(@Nullable String pName) {
|
||||
return this.resolver.apply(pName);
|
||||
}
|
||||
|
||||
public E byName(@Nullable String pName, E pDefaultValue) {
|
||||
return Objects.requireNonNullElse(this.byName(pName), pDefaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
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)$");
|
||||
|
||||
/**
|
||||
* Returns the time elapsed for the given number of ticks, in "mm:ss" format.
|
||||
*/
|
||||
public static String formatTickDuration(int pTicks) {
|
||||
int i = pTicks / 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 pText) {
|
||||
return STRIP_COLOR_PATTERN.matcher(pText).replaceAll("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether the given string is null or empty.
|
||||
*/
|
||||
public static boolean isNullOrEmpty(@Nullable String pString) {
|
||||
return StringUtils.isEmpty(pString);
|
||||
}
|
||||
|
||||
public static String truncateStringIfNecessary(String pString, int pMaxSize, boolean pAddEllipsis) {
|
||||
if (pString.length() <= pMaxSize) {
|
||||
return pString;
|
||||
} else {
|
||||
return pAddEllipsis && pMaxSize > 3 ? pString.substring(0, pMaxSize - 3) + "..." : pString.substring(0, pMaxSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static int lineCount(String pString) {
|
||||
if (pString.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
Matcher matcher = LINE_PATTERN.matcher(pString);
|
||||
|
||||
int i;
|
||||
for(i = 1; matcher.find(); ++i) {
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean endsWithNewLine(String pString) {
|
||||
return LINE_END_PATTERN.matcher(pString).find();
|
||||
}
|
||||
|
||||
public static String trimChatMessage(String p_216470_) {
|
||||
return truncateStringIfNecessary(p_216470_, 256, false);
|
||||
}
|
||||
}
|
||||
+26
@@ -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 pDelayedTask);
|
||||
|
||||
public interface DelayedTask {
|
||||
CompletableFuture<?> submit(Executor p_249412_);
|
||||
}
|
||||
}
|
||||
+89
@@ -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 pName) {
|
||||
this.name = pName;
|
||||
}
|
||||
|
||||
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 "));
|
||||
}
|
||||
}
|
||||
+15
@@ -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 pUnit);
|
||||
|
||||
public interface NanoTimeSource extends TimeSource, LongSupplier {
|
||||
default long get(TimeUnit p_239379_) {
|
||||
return p_239379_.convert(this.getAsLong(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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 pMinInclusive, int pMaxInclusive) {
|
||||
return UniformInt.of(pMinInclusive * 20, pMaxInclusive * 20);
|
||||
}
|
||||
}
|
||||
+49
@@ -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 pObject);
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public class Tuple<A, B> {
|
||||
private A a;
|
||||
private B b;
|
||||
|
||||
public Tuple(A pA, B pB) {
|
||||
this.a = pA;
|
||||
this.b = pB;
|
||||
}
|
||||
|
||||
public A getA() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public void setA(A pA) {
|
||||
this.a = pA;
|
||||
}
|
||||
|
||||
public B getB() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public void setB(B pB) {
|
||||
this.b = pB;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public enum Unit {
|
||||
INSTANCE;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
public @interface VisibleForDebug {
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
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 pSize) {
|
||||
this.size = pSize;
|
||||
}
|
||||
|
||||
public int getAndSet(int pIndex, int pValue) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
Validate.inclusiveBetween(0L, 0L, (long)pValue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry at the given location to the given value
|
||||
*/
|
||||
public void set(int pIndex, int pValue) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
Validate.inclusiveBetween(0L, 0L, (long)pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entry at the given index
|
||||
*/
|
||||
public int get(int pIndex) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the long array that is used to store the data in this BitArray. This is useful for sending packet data.
|
||||
*/
|
||||
public long[] getRaw() {
|
||||
return RAW;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public int getBits() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void getAll(IntConsumer pConsumer) {
|
||||
for(int i = 0; i < this.size; ++i) {
|
||||
pConsumer.accept(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void unpack(int[] p_198170_) {
|
||||
Arrays.fill(p_198170_, 0, this.size, 0);
|
||||
}
|
||||
|
||||
public BitStorage copy() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+56
@@ -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 pType) {
|
||||
this.type = pType;
|
||||
}
|
||||
|
||||
private static int currentVersion() {
|
||||
return SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
||||
}
|
||||
|
||||
public <T> Dynamic<T> update(DataFixer pFixer, Dynamic<T> pInput, int pVersion, int pNewVersion) {
|
||||
return pFixer.update(this.type, pInput, pVersion, pNewVersion);
|
||||
}
|
||||
|
||||
public <T> Dynamic<T> updateToCurrentVersion(DataFixer pFixer, Dynamic<T> pInput, int pVersion) {
|
||||
return this.update(pFixer, pInput, pVersion, currentVersion());
|
||||
}
|
||||
|
||||
public CompoundTag update(DataFixer pFixer, CompoundTag pTag, int pVersion, int pNewVersion) {
|
||||
return (CompoundTag)this.update(pFixer, new Dynamic<>(NbtOps.INSTANCE, pTag), pVersion, pNewVersion).getValue();
|
||||
}
|
||||
|
||||
public CompoundTag updateToCurrentVersion(DataFixer pFixer, CompoundTag pTag, int pVersion) {
|
||||
return this.update(pFixer, pTag, pVersion, currentVersion());
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES_FOR_LEVEL_LIST = Set.of(LEVEL.type);
|
||||
}
|
||||
}
|
||||
+805
@@ -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> pTypeReferences) {
|
||||
DataFixerBuilder datafixerbuilder = new DataFixerBuilder(SharedConstants.getCurrentVersion().getDataVersion().getVersion());
|
||||
addFixers(datafixerbuilder);
|
||||
if (pTypeReferences.isEmpty()) {
|
||||
return datafixerbuilder.buildUnoptimized();
|
||||
} else {
|
||||
Executor executor = Executors.newSingleThreadExecutor((new ThreadFactoryBuilder()).setNameFormat("Datafixer Bootstrap").setDaemon(true).setPriority(1).build());
|
||||
return datafixerbuilder.buildOptimized(pTypeReferences, executor);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addFixers(DataFixerBuilder pBuilder) {
|
||||
pBuilder.addSchema(99, V99::new);
|
||||
Schema schema = pBuilder.addSchema(100, V100::new);
|
||||
pBuilder.addFixer(new EntityEquipmentToArmorAndHandFix(schema, true));
|
||||
Schema schema1 = pBuilder.addSchema(101, SAME);
|
||||
pBuilder.addFixer(new BlockEntitySignTextStrictJsonFix(schema1, false));
|
||||
Schema schema2 = pBuilder.addSchema(102, V102::new);
|
||||
pBuilder.addFixer(new ItemIdFix(schema2, true));
|
||||
pBuilder.addFixer(new ItemPotionFix(schema2, false));
|
||||
Schema schema3 = pBuilder.addSchema(105, SAME);
|
||||
pBuilder.addFixer(new ItemSpawnEggFix(schema3, true));
|
||||
Schema schema4 = pBuilder.addSchema(106, V106::new);
|
||||
pBuilder.addFixer(new MobSpawnerEntityIdentifiersFix(schema4, true));
|
||||
Schema schema5 = pBuilder.addSchema(107, V107::new);
|
||||
pBuilder.addFixer(new EntityMinecartIdentifiersFix(schema5, true));
|
||||
Schema schema6 = pBuilder.addSchema(108, SAME);
|
||||
pBuilder.addFixer(new EntityStringUuidFix(schema6, true));
|
||||
Schema schema7 = pBuilder.addSchema(109, SAME);
|
||||
pBuilder.addFixer(new EntityHealthFix(schema7, true));
|
||||
Schema schema8 = pBuilder.addSchema(110, SAME);
|
||||
pBuilder.addFixer(new EntityHorseSaddleFix(schema8, true));
|
||||
Schema schema9 = pBuilder.addSchema(111, SAME);
|
||||
pBuilder.addFixer(new EntityPaintingItemFrameDirectionFix(schema9, true));
|
||||
Schema schema10 = pBuilder.addSchema(113, SAME);
|
||||
pBuilder.addFixer(new EntityRedundantChanceTagsFix(schema10, true));
|
||||
Schema schema11 = pBuilder.addSchema(135, V135::new);
|
||||
pBuilder.addFixer(new EntityRidingToPassengersFix(schema11, true));
|
||||
Schema schema12 = pBuilder.addSchema(143, V143::new);
|
||||
pBuilder.addFixer(new EntityTippedArrowFix(schema12, true));
|
||||
Schema schema13 = pBuilder.addSchema(147, SAME);
|
||||
pBuilder.addFixer(new EntityArmorStandSilentFix(schema13, true));
|
||||
Schema schema14 = pBuilder.addSchema(165, SAME);
|
||||
pBuilder.addFixer(new ItemWrittenBookPagesStrictJsonFix(schema14, true));
|
||||
Schema schema15 = pBuilder.addSchema(501, V501::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema15, "Add 1.10 entities fix", References.ENTITY));
|
||||
Schema schema16 = pBuilder.addSchema(502, SAME);
|
||||
pBuilder.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_;
|
||||
}));
|
||||
pBuilder.addFixer(new EntityZombieVillagerTypeFix(schema16, false));
|
||||
Schema schema17 = pBuilder.addSchema(505, SAME);
|
||||
pBuilder.addFixer(new OptionsForceVBOFix(schema17, false));
|
||||
Schema schema18 = pBuilder.addSchema(700, V700::new);
|
||||
pBuilder.addFixer(new EntityElderGuardianSplitFix(schema18, true));
|
||||
Schema schema19 = pBuilder.addSchema(701, V701::new);
|
||||
pBuilder.addFixer(new EntitySkeletonSplitFix(schema19, true));
|
||||
Schema schema20 = pBuilder.addSchema(702, V702::new);
|
||||
pBuilder.addFixer(new EntityZombieSplitFix(schema20, true));
|
||||
Schema schema21 = pBuilder.addSchema(703, V703::new);
|
||||
pBuilder.addFixer(new EntityHorseSplitFix(schema21, true));
|
||||
Schema schema22 = pBuilder.addSchema(704, V704::new);
|
||||
pBuilder.addFixer(new BlockEntityIdFix(schema22, true));
|
||||
Schema schema23 = pBuilder.addSchema(705, V705::new);
|
||||
pBuilder.addFixer(new EntityIdFix(schema23, true));
|
||||
Schema schema24 = pBuilder.addSchema(804, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemBannerColorFix(schema24, true));
|
||||
Schema schema25 = pBuilder.addSchema(806, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemWaterPotionFix(schema25, false));
|
||||
Schema schema26 = pBuilder.addSchema(808, V808::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema26, "added shulker box", References.BLOCK_ENTITY));
|
||||
Schema schema27 = pBuilder.addSchema(808, 1, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityShulkerColorFix(schema27, false));
|
||||
Schema schema28 = pBuilder.addSchema(813, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemShulkerBoxColorFix(schema28, false));
|
||||
pBuilder.addFixer(new BlockEntityShulkerBoxColorFix(schema28, false));
|
||||
Schema schema29 = pBuilder.addSchema(816, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsLowerCaseLanguageFix(schema29, false));
|
||||
Schema schema30 = pBuilder.addSchema(820, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema30, "totem item renamer", createRenamer("minecraft:totem", "minecraft:totem_of_undying")));
|
||||
Schema schema31 = pBuilder.addSchema(1022, V1022::new);
|
||||
pBuilder.addFixer(new WriteAndReadFix(schema31, "added shoulder entities to players", References.PLAYER));
|
||||
Schema schema32 = pBuilder.addSchema(1125, V1125::new);
|
||||
pBuilder.addFixer(new ChunkBedBlockEntityInjecterFix(schema32, true));
|
||||
pBuilder.addFixer(new BedItemColorFix(schema32, false));
|
||||
Schema schema33 = pBuilder.addSchema(1344, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsKeyLwjgl3Fix(schema33, false));
|
||||
Schema schema34 = pBuilder.addSchema(1446, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsKeyTranslationFix(schema34, false));
|
||||
Schema schema35 = pBuilder.addSchema(1450, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BlockStateStructureTemplateFix(schema35, false));
|
||||
Schema schema36 = pBuilder.addSchema(1451, V1451::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema36, "AddTrappedChestFix", References.BLOCK_ENTITY));
|
||||
Schema schema37 = pBuilder.addSchema(1451, 1, V1451_1::new);
|
||||
pBuilder.addFixer(new ChunkPalettedStorageFix(schema37, true));
|
||||
Schema schema38 = pBuilder.addSchema(1451, 2, V1451_2::new);
|
||||
pBuilder.addFixer(new BlockEntityBlockStateFix(schema38, true));
|
||||
Schema schema39 = pBuilder.addSchema(1451, 3, V1451_3::new);
|
||||
pBuilder.addFixer(new EntityBlockStateFix(schema39, true));
|
||||
pBuilder.addFixer(new ItemStackMapIdFix(schema39, false));
|
||||
Schema schema40 = pBuilder.addSchema(1451, 4, V1451_4::new);
|
||||
pBuilder.addFixer(new BlockNameFlatteningFix(schema40, true));
|
||||
pBuilder.addFixer(new ItemStackTheFlatteningFix(schema40, false));
|
||||
Schema schema41 = pBuilder.addSchema(1451, 5, V1451_5::new);
|
||||
pBuilder.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")));
|
||||
pBuilder.addFixer(new AddNewChoices(schema41, "RemoveNoteBlockFlowerPotFix", References.BLOCK_ENTITY));
|
||||
pBuilder.addFixer(new ItemStackSpawnEggFix(schema41, false, "minecraft:spawn_egg"));
|
||||
pBuilder.addFixer(new EntityWolfColorFix(schema41, false));
|
||||
pBuilder.addFixer(new BlockEntityBannerColorFix(schema41, false));
|
||||
pBuilder.addFixer(new LevelFlatGeneratorInfoFix(schema41, false));
|
||||
Schema schema42 = pBuilder.addSchema(1451, 6, V1451_6::new);
|
||||
pBuilder.addFixer(new StatsCounterFix(schema42, true));
|
||||
pBuilder.addFixer(new WriteAndReadFix(schema42, "Rewrite objectives", References.OBJECTIVE));
|
||||
pBuilder.addFixer(new BlockEntityJukeboxFix(schema42, false));
|
||||
Schema schema43 = pBuilder.addSchema(1451, 7, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new VillagerTradeFix(schema43, false));
|
||||
Schema schema44 = pBuilder.addSchema(1456, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityItemFrameDirectionFix(schema44, false));
|
||||
Schema schema45 = pBuilder.addSchema(1458, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityCustomNameToComponentFix(schema45, false));
|
||||
pBuilder.addFixer(new ItemCustomNameToComponentFix(schema45, false));
|
||||
pBuilder.addFixer(new BlockEntityCustomNameToComponentFix(schema45, false));
|
||||
Schema schema46 = pBuilder.addSchema(1460, V1460::new);
|
||||
pBuilder.addFixer(new EntityPaintingMotiveFix(schema46, false));
|
||||
Schema schema47 = pBuilder.addSchema(1466, V1466::new);
|
||||
pBuilder.addFixer(new ChunkToProtochunkFix(schema47, true));
|
||||
Schema schema48 = pBuilder.addSchema(1470, V1470::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema48, "Add 1.13 entities fix", References.ENTITY));
|
||||
Schema schema49 = pBuilder.addSchema(1474, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ColorlessShulkerEntityFix(schema49, false));
|
||||
pBuilder.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_;
|
||||
}));
|
||||
pBuilder.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 = pBuilder.addSchema(1475, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema50, "Flowing fixer", createRenamer(ImmutableMap.of("minecraft:flowing_water", "minecraft:water", "minecraft:flowing_lava", "minecraft:lava"))));
|
||||
Schema schema51 = pBuilder.addSchema(1480, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema51, "Rename coral blocks", createRenamer(RenamedCoralFix.RENAMED_IDS)));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema51, "Rename coral items", createRenamer(RenamedCoralFix.RENAMED_IDS)));
|
||||
Schema schema52 = pBuilder.addSchema(1481, V1481::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema52, "Add conduit", References.BLOCK_ENTITY));
|
||||
Schema schema53 = pBuilder.addSchema(1483, V1483::new);
|
||||
pBuilder.addFixer(new EntityPufferfishRenameFix(schema53, true));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema53, "Rename pufferfish egg item", createRenamer(EntityPufferfishRenameFix.RENAMED_IDS)));
|
||||
Schema schema54 = pBuilder.addSchema(1484, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema54, "Rename seagrass items", createRenamer(ImmutableMap.of("minecraft:sea_grass", "minecraft:seagrass", "minecraft:tall_sea_grass", "minecraft:tall_seagrass"))));
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema54, "Rename seagrass blocks", createRenamer(ImmutableMap.of("minecraft:sea_grass", "minecraft:seagrass", "minecraft:tall_sea_grass", "minecraft:tall_seagrass"))));
|
||||
pBuilder.addFixer(new HeightmapRenamingFix(schema54, false));
|
||||
Schema schema55 = pBuilder.addSchema(1486, V1486::new);
|
||||
pBuilder.addFixer(new EntityCodSalmonFix(schema55, true));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema55, "Rename cod/salmon egg items", createRenamer(EntityCodSalmonFix.RENAMED_EGG_IDS)));
|
||||
Schema schema56 = pBuilder.addSchema(1487, SAME_NAMESPACED);
|
||||
pBuilder.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"))));
|
||||
pBuilder.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 = pBuilder.addSchema(1488, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema57, "Rename kelp/kelptop", createRenamer(ImmutableMap.of("minecraft:kelp_top", "minecraft:kelp", "minecraft:kelp", "minecraft:kelp_plant"))));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema57, "Rename kelptop", createRenamer("minecraft:kelp_top", "minecraft:kelp")));
|
||||
pBuilder.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);
|
||||
}
|
||||
});
|
||||
pBuilder.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);
|
||||
}
|
||||
});
|
||||
pBuilder.addFixer(new IglooMetadataRemovalFix(schema57, false));
|
||||
Schema schema58 = pBuilder.addSchema(1490, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema58, "Rename melon_block", createRenamer("minecraft:melon_block", "minecraft:melon")));
|
||||
pBuilder.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 = pBuilder.addSchema(1492, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkStructuresTemplateRenameFix(schema59, false));
|
||||
Schema schema60 = pBuilder.addSchema(1494, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemStackEnchantmentNamesFix(schema60, false));
|
||||
Schema schema61 = pBuilder.addSchema(1496, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new LeavesFix(schema61, false));
|
||||
Schema schema62 = pBuilder.addSchema(1500, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BlockEntityKeepPacked(schema62, false));
|
||||
Schema schema63 = pBuilder.addSchema(1501, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new AdvancementsFix(schema63, false));
|
||||
Schema schema64 = pBuilder.addSchema(1502, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema64, "Recipes fix", References.RECIPE, createRenamer(RecipesFix.RECIPES)));
|
||||
Schema schema65 = pBuilder.addSchema(1506, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new LevelDataGeneratorOptionsFix(schema65, false));
|
||||
Schema schema66 = pBuilder.addSchema(1510, V1510::new);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema66, "Block renamening fix", createRenamer(EntityTheRenameningFix.RENAMED_BLOCKS)));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema66, "Item renamening fix", createRenamer(EntityTheRenameningFix.RENAMED_ITEMS)));
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema66, "Recipes renamening fix", References.RECIPE, createRenamer(RecipesRenameningFix.RECIPES)));
|
||||
pBuilder.addFixer(new EntityTheRenameningFix(schema66, true));
|
||||
pBuilder.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 = pBuilder.addSchema(1514, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ObjectiveDisplayNameFix(schema67, false));
|
||||
pBuilder.addFixer(new TeamDisplayNameFix(schema67, false));
|
||||
pBuilder.addFixer(new ObjectiveRenderTypeFix(schema67, false));
|
||||
Schema schema68 = pBuilder.addSchema(1515, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema68, "Rename coral fan blocks", createRenamer(RenamedCoralFansFix.RENAMED_IDS)));
|
||||
Schema schema69 = pBuilder.addSchema(1624, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new TrappedChestBlockEntityFix(schema69, false));
|
||||
Schema schema70 = pBuilder.addSchema(1800, V1800::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema70, "Added 1.14 mobs fix", References.ENTITY));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema70, "Rename dye items", createRenamer(DyeItemRenameFix.RENAMED_IDS)));
|
||||
Schema schema71 = pBuilder.addSchema(1801, V1801::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema71, "Added Illager Beast", References.ENTITY));
|
||||
Schema schema72 = pBuilder.addSchema(1802, SAME_NAMESPACED);
|
||||
pBuilder.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"))));
|
||||
pBuilder.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 = pBuilder.addSchema(1803, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemLoreFix(schema73, false));
|
||||
Schema schema74 = pBuilder.addSchema(1904, V1904::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema74, "Added Cats", References.ENTITY));
|
||||
pBuilder.addFixer(new EntityCatSplitFix(schema74, false));
|
||||
Schema schema75 = pBuilder.addSchema(1905, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkStatusFix(schema75, false));
|
||||
Schema schema76 = pBuilder.addSchema(1906, V1906::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema76, "Add POI Blocks", References.BLOCK_ENTITY));
|
||||
Schema schema77 = pBuilder.addSchema(1909, V1909::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema77, "Add jigsaw", References.BLOCK_ENTITY));
|
||||
Schema schema78 = pBuilder.addSchema(1911, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkStatusFix2(schema78, false));
|
||||
Schema schema79 = pBuilder.addSchema(1914, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new WeaponSmithChestLootTableFix(schema79, false));
|
||||
Schema schema80 = pBuilder.addSchema(1917, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new CatTypeFix(schema80, false));
|
||||
Schema schema81 = pBuilder.addSchema(1918, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new VillagerDataFix(schema81, "minecraft:villager"));
|
||||
pBuilder.addFixer(new VillagerDataFix(schema81, "minecraft:zombie_villager"));
|
||||
Schema schema82 = pBuilder.addSchema(1920, V1920::new);
|
||||
pBuilder.addFixer(new NewVillageFix(schema82, false));
|
||||
pBuilder.addFixer(new AddNewChoices(schema82, "Add campfire", References.BLOCK_ENTITY));
|
||||
Schema schema83 = pBuilder.addSchema(1925, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new MapIdFix(schema83, false));
|
||||
Schema schema84 = pBuilder.addSchema(1928, V1928::new);
|
||||
pBuilder.addFixer(new EntityRavagerRenameFix(schema84, true));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema84, "Rename ravager egg item", createRenamer(EntityRavagerRenameFix.RENAMED_IDS)));
|
||||
Schema schema85 = pBuilder.addSchema(1929, V1929::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema85, "Add Wandering Trader and Trader Llama", References.ENTITY));
|
||||
Schema schema86 = pBuilder.addSchema(1931, V1931::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema86, "Added Fox", References.ENTITY));
|
||||
Schema schema87 = pBuilder.addSchema(1936, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsAddTextBackgroundFix(schema87, false));
|
||||
Schema schema88 = pBuilder.addSchema(1946, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ReorganizePoi(schema88, false));
|
||||
Schema schema89 = pBuilder.addSchema(1948, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OminousBannerRenameFix(schema89));
|
||||
Schema schema90 = pBuilder.addSchema(1953, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OminousBannerBlockEntityRenameFix(schema90, false));
|
||||
Schema schema91 = pBuilder.addSchema(1955, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new VillagerRebuildLevelAndXpFix(schema91, false));
|
||||
pBuilder.addFixer(new ZombieVillagerRebuildXpFix(schema91, false));
|
||||
Schema schema92 = pBuilder.addSchema(1961, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkLightRemoveFix(schema92, false));
|
||||
Schema schema93 = pBuilder.addSchema(1963, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new RemoveGolemGossipFix(schema93, false));
|
||||
Schema schema94 = pBuilder.addSchema(2100, V2100::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema94, "Added Bee and Bee Stinger", References.ENTITY));
|
||||
pBuilder.addFixer(new AddNewChoices(schema94, "Add beehive", References.BLOCK_ENTITY));
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema94, "Rename sugar recipe", References.RECIPE, createRenamer("minecraft:sugar", "sugar_from_sugar_cane")));
|
||||
pBuilder.addFixer(new AdvancementsRenameFix(schema94, false, "Rename sugar recipe advancement", createRenamer("minecraft:recipes/misc/sugar", "minecraft:recipes/misc/sugar_from_sugar_cane")));
|
||||
Schema schema95 = pBuilder.addSchema(2202, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkBiomeFix(schema95, false));
|
||||
Schema schema96 = pBuilder.addSchema(2209, SAME_NAMESPACED);
|
||||
UnaryOperator<String> unaryoperator = createRenamer("minecraft:bee_hive", "minecraft:beehive");
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema96, "Rename bee_hive item to beehive", unaryoperator));
|
||||
pBuilder.addFixer(new PoiTypeRenameFix(schema96, "Rename bee_hive poi to beehive", unaryoperator));
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema96, "Rename bee_hive block to beehive", unaryoperator));
|
||||
Schema schema97 = pBuilder.addSchema(2211, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new StructureReferenceCountFix(schema97, false));
|
||||
Schema schema98 = pBuilder.addSchema(2218, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ForcePoiRebuild(schema98, false));
|
||||
Schema schema99 = pBuilder.addSchema(2501, V2501::new);
|
||||
pBuilder.addFixer(new FurnaceRecipeFix(schema99, true));
|
||||
Schema schema100 = pBuilder.addSchema(2502, V2502::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema100, "Added Hoglin", References.ENTITY));
|
||||
Schema schema101 = pBuilder.addSchema(2503, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new WallPropertyFix(schema101, false));
|
||||
pBuilder.addFixer(new AdvancementsRenameFix(schema101, false, "Composter category change", createRenamer("minecraft:recipes/misc/composter", "minecraft:recipes/decorations/composter")));
|
||||
Schema schema102 = pBuilder.addSchema(2505, V2505::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema102, "Added Piglin", References.ENTITY));
|
||||
pBuilder.addFixer(new MemoryExpiryDataFix(schema102, "minecraft:villager"));
|
||||
Schema schema103 = pBuilder.addSchema(2508, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema103, "Renamed fungi items to fungus", createRenamer(ImmutableMap.of("minecraft:warped_fungi", "minecraft:warped_fungus", "minecraft:crimson_fungi", "minecraft:crimson_fungus"))));
|
||||
pBuilder.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 = pBuilder.addSchema(2509, V2509::new);
|
||||
pBuilder.addFixer(new EntityZombifiedPiglinRenameFix(schema104));
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema104, "Rename zombie pigman egg item", createRenamer(EntityZombifiedPiglinRenameFix.RENAMED_IDS)));
|
||||
Schema schema105 = pBuilder.addSchema(2511, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityProjectileOwnerFix(schema105));
|
||||
Schema schema106 = pBuilder.addSchema(2514, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityUUIDFix(schema106));
|
||||
pBuilder.addFixer(new BlockEntityUUIDFix(schema106));
|
||||
pBuilder.addFixer(new PlayerUUIDFix(schema106));
|
||||
pBuilder.addFixer(new LevelUUIDFix(schema106));
|
||||
pBuilder.addFixer(new SavedDataUUIDFix(schema106));
|
||||
pBuilder.addFixer(new ItemStackUUIDFix(schema106));
|
||||
Schema schema107 = pBuilder.addSchema(2516, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new GossipUUIDFix(schema107, "minecraft:villager"));
|
||||
pBuilder.addFixer(new GossipUUIDFix(schema107, "minecraft:zombie_villager"));
|
||||
Schema schema108 = pBuilder.addSchema(2518, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new JigsawPropertiesFix(schema108, false));
|
||||
pBuilder.addFixer(new JigsawRotationFix(schema108, false));
|
||||
Schema schema109 = pBuilder.addSchema(2519, V2519::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema109, "Added Strider", References.ENTITY));
|
||||
Schema schema110 = pBuilder.addSchema(2522, V2522::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema110, "Added Zoglin", References.ENTITY));
|
||||
Schema schema111 = pBuilder.addSchema(2523, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new AttributesRename(schema111));
|
||||
Schema schema112 = pBuilder.addSchema(2527, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BitStorageAlignFix(schema112));
|
||||
Schema schema113 = pBuilder.addSchema(2528, SAME_NAMESPACED);
|
||||
pBuilder.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"))));
|
||||
pBuilder.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 = pBuilder.addSchema(2529, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new StriderGravityFix(schema114, false));
|
||||
Schema schema115 = pBuilder.addSchema(2531, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new RedstoneWireConnectionsFix(schema115));
|
||||
Schema schema116 = pBuilder.addSchema(2533, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new VillagerFollowRangeFix(schema116));
|
||||
Schema schema117 = pBuilder.addSchema(2535, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityShulkerRotationFix(schema117));
|
||||
Schema schema118 = pBuilder.addSchema(2550, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new WorldGenSettingsFix(schema118));
|
||||
Schema schema119 = pBuilder.addSchema(2551, V2551::new);
|
||||
pBuilder.addFixer(new WriteAndReadFix(schema119, "add types to WorldGenData", References.WORLD_GEN_SETTINGS));
|
||||
Schema schema120 = pBuilder.addSchema(2552, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema120, "Nether biome rename", References.BIOME, createRenamer("minecraft:nether", "minecraft:nether_wastes")));
|
||||
Schema schema121 = pBuilder.addSchema(2553, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema121, "Biomes fix", References.BIOME, createRenamer(BiomeFix.BIOMES)));
|
||||
Schema schema122 = pBuilder.addSchema(2558, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new MissingDimensionFix(schema122, false));
|
||||
pBuilder.addFixer(new OptionsRenameFieldFix(schema122, false, "Rename swapHands setting", "key_key.swapHands", "key_key.swapOffhand"));
|
||||
Schema schema123 = pBuilder.addSchema(2568, V2568::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema123, "Added Piglin Brute", References.ENTITY));
|
||||
Schema schema124 = pBuilder.addSchema(2571, V2571::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema124, "Added Goat", References.ENTITY));
|
||||
Schema schema125 = pBuilder.addSchema(2679, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new CauldronRenameFix(schema125, false));
|
||||
Schema schema126 = pBuilder.addSchema(2680, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema126, "Renamed grass path item to dirt path", createRenamer("minecraft:grass_path", "minecraft:dirt_path")));
|
||||
pBuilder.addFixer(BlockRenameFixWithJigsaw.create(schema126, "Renamed grass path block to dirt path", createRenamer("minecraft:grass_path", "minecraft:dirt_path")));
|
||||
Schema schema127 = pBuilder.addSchema(2684, V2684::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema127, "Added Sculk Sensor", References.BLOCK_ENTITY));
|
||||
Schema schema128 = pBuilder.addSchema(2686, V2686::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema128, "Added Axolotl", References.ENTITY));
|
||||
Schema schema129 = pBuilder.addSchema(2688, V2688::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema129, "Added Glow Squid", References.ENTITY));
|
||||
pBuilder.addFixer(new AddNewChoices(schema129, "Added Glow Item Frame", References.ENTITY));
|
||||
Schema schema130 = pBuilder.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();
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema130, "Renamed copper block items to new oxidized terms", createRenamer(immutablemap)));
|
||||
pBuilder.addFixer(BlockRenameFixWithJigsaw.create(schema130, "Renamed copper blocks to new oxidized terms", createRenamer(immutablemap)));
|
||||
Schema schema131 = pBuilder.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();
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema131, "Rename copper item suffixes", createRenamer(immutablemap1)));
|
||||
pBuilder.addFixer(BlockRenameFixWithJigsaw.create(schema131, "Rename copper blocks suffixes", createRenamer(immutablemap1)));
|
||||
Schema schema132 = pBuilder.addSchema(2693, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new AddFlagIfNotPresentFix(schema132, References.WORLD_GEN_SETTINGS, "has_increased_height_already", false));
|
||||
Schema schema133 = pBuilder.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();
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema133, "Renamed grimstone block items to deepslate", createRenamer(immutablemap2)));
|
||||
pBuilder.addFixer(BlockRenameFixWithJigsaw.create(schema133, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2)));
|
||||
Schema schema134 = pBuilder.addSchema(2700, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(2701, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new SavedDataFeaturePoolElementFix(schema135));
|
||||
Schema schema136 = pBuilder.addSchema(2702, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new AbstractArrowPickupFix(schema136));
|
||||
Schema schema137 = pBuilder.addSchema(2704, V2704::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema137, "Added Goat", References.ENTITY));
|
||||
Schema schema138 = pBuilder.addSchema(2707, V2707::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema138, "Added Marker", References.ENTITY));
|
||||
pBuilder.addFixer(new AddFlagIfNotPresentFix(schema138, References.WORLD_GEN_SETTINGS, "has_increased_height_already", true));
|
||||
Schema schema139 = pBuilder.addSchema(2710, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new StatsRenameFix(schema139, "Renamed play_one_minute stat to play_time", ImmutableMap.of("minecraft:play_one_minute", "minecraft:play_time")));
|
||||
Schema schema140 = pBuilder.addSchema(2717, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(ItemRenameFix.create(schema140, "Rename azalea_leaves_flowers", createRenamer(ImmutableMap.of("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves"))));
|
||||
pBuilder.addFixer(BlockRenameFix.create(schema140, "Rename azalea_leaves_flowers items", createRenamer(ImmutableMap.of("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves"))));
|
||||
Schema schema141 = pBuilder.addSchema(2825, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new AddFlagIfNotPresentFix(schema141, References.WORLD_GEN_SETTINGS, "has_increased_height_already", false));
|
||||
Schema schema142 = pBuilder.addSchema(2831, V2831::new);
|
||||
pBuilder.addFixer(new SpawnerDataFix(schema142));
|
||||
Schema schema143 = pBuilder.addSchema(2832, V2832::new);
|
||||
pBuilder.addFixer(new WorldGenSettingsHeightAndBiomeFix(schema143));
|
||||
pBuilder.addFixer(new ChunkHeightAndBiomeFix(schema143));
|
||||
Schema schema144 = pBuilder.addSchema(2833, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new WorldGenSettingsDisallowOldCustomWorldsFix(schema144));
|
||||
Schema schema145 = pBuilder.addSchema(2838, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema145, "Caves and Cliffs biome renames", References.BIOME, createRenamer(CavesAndCliffsRenames.RENAMES)));
|
||||
Schema schema146 = pBuilder.addSchema(2841, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkProtoTickListFix(schema146));
|
||||
Schema schema147 = pBuilder.addSchema(2842, V2842::new);
|
||||
pBuilder.addFixer(new ChunkRenamesFix(schema147));
|
||||
Schema schema148 = pBuilder.addSchema(2843, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OverreachingTickFix(schema148));
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema148, "Remove Deep Warm Ocean", References.BIOME, createRenamer("minecraft:deep_warm_ocean", "minecraft:warm_ocean")));
|
||||
Schema schema149 = pBuilder.addSchema(2846, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(2852, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new WorldGenSettingsDisallowOldCustomWorldsFix(schema150));
|
||||
Schema schema151 = pBuilder.addSchema(2967, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new StructureSettingsFlattenFix(schema151));
|
||||
Schema schema152 = pBuilder.addSchema(2970, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new StructuresBecomeConfiguredFix(schema152));
|
||||
Schema schema153 = pBuilder.addSchema(3076, V3076::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema153, "Added Sculk Catalyst", References.BLOCK_ENTITY));
|
||||
Schema schema154 = pBuilder.addSchema(3077, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkDeleteIgnoredLightDataFix(schema154));
|
||||
Schema schema155 = pBuilder.addSchema(3078, V3078::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema155, "Added Frog", References.ENTITY));
|
||||
pBuilder.addFixer(new AddNewChoices(schema155, "Added Tadpole", References.ENTITY));
|
||||
pBuilder.addFixer(new AddNewChoices(schema155, "Added Sculk Shrieker", References.BLOCK_ENTITY));
|
||||
Schema schema156 = pBuilder.addSchema(3081, V3081::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema156, "Added Warden", References.ENTITY));
|
||||
Schema schema157 = pBuilder.addSchema(3082, V3082::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema157, "Added Chest Boat", References.ENTITY));
|
||||
Schema schema158 = pBuilder.addSchema(3083, V3083::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema158, "Added Allay", References.ENTITY));
|
||||
Schema schema159 = pBuilder.addSchema(3084, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(3086, SAME_NAMESPACED);
|
||||
pBuilder.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();
|
||||
pBuilder.addFixer(new CriteriaRenameFix(schema160, "Migrate cat variant advancement", "minecraft:husbandry/complete_catalogue", (p_216517_) -> {
|
||||
return immutablemap3.getOrDefault(p_216517_, p_216517_);
|
||||
}));
|
||||
Schema schema161 = pBuilder.addSchema(3087, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(3090, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityPaintingFieldsRenameFix(schema162));
|
||||
Schema schema163 = pBuilder.addSchema(3093, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EntityGoatMissingStateFix(schema163));
|
||||
Schema schema164 = pBuilder.addSchema(3094, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new GoatHornIdFix(schema164));
|
||||
Schema schema165 = pBuilder.addSchema(3097, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new FilteredBooksFix(schema165));
|
||||
pBuilder.addFixer(new FilteredSignsFix(schema165));
|
||||
Map<String, String> map = Map.of("minecraft:british", "minecraft:british_shorthair");
|
||||
pBuilder.addFixer(new VariantRenameFix(schema165, "Rename british shorthair", References.ENTITY, "minecraft:cat", map));
|
||||
pBuilder.addFixer(new CriteriaRenameFix(schema165, "Migrate cat variant advancement for british shorthair", "minecraft:husbandry/complete_catalogue", (p_216531_) -> {
|
||||
return map.getOrDefault(p_216531_, p_216531_);
|
||||
}));
|
||||
pBuilder.addFixer(new PoiTypeRemoveFix(schema165, "Remove unpopulated villager PoI types", Set.of("minecraft:unemployed", "minecraft:nitwit")::contains));
|
||||
Schema schema166 = pBuilder.addSchema(3108, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BlendingDataRemoveFromNetherEndFix(schema166));
|
||||
Schema schema167 = pBuilder.addSchema(3201, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsProgrammerArtFix(schema167));
|
||||
Schema schema168 = pBuilder.addSchema(3202, V3202::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema168, "Added Hanging Sign", References.BLOCK_ENTITY));
|
||||
Schema schema169 = pBuilder.addSchema(3203, V3203::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema169, "Added Camel", References.ENTITY));
|
||||
Schema schema170 = pBuilder.addSchema(3204, V3204::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema170, "Added Chiseled Bookshelf", References.BLOCK_ENTITY));
|
||||
Schema schema171 = pBuilder.addSchema(3209, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ItemStackSpawnEggFix(schema171, false, "minecraft:pig_spawn_egg"));
|
||||
Schema schema172 = pBuilder.addSchema(3214, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsAmbientOcclusionFix(schema172));
|
||||
Schema schema173 = pBuilder.addSchema(3319, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new OptionsAccessibilityOnboardFix(schema173));
|
||||
Schema schema174 = pBuilder.addSchema(3322, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new EffectDurationFix(schema174));
|
||||
Schema schema175 = pBuilder.addSchema(3325, V3325::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema175, "Added displays", References.ENTITY));
|
||||
Schema schema176 = pBuilder.addSchema(3326, V3326::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema176, "Added Sniffer", References.ENTITY));
|
||||
Schema schema177 = pBuilder.addSchema(3327, V3327::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema177, "Archaeology", References.BLOCK_ENTITY));
|
||||
Schema schema178 = pBuilder.addSchema(3328, V3328::new);
|
||||
pBuilder.addFixer(new AddNewChoices(schema178, "Added interaction", References.ENTITY));
|
||||
Schema schema179 = pBuilder.addSchema(3438, V3438::new);
|
||||
pBuilder.addFixer(BlockEntityRenameFix.create(schema179, "Rename Suspicious Sand to Brushable Block", createRenamer("minecraft:suspicious_sand", "minecraft:brushable_block")));
|
||||
pBuilder.addFixer(new EntityBrushableBlockFieldsRenameFix(schema179));
|
||||
pBuilder.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"))));
|
||||
pBuilder.addFixer(new AddNewChoices(schema179, "Added calibrated sculk sensor", References.BLOCK_ENTITY));
|
||||
Schema schema180 = pBuilder.addSchema(3439, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BlockEntitySignDoubleSidedEditableTextFix(schema180, "Updated sign text format for Signs", "minecraft:sign"));
|
||||
pBuilder.addFixer(new BlockEntitySignDoubleSidedEditableTextFix(schema180, "Updated sign text format for Hanging Signs", "minecraft:hanging_sign"));
|
||||
Schema schema181 = pBuilder.addSchema(3440, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new NamespacedTypeRenameFix(schema181, "Replace experimental 1.20 overworld", References.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST, createRenamer("minecraft:overworld_update_1_20", "minecraft:overworld")));
|
||||
pBuilder.addFixer(new FeatureFlagRemoveFix(schema181, "Remove 1.20 feature toggle", Set.of("minecraft:update_1_20")));
|
||||
Schema schema182 = pBuilder.addSchema(3441, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new BlendingDataFix(schema182));
|
||||
Schema schema183 = pBuilder.addSchema(3447, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(3448, V3448::new);
|
||||
pBuilder.addFixer(new DecoratedPotFieldRenameFix(schema184));
|
||||
Schema schema185 = pBuilder.addSchema(3450, SAME_NAMESPACED);
|
||||
pBuilder.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 = pBuilder.addSchema(3451, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new ChunkDeleteLightFix(schema186));
|
||||
Schema schema187 = pBuilder.addSchema(3459, SAME_NAMESPACED);
|
||||
pBuilder.addFixer(new LegacyDragonFightFix(schema187));
|
||||
}
|
||||
|
||||
private static UnaryOperator<String> createRenamer(Map<String, String> pRenameMap) {
|
||||
return (p_216526_) -> {
|
||||
return pRenameMap.getOrDefault(p_216526_, p_216526_);
|
||||
};
|
||||
}
|
||||
|
||||
private static UnaryOperator<String> createRenamer(String pOldName, String pNewName) {
|
||||
return (p_216523_) -> {
|
||||
return Objects.equals(p_216523_, pOldName) ? pNewName : p_216523_;
|
||||
};
|
||||
}
|
||||
}
|
||||
+66
@@ -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 pBits, int pSize) {
|
||||
this(pBits, pSize, new long[Mth.roundToward(pSize * pBits, 64) / 64]);
|
||||
}
|
||||
|
||||
public PackedBitStorage(int pBits, int pSize, long[] pData) {
|
||||
Validate.inclusiveBetween(1L, 32L, (long)pBits);
|
||||
this.size = pSize;
|
||||
this.bits = pBits;
|
||||
this.data = pData;
|
||||
this.mask = (1L << pBits) - 1L;
|
||||
int i = Mth.roundToward(pSize * pBits, 64) / 64;
|
||||
if (pData.length != i) {
|
||||
throw new IllegalArgumentException("Invalid length given for storage, got: " + pData.length + " but expected: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int pIndex, int pValue) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
Validate.inclusiveBetween(0L, this.mask, (long)pValue);
|
||||
int i = pIndex * this.bits;
|
||||
int j = i >> 6;
|
||||
int k = (pIndex + 1) * this.bits - 1 >> 6;
|
||||
int l = i ^ j << 6;
|
||||
this.data[j] = this.data[j] & ~(this.mask << l) | ((long)pValue & this.mask) << l;
|
||||
if (j != k) {
|
||||
int i1 = 64 - l;
|
||||
int j1 = this.bits - i1;
|
||||
this.data[k] = this.data[k] >>> j1 << j1 | ((long)pValue & this.mask) >> i1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int get(int pIndex) {
|
||||
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)pIndex);
|
||||
int i = pIndex * this.bits;
|
||||
int j = i >> 6;
|
||||
int k = (pIndex + 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;
|
||||
}
|
||||
}
|
||||
+44
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, 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<?> pTyped, String pChoiceName, Function<Dynamic<?>, Dynamic<?>> pUpdater) {
|
||||
Type<?> type = this.getInputSchema().getChoiceType(References.ENTITY, pChoiceName);
|
||||
Type<?> type1 = this.getOutputSchema().getChoiceType(References.ENTITY, pChoiceName);
|
||||
return pTyped.updateTyped(DSL.namedChoice(pChoiceName, type), type1, (p_145057_) -> {
|
||||
return p_145057_.update(DSL.remainderFinder(), pUpdater);
|
||||
});
|
||||
}
|
||||
}
|
||||
+54
@@ -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 pOutputSchema, String pName) {
|
||||
super(pOutputSchema, false);
|
||||
this.name = pName;
|
||||
}
|
||||
|
||||
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>> pRecords);
|
||||
}
|
||||
+78
@@ -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 pOutputSchema, DSL.TypeReference pTypeReference) {
|
||||
super(pOutputSchema, false);
|
||||
this.typeReference = pTypeReference;
|
||||
}
|
||||
|
||||
protected Typed<?> updateNamedChoice(Typed<?> pTyped, String pChoiceName, Function<Dynamic<?>, Dynamic<?>> pUpdater) {
|
||||
Type<?> type = this.getInputSchema().getChoiceType(this.typeReference, pChoiceName);
|
||||
Type<?> type1 = this.getOutputSchema().getChoiceType(this.typeReference, pChoiceName);
|
||||
return pTyped.updateTyped(DSL.namedChoice(pChoiceName, type), type1, (p_14607_) -> {
|
||||
return p_14607_.update(DSL.remainderFinder(), pUpdater);
|
||||
});
|
||||
}
|
||||
|
||||
protected static Optional<Dynamic<?>> replaceUUIDString(Dynamic<?> pDynamic, String pOldKey, String pNewKey) {
|
||||
return createUUIDFromString(pDynamic, pOldKey).map((p_14616_) -> {
|
||||
return pDynamic.remove(pOldKey).set(pNewKey, p_14616_);
|
||||
});
|
||||
}
|
||||
|
||||
protected static Optional<Dynamic<?>> replaceUUIDMLTag(Dynamic<?> pDynamic, String pOldKey, String pNewKey) {
|
||||
return pDynamic.get(pOldKey).result().flatMap(AbstractUUIDFix::createUUIDFromML).map((p_14598_) -> {
|
||||
return pDynamic.remove(pOldKey).set(pNewKey, p_14598_);
|
||||
});
|
||||
}
|
||||
|
||||
protected static Optional<Dynamic<?>> replaceUUIDLeastMost(Dynamic<?> pDynamic, String pOldKey, String pNewKey) {
|
||||
String s = pOldKey + "Most";
|
||||
String s1 = pOldKey + "Least";
|
||||
return createUUIDFromLongs(pDynamic, s, s1).map((p_14604_) -> {
|
||||
return pDynamic.remove(s).remove(s1).set(pNewKey, p_14604_);
|
||||
});
|
||||
}
|
||||
|
||||
protected static Optional<Dynamic<?>> createUUIDFromString(Dynamic<?> pDynamic, String pUuidKey) {
|
||||
return pDynamic.get(pUuidKey).result().flatMap((p_14586_) -> {
|
||||
String s = p_14586_.asString((String)null);
|
||||
if (s != null) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
return createUUIDTag(pDynamic, 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<?> pDynamic, String pMostKey, String pLeastKey) {
|
||||
long i = pDynamic.get(pMostKey).asLong(0L);
|
||||
long j = pDynamic.get(pLeastKey).asLong(0L);
|
||||
return i != 0L && j != 0L ? createUUIDTag(pDynamic, i, j) : Optional.empty();
|
||||
}
|
||||
|
||||
protected static Optional<Dynamic<?>> createUUIDTag(Dynamic<?> pDynamic, long pMost, long pLeast) {
|
||||
return Optional.of(pDynamic.createIntList(Arrays.stream(new int[]{(int)(pMost >> 32), (int)pMost, (int)(pLeast >> 32), (int)pLeast})));
|
||||
}
|
||||
}
|
||||
+34
@@ -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 pOutputSchema, DSL.TypeReference pTypeReference, String pFlagKey, boolean pFlagValue) {
|
||||
super(pOutputSchema, true);
|
||||
this.flagValue = pFlagValue;
|
||||
this.flagKey = pFlagKey;
|
||||
this.name = "AddFlagIfNotPresentFix_" + this.flagKey + "=" + this.flagValue + " for " + pOutputSchema.getVersionKey();
|
||||
this.typeReference = pTypeReference;
|
||||
}
|
||||
|
||||
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);
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+41
@@ -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 pOutputSchema, String pName, DSL.TypeReference pType) {
|
||||
super(pOutputSchema, true);
|
||||
this.name = pName;
|
||||
this.type = pType;
|
||||
}
|
||||
|
||||
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 pName, TaggedChoice.TaggedChoiceType<K> pType, TaggedChoice.TaggedChoiceType<?> pNewType) {
|
||||
if (pType.getKeyType() != pNewType.getKeyType()) {
|
||||
throw new IllegalStateException("Could not inject: key type is not the same");
|
||||
} else {
|
||||
return this.fixTypeEverywhere(pName, pType, (TaggedChoice.TaggedChoiceType<K>)pNewType, (p_14636_) -> {
|
||||
return (p_145061_) -> {
|
||||
if (!((TaggedChoice.TaggedChoiceType<K>)pNewType).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_;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package net.minecraft.util.datafix.fixes;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.datafixers.schemas.Schema;
|
||||
import java.util.Map;
|
||||
|
||||
public class AdvancementsFix extends AdvancementsRenameFix {
|
||||
private static final Map<String, String> RENAMES = ImmutableMap.<String, String>builder().put("minecraft:recipes/brewing/speckled_melon", "minecraft:recipes/brewing/glistering_melon_slice").put("minecraft:recipes/building_blocks/black_stained_hardened_clay", "minecraft:recipes/building_blocks/black_terracotta").put("minecraft:recipes/building_blocks/blue_stained_hardened_clay", "minecraft:recipes/building_blocks/blue_terracotta").put("minecraft:recipes/building_blocks/brown_stained_hardened_clay", "minecraft:recipes/building_blocks/brown_terracotta").put("minecraft:recipes/building_blocks/cyan_stained_hardened_clay", "minecraft:recipes/building_blocks/cyan_terracotta").put("minecraft:recipes/building_blocks/gray_stained_hardened_clay", "minecraft:recipes/building_blocks/gray_terracotta").put("minecraft:recipes/building_blocks/green_stained_hardened_clay", "minecraft:recipes/building_blocks/green_terracotta").put("minecraft:recipes/building_blocks/light_blue_stained_hardened_clay", "minecraft:recipes/building_blocks/light_blue_terracotta").put("minecraft:recipes/building_blocks/light_gray_stained_hardened_clay", "minecraft:recipes/building_blocks/light_gray_terracotta").put("minecraft:recipes/building_blocks/lime_stained_hardened_clay", "minecraft:recipes/building_blocks/lime_terracotta").put("minecraft:recipes/building_blocks/magenta_stained_hardened_clay", "minecraft:recipes/building_blocks/magenta_terracotta").put("minecraft:recipes/building_blocks/orange_stained_hardened_clay", "minecraft:recipes/building_blocks/orange_terracotta").put("minecraft:recipes/building_blocks/pink_stained_hardened_clay", "minecraft:recipes/building_blocks/pink_terracotta").put("minecraft:recipes/building_blocks/purple_stained_hardened_clay", "minecraft:recipes/building_blocks/purple_terracotta").put("minecraft:recipes/building_blocks/red_stained_hardened_clay", "minecraft:recipes/building_blocks/red_terracotta").put("minecraft:recipes/building_blocks/white_stained_hardened_clay", "minecraft:recipes/building_blocks/white_terracotta").put("minecraft:recipes/building_blocks/yellow_stained_hardened_clay", "minecraft:recipes/building_blocks/yellow_terracotta").put("minecraft:recipes/building_blocks/acacia_wooden_slab", "minecraft:recipes/building_blocks/acacia_slab").put("minecraft:recipes/building_blocks/birch_wooden_slab", "minecraft:recipes/building_blocks/birch_slab").put("minecraft:recipes/building_blocks/dark_oak_wooden_slab", "minecraft:recipes/building_blocks/dark_oak_slab").put("minecraft:recipes/building_blocks/jungle_wooden_slab", "minecraft:recipes/building_blocks/jungle_slab").put("minecraft:recipes/building_blocks/oak_wooden_slab", "minecraft:recipes/building_blocks/oak_slab").put("minecraft:recipes/building_blocks/spruce_wooden_slab", "minecraft:recipes/building_blocks/spruce_slab").put("minecraft:recipes/building_blocks/brick_block", "minecraft:recipes/building_blocks/bricks").put("minecraft:recipes/building_blocks/chiseled_stonebrick", "minecraft:recipes/building_blocks/chiseled_stone_bricks").put("minecraft:recipes/building_blocks/end_bricks", "minecraft:recipes/building_blocks/end_stone_bricks").put("minecraft:recipes/building_blocks/lit_pumpkin", "minecraft:recipes/building_blocks/jack_o_lantern").put("minecraft:recipes/building_blocks/magma", "minecraft:recipes/building_blocks/magma_block").put("minecraft:recipes/building_blocks/melon_block", "minecraft:recipes/building_blocks/melon").put("minecraft:recipes/building_blocks/mossy_stonebrick", "minecraft:recipes/building_blocks/mossy_stone_bricks").put("minecraft:recipes/building_blocks/nether_brick", "minecraft:recipes/building_blocks/nether_bricks").put("minecraft:recipes/building_blocks/pillar_quartz_block", "minecraft:recipes/building_blocks/quartz_pillar").put("minecraft:recipes/building_blocks/red_nether_brick", "minecraft:recipes/building_blocks/red_nether_bricks").put("minecraft:recipes/building_blocks/snow", "minecraft:recipes/building_blocks/snow_block").put("minecraft:recipes/building_blocks/smooth_red_sandstone", "minecraft:recipes/building_blocks/cut_red_sandstone").put("minecraft:recipes/building_blocks/smooth_sandstone", "minecraft:recipes/building_blocks/cut_sandstone").put("minecraft:recipes/building_blocks/stonebrick", "minecraft:recipes/building_blocks/stone_bricks").put("minecraft:recipes/building_blocks/stone_stairs", "minecraft:recipes/building_blocks/cobblestone_stairs").put("minecraft:recipes/building_blocks/string_to_wool", "minecraft:recipes/building_blocks/white_wool_from_string").put("minecraft:recipes/decorations/fence", "minecraft:recipes/decorations/oak_fence").put("minecraft:recipes/decorations/purple_shulker_box", "minecraft:recipes/decorations/shulker_box").put("minecraft:recipes/decorations/slime", "minecraft:recipes/decorations/slime_block").put("minecraft:recipes/decorations/snow_layer", "minecraft:recipes/decorations/snow").put("minecraft:recipes/misc/bone_meal_from_block", "minecraft:recipes/misc/bone_meal_from_bone_blocLine truncated
|
||||
|
||||
public AdvancementsFix(Schema pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "AdvancementsFix", (p_14648_) -> {
|
||||
return RENAMES.getOrDefault(p_14648_, p_14648_);
|
||||
});
|
||||
}
|
||||
}
|
||||
+31
@@ -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 pOutputSchema, boolean pChangesType, String pName, Function<String, String> pRenamer) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
this.name = pName;
|
||||
this.renamer = pRenamer;
|
||||
}
|
||||
|
||||
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));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+59
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, 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_);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+33
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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_;
|
||||
});
|
||||
}
|
||||
}
|
||||
+8
@@ -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();
|
||||
}
|
||||
+131
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, 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<?> pTyped) {
|
||||
return pTyped.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 pNumBits, int pBitWidth) {
|
||||
long[] along = p_14778_.asLongStream().toArray();
|
||||
long[] along1 = addPadding(pNumBits, pBitWidth, along);
|
||||
return p_14777_.createLongList(LongStream.of(along1));
|
||||
}
|
||||
|
||||
public static long[] addPadding(int pNumBits, int pBitWidth, long[] pInputData) {
|
||||
int i = pInputData.length;
|
||||
if (i == 0) {
|
||||
return pInputData;
|
||||
} else {
|
||||
long j = (1L << pBitWidth) - 1L;
|
||||
int k = 64 / pBitWidth;
|
||||
int l = (pNumBits + k - 1) / k;
|
||||
long[] along = new long[l];
|
||||
int i1 = 0;
|
||||
int j1 = 0;
|
||||
long k1 = 0L;
|
||||
int l1 = 0;
|
||||
long i2 = pInputData[0];
|
||||
long j2 = i > 1 ? pInputData[1] : 0L;
|
||||
|
||||
for(int k2 = 0; k2 < pNumBits; ++k2) {
|
||||
int l2 = k2 * pBitWidth;
|
||||
int i3 = l2 >> 6;
|
||||
int j3 = (k2 + 1) * pBitWidth - 1 >> 6;
|
||||
int k3 = l2 ^ i3 << 6;
|
||||
if (i3 != l1) {
|
||||
i2 = j2;
|
||||
j2 = i3 + 1 < i ? pInputData[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 + pBitWidth;
|
||||
if (j4 >= 64) {
|
||||
along[i1++] = k1;
|
||||
k1 = l3;
|
||||
j1 = pBitWidth;
|
||||
} else {
|
||||
k1 |= l3 << j1;
|
||||
j1 = j4;
|
||||
}
|
||||
}
|
||||
|
||||
if (k1 != 0L) {
|
||||
along[i1] = k1;
|
||||
}
|
||||
|
||||
return along;
|
||||
}
|
||||
}
|
||||
}
|
||||
+58
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, false);
|
||||
this.name = "Blending Data Fix v" + pOutputSchema.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<?> pChunkTag, OptionalDynamic<?> p_240280_) {
|
||||
pChunkTag = pChunkTag.remove("blending_data");
|
||||
boolean flag = "minecraft:overworld".equals(p_240280_.get("dimension").asString().result().orElse(""));
|
||||
Optional<? extends Dynamic<?>> optional = pChunkTag.get("Status").result();
|
||||
if (flag && optional.isPresent()) {
|
||||
String s = NamespacedSchema.ensureNamespaced(optional.get().asString("empty"));
|
||||
Optional<? extends Dynamic<?>> optional1 = pChunkTag.get("below_zero_retrogen").result();
|
||||
if (!STATUSES_TO_SKIP_BLENDING.contains(s)) {
|
||||
pChunkTag = updateBlendingData(pChunkTag, 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)) {
|
||||
pChunkTag = updateBlendingData(pChunkTag, 256, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pChunkTag;
|
||||
}
|
||||
|
||||
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_)))));
|
||||
}
|
||||
}
|
||||
+29
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, 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<?> pChunkTag, OptionalDynamic<?> p_240319_) {
|
||||
boolean flag = "minecraft:overworld".equals(p_240319_.get("dimension").asString().result().orElse(""));
|
||||
return flag ? pChunkTag : pChunkTag.remove("blending_data");
|
||||
}
|
||||
}
|
||||
+32
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "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<?> pTyped) {
|
||||
return pTyped.update(DSL.remainderFinder(), this::fixTag);
|
||||
}
|
||||
}
|
||||
+32
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "BlockEntityBlockStateFix", References.BLOCK_ENTITY, "minecraft:piston");
|
||||
}
|
||||
|
||||
protected Typed<?> fix(Typed<?> pTyped) {
|
||||
Type<?> type = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:piston");
|
||||
Type<?> type1 = type.findFieldType("blockState");
|
||||
OpticFinder<?> opticfinder = DSL.fieldFinder("blockState", type1);
|
||||
Dynamic<?> dynamic = pTyped.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(pTyped.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());
|
||||
}
|
||||
}
|
||||
+26
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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_);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+56
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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_);
|
||||
});
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
+36
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "BlockEntityJukeboxFix", References.BLOCK_ENTITY, "minecraft:jukebox");
|
||||
}
|
||||
|
||||
protected Typed<?> fix(Typed<?> pTyped) {
|
||||
Type<?> type = this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:jukebox");
|
||||
Type<?> type1 = type.findFieldType("RecordItem");
|
||||
OpticFinder<?> opticfinder = DSL.fieldFinder("RecordItem", type1);
|
||||
Dynamic<?> dynamic = pTyped.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 pTyped.set(opticfinder, type1.readTyped(dynamic1).result().orElseThrow(() -> {
|
||||
return new IllegalStateException("Could not create record item stack.");
|
||||
}).getFirst()).set(DSL.remainderFinder(), dynamic);
|
||||
}
|
||||
}
|
||||
|
||||
return pTyped;
|
||||
}
|
||||
}
|
||||
+20
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "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<?> pTyped) {
|
||||
return pTyped.update(DSL.remainderFinder(), BlockEntityKeepPacked::fixTag);
|
||||
}
|
||||
}
|
||||
+32
@@ -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 pOutputSchema, String pName, UnaryOperator<String> pNameChangeLookup) {
|
||||
super(pOutputSchema, true);
|
||||
this.name = pName;
|
||||
this.nameChangeLookup = pNameChangeLookup;
|
||||
}
|
||||
|
||||
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 pOutputSchema, String pName, UnaryOperator<String> pNameChangeLookup) {
|
||||
return new BlockEntityRenameFix(pOutputSchema, pName, pNameChangeLookup);
|
||||
}
|
||||
}
|
||||
+17
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "BlockEntityShulkerBoxColorFix", References.BLOCK_ENTITY, "minecraft:shulker_box");
|
||||
}
|
||||
|
||||
protected Typed<?> fix(Typed<?> pTyped) {
|
||||
return pTyped.update(DSL.remainderFinder(), (p_14860_) -> {
|
||||
return p_14860_.remove("Color");
|
||||
});
|
||||
}
|
||||
}
|
||||
+53
@@ -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 pOutputSchema, String pName, String pEntityName) {
|
||||
super(pOutputSchema, false, pName, References.BLOCK_ENTITY, pEntityName);
|
||||
}
|
||||
|
||||
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> pTag, String pKey) {
|
||||
Dynamic<T> dynamic = pTag.createString(getEmptyComponent());
|
||||
return pTag.createList(Stream.of(pTag.get(pKey + "1").result().orElse(dynamic), pTag.get(pKey + "2").result().orElse(dynamic), pTag.get(pKey + "3").result().orElse(dynamic), pTag.get(pKey + "4").result().orElse(dynamic)));
|
||||
}
|
||||
|
||||
private static <T> Dynamic<T> getEmptyTextList(Dynamic<T> pTag) {
|
||||
Dynamic<T> dynamic = pTag.createString(getEmptyComponent());
|
||||
return pTag.createList(Stream.of(dynamic, dynamic, dynamic, dynamic));
|
||||
}
|
||||
|
||||
private static String getEmptyComponent() {
|
||||
return Component.Serializer.toJson(CommonComponents.EMPTY);
|
||||
}
|
||||
|
||||
protected Typed<?> fix(Typed<?> pTyped) {
|
||||
return pTyped.update(DSL.remainderFinder(), BlockEntitySignDoubleSidedEditableTextFix::fixTag);
|
||||
}
|
||||
}
|
||||
+98
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "BlockEntitySignTextStrictJsonFix", References.BLOCK_ENTITY, "Sign");
|
||||
}
|
||||
|
||||
private Dynamic<?> updateLine(Dynamic<?> pDynamic, String pKey) {
|
||||
String s = pDynamic.get(pKey).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 pDynamic.set(pKey, pDynamic.createString(Component.Serializer.toJson(component)));
|
||||
}
|
||||
|
||||
protected Typed<?> fix(Typed<?> pTyped) {
|
||||
return pTyped.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");
|
||||
});
|
||||
}
|
||||
}
|
||||
+30
@@ -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 pOutputSchema) {
|
||||
super(pOutputSchema, 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_);
|
||||
}
|
||||
}
|
||||
+37
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
@@ -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 pOutputSchema, String pName) {
|
||||
super(pOutputSchema, false);
|
||||
this.name = pName;
|
||||
}
|
||||
|
||||
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 pOutputSchema, String pName, final Function<String, String> pRenamer) {
|
||||
return new BlockRenameFix(pOutputSchema, pName) {
|
||||
protected String fixBlock(String p_14932_) {
|
||||
return pRenamer.apply(p_14932_);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+57
@@ -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_);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+1860
File diff suppressed because it is too large.
Load diff
+18
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
public TypeRewriteRule makeRule() {
|
||||
return this.fixTypeEverywhereTyped("BlockStateStructureTemplateFix", this.getInputSchema().getType(References.BLOCK_STATE), (p_15004_) -> {
|
||||
return p_15004_.update(DSL.remainderFinder(), BlockStateData::upgradeBlockStateTag);
|
||||
});
|
||||
}
|
||||
}
|
||||
+20
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType, "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<?> pTyped) {
|
||||
return pTyped.update(DSL.remainderFinder(), this::fixTag);
|
||||
}
|
||||
}
|
||||
+30
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
+10
@@ -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() {
|
||||
}
|
||||
}
|
||||
+83
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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_;
|
||||
}));
|
||||
}
|
||||
}
|
||||
+54
@@ -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 pOutputSchema, boolean pChangesType) {
|
||||
super(pOutputSchema, pChangesType);
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Loaded 100 of 14134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user