mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 20:39:10 +00:00
初步兼容1.21.9
This commit is contained in:
@@ -100,7 +100,8 @@ public abstract class BlockBehavior {
|
||||
return false;
|
||||
}
|
||||
|
||||
// BlockState state, Level level, BlockPos pos
|
||||
// 1.20.1~1.21.8 BlockState state, Level level, BlockPos pos
|
||||
// 1.21.9+ BlockState state, Level level, BlockPos pos
|
||||
public int getAnalogOutputSignal(Object thisBlock, Object[] args) throws Exception {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,63 +19,148 @@ public class ResolutionMergePackMcMeta implements Resolution {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private static class MinMax {
|
||||
int min;
|
||||
int max;
|
||||
|
||||
MinMax(int min, int max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
record MinMax(int min, int max) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public static void mergeMcMeta(Path file1, Path file2, JsonElement customDescription) throws IOException {
|
||||
JsonElement elem1 = GsonHelper.readJsonFile(file1);
|
||||
JsonElement elem2 = GsonHelper.readJsonFile(file2);
|
||||
JsonObject mcmeta1 = GsonHelper.readJsonFile(file1).getAsJsonObject();
|
||||
JsonObject mcmeta2 = GsonHelper.readJsonFile(file2).getAsJsonObject();
|
||||
|
||||
JsonObject merged = mergeValues(elem1.getAsJsonObject(), elem2.getAsJsonObject())
|
||||
.getAsJsonObject();
|
||||
JsonObject merged = mergeValues(mcmeta1, mcmeta2).getAsJsonObject();
|
||||
|
||||
if (merged.has("pack")) {
|
||||
JsonObject pack = merged.getAsJsonObject("pack");
|
||||
if (mcmeta1.has("pack") && mcmeta2.has("pack")) {
|
||||
JsonObject mergedPack = merged.getAsJsonObject("pack");
|
||||
JsonObject mcmeta1Pack = mcmeta1.getAsJsonObject("pack");
|
||||
JsonObject mcmeta2Pack = mcmeta2.getAsJsonObject("pack");
|
||||
|
||||
int pf1 = elem1.getAsJsonObject().getAsJsonObject("pack")
|
||||
.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
int pf2 = elem2.getAsJsonObject().getAsJsonObject("pack")
|
||||
.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
pack.addProperty("pack_format", Math.max(pf1, pf2));
|
||||
int minPackFormat = Integer.MAX_VALUE;
|
||||
int maxPackFormat = Integer.MIN_VALUE;
|
||||
JsonArray mergedMinFormat = null;
|
||||
JsonArray mergedMaxFormat = null;
|
||||
|
||||
JsonElement sf1 = elem1.getAsJsonObject().getAsJsonObject("pack")
|
||||
.get("supported_formats");
|
||||
JsonElement sf2 = elem2.getAsJsonObject().getAsJsonObject("pack")
|
||||
.get("supported_formats");
|
||||
if (mcmeta1Pack.has("pack_format") && mcmeta2Pack.has("pack_format")) {
|
||||
int packFormat1 = mcmeta1Pack.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
int packFormat2 = mcmeta2Pack.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
int mergedPackFormat = maxPackFormat = Math.max(packFormat1, packFormat2);
|
||||
minPackFormat = Math.min(packFormat1, packFormat2);
|
||||
mergedPack.addProperty("pack_format", mergedPackFormat);
|
||||
} else if (mcmeta1Pack.has("pack_format")) {
|
||||
minPackFormat = maxPackFormat = mcmeta1Pack.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
} else if (mcmeta2Pack.has("pack_format")) {
|
||||
minPackFormat = maxPackFormat = mcmeta2Pack.getAsJsonPrimitive("pack_format").getAsInt();
|
||||
}
|
||||
|
||||
if (sf1 != null || sf2 != null) {
|
||||
MinMax mergedMinMax = getMergedMinMax(sf1, sf2, pf1, pf2);
|
||||
if (mcmeta1Pack.has("min_format") || mcmeta2Pack.has("min_format")) {
|
||||
int[] minFormat1 = new int[]{Integer.MAX_VALUE, 0};
|
||||
int[] minFormat2 = new int[]{Integer.MAX_VALUE, 0};
|
||||
|
||||
JsonElement mergedSf = createSupportedFormatsElement(
|
||||
sf1 != null ? sf1 : sf2,
|
||||
if (mcmeta1Pack.has("min_format")) {
|
||||
JsonElement minFormat = mcmeta1Pack.get("min_format");
|
||||
if (minFormat.isJsonPrimitive()) {
|
||||
minFormat1[0] = minFormat.getAsInt();
|
||||
}
|
||||
if (minFormat.isJsonArray()) {
|
||||
JsonArray minFormatArray = minFormat.getAsJsonArray();
|
||||
minFormat1[0] = minFormatArray.get(0).getAsInt();
|
||||
if (minFormatArray.size() > 1) {
|
||||
minFormat1[1] = minFormatArray.get(1).getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mcmeta2Pack.has("min_format")) {
|
||||
JsonElement minFormat = mcmeta2Pack.get("min_format");
|
||||
if (minFormat.isJsonPrimitive()) {
|
||||
minFormat2[0] = minFormat.getAsInt();
|
||||
}
|
||||
if (mcmeta2Pack.isJsonArray()) {
|
||||
JsonArray minFormatArray = minFormat.getAsJsonArray();
|
||||
minFormat2[0] = minFormatArray.get(0).getAsInt();
|
||||
if (minFormatArray.size() > 1) {
|
||||
minFormat2[1] = minFormatArray.get(1).getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
minPackFormat = Math.min(minPackFormat, Math.min(minFormat1[0], minFormat2[0]));
|
||||
mergedMinFormat = new JsonArray(2);
|
||||
mergedMinFormat.add(minPackFormat);
|
||||
mergedMinFormat.add(Math.min(minFormat1[1], minFormat2[1]));
|
||||
mergedPack.add("min_format", mergedMinFormat);
|
||||
}
|
||||
|
||||
if (mcmeta1Pack.has("max_format") || mcmeta2Pack.has("max_format")) {
|
||||
int[] maxFormat1 = new int[]{Integer.MIN_VALUE, 0};
|
||||
int[] maxFormat2 = new int[]{Integer.MIN_VALUE, 0};
|
||||
|
||||
if (mcmeta1Pack.has("max_format")) {
|
||||
JsonElement maxFormat = mcmeta1Pack.get("max_format");
|
||||
if (maxFormat.isJsonPrimitive()) {
|
||||
maxFormat1[0] = maxFormat.getAsInt();
|
||||
}
|
||||
if (maxFormat.isJsonArray()) {
|
||||
JsonArray maxFormatArray = maxFormat.getAsJsonArray();
|
||||
maxFormat1[0] = maxFormatArray.get(0).getAsInt();
|
||||
if (maxFormatArray.size() > 1) {
|
||||
maxFormat1[1] = maxFormatArray.get(1).getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mcmeta2Pack.has("max_format")) {
|
||||
JsonElement maxFormat = mcmeta2Pack.get("max_format");
|
||||
if (maxFormat.isJsonPrimitive()) {
|
||||
maxFormat2[0] = maxFormat.getAsInt();
|
||||
}
|
||||
if (maxFormat.isJsonArray()) {
|
||||
JsonArray maxFormatArray = maxFormat.getAsJsonArray();
|
||||
maxFormat2[0] = maxFormatArray.get(0).getAsInt();
|
||||
if (maxFormatArray.size() > 1) {
|
||||
maxFormat2[1] = maxFormatArray.get(1).getAsInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxPackFormat = Math.max(maxPackFormat, Math.max(maxFormat1[0], maxFormat2[0]));
|
||||
mergedMaxFormat = new JsonArray(2);
|
||||
mergedMaxFormat.add(maxPackFormat);
|
||||
mergedMaxFormat.add(Math.max(maxFormat1[1], maxFormat2[1]));
|
||||
mergedPack.add("max_format", mergedMaxFormat);
|
||||
}
|
||||
|
||||
JsonElement supportedFormats1 = mcmeta1Pack.get("supported_formats");
|
||||
JsonElement supportedFormats2 = mcmeta2Pack.get("supported_formats");
|
||||
|
||||
if (supportedFormats1 != null || supportedFormats2 != null) {
|
||||
MinMax mergedMinMax = getMergedMinMax(supportedFormats1, supportedFormats2, minPackFormat, maxPackFormat);
|
||||
JsonElement mergedSupportedFormats = createSupportedFormatsElement(
|
||||
supportedFormats1 != null ? supportedFormats1 : supportedFormats2,
|
||||
mergedMinMax.min,
|
||||
mergedMinMax.max
|
||||
);
|
||||
|
||||
pack.add("supported_formats", mergedSf);
|
||||
if (mergedMinFormat != null && !mergedMinFormat.isEmpty()) {
|
||||
mergedMinFormat.set(0, new JsonPrimitive(Math.min(mergedMinMax.min, mergedMinFormat.get(0).getAsInt())));
|
||||
}
|
||||
if (mergedMaxFormat != null && !mergedMaxFormat.isEmpty()) {
|
||||
mergedMaxFormat.set(0, new JsonPrimitive(Math.max(mergedMinMax.max, mergedMaxFormat.get(0).getAsInt())));
|
||||
}
|
||||
mergedPack.add("supported_formats", mergedSupportedFormats);
|
||||
}
|
||||
|
||||
if (customDescription != null) {
|
||||
pack.add("description", customDescription);
|
||||
mergedPack.add("description", customDescription);
|
||||
} else {
|
||||
JsonPrimitive desc1 = elem1.getAsJsonObject().getAsJsonObject("pack")
|
||||
JsonPrimitive description1 = mcmeta1.getAsJsonObject().getAsJsonObject("pack")
|
||||
.getAsJsonPrimitive("description");
|
||||
JsonPrimitive desc2 = elem2.getAsJsonObject().getAsJsonObject("pack")
|
||||
JsonPrimitive description2 = mcmeta2.getAsJsonObject().getAsJsonObject("pack")
|
||||
.getAsJsonPrimitive("description");
|
||||
|
||||
String mergedDesc = (desc1 != null ? desc1.getAsString() : "")
|
||||
+ (desc1 != null && desc2 != null ? "\n" : "")
|
||||
+ (desc2 != null ? desc2.getAsString() : "");
|
||||
String mergedDesc = (description1 != null ? description1.getAsString() : "")
|
||||
+ (description1 != null && description2 != null ? "\n" : "")
|
||||
+ (description2 != null ? description2.getAsString() : "");
|
||||
|
||||
if (!mergedDesc.isEmpty()) {
|
||||
pack.addProperty("description", mergedDesc);
|
||||
mergedPack.addProperty("description", mergedDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,16 +168,14 @@ public class ResolutionMergePackMcMeta implements Resolution {
|
||||
GsonHelper.writeJsonFile(merged, file1);
|
||||
}
|
||||
|
||||
private static MinMax getMergedMinMax(JsonElement sf1, JsonElement sf2, int pf1, int pf2) {
|
||||
private static MinMax getMergedMinMax(JsonElement sf1, JsonElement sf2, int minPackFormat, int maxPackFormat) {
|
||||
MinMax mm1 = parseSupportedFormats(sf1);
|
||||
MinMax mm2 = parseSupportedFormats(sf2);
|
||||
|
||||
int finalMin = Math.min(mm1.min, mm2.min);
|
||||
int finalMax = Math.max(mm1.max, mm2.max);
|
||||
int pfMin = Math.min(pf1, pf2);
|
||||
int pfMax = Math.max(pf1, pf2);
|
||||
finalMin = Math.min(pfMin, finalMin);
|
||||
finalMax = Math.max(pfMax, finalMax);
|
||||
finalMin = Math.min(minPackFormat, finalMin);
|
||||
finalMax = Math.max(maxPackFormat, finalMax);
|
||||
|
||||
return new MinMax(finalMin, finalMax);
|
||||
}
|
||||
@@ -110,7 +193,7 @@ public class ResolutionMergePackMcMeta implements Resolution {
|
||||
if (supported.isJsonArray()) {
|
||||
JsonArray arr = supported.getAsJsonArray();
|
||||
int min = arr.get(0).getAsInt();
|
||||
int max = arr.get(arr.size()-1).getAsInt();
|
||||
int max = arr.get(arr.size() - 1).getAsInt();
|
||||
return new MinMax(min, max);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.registry.Registry;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.sparrow.nbt.NBT;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -76,7 +77,7 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
public <T, C extends Collection<T>> C readCollection(IntFunction<C> collectionFactory, Reader<T> reader) {
|
||||
int i = this.readVarInt();
|
||||
C collection = collectionFactory.apply(i);
|
||||
for(int j = 0; j < i; ++j) {
|
||||
for (int j = 0; j < i; ++j) {
|
||||
collection.add(reader.apply(this));
|
||||
}
|
||||
return collection;
|
||||
@@ -93,7 +94,7 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
public <T> T[] readArray(Reader<T> reader, Class<T> type) {
|
||||
int i = this.readVarInt();
|
||||
T[] array = (T[]) Array.newInstance(type, i);
|
||||
for(int j = 0; j < i; ++j) {
|
||||
for (int j = 0; j < i; ++j) {
|
||||
array[j] = reader.apply(this);
|
||||
}
|
||||
return array;
|
||||
@@ -101,7 +102,7 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
|
||||
public <T> void writeArray(T[] array, Writer<T> writer) {
|
||||
this.writeVarInt(array.length);
|
||||
for(T t : array) {
|
||||
for (T t : array) {
|
||||
writer.accept(this, t);
|
||||
}
|
||||
}
|
||||
@@ -351,7 +352,7 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
}
|
||||
|
||||
public long[] readFixedSizeLongArray(long[] output) {
|
||||
for(int i = 0; i < output.length; ++i) {
|
||||
for (int i = 0; i < output.length; ++i) {
|
||||
output[i] = this.readLong();
|
||||
}
|
||||
return output;
|
||||
@@ -473,12 +474,12 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
|
||||
public void writeHolderSet(Either<List<Integer>, Key> holderSet) {
|
||||
holderSet.ifLeft(
|
||||
ints -> {
|
||||
writeVarInt(ints.size() + 1);
|
||||
for (Integer anInt : ints) {
|
||||
writeVarInt(anInt);
|
||||
ints -> {
|
||||
writeVarInt(ints.size() + 1);
|
||||
for (Integer anInt : ints) {
|
||||
writeVarInt(anInt);
|
||||
}
|
||||
}
|
||||
}
|
||||
).ifRight(key -> {
|
||||
writeVarInt(0);
|
||||
writeKey(key);
|
||||
@@ -599,13 +600,57 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Enum<T>> T readEnumConstant(Class<T> enumClass) {
|
||||
return (T)((Enum<T>[])enumClass.getEnumConstants())[this.readVarInt()];
|
||||
return (T) ((Enum<T>[]) enumClass.getEnumConstants())[this.readVarInt()];
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeEnumConstant(Enum<?> instance) {
|
||||
return this.writeVarInt(instance.ordinal());
|
||||
}
|
||||
|
||||
public Vec3d readLpVec3() {
|
||||
int unsignedByte = this.readUnsignedByte();
|
||||
if (unsignedByte == 0) {
|
||||
return Vec3d.ZERO;
|
||||
} else {
|
||||
int unsignedByte1 = this.readUnsignedByte();
|
||||
long unsignedInt = this.readUnsignedInt();
|
||||
long l = unsignedInt << 16 | (long) (unsignedByte1 << 8) | (long) unsignedByte;
|
||||
long l1 = unsignedByte & 3;
|
||||
if ((unsignedByte & 4) == 4) {
|
||||
l1 |= ((long) this.readVarInt() & 4294967295L) << 2;
|
||||
}
|
||||
return new Vec3d(
|
||||
(Math.min((double) ((l >> 3) & 32767L), (double) 32766.0F) * (double) 2.0F / (double) 32766.0F - (double) 1.0F) * (double) l1,
|
||||
(Math.min((double) ((l >> 18) & 32767L), (double) 32766.0F) * (double) 2.0F / (double) 32766.0F - (double) 1.0F) * (double) l1,
|
||||
(Math.min((double) ((l >> 33) & 32767L), (double) 32766.0F) * (double) 2.0F / (double) 32766.0F - (double) 1.0F) * (double) l1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLpVec3(Vec3d vec3) {
|
||||
double d = Double.isNaN(vec3.x) ? (double) 0.0F : Math.clamp(vec3.x, -1.7179869183E10, 1.7179869183E10);
|
||||
double d1 = Double.isNaN(vec3.y) ? (double) 0.0F : Math.clamp(vec3.y, -1.7179869183E10, 1.7179869183E10);
|
||||
double d2 = Double.isNaN(vec3.z) ? (double) 0.0F : Math.clamp(vec3.z, -1.7179869183E10, 1.7179869183E10);
|
||||
double max = MCUtils.absMax(d, MCUtils.absMax(d1, d2));
|
||||
if (max < 3.051944088384301E-5) {
|
||||
this.writeByte(0);
|
||||
} else {
|
||||
long l = MCUtils.ceilLong(max);
|
||||
boolean flag = (l & 3L) != l;
|
||||
long l1 = flag ? l & 3L | 4L : l;
|
||||
long l2 = (Math.round(((d / (double) l) * (double) 0.5F + (double) 0.5F) * (double) 32766.0F)) << 3;
|
||||
long l3 = (Math.round(((d1 / (double) l) * (double) 0.5F + (double) 0.5F) * (double) 32766.0F)) << 18;
|
||||
long l4 = (Math.round(((d2 / (double) l) * (double) 0.5F + (double) 0.5F) * (double) 32766.0F)) << 33;
|
||||
long l5 = l1 | l2 | l3 | l4;
|
||||
this.writeByte((byte) ((int) l5));
|
||||
this.writeByte((byte) ((int) (l5 >> 8)));
|
||||
this.writeInt((int) (l5 >> 16));
|
||||
if (flag) {
|
||||
this.writeVarInt((int) (l >> 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer<T> extends BiConsumer<FriendlyByteBuf, T> {
|
||||
|
||||
|
||||
@@ -282,4 +282,13 @@ public class MCUtils {
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return value < min ? min : Math.min(value, max);
|
||||
}
|
||||
|
||||
public static double absMax(double x, double y) {
|
||||
return Math.max(Math.abs(x), Math.abs(y));
|
||||
}
|
||||
|
||||
public static long ceilLong(double value) {
|
||||
long l = (long)value;
|
||||
return value > (double)l ? l + 1L : l;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public final class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
PACK_FORMATS.put(1_21_06, 63);
|
||||
PACK_FORMATS.put(1_21_07, 64);
|
||||
PACK_FORMATS.put(1_21_08, 64);
|
||||
PACK_FORMATS.put(1_21_09, 69);
|
||||
PACK_FORMATS.put(1_99_99, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,5 +19,6 @@ public final class MinecraftVersions {
|
||||
public static final MinecraftVersion V1_21_6 = new MinecraftVersion("1.21.6");
|
||||
public static final MinecraftVersion V1_21_7 = new MinecraftVersion("1.21.7");
|
||||
public static final MinecraftVersion V1_21_8 = new MinecraftVersion("1.21.8");
|
||||
public static final MinecraftVersion V1_21_9 = new MinecraftVersion("1.21.9");
|
||||
public static final MinecraftVersion FUTURE = new MinecraftVersion("1.99.99");
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class VersionHelper {
|
||||
private static final boolean v1_21_6;
|
||||
private static final boolean v1_21_7;
|
||||
private static final boolean v1_21_8;
|
||||
private static final boolean v1_21_9;
|
||||
|
||||
static {
|
||||
try (InputStream inputStream = Class.forName("net.minecraft.obfuscate.DontObfuscate").getResourceAsStream("/version.json")) {
|
||||
@@ -68,6 +69,7 @@ public class VersionHelper {
|
||||
v1_21_6 = version >= 12106;
|
||||
v1_21_7 = version >= 12107;
|
||||
v1_21_8 = version >= 12108;
|
||||
v1_21_9 = version >= 12109;
|
||||
|
||||
majorVersion = major;
|
||||
minorVersion = minor;
|
||||
@@ -239,4 +241,8 @@ public class VersionHelper {
|
||||
public static boolean isOrAbove1_21_8() {
|
||||
return v1_21_8;
|
||||
}
|
||||
|
||||
public static boolean isOrAbove1_21_9() {
|
||||
return v1_21_9;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.world;
|
||||
import net.momirealms.craftengine.core.util.MCUtils;
|
||||
|
||||
public class Vec3d implements Position {
|
||||
public static final Vec3d ZERO = new Vec3d(0, 0, 0);
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
|
||||
Reference in New Issue
Block a user