commit code generation steps
This commit is contained in:
parent
d6c695a353
commit
6c56f28a7c
15 changed files with 701 additions and 282 deletions
|
@ -5,14 +5,19 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetadataClass.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/VersionCheck.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaOffset.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/TypeHolder.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/code-gen/src/main/resources/offset-calculator.json" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityUuidProvider.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityUuidProvider.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/CompatibilityIndex.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/build.gradle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/Main.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaClass.java" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaClass.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaMethod.java" beforeDir="false" afterPath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaMethod.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaClass.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetaMethod.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/java/me/tofaa/entitylib/codegen/MetadataClass.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/code-gen/src/main/resources/EntityMeta.json" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -275,6 +280,7 @@
|
|||
<workItem from="1706601592145" duration="1670000" />
|
||||
<workItem from="1706614921404" duration="10508000" />
|
||||
<workItem from="1706696719616" duration="4783000" />
|
||||
<workItem from="1706784821835" duration="5673000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
|
|
@ -16,6 +16,7 @@ public interface EntityUuidProvider {
|
|||
public @NotNull UUID provide(EntityType entityType) {
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package me.tofaa.entitylib.meta;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
||||
|
||||
public interface CompatibilityIndex {
|
||||
|
||||
byte getOffSet(byte latestOffset, EntityDataType<?> type);
|
||||
|
||||
}
|
|
@ -97,30 +97,6 @@ public class EntityMeta implements EntityMetadataProvider {
|
|||
setMaskBit(OFFSET, INVISIBLE_BIT, value);
|
||||
}
|
||||
|
||||
public short getAirTicks() {
|
||||
return this.metadata.getIndex((byte) 1, (short) 300);
|
||||
}
|
||||
|
||||
public void setAirTicks(short value) {
|
||||
this.metadata.setIndex((byte) 1, EntityDataTypes.SHORT, value);
|
||||
}
|
||||
|
||||
public Component getCustomName() {
|
||||
return this.metadata.getIndex(offset(OFFSET, 2), null);
|
||||
}
|
||||
|
||||
public void setCustomName(Component value) {
|
||||
this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.ADV_COMPONENT, value);
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
return this.metadata.getIndex(offset(OFFSET, 3), false);
|
||||
}
|
||||
|
||||
public void setCustomNameVisible(boolean value) {
|
||||
this.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.BOOLEAN, value);
|
||||
}
|
||||
|
||||
public boolean hasGlowingEffect() {
|
||||
return getMaskBit(OFFSET, HAS_GLOWING_EFFECT_BIT);
|
||||
}
|
||||
|
@ -145,6 +121,30 @@ public class EntityMeta implements EntityMetadataProvider {
|
|||
setMaskBit(OFFSET, FLYING_WITH_ELYTRA_BIT, value);
|
||||
}
|
||||
|
||||
public short getAirTicks() {
|
||||
return this.metadata.getIndex((byte) 1, (short) 300);
|
||||
}
|
||||
|
||||
public void setAirTicks(short value) {
|
||||
this.metadata.setIndex((byte) 1, EntityDataTypes.SHORT, value);
|
||||
}
|
||||
|
||||
public Component getCustomName() {
|
||||
return this.metadata.getIndex(offset(OFFSET, 2), null);
|
||||
}
|
||||
|
||||
public void setCustomName(Component value) {
|
||||
this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.ADV_COMPONENT, value);
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
return this.metadata.getIndex(offset(OFFSET, 3), false);
|
||||
}
|
||||
|
||||
public void setCustomNameVisible(boolean value) {
|
||||
this.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.BOOLEAN, value);
|
||||
}
|
||||
|
||||
public boolean isSilent() {
|
||||
return this.metadata.getIndex((byte) 4, false);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,259 @@
|
|||
// This class is generated by code-gen module. Do not edit manually.
|
||||
//
|
||||
package me.tofaa.entitylib.meta;
|
||||
|
||||
import static me.tofaa.entitylib.EntityLib.getApi;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@SuppressWarnings("unused")
|
||||
public final class MetaOffsetConverter {
|
||||
private MetaOffsetConverter() {
|
||||
}
|
||||
|
||||
public static byte airTicksOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 47) {
|
||||
return 1;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte customNameOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 2;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte customNameVisibleOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 3;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte silentOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 4;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte hasNoGravityOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 5;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte poseOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 6;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte ticksFrozenInPowderedSnowOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 47 && protocolVersion <= 765) {
|
||||
return 7;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte interpolationDelayOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 762 && protocolVersion <= 765) {
|
||||
return 8;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte transformationDurationOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 762 && protocolVersion <= 765) {
|
||||
return 9;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte positionRotationInterpolationDurationOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 10;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte translationOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 11;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 10;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte scaleOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 12;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 11;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte leftRotationOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 13;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 12;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte rightRotationOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 14;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 13;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte billboardConstraintsOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 15;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 14;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte brightnessOverrideOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 16;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 15;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte viewRangeOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 17;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 16;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte shadowRadiusOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 18;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 17;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte shadowStrengthOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 19;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 18;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte widthOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 20;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 19;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte heightOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 21;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 20;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte glowColorOverrideOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 22;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 21;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte blockIdOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 23;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 22;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte itemOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 24;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 23;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
|
||||
public static byte displayTypeOffset() {
|
||||
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
|
||||
if (protocolVersion >= 764 && protocolVersion <= 765) {
|
||||
return 25;
|
||||
}
|
||||
if (protocolVersion >= 762 && protocolVersion <= 763) {
|
||||
return 24;
|
||||
}
|
||||
throw new RuntimeException("Unknown protocol version for this method");
|
||||
}
|
||||
}
|
|
@ -12,15 +12,6 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
// adding autogenerated sources to the main source set
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDirs += 'autogenerated'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
implementation 'com.squareup:javapoet:1.13.0'
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.squareup.javapoet.*;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static me.tofaa.entitylib.codegen.MetadataClass.createMetadataClass;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public final class Main {
|
||||
|
||||
private Main() {}
|
||||
static final File OUT = new File("./code-gen/autogenerated/");
|
||||
private static final File OUT = new File("./api/src/main/java");
|
||||
static {
|
||||
if (!OUT.exists()) {
|
||||
OUT.mkdirs();
|
||||
|
@ -27,34 +27,50 @@ public final class Main {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
createMetadataClass();
|
||||
List<MetaClass> metaClasses = new ArrayList<>();
|
||||
|
||||
// test
|
||||
MetaMethod method = new MetaMethod("username", String.class, "\"\"", "EntityDataType.STRING", List.of(new VersionCheck(47, 47, (byte) 0)));
|
||||
MetaClass obj = new MetaClass("me.tofaa.entitylib.meta:EntityMeta", null, List.of(method));
|
||||
TypeSpec.Builder baseBuilder = TypeSpec.classBuilder(ClassName.get("me.tofaa.entitylib.meta", "MetaOffsetConverter"))
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||
.addAnnotation(ApiStatus.Internal.class)
|
||||
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
|
||||
.addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).build());
|
||||
|
||||
writeClass(obj);
|
||||
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES).create();
|
||||
InputStream stream = Main.class.getResourceAsStream("/offset-calculator.json");
|
||||
if (stream == null) {
|
||||
throw new RuntimeException("offset-calculator.json not found");
|
||||
}
|
||||
InputStreamReader reader = new InputStreamReader(stream);
|
||||
TypeHolder[] types = gson.fromJson(reader, TypeHolder[].class);
|
||||
for (TypeHolder type : types) {
|
||||
System.out.println("Generating type" + type.className());
|
||||
|
||||
private static void writeClass(MetaClass metaClass) {
|
||||
TypeSpec typeSpec = metaClass.create();
|
||||
JavaFile javaFile = JavaFile.builder("me.tofaa.entitylib.meta", typeSpec).build();
|
||||
try {
|
||||
javaFile.writeToPath(OUT.toPath());
|
||||
for (MetaOffset offset : type.offsets()) {
|
||||
|
||||
MethodSpec.Builder method = MethodSpec.methodBuilder(offset.name() + "Offset")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
.returns(byte.class);
|
||||
|
||||
String version = "int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion()";
|
||||
method.addStatement(version);
|
||||
for (VersionCheck check : offset.checks()) {
|
||||
method.beginControlFlow("if (protocolVersion >= $L && protocolVersion <= $L)", check.to(), check.from());
|
||||
method.addStatement("return $L", check.offset());
|
||||
method.endControlFlow();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
method.addStatement("throw new RuntimeException(\"Unknown protocol version for this method\")");
|
||||
baseBuilder.addMethod(method.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Include comment in generated code
|
||||
public static TypeSpec.Builder builder(String packageName, String className) {
|
||||
return TypeSpec.classBuilder(ClassName.get(packageName, className))
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addJavadoc("AUTOGENERATED CODE BY ENTITYLIB CODEGEN\n")
|
||||
.addJavadoc("DO NOT EDIT\n");
|
||||
TypeSpec base = baseBuilder.build();
|
||||
System.out.println("Writing to file");
|
||||
JavaFile file = JavaFile.builder("me.tofaa.entitylib.meta", base)
|
||||
.addStaticImport(ClassName.get("me.tofaa.entitylib", "EntityLib"), "getApi")
|
||||
.addFileComment("This class is generated by code-gen module. Do not edit manually.\n")
|
||||
.indent(" ")
|
||||
.skipJavaLangImports(true)
|
||||
.build();
|
||||
file.writeTo(OUT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.tofaa.entitylib.codegen.Main.builder;
|
||||
|
||||
public record MetaClass(
|
||||
String name,
|
||||
String extendsClass,
|
||||
List<MetaMethod> methods
|
||||
) {
|
||||
|
||||
|
||||
public TypeSpec create() {
|
||||
String split[] = name.split(":");
|
||||
String packageName = split[0];
|
||||
String className = split[1];
|
||||
|
||||
TypeSpec.Builder builder = builder(packageName, className);
|
||||
if (extendsClass != null) {
|
||||
String[] extendsSplit = extendsClass.split(":");
|
||||
builder.superclass(ClassName.get(extendsSplit[0], extendsSplit[1]));
|
||||
|
||||
builder.addField(int.class, "entityId");
|
||||
builder.addField(ClassName.get("me.tofaa.entitylib.meta", "Metadata"), "metadata");
|
||||
|
||||
}
|
||||
for (MetaMethod method : methods) {
|
||||
builder.addMethods(method.create());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public record MetaMethod(
|
||||
String name,
|
||||
Type returnType,
|
||||
String defaultReturn,
|
||||
String dataType,
|
||||
List<VersionCheck> versionChecks
|
||||
) {
|
||||
|
||||
public List<MethodSpec> create() {
|
||||
|
||||
String methodBasedName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
|
||||
/* offset calculator first */
|
||||
MethodSpec.Builder calculator = MethodSpec.methodBuilder(
|
||||
"calculate" + methodBasedName + "Offset")
|
||||
.returns(byte.class)
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
|
||||
.addParameter(int.class, "version");
|
||||
for (VersionCheck check : versionChecks) {
|
||||
calculator.beginControlFlow("if (version >= $L && version <= $L)", check.from(), check.to());
|
||||
calculator.addStatement("return $L", check.offset());
|
||||
calculator.endControlFlow();
|
||||
}
|
||||
// throw exception if version is not in range
|
||||
calculator.addStatement("throw new IllegalArgumentException(\"Version \" + version + \" is not in range\")");
|
||||
|
||||
String versionVariable = "byte offset = calculate" + methodBasedName + "Offset(EntityLib.getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion())";
|
||||
|
||||
/* getter method spec. No params */
|
||||
String getterName = "get";
|
||||
if (returnType == TypeName.BOOLEAN) {
|
||||
getterName = "is";
|
||||
}
|
||||
MethodSpec.Builder getter = MethodSpec.methodBuilder(getterName + methodBasedName)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(returnType)
|
||||
.addStatement(versionVariable)
|
||||
.addStatement("return metadata.getIndex(" + "offset," + defaultReturn + ");");
|
||||
|
||||
MethodSpec.Builder setter = MethodSpec.methodBuilder("set" + methodBasedName)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(void.class)
|
||||
.addParameter(returnType, "value")
|
||||
.addStatement(versionVariable)
|
||||
.addStatement("metadata.setIndex(" + "offset, " + dataType + ", " + "value" + ");");
|
||||
|
||||
return List.of(
|
||||
calculator.build(),
|
||||
getter.build(),
|
||||
setter.build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
public record MetaOffset(String name, VersionCheck[] checks) {
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeVariableName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static me.tofaa.entitylib.codegen.Main.OUT;
|
||||
import static me.tofaa.entitylib.codegen.Main.builder;
|
||||
|
||||
public final class MetadataClass {
|
||||
|
||||
private MetadataClass() {
|
||||
|
||||
}
|
||||
public static void createMetadataClass() {
|
||||
|
||||
TypeSpec.Builder builder = builder("me.tofaa.entitylib.meta", "Metadata");
|
||||
builder.addField(int.class, "entityId", Modifier.PRIVATE, Modifier.FINAL);
|
||||
builder.addField(TypeToken.getParameterized(Map.class, Byte.class, EntityData.class).getType(), "metadataMap", Modifier.PRIVATE, Modifier.FINAL);
|
||||
MethodSpec.Builder constructor = MethodSpec.constructorBuilder()
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addCode("this.entityId = entityId;\n")
|
||||
.addCode("this.metadataMap = new java.util.concurrent.ConcurrentHashMap<>();\n")
|
||||
.addParameter(int.class, "entityId");
|
||||
|
||||
MethodSpec.Builder getIndex = MethodSpec.methodBuilder("getIndex")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addTypeVariable(TypeVariableName.get("T"))
|
||||
.addParameter(byte.class, "index")
|
||||
.addParameter(TypeVariableName.get("T"), "defaultValue")
|
||||
.returns(TypeVariableName.get("T"))
|
||||
.addCode("EntityData entityData = metadataMap.get(index);\n")
|
||||
.addCode("if (entityData == null) return defaultValue;\n")
|
||||
.addCode("if (entityData.getValue() == null) return defaultValue;\n")
|
||||
.addCode("return (T) entityData.getValue();\n");
|
||||
|
||||
MethodSpec.Builder setIndex = MethodSpec.methodBuilder("setIndex")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addTypeVariable(TypeVariableName.get("T"))
|
||||
.addParameter(byte.class, "index")
|
||||
.addParameter(EntityDataType.class, "dataType")
|
||||
.addParameter(TypeVariableName.get("T"), "value")
|
||||
.addCode("EntityData data = new EntityData(index, dataType, value);\n")
|
||||
.addCode("this.metadataMap.put(index, data);\n");
|
||||
|
||||
MethodSpec.Builder getEntries = MethodSpec.methodBuilder("getEntries")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(TypeToken.getParameterized(List.class, EntityData.class).getType())
|
||||
.addCode("return new java.util.ArrayList<>(metadataMap.values());\n")
|
||||
.addAnnotation(NotNull.class);
|
||||
|
||||
MethodSpec.Builder createPacket = MethodSpec.methodBuilder("createPacket")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(WrapperPlayServerEntityMetadata.class)
|
||||
.addCode("return new WrapperPlayServerEntityMetadata(entityId, getEntries());\n")
|
||||
.addAnnotation(NotNull.class);
|
||||
|
||||
builder.addMethod(constructor.build());
|
||||
builder.addMethod(getIndex.build());
|
||||
builder.addMethod(setIndex.build());
|
||||
builder.addMethod(getEntries.build());
|
||||
builder.addMethod(createPacket.build());
|
||||
|
||||
JavaFile javaFile = JavaFile.builder("me.tofaa.entitylib.meta", builder.build()).build();
|
||||
try {
|
||||
javaFile.writeToPath(OUT.toPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package me.tofaa.entitylib.codegen;
|
||||
|
||||
public record TypeHolder(String className, MetaOffset[] offsets) {
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"class-id": "me.tofaa.entitylib.codegen:User",
|
||||
"methods": [
|
||||
|
||||
{
|
||||
"name": "getUsername",
|
||||
"return-type": "java.lang.String",
|
||||
"parameters": [
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
}
|
347
code-gen/src/main/resources/offset-calculator.json
Normal file
347
code-gen/src/main/resources/offset-calculator.json
Normal file
|
@ -0,0 +1,347 @@
|
|||
[
|
||||
{
|
||||
"class-name": "EntityMeta",
|
||||
"offsets": [
|
||||
{
|
||||
"name": "airTicks",
|
||||
"checks": [
|
||||
{
|
||||
"from": 47,
|
||||
"to": 47,
|
||||
"offset": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "customName",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "customNameVisible",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "silent",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "hasNoGravity",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pose",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ticksFrozenInPowderedSnow",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 47,
|
||||
"offset": 7
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"class-name": "AbstractDisplayMeta",
|
||||
"offsets": [
|
||||
{
|
||||
"name": "interpolationDelay",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 762,
|
||||
"offset": 8
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "transformationDuration",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 762,
|
||||
"offset": 9
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "positionRotationInterpolationDuration",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "translation",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 11
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "scale",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 12
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 11
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "leftRotation",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 13
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 12
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "rightRotation",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 14
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 13
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "billboardConstraints",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 15
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 14
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "brightnessOverride",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 16
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 15
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "viewRange",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 17
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 16
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "shadowRadius",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 18
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 17
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "shadowStrength",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 19
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 18
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "width",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 20
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 19
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "height",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 21
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 20
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "glowColorOverride",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 22
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 21
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"class-name": "BlockDisplayMeta",
|
||||
"offsets": [
|
||||
{
|
||||
"name": "blockId",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 23
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 22
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"class-name": "ItemDisplay",
|
||||
"offsets": [
|
||||
{
|
||||
"name": "item",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 24
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 23
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "displayType",
|
||||
"checks": [
|
||||
{
|
||||
"from": 765,
|
||||
"to": 764,
|
||||
"offset": 25
|
||||
},
|
||||
{
|
||||
"from": 763,
|
||||
"to": 762,
|
||||
"offset": 24
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -8,6 +8,7 @@ import me.tofaa.entitylib.APIConfig;
|
|||
import me.tofaa.entitylib.EntityLib;
|
||||
import me.tofaa.entitylib.EntityLibAPI;
|
||||
import me.tofaa.entitylib.WorldWrapper;
|
||||
import me.tofaa.entitylib.meta.mobs.passive.ChickenMeta;
|
||||
import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform;
|
||||
import me.tofaa.entitylib.wrapper.WrapperEntity;
|
||||
import org.bukkit.World;
|
||||
|
@ -25,7 +26,6 @@ public class TestEntityLibPlugin extends JavaPlugin implements Listener {
|
|||
private WrapperEntity e;
|
||||
private WorldWrapper<World> world;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
|
@ -49,7 +49,9 @@ public class TestEntityLibPlugin extends JavaPlugin implements Listener {
|
|||
}
|
||||
world = api.wrapWorld(player.getWorld());
|
||||
e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
|
||||
|
||||
ChickenMeta meta = (ChickenMeta) e.getEntityMeta();
|
||||
meta.setBaby(!meta.isBaby());
|
||||
meta.setHasGlowingEffect(!meta.hasGlowingEffect());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue