Update BlockGenerator and add the 1.17 blocks.

This commit is contained in:
Articdive 2021-06-11 17:47:26 +02:00
parent 7a76040457
commit 1a67ab806a
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
17 changed files with 3474 additions and 1150 deletions

View File

@ -3,16 +3,7 @@ package net.minestom.codegen.attribute;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -51,7 +42,7 @@ public final class AttributeGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registryClassName = ClassName.get("net.minestom.server.registry", "Registry");
JsonArray attributes = GSON.fromJson(new JsonReader(new InputStreamReader(attributesFile)), JsonArray.class);
JsonArray attributes = GSON.fromJson(new InputStreamReader(attributesFile), JsonArray.class);
List<JavaFile> filesToWrite = new ArrayList<>();
ClassName attributeClassName = ClassName.get("net.minestom.server.attribute", "Attribute");

View File

@ -1,12 +1,8 @@
package net.minestom.codegen.blocks;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.google.gson.*;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import net.minestom.codegen.util.NameUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@ -16,10 +12,7 @@ import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
public final class BlockGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(BlockGenerator.class);
@ -55,375 +48,228 @@ public final class BlockGenerator extends MinestomCodeGenerator {
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
ClassName namespaceIDCN = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName blockPropertyCN = ClassName.get("net.minestom.server.instance.block", "BlockProperty");
ClassName blockCN = ClassName.get("net.minestom.server.instance.block", "Block");
ClassName blockImplCN = ClassName.get("net.minestom.server.instance.block", "BlockImpl");
JsonArray blocks = GSON.fromJson(new JsonReader(new InputStreamReader(blocksFile)), JsonArray.class);
ClassName blockClassName = ClassName.get("net.minestom.server.instance.block", "Block");
ClassName blockAltClassName = ClassName.get("net.minestom.server.instance.block", "BlockAlternative");
List<JavaFile> filesToWrite = new ArrayList<>();
// Block
TypeSpec.Builder blockClass = TypeSpec.enumBuilder(blockClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
blockClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.SHORT, "defaultID")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.DOUBLE, "hardness")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.DOUBLE, "resistance")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.BOOLEAN, "isAir")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.BOOLEAN, "isSolid")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.BOOLEAN, "blockEntity")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(TypeName.BOOLEAN, "singleState")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
blockClass.addField(
FieldSpec.builder(ParameterizedTypeName.get(ClassName.get("java.util", "List"), blockAltClassName), "alternatives")
.initializer("new $T<>()", ClassName.get("java.util", "ArrayList"))
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
.addAnnotation(NotNull.class)
.build()
);
// static field
blockClass.addField(
FieldSpec.builder(ArrayTypeName.of(blockClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
// Block constructor
blockClass.addMethod(
JsonArray blockProperties;
blockProperties = GSON.fromJson(new InputStreamReader(blockPropertyFile), JsonArray.class);
ClassName blockPropertiesCN = ClassName.get("net.minestom.server.instance.block", "BlockProperties");
// Particle
TypeSpec.Builder blockPropertiesClass = TypeSpec.classBuilder(blockPropertiesCN)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
// Add @SuppressWarnings("unused")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
.addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
// Add private constructor
blockPropertiesClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addParameter(TypeName.SHORT, "defaultID")
.addParameter(TypeName.DOUBLE, "hardness")
.addParameter(TypeName.DOUBLE, "resistance")
.addParameter(TypeName.BOOLEAN, "isAir")
.addParameter(TypeName.BOOLEAN, "isSolid")
.addParameter(TypeName.BOOLEAN, "blockEntity")
.addParameter(TypeName.BOOLEAN, "singleState")
.addModifiers(Modifier.PRIVATE)
.build()
);
// This stores the classes of the field names, e.g. WATERLOGGED --> Boolean
Map<String, Class<?>> propertyClassMap = new HashMap<>();
Map<String, String> propertyKeyMap = new HashMap<>();
Map<String, String[]> propertyValueMap = new HashMap<>();
// Use data
for (JsonElement e : blockProperties) {
JsonObject blockProperty = e.getAsJsonObject();
.addStatement("this.id = id")
.addStatement("this.defaultID = defaultID")
.addStatement("this.hardness = hardness")
.addStatement("this.resistance = resistance")
.addStatement("this.isAir = isAir")
.addStatement("this.isSolid = isSolid")
.addStatement("this.blockEntity = blockEntity")
.addStatement("this.singleState = singleState")
.beginControlFlow("if (singleState)")
.addStatement("addBlockAlternative(new $T(defaultID))", blockAltClassName)
.endControlFlow()
.addStatement("$T.blocks.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
blockClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// addBlockState method
blockClass.addMethod(
MethodSpec.methodBuilder("addBlockAlternative")
.addParameter(ParameterSpec.builder(blockAltClassName, "alternative").addAnnotation(NotNull.class).build())
String propertyName = blockProperty.get("name").getAsString();
JsonArray blockValues = blockProperty.get("values").getAsJsonArray();
JsonPrimitive firstElement = blockValues.get(0).getAsJsonPrimitive();
Class<?> type;
StringBuilder values = new StringBuilder();
if (firstElement.isBoolean()) {
type = Boolean.class;
values = new StringBuilder("true, false");
} else if (firstElement.isNumber()) {
type = Integer.class;
for (JsonElement blockValue : blockValues) {
int i = blockValue.getAsInt();
values.append(i).append(", ");
}
// Delete final ', '
values.delete(values.lastIndexOf(","), values.length());
} else {
type = String.class;
for (JsonElement blockValue : blockValues) {
String s = blockValue.getAsString();
values.append("\"").append(s).append("\", ");
}
// Delete final ', '
values.delete(values.lastIndexOf(","), values.length());
}
String propertyKey = blockProperty.get("key").getAsString();
propertyKeyMap.put(propertyName, propertyKey);
propertyClassMap.put(propertyName, type);
propertyValueMap.put(propertyName, values.toString().split(", "));
// Adds the field to the main class
// e.g. BlockProperty<Boolean> WATERLOGGED = new BlockProperty<Boolean>("waterlogged", true, false)
blockPropertiesClass.addField(
FieldSpec.builder(
ParameterizedTypeName.get(blockPropertyCN, TypeName.get(type)),
propertyName
).initializer(
"new $T<>($S, $L)",
blockPropertyCN,
propertyKey,
values
).addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).build()
);
}
JsonArray blocks;
blocks = GSON.fromJson(new InputStreamReader(blocksFile), JsonArray.class);
ClassName blocksCN = ClassName.get("net.minestom.server.instance.block", "BlockConstants");
// BlockConstants class
TypeSpec.Builder blockConstantsClass = TypeSpec.interfaceBuilder(blocksCN)
// Add @SuppressWarnings("unused")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
.addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
.addStatement("this.alternatives.add(alternative)")
.addStatement("BlockArray.blocks[alternative.getId()] = this")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.build()
);
// getId method
blockClass.addMethod(
MethodSpec.methodBuilder("getBlockId")
.returns(TypeName.SHORT)
.addStatement("return defaultID")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getName method
blockClass.addMethod(
MethodSpec.methodBuilder("getName")
.addAnnotation(NotNull.class)
.returns(ClassName.get(String.class))
.addStatement("return this.id.asString()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getHardness method
blockClass.addMethod(
MethodSpec.methodBuilder("getHardness")
.returns(TypeName.DOUBLE)
.addStatement("return this.hardness")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getResistance method
blockClass.addMethod(
MethodSpec.methodBuilder("getResistance")
.returns(TypeName.DOUBLE)
.addStatement("return this.resistance")
.addModifiers(Modifier.PUBLIC)
.build()
);
// breakInstantaneously method
blockClass.addMethod(
MethodSpec.methodBuilder("breaksInstantaneously")
.returns(TypeName.BOOLEAN)
.addStatement("return this.hardness == 0")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getBlockStates method
blockClass.addMethod(
MethodSpec.methodBuilder("getAlternatives")
.returns(ParameterizedTypeName.get(ClassName.get(List.class), blockAltClassName))
.addAnnotation(NotNull.class)
.addStatement("return this.alternatives")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL) // Should this be final, for now I guess so.
.build()
);
// isAir method
blockClass.addMethod(
MethodSpec.methodBuilder("isAir")
.returns(TypeName.BOOLEAN)
// UPDATE: Make sure they didn't add new AIR types.
.addStatement("return isAir")
.addModifiers(Modifier.PUBLIC)
.build()
);
// isLiquid method
blockClass.addMethod(
MethodSpec.methodBuilder("isLiquid")
.returns(TypeName.BOOLEAN)
// UPDATE: Make sure they didn't add new liquids.
.addStatement("return this == WATER || this == LAVA")
.addModifiers(Modifier.PUBLIC)
.build()
);
// isSolid method
blockClass.addMethod(
MethodSpec.methodBuilder("isSolid")
.returns(TypeName.BOOLEAN)
// UPDATE: Make sure they didn't add new liquids.
.addStatement("return isSolid")
.addModifiers(Modifier.PUBLIC)
.build()
);
// hasBlockEntity method
blockClass.addMethod(
MethodSpec.methodBuilder("hasBlockEntity")
.returns(TypeName.BOOLEAN)
.addStatement("return blockEntity")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getAlternative method
blockClass.addMethod(
MethodSpec.methodBuilder("getAlternative")
.returns(blockAltClassName)
.addParameter(TypeName.SHORT, "blockId")
.addAnnotation(Nullable.class)
.beginControlFlow("for ($T alt : alternatives) ", blockAltClassName)
.beginControlFlow("if (alt.getId() == blockId)")
.addStatement("return alt")
.endControlFlow()
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC)
.build()
);
// withProperties method
blockClass.addMethod(
MethodSpec.methodBuilder("withProperties")
.returns(TypeName.SHORT)
.addParameter(
ParameterSpec.builder(ArrayTypeName.of(String.class), "properties").addAnnotation(NotNull.class).build()
).varargs()
.beginControlFlow("for ($T alt : alternatives)", blockAltClassName)
.beginControlFlow("if ($T.equals(alt.getProperties(), properties))", Arrays.class)
.addStatement("return alt.getId()")
.endControlFlow()
.endControlFlow()
.addStatement("return this.defaultID")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromStateId method
blockClass.addMethod(
MethodSpec.methodBuilder("fromStateId")
.returns(blockClassName)
.addParameter(TypeName.SHORT, "blockStateId")
.addStatement("return BlockArray.blocks[blockStateId]")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// fromId Method
blockClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(blockClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
blockClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Staticblock in Block enum
CodeBlock.Builder staticBlock = CodeBlock.builder();
// Use data
for (JsonElement b : blocks) {
JsonObject block = b.getAsJsonObject();
String blockName = block.get("name").getAsString();
JsonArray states = block.get("states").getAsJsonArray();
// Enum constant in Block
blockClass.addEnumConstant(blockName, TypeSpec.anonymousClassBuilder(
"$T.from($S), (short) $L, $L, $L, $L, $L, $L, $L",
namespaceIDClassName,
block.get("id").getAsString(),
block.get("defaultBlockState").getAsShort(),
states.get(0).getAsJsonObject().get("destroySpeed").getAsDouble(),
block.get("explosionResistance").getAsDouble(),
states.get(0).getAsJsonObject().get("isAir").getAsBoolean(),
states.get(0).getAsJsonObject().get("isSolid").getAsBoolean(),
block.get("blockEntity").getAsBoolean(),
states.size() == 1
).build()
);
if (states.size() > 1) {
ClassName blockStateSpecificClassName = ClassName.get(
"net.minestom.server.instance.block.states",
NameUtil.convertSnakeCaseToCamelCase(blockName.toLowerCase())
);
// Handle the properties
// Create a subclass for each Block and reference the main BlockProperty.
JsonArray properties = block.get("properties").getAsJsonArray();
if (properties.size() != 0) {
// Create a subclass called "blockName"
// e.g. subclass AIR in BlockProperties
TypeSpec.Builder subClass = TypeSpec.classBuilder(blockPropertiesCN.nestedClass(blockName))
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.addJavadoc(
"Represents the $L {@link $T $L} that {@link $T#$N} can have:\n",
properties.size(),
blockPropertyCN,
properties.size() > 1 ? "properties" : "property",
blocksCN,
blockName
).addJavadoc("<ul>\n");
// Common blockStateSpecificClass structure
TypeSpec.Builder blockStateSpecificClass = TypeSpec.classBuilder(blockStateSpecificClassName)
.addAnnotation(
AnnotationSpec.builder(Deprecated.class)
.addMember("since", "$S", "forever")
.addMember("forRemoval", "$L", false).build()
)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL).addJavadoc("Completely internal. DO NOT USE. IF YOU ARE A USER AND FACE A PROBLEM WHILE USING THIS CODE, THAT'S ON YOU.");
// Store a list of values for the getProperties() method.
StringBuilder values = new StringBuilder();
// Go through all properties the block has.
for (JsonElement property : properties) {
String propertyName = property.getAsString().toUpperCase(Locale.ROOT);
// initStates method
MethodSpec.Builder initStatesMethod = MethodSpec.methodBuilder("initStates")
.addJavadoc("Completely internal. DO NOT USE. IF YOU ARE A USER AND FACE A PROBLEM WHILE USING THIS CODE, THAT'S ON YOU.")
.addAnnotation(
AnnotationSpec.builder(Deprecated.class)
.addMember("since", "$S", "forever")
.addMember("forRemoval", "$L", false).build()
)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
// init States methods in block specific classes
for (JsonElement s : states) {
JsonObject state = s.getAsJsonObject();
// block state properties
JsonObject properties = state.get("properties").getAsJsonObject();
if (properties.size() != 0) {
StringBuilder propertiesStr = new StringBuilder();
// has properties
for (Map.Entry<String, JsonElement> entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue().getAsString().toLowerCase();
propertiesStr.append('"').append(key).append('=').append(value).append("\", ");
// Add a static field that delegates to the BlockProperties static definition
FieldSpec.Builder field = FieldSpec.builder(
ParameterizedTypeName.get(blockPropertyCN, TypeName.get(propertyClassMap.get(propertyName))),
propertyName)
.initializer("$T.$N", blockPropertiesCN, propertyName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.addJavadoc("Definition: \"$L\" = [", propertyKeyMap.get(propertyName));
// Results in "key" = ["value1", "value2"...]
String[] propertyVals = propertyValueMap.get(propertyName);
for (int i = 0; i < propertyVals.length; i++) {
if (i == propertyVals.length - 1) {
field.addJavadoc("$L]", propertyVals[i].toLowerCase());
} else {
field.addJavadoc("$L, ", propertyVals[i].toLowerCase());
}
// Delete last comma and space
propertiesStr.deleteCharAt(propertiesStr.length() - 1);
propertiesStr.deleteCharAt(propertiesStr.length() - 1);
initStatesMethod.addStatement(
"$T.$N.addBlockAlternative(new $T((short) $L, **REPLACE**))".replace("**REPLACE**", propertiesStr.toString()),
blockClassName,
blockName,
blockAltClassName,
state.get("id").getAsShort()
);
} else {
// has no properties
initStatesMethod.addStatement(
"$T.$N.addBlockAlternative(new $T((short) $L))",
blockClassName,
blockName,
blockAltClassName,
state.get("id").getAsShort()
);
}
// Add field to subclass
subClass.addField(field.build());
values.append(propertyName).append(", ");
subClass.addJavadoc("<li>{@link $T#$N}</li>\n", blockPropertiesCN, propertyName);
}
// Add initStates method
blockStateSpecificClass.addMethod(initStatesMethod.build());
// Add initStates method refence to static block
staticBlock.addStatement("$T.initStates()", blockStateSpecificClassName);
// Add BlockStates to list of files we need to write:
filesToWrite.add(
JavaFile.builder("net.minestom.server.instance.block.states", blockStateSpecificClass.build()
)
.indent(" ")
.skipJavaLangImports(true)
.build());
subClass.addJavadoc("</ul>");
// Delete final ', '
values.delete(values.lastIndexOf(","), values.length());
// Add a static method to get all the properties
subClass.addMethod(
MethodSpec.methodBuilder("getProperties")
.returns(
// List<BlockProperty<?>>
ParameterizedTypeName.get(
ClassName.get(List.class),
// BlockProperty<?>
ParameterizedTypeName.get(blockPropertyCN, TypeVariableName.get("?"))
)
)
.addStatement(
"return $T.of($L)",
// If it has multiple properties --> Arrays.asList() else Collections.singletonList()
ClassName.get(List.class),
values
)
.addModifiers(Modifier.STATIC)
.build()
);
blockPropertiesClass.addType(subClass.build());
}
JsonArray states = block.getAsJsonArray("states");
// Now handle the fields in Blocks.
// If we don't have properties
if (properties.size() == 0) {
// This is a block like Stone that only has 1 BlockState.
blockConstantsClass.addField(
FieldSpec.builder(blockCN, blockName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// Blocks.STONE = new BlockImpl(NamespaceID.from("minecraft:stone"), 1, Collections.emptyList())
"$T.create($T.from($S), (short) $L, (short) $L, (short) $L, (short) $L, $T.emptyList())",
blockImplCN,
namespaceIDCN,
block.get("id").getAsString(),
// Block id
block.get("numericalID").getAsShort(),
// First state id
states.get(0).getAsJsonObject().get("id").getAsShort(),
// Last state id
states.get(states.size() - 1).getAsJsonObject().get("id").getAsShort(),
// Default state id
block.get("defaultBlockState").getAsShort(),
ClassName.get(Collections.class)
)
.build()
);
} else {
// This is a block that has multiple properties.
blockConstantsClass.addField(
FieldSpec.builder(blockCN, blockName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// Blocks.GRASS_BLOCK = new BlockImpl(NamespaceID.from("minecraft:grass_block"), 9, 8, varargsProperty)
"$T.create($T.from($S), (short) $L, (short) $L, (short) $L, (short) $L, $T.$N.getProperties())",
blockImplCN,
namespaceIDCN,
block.get("id").getAsString(),
// Block id
block.get("numericalID").getAsShort(),
// First id
block.getAsJsonArray("states").get(0).getAsJsonObject().get("id").getAsShort(),
// Last state id
states.get(states.size() - 1).getAsJsonObject().get("id").getAsShort(),
// DefaultBlockStateId
block.get("defaultBlockState").getAsShort(),
blockPropertiesCN,
blockName
)
.build()
);
}
}
blockClass.addStaticBlock(staticBlock.build());
// Add ignore deprecations annotation
blockClass.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "deprecation").build());
// Add Block & BlockState to list of files we need to write:
filesToWrite.add(
JavaFile.builder("net.minestom.server.instance.block", blockClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
writeFiles(
List.of(
JavaFile.builder("net.minestom.server.instance.block", blockPropertiesClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build(),
JavaFile.builder("net.minestom.server.instance.block", blockConstantsClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
// Write files to outputFolder
writeFiles(filesToWrite, outputFolder);
}
}
}

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.entity;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import net.minestom.codegen.util.NameUtil;
@ -201,7 +200,7 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray entities = GSON.fromJson(new JsonReader(new InputStreamReader(entitiesFile)), JsonArray.class);
JsonArray entities = GSON.fromJson(new InputStreamReader(entitiesFile), JsonArray.class);
ClassName entityClassName = ClassName.get("net.minestom.server.entity", "EntityType");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.entity;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
@ -43,7 +44,7 @@ public final class VillagerProfessionGenerator extends MinestomCodeGenerator {
ClassName rawVillagerProfessionDataClassName = ClassName.get("net.minestom.server.raw_data", "RawVillagerProfessionData");
ClassName registryClassName = ClassName.get("net.minestom.server.registry", "Registry");
JsonArray villagerProfessions = GSON.fromJson(new JsonReader(new InputStreamReader(villagerProfessionsFile)), JsonArray.class);
JsonArray villagerProfessions = GSON.fromJson(new InputStreamReader(villagerProfessionsFile), JsonArray.class);
ClassName villagerProfessionClassName = ClassName.get("net.minestom.server.entity.metadata.villager", "VillagerProfession");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.entity;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
@ -41,7 +42,7 @@ public final class VillagerTypeGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registryClassName = ClassName.get("net.minestom.server.registry", "Registry");
JsonArray villagerTypes = GSON.fromJson(new JsonReader(new InputStreamReader(villagerTypesFile)), JsonArray.class);
JsonArray villagerTypes = GSON.fromJson(new InputStreamReader(villagerTypesFile), JsonArray.class);
ClassName villagerTypeClassName = ClassName.get("net.minestom.server.entity.metadata.villager", "VillagerType");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.fluid;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class FluidGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class FluidGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray fluids = GSON.fromJson(new JsonReader(new InputStreamReader(fluidsFile)), JsonArray.class);
JsonArray fluids = GSON.fromJson(new InputStreamReader(fluidsFile), JsonArray.class);
ClassName fluidClassName = ClassName.get("net.minestom.server.fluid", "Fluid");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.item;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class EnchantmentGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class EnchantmentGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray enchantments = GSON.fromJson(new JsonReader(new InputStreamReader(enchantmentsFile)), JsonArray.class);
JsonArray enchantments = GSON.fromJson(new InputStreamReader(enchantmentsFile), JsonArray.class);
ClassName enchantmentClassName = ClassName.get("net.minestom.server.item", "Enchantment");
// Enchantment

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.item;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.function.Supplier;
@ -43,7 +44,7 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
ClassName blockCN = ClassName.get("net.minestom.server.instance.block", "Block");
ParameterizedTypeName blocksCNSupplier = ParameterizedTypeName.get(ClassName.get(Supplier.class), blockCN);
JsonArray items = GSON.fromJson(new JsonReader(new InputStreamReader(itemsFile)), JsonArray.class);
JsonArray items = GSON.fromJson(new InputStreamReader(itemsFile), JsonArray.class);
ClassName itemClassName = ClassName.get("net.minestom.server.item", "Material");
// Item

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.particle;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class ParticleGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class ParticleGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray particles = GSON.fromJson(new JsonReader(new InputStreamReader(particlesFile)), JsonArray.class);
JsonArray particles = GSON.fromJson(new InputStreamReader(particlesFile), JsonArray.class);
ClassName particleClassName = ClassName.get("net.minestom.server.particle", "Particle");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.potion;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class PotionEffectGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray potionEffects = GSON.fromJson(new JsonReader(new InputStreamReader(potionEffectsFile)), JsonArray.class);
JsonArray potionEffects = GSON.fromJson(new InputStreamReader(potionEffectsFile), JsonArray.class);
ClassName potionEffectClassName = ClassName.get("net.minestom.server.potion", "PotionEffect");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.potion;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class PotionTypeGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class PotionTypeGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray potions = GSON.fromJson(new JsonReader(new InputStreamReader(potionsFile)), JsonArray.class);
JsonArray potions = GSON.fromJson(new InputStreamReader(potionsFile), JsonArray.class);
ClassName potionTypeClassName = ClassName.get("net.minestom.server.potion", "PotionType");
// Particle

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.sound;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -12,7 +11,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class SoundEventGenerator extends MinestomCodeGenerator {
@ -40,7 +41,7 @@ public final class SoundEventGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray sounds = GSON.fromJson(new JsonReader(new InputStreamReader(soundsFile)), JsonArray.class);
JsonArray sounds = GSON.fromJson(new InputStreamReader(soundsFile), JsonArray.class);
ClassName soundClassName = ClassName.get("net.minestom.server.sound", "SoundEvent");
// Sound
TypeSpec.Builder soundClass = TypeSpec.enumBuilder(soundClassName)

View File

@ -3,7 +3,6 @@ package net.minestom.codegen.statistics;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
@ -42,7 +41,7 @@ public final class StatisticGenerator extends MinestomCodeGenerator {
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonArray statistics = GSON.fromJson(new JsonReader(new InputStreamReader(statisticsFile)), JsonArray.class);
JsonArray statistics = GSON.fromJson(new InputStreamReader(statisticsFile), JsonArray.class);
ClassName statisticClassName = ClassName.get("net.minestom.server.statistic", "StatisticType");
// Particle

View File

@ -122,7 +122,7 @@ public class PFBlockDescription implements IBlockDescription {
&& !Block.CHEST.compare(block) && !Block.ENDER_CHEST.compare(block) && !Block.GRINDSTONE.compare(block)
&& !Block.TRAPPED_CHEST.compare(block) && !Block.SOUL_SAND.compare(block)
&& !Block.SOUL_SOIL.compare(block) && !Block.LANTERN.compare(block) && !Block.COCOA.compare(block)
&& !Block.CONDUIT.compare(block) && !Block.GRASS_PATH.compare(block) && !Block.FARMLAND.compare(block)
&& !Block.CONDUIT.compare(block) && !Block.DIRT_PATH.compare(block) && !Block.FARMLAND.compare(block)
&& !Block.END_ROD.compare(block) && !Block.STONECUTTER.compare(block) && !Block.BELL.compare(block);
}

View File

@ -131,7 +131,7 @@ public class PFBlockObject implements IBlockObject {
&& !Block.CHEST.compare(block) && !Block.ENDER_CHEST.compare(block) && !Block.GRINDSTONE.compare(block)
&& !Block.TRAPPED_CHEST.compare(block) && !Block.SOUL_SAND.compare(block)
&& !Block.SOUL_SOIL.compare(block) && !Block.LANTERN.compare(block) && !Block.COCOA.compare(block)
&& !Block.CONDUIT.compare(block) && !Block.GRASS_PATH.compare(block) && !Block.FARMLAND.compare(block)
&& !Block.CONDUIT.compare(block) && !Block.DIRT_PATH.compare(block) && !Block.FARMLAND.compare(block)
&& !Block.END_ROD.compare(block) && !Block.STONECUTTER.compare(block) && !Block.BELL.compare(block);
}