Make version handling more flexible

This commit is contained in:
Blue (Lukas Rieger) 2021-05-23 10:12:34 +02:00
parent 9447606267
commit c1f3122c68
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
24 changed files with 263 additions and 217 deletions

View File

@ -26,15 +26,15 @@
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
import de.bluecolored.bluemap.common.web.WebSettings;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.config.*;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.mca.MCAWorld;
import de.bluecolored.bluemap.core.map.hires.RenderSettings;
import de.bluecolored.bluemap.core.mca.MCAWorld;
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
import de.bluecolored.bluemap.core.resourcepack.ResourcePack;
import de.bluecolored.bluemap.common.web.WebSettings;
import de.bluecolored.bluemap.core.world.SlicedWorld;
import de.bluecolored.bluemap.core.world.World;
import org.apache.commons.io.FileUtils;
@ -197,7 +197,7 @@ private synchronized void loadWorldsAndMaps() throws IOException, InterruptedExc
public synchronized ResourcePack getResourcePack() throws IOException, InterruptedException {
if (resourcePack == null) {
File defaultResourceFile = new File(getCoreConfig().getDataFolder(), "minecraft-client-" + minecraftVersion.getVersionString() + ".jar");
File defaultResourceFile = new File(getCoreConfig().getDataFolder(), "minecraft-client-" + minecraftVersion.getResource().getVersion().getVersionString() + ".jar");
File resourceExtensionsFile = new File(getCoreConfig().getDataFolder(), "resourceExtensions.zip");
File textureExportFile = new File(getRenderConfig().getWebRoot(), "data" + File.separator + "textures.json");
@ -210,9 +210,9 @@ public synchronized ResourcePack getResourcePack() throws IOException, Interrupt
//download file
try {
Logger.global.logInfo("Downloading " + minecraftVersion.getClientDownloadUrl() + " to " + defaultResourceFile + " ...");
Logger.global.logInfo("Downloading " + minecraftVersion.getResource().getClientUrl() + " to " + defaultResourceFile + " ...");
FileUtils.forceMkdirParent(defaultResourceFile);
FileUtils.copyURLToFile(new URL(minecraftVersion.getClientDownloadUrl()), defaultResourceFile, 10000, 10000);
FileUtils.copyURLToFile(new URL(minecraftVersion.getResource().getClientUrl()), defaultResourceFile, 10000, 10000);
} catch (IOException e) {
throw new IOException("Failed to download resources!", e);
}
@ -226,7 +226,7 @@ public synchronized ResourcePack getResourcePack() throws IOException, Interrupt
if (resourceExtensionsFile.exists()) FileUtils.forceDelete(resourceExtensionsFile);
FileUtils.forceMkdirParent(resourceExtensionsFile);
FileUtils.copyURLToFile(Plugin.class.getResource("/de/bluecolored/bluemap/" + minecraftVersion.getResourcePrefix() + "/resourceExtensions.zip"), resourceExtensionsFile, 10000, 10000);
FileUtils.copyURLToFile(Plugin.class.getResource("/de/bluecolored/bluemap/" + minecraftVersion.getResource().getResourcePrefix() + "/resourceExtensions.zip"), resourceExtensionsFile, 10000, 10000);
//find more resource packs
File[] resourcePacks = resourcePackFolder.listFiles();

View File

@ -74,7 +74,7 @@ public class Plugin {
private WebServerConfig webServerConfig;
private PluginConfig pluginConfig;
private PluginStatus pluginStatus;
private PluginState pluginState;
private Map<UUID, World> worlds;
private Map<String, BmMap> maps;
@ -122,15 +122,15 @@ public void load() throws IOException, ParseResourceException {
true
));
//load plugin status
//load plugin state
try {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()
.file(new File(getCoreConfig().getDataFolder(), "pluginStatus.json"))
.file(new File(getCoreConfig().getDataFolder(), "pluginState.json"))
.build();
pluginStatus = loader.load().get(PluginStatus.class);
pluginState = loader.load().get(PluginState.class);
} catch (SerializationException ex) {
Logger.global.logWarning("Failed to load pluginStatus.json (invalid format), creating a new one...");
pluginStatus = new PluginStatus();
Logger.global.logWarning("Failed to load pluginState.json (invalid format), creating a new one...");
pluginState = new PluginState();
}
//create and start webserver
@ -183,13 +183,13 @@ public void load() throws IOException, ParseResourceException {
//update all maps
for (BmMap map : maps.values()) {
if (pluginStatus.getMapStatus(map).isUpdateEnabled()) {
if (pluginState.getMapState(map).isUpdateEnabled()) {
renderManager.scheduleRenderTask(new MapUpdateTask(map));
}
}
//start render-manager
if (pluginStatus.isRenderThreadsEnabled()) {
if (pluginState.isRenderThreadsEnabled()) {
renderManager.start(coreConfig.getRenderThreadCount());
} else {
Logger.global.logInfo("Render-Threads are STOPPED! Use the command 'bluemap start' to start them.");
@ -233,7 +233,7 @@ public void run() {
//watch map-changes
this.regionFileWatchServices = new HashMap<>();
for (BmMap map : maps.values()) {
if (pluginStatus.getMapStatus(map).isUpdateEnabled()) {
if (pluginState.getMapState(map).isUpdateEnabled()) {
startWatchingMap(map);
}
}
@ -302,7 +302,7 @@ public void unload() {
webServerConfig = null;
pluginConfig = null;
pluginStatus = null;
pluginState = null;
//done
loaded = false;
@ -318,14 +318,14 @@ public void reload() throws IOException, ParseResourceException {
}
public synchronized void save() {
if (pluginStatus != null) {
if (pluginState != null) {
try {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()
.file(new File(getCoreConfig().getDataFolder(), "pluginStatus.json"))
.file(new File(getCoreConfig().getDataFolder(), "pluginState.json"))
.build();
loader.save(loader.createNode().set(PluginStatus.class, pluginStatus));
loader.save(loader.createNode().set(PluginState.class, pluginState));
} catch (IOException ex) {
Logger.global.logError("Failed to save pluginStatus.json!", ex);
Logger.global.logError("Failed to save pluginState.json!", ex);
}
}
@ -379,8 +379,8 @@ public PluginConfig getPluginConfig() {
return pluginConfig;
}
public PluginStatus getPluginStatus() {
return pluginStatus;
public PluginState getPluginState() {
return pluginState;
}
public World getWorld(UUID uuid){

View File

@ -32,10 +32,10 @@
@SuppressWarnings("FieldMayBeFinal")
@ConfigSerializable
public class PluginStatus {
public class PluginState {
private boolean renderThreadsEnabled = true;
private Map<String, MapStatus> maps = new HashMap<>();
private Map<String, MapState> maps = new HashMap<>();
public boolean isRenderThreadsEnabled() {
return renderThreadsEnabled;
@ -45,12 +45,12 @@ public void setRenderThreadsEnabled(boolean renderThreadsEnabled) {
this.renderThreadsEnabled = renderThreadsEnabled;
}
public MapStatus getMapStatus(BmMap map) {
return maps.computeIfAbsent(map.getId(), k -> new MapStatus());
public MapState getMapState(BmMap map) {
return maps.computeIfAbsent(map.getId(), k -> new MapState());
}
@ConfigSerializable
public static class MapStatus {
public static class MapState {
private boolean updateEnabled = true;

View File

@ -44,7 +44,7 @@
import de.bluecolored.bluemap.api.marker.MarkerSet;
import de.bluecolored.bluemap.api.marker.POIMarker;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.PluginStatus;
import de.bluecolored.bluemap.common.plugin.PluginState;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
import de.bluecolored.bluemap.common.plugin.text.TextColor;
@ -351,16 +351,19 @@ public int versionCommand(CommandContext<S> context) {
source.sendMessage(Text.of(TextFormat.BOLD, TextColor.BLUE, "Version: ", TextColor.WHITE, BlueMap.VERSION));
source.sendMessage(Text.of(TextColor.GRAY, "Implementation: ", TextColor.WHITE, plugin.getImplementationType()));
source.sendMessage(Text.of(TextColor.GRAY, "Minecraft compatibility: ", TextColor.WHITE, plugin.getMinecraftVersion().getVersionString()));
source.sendMessage(Text.of(
TextColor.GRAY, "Minecraft compatibility: ", TextColor.WHITE, plugin.getMinecraftVersion().getVersionString(),
TextColor.GRAY, " (" + plugin.getMinecraftVersion().getResource().getVersion().getVersionString() + ")"
));
source.sendMessage(Text.of(TextColor.GRAY, "Render-threads: ", TextColor.WHITE, renderThreadCount));
source.sendMessage(Text.of(TextColor.GRAY, "Available processors: ", TextColor.WHITE, Runtime.getRuntime().availableProcessors()));
source.sendMessage(Text.of(TextColor.GRAY, "Available memory: ", TextColor.WHITE, (Runtime.getRuntime().maxMemory() / 1024L / 1024L) + " MiB"));
if (plugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MC_1_15)) {
if (plugin.getMinecraftVersion().isAtLeast(new MinecraftVersion(1, 15))) {
String clipboardValue =
"Version: " + BlueMap.VERSION + "\n" +
"Implementation: " + plugin.getImplementationType() + "\n" +
"Minecraft compatibility: " + plugin.getMinecraftVersion().getVersionString() + "\n" +
"Minecraft compatibility: " + plugin.getMinecraftVersion().getVersionString() + " (" + plugin.getMinecraftVersion().getResource().getVersion().getVersionString() + ")\n" +
"Render-threads: " + renderThreadCount + "\n" +
"Available processors: " + Runtime.getRuntime().availableProcessors() + "\n" +
"Available memory: " + Runtime.getRuntime().maxMemory() / 1024L / 1024L + " MiB";
@ -537,7 +540,7 @@ public int stopCommand(CommandContext<S> context) {
if (plugin.getRenderManager().isRunning()) {
new Thread(() -> {
plugin.getPluginStatus().setRenderThreadsEnabled(false);
plugin.getPluginState().setRenderThreadsEnabled(false);
plugin.getRenderManager().stop();
source.sendMessage(Text.of(TextColor.GREEN, "Render-Threads stopped!"));
@ -557,7 +560,7 @@ public int startCommand(CommandContext<S> context) {
if (!plugin.getRenderManager().isRunning()) {
new Thread(() -> {
plugin.getPluginStatus().setRenderThreadsEnabled(true);
plugin.getPluginState().setRenderThreadsEnabled(true);
plugin.getRenderManager().start(plugin.getCoreConfig().getRenderThreadCount());
source.sendMessage(Text.of(TextColor.GREEN, "Render-Threads started!"));
@ -584,10 +587,10 @@ public int freezeCommand(CommandContext<S> context) {
return 0;
}
PluginStatus.MapStatus mapStatus = plugin.getPluginStatus().getMapStatus(map);
if (mapStatus.isUpdateEnabled()) {
PluginState.MapState mapState = plugin.getPluginState().getMapState(map);
if (mapState.isUpdateEnabled()) {
new Thread(() -> {
mapStatus.setUpdateEnabled(false);
mapState.setUpdateEnabled(false);
plugin.stopWatchingMap(map);
plugin.getRenderManager().removeRenderTasksIf(task -> {
@ -625,10 +628,10 @@ public int unfreezeCommand(CommandContext<S> context) {
return 0;
}
PluginStatus.MapStatus mapStatus = plugin.getPluginStatus().getMapStatus(map);
if (!mapStatus.isUpdateEnabled()) {
PluginState.MapState mapState = plugin.getPluginState().getMapState(map);
if (!mapState.isUpdateEnabled()) {
new Thread(() -> {
mapStatus.setUpdateEnabled(true);
mapState.setUpdateEnabled(true);
plugin.startWatchingMap(map);
plugin.getRenderManager().scheduleRenderTask(new MapUpdateTask(map));
@ -829,7 +832,7 @@ public int mapsCommand(CommandContext<S> context) {
source.sendMessage(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
for (BmMap map : plugin.getMapTypes()) {
boolean unfrozen = plugin.getPluginStatus().getMapStatus(map).isUpdateEnabled();
boolean unfrozen = plugin.getPluginState().getMapState(map).isUpdateEnabled();
if (unfrozen) {
source.sendMessage(Text.of(
TextColor.GRAY, " - ",

View File

@ -24,66 +24,150 @@
*/
package de.bluecolored.bluemap.core;
import de.bluecolored.bluemap.core.util.Lazy;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public enum MinecraftVersion {
MC_1_12 (101200, "1.12", "mc1_12", "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"),
MC_1_13 (101300, "1.13", "mc1_13", "https://launcher.mojang.com/v1/objects/30bfe37a8db404db11c7edf02cb5165817afb4d9/client.jar"),
MC_1_14 (101400, "1.14", "mc1_13", "https://launcher.mojang.com/v1/objects/8c325a0c5bd674dd747d6ebaa4c791fd363ad8a9/client.jar"),
MC_1_15 (101500, "1.15", "mc1_15", "https://launcher.mojang.com/v1/objects/e3f78cd16f9eb9a52307ed96ebec64241cc5b32d/client.jar"),
MC_1_16 (101600, "1.16", "mc1_16", "https://launcher.mojang.com/v1/objects/653e97a2d1d76f87653f02242d243cdee48a5144/client.jar");
public class MinecraftVersion implements Comparable<MinecraftVersion> {
private static final Pattern VERSION_REGEX = Pattern.compile("(?:(?<major>\\d+)\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?(?:\\-(?:pre|rc)\\d+)?");
private final int versionOrdinal;
private final String versionString;
private final String resourcePrefix;
private final String clientDownloadUrl;
MinecraftVersion(int versionOrdinal, String versionString, String resourcePrefix, String clientDownloadUrl) {
this.versionOrdinal = versionOrdinal;
this.versionString = versionString;
this.resourcePrefix = resourcePrefix;
this.clientDownloadUrl = clientDownloadUrl;
public static final MinecraftVersion LATEST_SUPPORTED = new MinecraftVersion(1, 16, 5);
public static final MinecraftVersion EARLIEST_SUPPORTED = new MinecraftVersion(1, 12, 2);
public static final MinecraftVersion THE_FLATTENING = new MinecraftVersion(1, 13);
private final int major, minor, patch;
private final Lazy<MinecraftResource> resource;
public MinecraftVersion(int major, int minor) {
this(major, minor, 0);
}
public MinecraftVersion(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.resource = new Lazy<>(this::findBestMatchingResource);
}
public String getVersionString() {
return this.versionString;
return major + "." + minor + "." + patch;
}
public String getResourcePrefix() {
return this.resourcePrefix;
}
public String getClientDownloadUrl() {
return this.clientDownloadUrl;
public MinecraftResource getResource() {
return this.resource.getValue();
}
public boolean isAtLeast(MinecraftVersion minVersion) {
return this.versionOrdinal >= minVersion.versionOrdinal;
return compareTo(minVersion) >= 0;
}
public boolean isAtMost(MinecraftVersion maxVersion) {
return this.versionOrdinal <= maxVersion.versionOrdinal;
return compareTo(maxVersion) <= 0;
}
public static MinecraftVersion fromVersionString(String versionString) {
public boolean isBefore(MinecraftVersion minVersion) {
return compareTo(minVersion) < 0;
}
public boolean isAfter(MinecraftVersion minVersion) {
return compareTo(minVersion) > 0;
}
@Override
public int compareTo(MinecraftVersion other) {
int result;
result = Integer.compare(major, other.major);
if (result != 0) return result;
result = Integer.compare(minor, other.minor);
if (result != 0) return result;
result = Integer.compare(patch, other.patch);
return result;
}
public boolean majorEquals(MinecraftVersion that) {
return major == that.major;
}
public boolean minorEquals(MinecraftVersion that) {
return major == that.major && minor == that.minor;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MinecraftVersion that = (MinecraftVersion) o;
return major == that.major && minor == that.minor && patch == that.patch;
}
@Override
public int hashCode() {
return Objects.hash(major, minor, patch);
}
private MinecraftResource findBestMatchingResource() {
MinecraftResource[] resources = MinecraftResource.values();
Arrays.sort(resources, Comparator.comparing(MinecraftResource::getVersion).reversed());
for (MinecraftResource resource : resources){
if (isAtLeast(resource.version)) return resource;
}
return resources[resources.length - 1];
}
public static MinecraftVersion of(String versionString) {
Matcher matcher = VERSION_REGEX.matcher(versionString);
if (!matcher.matches()) throw new IllegalArgumentException("Not a valid version string!");
String normalizedVersionString = matcher.group("major") + "." + matcher.group("minor");
for (MinecraftVersion mcv : values()) {
if (mcv.versionString.equals(normalizedVersionString)) return mcv;
}
throw new IllegalArgumentException("No matching version found!");
int major = Integer.parseInt(matcher.group("major"));
int minor = Integer.parseInt(matcher.group("minor"));
int patch = 0;
String patchString = matcher.group("patch");
if (patchString != null) patch = Integer.parseInt(patchString);
return new MinecraftVersion(major, minor, patch);
}
public static MinecraftVersion getLatest() {
return MC_1_16;
public enum MinecraftResource {
MC_1_12 (new MinecraftVersion(1, 12), "mc1_12", "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"),
MC_1_13 (new MinecraftVersion(1, 13), "mc1_13", "https://launcher.mojang.com/v1/objects/30bfe37a8db404db11c7edf02cb5165817afb4d9/client.jar"),
MC_1_14 (new MinecraftVersion(1, 14), "mc1_13", "https://launcher.mojang.com/v1/objects/8c325a0c5bd674dd747d6ebaa4c791fd363ad8a9/client.jar"),
MC_1_15 (new MinecraftVersion(1, 15), "mc1_15", "https://launcher.mojang.com/v1/objects/e3f78cd16f9eb9a52307ed96ebec64241cc5b32d/client.jar"),
MC_1_16 (new MinecraftVersion(1, 16), "mc1_16", "https://launcher.mojang.com/v1/objects/228fdf45541c4c2fe8aec4f20e880cb8fcd46621/client.jar"),
MC_1_16_2 (new MinecraftVersion(1, 16, 2), "mc1_16", "https://launcher.mojang.com/v1/objects/653e97a2d1d76f87653f02242d243cdee48a5144/client.jar");
private final MinecraftVersion version;
private final String resourcePrefix;
private final String clientUrl;
MinecraftResource(MinecraftVersion version, String resourcePrefix, String clientUrl) {
this.version = version;
this.resourcePrefix = resourcePrefix;
this.clientUrl = clientUrl;
}
public MinecraftVersion getVersion() {
return version;
}
public String getResourcePrefix() {
return resourcePrefix;
}
public String getClientUrl() {
return clientUrl;
}
}
}

View File

@ -30,7 +30,6 @@
import de.bluecolored.bluemap.core.resourcepack.ResourcePack;
import de.bluecolored.bluemap.core.resourcepack.ResourcePack.Resource;
import de.bluecolored.bluemap.core.util.FileUtils;
import de.bluecolored.bluemap.core.util.Preconditions;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
@ -120,7 +119,7 @@ public ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL de
public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) throws IOException {
//load blockColors.json from resources, config-folder and resourcepack
URL blockColorsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResourcePrefix() + "/blockColors.json");
URL blockColorsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockColors.json");
File blockColorsConfigFile = new File(configFolder, "blockColors.json");
ConfigurationNode blockColorsConfigNode = loadOrCreate(
blockColorsConfigFile,
@ -133,7 +132,7 @@ public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) th
resourcePack.getBlockColorCalculator().loadColorConfig(blockColorsConfigNode);
//load blockIds.json from resources, config-folder and resourcepack
URL blockIdsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResourcePrefix() + "/blockIds.json");
URL blockIdsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockIds.json");
File blockIdsConfigFile = new File(configFolder, "blockIds.json");
ConfigurationNode blockIdsConfigNode = loadOrCreate(
blockIdsConfigFile,
@ -148,7 +147,7 @@ public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) th
);
//load blockProperties.json from resources, config-folder and resourcepack
URL blockPropertiesConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResourcePrefix() + "/blockProperties.json");
URL blockPropertiesConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockProperties.json");
File blockPropertiesConfigFile = new File(configFolder, "blockProperties.json");
ConfigurationNode blockPropertiesConfigNode = loadOrCreate(
blockPropertiesConfigFile,
@ -164,7 +163,7 @@ public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) th
);
//load biomes.json from resources, config-folder and resourcepack
URL biomeConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResourcePrefix() + "/biomes.json");
URL biomeConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/biomes.json");
File biomeConfigFile = new File(configFolder, "biomes.json");
ConfigurationNode biomeConfigNode = loadOrCreate(
biomeConfigFile,

View File

@ -27,6 +27,7 @@
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector3i;
import com.flowpowered.math.vector.Vector4f;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.map.hires.blockmodel.BlockStateModel;
import de.bluecolored.bluemap.core.map.hires.blockmodel.BlockStateModelFactory;
import de.bluecolored.bluemap.core.resourcepack.NoSuchResourceException;
@ -46,14 +47,11 @@ public class HiresModelRenderer {
public HiresModelRenderer(ResourcePack resourcePack, RenderSettings renderSettings) {
this.renderSettings = renderSettings;
this.modelFactory = new BlockStateModelFactory(resourcePack, renderSettings);
switch (resourcePack.getMinecraftVersion()) {
case MC_1_12:
grassId = "minecraft:tall_grass";
break;
default:
grassId = "minecraft:grass";
break;
if (resourcePack.getMinecraftVersion().isBefore(MinecraftVersion.THE_FLATTENING)) {
grassId = "minecraft:tall_grass";
} else {
grassId = "minecraft:grass";
}
}

View File

@ -56,18 +56,20 @@ public class LiquidModelBuilder {
"minecraft:bubble_column"
));
private BlockState liquidBlockState;
private Block block;
private MinecraftVersion minecraftVersion;
private RenderSettings renderSettings;
private BlockColorCalculator colorCalculator;
private final BlockState liquidBlockState;
private final Block block;
private final RenderSettings renderSettings;
private final BlockColorCalculator colorCalculator;
private final boolean useWaterColorMap;
public LiquidModelBuilder(Block block, BlockState liquidBlockState, MinecraftVersion minecraftVersion, RenderSettings renderSettings, BlockColorCalculator colorCalculator) {
this.block = block;
this.minecraftVersion = minecraftVersion;
this.renderSettings = renderSettings;
this.liquidBlockState = liquidBlockState;
this.colorCalculator = colorCalculator;
this.useWaterColorMap = minecraftVersion.isAtLeast(new MinecraftVersion(1, 13));
}
public BlockStateModel build(TransformedBlockModelResource bmr) {
@ -108,7 +110,7 @@ public BlockStateModel build(BlockModelResource bmr) {
int textureId = texture.getId();
Vector3f tintcolor = Vector3f.ONE;
if (minecraftVersion != MinecraftVersion.MC_1_12 && liquidBlockState.getFullId().equals("minecraft:water")) {
if (useWaterColorMap && liquidBlockState.getFullId().equals("minecraft:water")) {
tintcolor = colorCalculator.getWaterAverageColor(block);
}

View File

@ -37,13 +37,11 @@
import java.util.Set;
public class DoorExtension implements BlockStateExtension {
private final Set<String> affectedBlockIds;
public DoorExtension(MinecraftVersion version) {
switch (version) {
case MC_1_12:
affectedBlockIds = new HashSet<>(Arrays.asList(
if (version.isBefore(MinecraftVersion.THE_FLATTENING)) {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:wooden_door",
"minecraft:iron_door",
"minecraft:spruce_door",
@ -51,10 +49,9 @@ public DoorExtension(MinecraftVersion version) {
"minecraft:jungle_door",
"minecraft:acacia_door",
"minecraft:dark_oak_door"
));
break;
default:
affectedBlockIds = new HashSet<>(Arrays.asList(
));
} else {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:oak_door",
"minecraft:iron_door",
"minecraft:spruce_door",
@ -62,8 +59,7 @@ public DoorExtension(MinecraftVersion version) {
"minecraft:jungle_door",
"minecraft:acacia_door",
"minecraft:dark_oak_door"
));
break;
));
}
}

View File

@ -30,32 +30,25 @@
import de.bluecolored.bluemap.core.util.Direction;
import de.bluecolored.bluemap.core.world.BlockState;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.*;
public class DoublePlantExtension implements BlockStateExtension {
private final Set<String> affectedBlockIds;
public DoublePlantExtension(MinecraftVersion version) {
switch (version) {
case MC_1_12:
affectedBlockIds = new HashSet<>(Arrays.asList(
if (version.isBefore(MinecraftVersion.THE_FLATTENING)) {
affectedBlockIds = new HashSet<>(Collections.singletonList(
"minecraft:double_plant"
));
break;
default:
affectedBlockIds = new HashSet<>(Arrays.asList(
));
} else {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:sunflower",
"minecraft:lilac",
"minecraft:tall_grass",
"minecraft:large_fern",
"minecraft:rose_bush",
"minecraft:peony"
));
break;
));
}
}

View File

@ -41,23 +41,20 @@ public class SnowyExtension implements BlockStateExtension {
private final String snowBlockId;
public SnowyExtension(MinecraftVersion version) {
switch (version) {
case MC_1_12:
affectedBlockIds = new HashSet<>(Arrays.asList(
if (version.isBefore(MinecraftVersion.THE_FLATTENING)) {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:grass",
"minecraft:mycelium"
));
snowLayerId = "minecraft:snow_layer";
snowBlockId = "minecraft:snow";
break;
default:
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:grass_block",
"minecraft:podzol"
));
snowLayerId = "minecraft:snow";
snowBlockId = "minecraft:snow_block";
break;
));
snowLayerId = "minecraft:snow_layer";
snowBlockId = "minecraft:snow";
} else {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:grass_block",
"minecraft:podzol"
));
snowLayerId = "minecraft:snow";
snowBlockId = "minecraft:snow_block";
}
}

View File

@ -35,27 +35,24 @@ public class WoodenFenceConnectExtension extends ConnectSameOrFullBlockExtension
private final Set<String> affectedBlockIds;
public WoodenFenceConnectExtension(MinecraftVersion version) {
switch (version) {
case MC_1_12:
affectedBlockIds = new HashSet<>(Arrays.asList(
if (version.isBefore(MinecraftVersion.THE_FLATTENING)) {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:fence",
"minecraft:spruce_fence",
"minecraft:birch_fence",
"minecraft:jungle_fence",
"minecraft:dark_oak_fence",
"minecraft:acacia_fence"
));
break;
default:
affectedBlockIds = new HashSet<>(Arrays.asList(
));
} else {
affectedBlockIds = new HashSet<>(Arrays.asList(
"minecraft:oak_fence",
"minecraft:spruce_fence",
"minecraft:birch_fence",
"minecraft:jungle_fence",
"minecraft:dark_oak_fence",
"minecraft:acacia_fence"
));
break;
));
}
}

View File

@ -26,6 +26,7 @@
import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resourcepack.PropertyCondition.All;
import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess;
@ -44,7 +45,9 @@
import java.util.Map.Entry;
public class BlockStateResource {
private static final MinecraftVersion NEW_MODEL_PATH_VERSION = new MinecraftVersion(1, 13);
private final List<Variant> variants = new ArrayList<>(0);
private final Collection<Variant> multipart = new ArrayList<>(0);
@ -242,13 +245,10 @@ private Weighted<TransformedBlockModelResource> loadModel(ConfigurationNode node
String modelPath;
switch (resourcePack.getMinecraftVersion()) {
case MC_1_12:
modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models/block") + ".json";
break;
default:
modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models") + ".json";
break;
if (resourcePack.getMinecraftVersion().isBefore(NEW_MODEL_PATH_VERSION)) {
modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models/block") + ".json";
}else {
modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models") + ".json";
}
BlockModelResource model = resourcePack.blockModelResources.get(modelPath);

View File

@ -44,6 +44,7 @@ public Lazy(T value) {
public T getValue() {
if (!isLoaded()) {
this.value = loader.get();
this.loader = null;
}
return this.value;

View File

@ -210,11 +210,11 @@ public static void main(String[] args) {
}
//minecraft version
MinecraftVersion version = MinecraftVersion.getLatest();
MinecraftVersion version = MinecraftVersion.LATEST_SUPPORTED;
if (cmd.hasOption("v")) {
String versionString = cmd.getOptionValue("v");
try {
version = MinecraftVersion.fromVersionString(versionString);
version = MinecraftVersion.of(versionString);
} catch (IllegalArgumentException e) {
Logger.global.logWarning("Could not determine a version from the provided version-string: '" + versionString + "'");
System.exit(1);

View File

@ -24,24 +24,8 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.commands.Commands;
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
@ -60,6 +44,14 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
public class FabricMod implements ModInitializer, ServerInterface {
@ -81,7 +73,7 @@ public FabricMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
pluginInstance = new Plugin(MinecraftVersion.MC_1_15, "fabric-1.15.2", this);
pluginInstance = new Plugin(new MinecraftVersion(1, 15, 2), "fabric-1.15.2", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new FabricEventForwarder(this);

View File

@ -24,24 +24,8 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.commands.Commands;
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
@ -62,6 +46,14 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.WorldSavePath;
import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
public class FabricMod implements ModInitializer, ServerInterface {
@ -83,7 +75,7 @@ public FabricMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
pluginInstance = new Plugin(MinecraftVersion.MC_1_16, "fabric-1.16.1", this);
pluginInstance = new Plugin(new MinecraftVersion(1, 16, 1), "fabric-1.16.1", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new FabricEventForwarder(this);

View File

@ -24,24 +24,8 @@
*/
package de.bluecolored.bluemap.fabric;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import org.apache.logging.log4j.LogManager;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.commands.Commands;
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
@ -62,6 +46,14 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.WorldSavePath;
import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
public class FabricMod implements ModInitializer, ServerInterface {
@ -83,7 +75,7 @@ public FabricMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
pluginInstance = new Plugin(MinecraftVersion.MC_1_16, "fabric-1.16.2", this);
pluginInstance = new Plugin(new MinecraftVersion(1, 16, 2), "fabric-1.16.2", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new FabricEventForwarder(this);

View File

@ -78,7 +78,7 @@ public ForgeMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
this.pluginInstance = new Plugin(MinecraftVersion.MC_1_14, "forge-1.14.4", this);
this.pluginInstance = new Plugin(new MinecraftVersion(1, 14, 4), "forge-1.14.4", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new ForgeEventForwarder();

View File

@ -78,7 +78,7 @@ public ForgeMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
this.pluginInstance = new Plugin(MinecraftVersion.MC_1_15, "forge-1.15.2", this);
this.pluginInstance = new Plugin(new MinecraftVersion(1, 15, 2), "forge-1.15.2", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new ForgeEventForwarder();

View File

@ -80,7 +80,7 @@ public ForgeMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
this.pluginInstance = new Plugin(MinecraftVersion.MC_1_16, "forge-1.16.2", this);
this.pluginInstance = new Plugin(new MinecraftVersion(1, 16, 2), "forge-1.16.2", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new ForgeEventForwarder();

View File

@ -69,14 +69,14 @@ public class BukkitPlugin extends JavaPlugin implements ServerInterface, Listene
public BukkitPlugin() {
Logger.global = new JavaLogger(getLogger());
MinecraftVersion version = MinecraftVersion.getLatest();
MinecraftVersion version = MinecraftVersion.LATEST_SUPPORTED;
//try to get best matching minecraft-version
try {
String versionString = getServer().getBukkitVersion();
Matcher versionMatcher = Pattern.compile("(\\d+\\.\\d+\\.\\d+)[-_].*").matcher(versionString);
if (!versionMatcher.matches()) throw new IllegalArgumentException();
version = MinecraftVersion.fromVersionString(versionMatcher.group(1));
version = MinecraftVersion.of(versionMatcher.group(1));
} catch (IllegalArgumentException e) {
Logger.global.logWarning("Failed to detect the minecraft version of this server! Using latest version: " + version.getVersionString());
}

View File

@ -86,14 +86,14 @@ public SpongePlugin(org.slf4j.Logger logger, Metrics.Factory metricsFactory) {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
MinecraftVersion version = MinecraftVersion.MC_1_12;
MinecraftVersion version = new MinecraftVersion(1, 12);
try {
version = MinecraftVersion.fromVersionString(Sponge.getPlatform().getMinecraftVersion().getName());
version = MinecraftVersion.of(Sponge.getPlatform().getMinecraftVersion().getName());
} catch (IllegalArgumentException e) {
Logger.global.logWarning("Failed to find a matching version for version-name '" + Sponge.getPlatform().getMinecraftVersion().getName() + "'! Using latest known sponge-version: " + version.getVersionString());
}
this.pluginInstance = new Plugin(version, "sponge", this);
this.pluginInstance = new Plugin(version, "sponge-7.2.0", this);
this.commands = new SpongeCommands(pluginInstance);
//bstats

View File

@ -93,14 +93,14 @@ public SpongePlugin(org.apache.logging.log4j.Logger logger, PluginContainer plug
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
final String versionFromSponge = Sponge.platform().container(Platform.Component.GAME).metadata().version();
MinecraftVersion version = MinecraftVersion.MC_1_16;
MinecraftVersion version = new MinecraftVersion(1, 16);
try {
version = MinecraftVersion.fromVersionString(versionFromSponge);
version = MinecraftVersion.of(versionFromSponge);
} catch (IllegalArgumentException e) {
Logger.global.logWarning("Failed to find a matching version for version-name '" + versionFromSponge + "'! Using latest known sponge-version: " + version.getVersionString());
}
this.pluginInstance = new Plugin(version, "sponge", this);
this.pluginInstance = new Plugin(version, "sponge-8.0.0", this);
this.commands = new SpongeCommands(pluginInstance);
//bstats