9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-22 08:19:19 +00:00

it's still not working, but we finished all patches

This commit is contained in:
NONPLAYT
2025-01-18 17:14:26 +03:00
parent 1ea35a85c1
commit 11abf6d877
10 changed files with 206 additions and 167 deletions

View File

@@ -164,15 +164,10 @@ public class DivineConfig {
}
public static int linearFlushFrequency = 5;
public static int linearFlushThreads = 1;
public static boolean throwOnUnknownExtension = false;
private static void linearSettings() {
linearFlushFrequency = getInt("settings.region-format.linear.flush-frequency", linearFlushFrequency);
linearFlushThreads = getInt("settings.region-format.linear.flush-max-threads", linearFlushThreads);
if (linearFlushThreads < 0)
linearFlushThreads = Math.max(Runtime.getRuntime().availableProcessors() + linearFlushThreads, 1);
else
linearFlushThreads = Math.max(linearFlushThreads, 1);
throwOnUnknownExtension = getBoolean("settings.region-format.linear.throw-on-unknown-extension", throwOnUnknownExtension);
}
public static boolean asyncPathfinding = true;

View File

@@ -94,19 +94,26 @@ public class DivineWorldConfig {
suppressErrorsFromDirtyAttributes = getBoolean("suppress-errors-from-dirty-attributes", suppressErrorsFromDirtyAttributes);
}
public RegionFileFormat regionFormat = RegionFileFormat.ANVIL;
public boolean snowballCanKnockback = true;
public boolean eggCanKnockback = true;
private void setSnowballAndEggKnockback() {
snowballCanKnockback = getBoolean("gameplay-mechanics.projectiles.snowball.knockback", snowballCanKnockback);
eggCanKnockback = getBoolean("gameplay-mechanics.projectiles.egg.knockback", eggCanKnockback);
}
public RegionFileFormat regionFormatName = RegionFileFormat.MCA;
public int linearCompressionLevel = 1;
private void regionFormatSettings() {
regionFormat = RegionFileFormat.fromString(getString("region-format.format", regionFormat.name()));
if (regionFormat.equals(RegionFileFormat.INVALID)) {
log(Level.SEVERE, "Unknown region format in linear.yml: " + regionFormat);
regionFormatName = RegionFileFormat.fromExtension(getString("region-format.format", regionFormatName.name()));
if (regionFormatName.equals(RegionFileFormat.UNKNOWN)) {
log(Level.SEVERE, "Unknown region file type!");
log(Level.SEVERE, "Falling back to ANVIL region file format.");
regionFormat = RegionFileFormat.ANVIL;
regionFormatName = RegionFileFormat.MCA;
}
linearCompressionLevel = getInt("region-format.linear.compression-level", linearCompressionLevel);
if (linearCompressionLevel > 23 || linearCompressionLevel < 1) {
log(Level.SEVERE, "Linear region compression level should be between 1 and 22 in linear.yml: " + linearCompressionLevel);
log(Level.SEVERE, "Linear region compression level should be between 1 and 22 in config: " + linearCompressionLevel);
log(Level.SEVERE, "Falling back to compression level 1.");
linearCompressionLevel = 1;
}

View File

@@ -8,7 +8,7 @@ import java.nio.file.Path;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.ChunkPos;
public interface AbstractRegionFile {
public interface AbstractRegionFile extends AutoCloseable {
Path getPath();
void flush() throws IOException;
void clear(ChunkPos pos) throws IOException;

View File

@@ -7,6 +7,7 @@ import net.minecraft.world.level.chunk.storage.RegionFileVersion;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import space.bxteam.divinemc.configuration.DivineConfig;
public class AbstractRegionFileFactory {
@Contract("_, _, _, _ -> new")
@@ -14,12 +15,37 @@ public class AbstractRegionFileFactory {
return getAbstractRegionFile(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync);
}
@Contract("_, _, _, _, _ -> new")
public static @NotNull AbstractRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync, boolean canRecalcHeader) throws IOException {
return getAbstractRegionFile(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync, canRecalcHeader);
}
@Contract("_, _, _, _, _ -> new")
public static @NotNull AbstractRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync) throws IOException {
if (path.toString().endsWith(".linear")) {
return new LinearRegionFile(path, storageKey.linearCompressionLevel());
} else {
return new RegionFile(storageKey, path, directory, compressionFormat, dsync);
return getAbstractRegionFile(storageKey, path, directory, compressionFormat, dsync, true);
}
@Contract("_, _, _, _, _, _ -> new")
public static @NotNull AbstractRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, @NotNull Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync, boolean canRecalcHeader) throws IOException {
final String fullFileName = path.getFileName().toString();
final String[] fullNameSplit = fullFileName.split("\\.");
final String extensionName = fullNameSplit[fullNameSplit.length - 1];
switch (RegionFileFormat.fromExtension(extensionName)) {
case UNKNOWN -> {
if (DivineConfig.throwOnUnknownExtension) {
throw new IllegalArgumentException("Unknown region file extension for file: " + fullFileName + "!");
}
return new RegionFile(storageKey, path, directory, compressionFormat, dsync);
}
case LINEAR -> {
return new LinearRegionFile(path, storageKey.linearCompressionLevel());
}
default -> {
return new RegionFile(storageKey, path, directory, compressionFormat, dsync);
}
}
}
}

View File

@@ -1,16 +1,55 @@
package space.bxteam.divinemc.region;
public enum RegionFileFormat {
ANVIL,
LINEAR,
INVALID;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public static RegionFileFormat fromString(String format) {
for (RegionFileFormat rff : values()) {
if (rff.name().equalsIgnoreCase(format)) {
return rff;
public enum RegionFileFormat {
LINEAR(".linear"),
MCA(".mca"),
UNKNOWN(null);
private final String extensionName;
RegionFileFormat(String extensionName) {
this.extensionName = extensionName;
}
public String getExtensionName() {
return this.extensionName;
}
@Contract(pure = true)
public static RegionFileFormat fromName(@NotNull String name) {
switch (name.toUpperCase(Locale.ROOT)) {
default -> {
return UNKNOWN;
}
case "MCA" -> {
return MCA;
}
case "LINEAR" -> {
return LINEAR;
}
}
}
@Contract(pure = true)
public static RegionFileFormat fromExtension(@NotNull String name) {
switch (name.toLowerCase()) {
case "mca" -> {
return MCA;
}
case "linear" -> {
return LINEAR;
}
default -> {
return UNKNOWN;
}
}
return RegionFileFormat.INVALID;
}
}