1.16+ support and remove unused imports in generated Block enum

This commit is contained in:
jglrxavpok 2020-06-29 16:41:29 +02:00
parent 290d922e3a
commit c9589ae526
4 changed files with 11 additions and 13 deletions

View File

@ -3,11 +3,9 @@
//============================== //==============================
package net.minestom.server.instance.block; package net.minestom.server.instance.block;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
import net.minestom.server.instance.block.BlockAlternative;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
import net.minestom.server.instance.block.states.*; import net.minestom.server.instance.block.states.*;
@SuppressWarnings({"deprecation"}) @SuppressWarnings({"deprecation"})

View File

@ -26,15 +26,19 @@ public class BlockEnumGenerator {
public static final String BURGER_URL_BASE_URL = "https://pokechu22.github.io/Burger/"; public static final String BURGER_URL_BASE_URL = "https://pokechu22.github.io/Burger/";
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
String targetVersion;
if(args.length < 1) {
System.err.println("Usage: <MC version> [target folder]");
return;
}
targetVersion = args[0];
try { try {
ResourceGatherer.ensureResourcesArePresent(null); // TODO ResourceGatherer.ensureResourcesArePresent(targetVersion, null); // TODO
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
String targetVersion = "1.15.2";
if(args.length >= 1) {
targetVersion = args[0];
}
String targetPart = DEFAULT_TARGET_PATH; String targetPart = DEFAULT_TARGET_PATH;
if(args.length >= 2) { if(args.length >= 2) {
@ -79,11 +83,9 @@ public class BlockEnumGenerator {
EnumGenerator blockGenerator = new EnumGenerator(packageName, className); EnumGenerator blockGenerator = new EnumGenerator(packageName, className);
blockGenerator.addClassAnnotation("@SuppressWarnings({\"deprecation\"})"); blockGenerator.addClassAnnotation("@SuppressWarnings({\"deprecation\"})");
blockGenerator.addImport(NamespaceID.class.getCanonicalName()); blockGenerator.addImport(NamespaceID.class.getCanonicalName());
blockGenerator.addImport(BlockAlternative.class.getCanonicalName());
blockGenerator.addImport(List.class.getCanonicalName()); blockGenerator.addImport(List.class.getCanonicalName());
blockGenerator.addImport(ArrayList.class.getCanonicalName()); blockGenerator.addImport(ArrayList.class.getCanonicalName());
blockGenerator.addImport(Arrays.class.getCanonicalName()); blockGenerator.addImport(Arrays.class.getCanonicalName());
blockGenerator.addImport(Short2ObjectOpenHashMap.class.getCanonicalName());
blockGenerator.addImport(blockGenerator.getPackage()+".states.*"); blockGenerator.addImport(blockGenerator.getPackage()+".states.*");
blockGenerator.addHardcodedField("List<BlockAlternative>", "alternatives", "new ArrayList<BlockAlternative>()"); blockGenerator.addHardcodedField("List<BlockAlternative>", "alternatives", "new ArrayList<BlockAlternative>()");
blockGenerator.setParams("String namespaceID", "short defaultID", "double hardness", "double resistance", "boolean isAir", "boolean isSolid", "NamespaceID blockEntity", "boolean singleState"); blockGenerator.setParams("String namespaceID", "short defaultID", "double hardness", "double resistance", "boolean isAir", "boolean isSolid", "NamespaceID blockEntity", "boolean singleState");

View File

@ -119,7 +119,7 @@ public class MinecraftServer {
// Registry // Registry
try { try {
ResourceGatherer.ensureResourcesArePresent(null); // TODO: provide a way to give a path override, probably via launch arguments? ResourceGatherer.ensureResourcesArePresent("1.15.2", null); // TODO: provide a way to give a path override, probably via launch arguments?
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("An error happened during resource gathering. Minestom will attempt to load anyway, but things may not work, and crashes can happen.", e); LOGGER.error("An error happened during resource gathering. Minestom will attempt to load anyway, but things may not work, and crashes can happen.", e);
} }

View File

@ -23,7 +23,7 @@ public class ResourceGatherer {
* If it is not, download the minecraft server jar, run the data generator and extract the wanted files * If it is not, download the minecraft server jar, run the data generator and extract the wanted files
* If it is already present, directly return * If it is already present, directly return
*/ */
public static void ensureResourcesArePresent(File minecraftFolderOverride) throws IOException { public static void ensureResourcesArePresent(String version, File minecraftFolderOverride) throws IOException {
if (DATA_FOLDER.exists()) { if (DATA_FOLDER.exists()) {
return; return;
} }
@ -33,8 +33,6 @@ public class ResourceGatherer {
throw new IOException("Failed to create tmp folder."); throw new IOException("Failed to create tmp folder.");
} }
final String version = "1.15.2"; // TODO: Do not hardcode
LOGGER.info("Starting download of Minecraft server jar for version " + version + " from Mojang servers..."); LOGGER.info("Starting download of Minecraft server jar for version " + version + " from Mojang servers...");
File minecraftFolder = getMinecraftFolder(minecraftFolderOverride); File minecraftFolder = getMinecraftFolder(minecraftFolderOverride);
if (!minecraftFolder.exists()) { if (!minecraftFolder.exists()) {