diff --git a/AnnotatedNBT/build.gradle b/AnnotatedNBT/build.gradle deleted file mode 100644 index 466c0f25..00000000 --- a/AnnotatedNBT/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -buildscript { - repositories { - //jcenter() - maven { url = "http://files.minecraftforge.net/maven" } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - } -} - -plugins { - id 'io.franzbecker.gradle-lombok' /*version '1.11'*/ - id 'java' -} - -apply plugin: 'java' -apply plugin: 'net.minecraftforge.gradle.forge' - -group 'org.dimdev.annotatednbt' -version '1.0.0-beta' - -sourceCompatibility = 1.8 - -repositories { - mavenCentral() -} - -minecraft { - runDir = "run" - version = "1.12.2-14.23.1.2555" - mappings = "snapshot_20171007" -} diff --git a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/IndentedPrintWriter.java b/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/IndentedPrintWriter.java deleted file mode 100644 index 1d43c772..00000000 --- a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/IndentedPrintWriter.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.dimdev.ddutils.nbt; - -import java.io.PrintWriter; -import java.io.Writer; -import java.util.Collections; - -public class IndentedPrintWriter extends PrintWriter { // TODO: verify indentation using a marking system when passing? - - private int indent = 0; - private boolean startOfLine; - - public IndentedPrintWriter(Writer out) { - super(out); - } - - public void indent(int n) { - if (indent + n < 0) throw new IllegalArgumentException("Can't set indentation to less than 0!"); - indent += n; - } - - public void unindent(int n) { - indent(-n); - } - - public void indent() { - indent(4); - } - - public void unindent() { - indent(-4); - } - - @Override - public void print(String s) { - if (startOfLine) { - super.print(String.join("", Collections.nCopies(indent, " "))); - } - super.print(s); - startOfLine = false; - } - - @Override - public void println() { - super.println(); - startOfLine = true; - } -} diff --git a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBT.java b/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBT.java deleted file mode 100644 index e300cc81..00000000 --- a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBT.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.dimdev.ddutils.nbt; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.TYPE, ElementType.FIELD}) // TODO: split annotation, error when set on field but not containing class -@Retention(RetentionPolicy.SOURCE) -public @interface SavedToNBT { - -} diff --git a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java b/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java deleted file mode 100644 index 746f480c..00000000 --- a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java +++ /dev/null @@ -1,640 +0,0 @@ -package org.dimdev.ddutils.nbt; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.*; -import javax.lang.model.type.*; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; -import javax.tools.JavaFileObject; -import java.io.IOException; -import java.util.*; - -@SupportedAnnotationTypes("org.dimdev.ddutils.nbt.SavedToNBT") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class SavedToNBTProcessor extends AbstractProcessor { - - private static final String BOOLEAN = "java.lang.Boolean"; - private static final String BYTE = "java.lang.Byte"; - private static final String SHORT = "java.lang.Short"; - private static final String INTEGER = "java.lang.Integer"; - private static final String LONG = "java.lang.Long"; - private static final String CHAR = "java.lang.Char"; - private static final String FLOAT = "java.lang.Float"; - private static final String DOUBLE = "java.lang.Double"; - private static final String STRING = "java.lang.String"; - private static final String COLLECTION = "java.util.Collection"; // TODO: Allow storing any Iterable? - private static final String MAP = "java.util.Map"; - private static final String MAP_ENTRY = "java.util.Map.Entry"; - private static final String NBT_STORABLE = "org.dimdev.ddutils.nbt.INBTStorable"; - private static final String VEC_3I = "net.minecraft.util.math.Vec3i"; - private static final String LOCATION = "org.dimdev.ddutils.Location"; - private static final String RGBA = "org.dimdev.ddutils.RGBA"; - private static final String VIRTUAL_LOCATION = "org.dimdev.dimdoors.shared.VirtualLocation"; - private static final String UUID = "java.util.UUID"; - - private Map varCounter = new HashMap<>(); - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { // TODO: generics, inheritance, different exception for error type - roundEnv.getElementsAnnotatedWith(SavedToNBT.class); - for (Element element : roundEnv.getElementsAnnotatedWith(SavedToNBT.class)) { - if (element.getKind() != ElementKind.CLASS) continue; - - TypeElement classElement = (TypeElement) element; - Element enclosingElement = classElement; - while (!(enclosingElement instanceof PackageElement)) { - enclosingElement = enclosingElement.getEnclosingElement(); - } - PackageElement packageElement = (PackageElement) enclosingElement; - JavaFileObject jfo; - IndentedPrintWriter w; - try { - jfo = processingEnv.getFiler().createSourceFile(packageElement.getQualifiedName() + "."+ classElement.getSimpleName() + "NBTWriter"); - w = new IndentedPrintWriter(jfo.openWriter()); - } catch (IOException e) { - throw new RuntimeException(e); - } - - String type = classElement.getSimpleName().toString(); - - List savedFields = new ArrayList<>(); - for (Element enclosedElement : classElement.getEnclosedElements()) { - if (enclosedElement.getKind() == ElementKind.FIELD && enclosedElement.getAnnotationsByType(SavedToNBT.class).length > 0) { - savedFields.add((VariableElement) enclosedElement); - } - } - - w.println("package " + packageElement.getQualifiedName() + ";"); - w.println(); - w.println("import net.minecraft.nbt.*;"); - w.println(); - w.println("public final class " + type + "NBTWriter {"); - w.println(); - w.indent(); - w.print("public static void writeToNBT(" + classElement.getQualifiedName() + " obj, NBTTagCompound nbt) {"); - w.indent(); - for (VariableElement field : savedFields) { - w.println(); - writeFieldWriteCode(w, field.asType(), field.getSimpleName().toString()); - } - varCounter.clear(); - if (savedFields.size() == 0) w.println(); - w.unindent(); - w.println("}"); - w.println(); - w.println("@SuppressWarnings({\"OverlyStrongTypeCast\", \"RedundantSuppression\"})"); // We want the cast to fail if it's ther wrong type - w.print("public static void readFromNBT(" + classElement.getQualifiedName() + " obj, NBTTagCompound nbt) {"); - w.indent(); - for (VariableElement field : savedFields) { - w.println(); - writeFieldReadCode(w, field.asType(), field.getSimpleName().toString()); - } - varCounter.clear(); - if (savedFields.size() == 0) w.println(); - w.unindent(); - w.println("}"); - w.unindent(); - w.println("}"); - w.close(); - } - return true; - } - - // Writing - - // This tries to write using a .set method, and creates and fills a tag only if necessary - private void writeFieldWriteCode(IndentedPrintWriter w, TypeMirror type, String name) { // TODO: store boxed primitives and boxed primitive collections as primitives - w.println("// Write field " + type + " " + name); - switch (type.getKind()) { - case BOOLEAN: - w.println("nbt.setBoolean(\"" + name + "\", obj." + name + ");"); - break; - case BYTE: - w.println("nbt.setByte(\"" + name + "\", obj." + name + ");"); - break; - case SHORT: - w.println("nbt.setShort(\"" + name + "\", obj." + name + ");"); - break; - case INT: - w.println("nbt.setInteger(\"" + name + "\", obj." + name + ");"); - break; - case LONG: - w.println("nbt.setLong(\"" + name + "\", obj." + name + ");"); - break; - case CHAR: - w.println("nbt.setInteger(\"" + name + "\", (int) obj." + name + ");"); // TODO: use short? - break; - case FLOAT: - w.println("nbt.setFloat(\"" + name + "\", obj." + name + ");"); - break; - case DOUBLE: - w.println("nbt.setDouble(\"" + name + "\", obj." + name + ");"); - break; - case ARRAY: - TypeMirror componentType = ((ArrayType) type).getComponentType(); - if (componentType.getKind() == TypeKind.BYTE) { // TODO: store boolean array as byte array - w.println("nbt.setByteArray(\"" + name + "\", obj." + name + ");"); - } else if (componentType.getKind() == TypeKind.INT) { - w.println("nbt.setIntArray(\"" + name + "\", obj." + name + ");"); - } else { - makeNBTObject(w, type, "obj." + name, newVar("tag")); // TODO: name should depend on field name - w.println("nbt.setTag(\"" + name + "\", " + var("tag") + ");"); - } - break; - case DECLARED: - DeclaredType declaredType = (DeclaredType) type; - Types tu = processingEnv.getTypeUtils(); - Elements eu = processingEnv.getElementUtils(); - switch (declaredType.toString()) { - // TODO: less code duplication - case BOOLEAN: - w.println("nbt.setBoolean(\"" + name + "\", obj." + name + ");"); - break; - case BYTE: - w.println("nbt.setByte(\"" + name + "\", obj." + name + ");"); - break; - case SHORT: - w.println("nbt.setShort(\"" + name + "\", obj." + name + ");"); - break; - case INTEGER: - w.println("nbt.setInteger(\"" + name + "\", obj." + name + ");"); - break; - case LONG: - w.println("nbt.setLong(\"" + name + "\", obj." + name + ");"); - break; - case CHAR: - w.println("nbt.setInteger(\"" + name + "\", (int) obj." + name + ");"); // TODO: use short? - break; - case FLOAT: - w.println("nbt.setFloat(\"" + name + "\", obj." + name + ");"); - break; - case DOUBLE: - w.println("nbt.setDouble(\"" + name + "\", obj." + name + ");"); - break; - // - case STRING: - w.println("nbt.setString(\"" + name + "\", obj." + name + ");"); - break; - case UUID: - w.println("nbt.setUUID(\"" + name + "\", obj." + name + ");"); - break; - default: - w.println("if (obj." + name + " != null) {"); - w.indent(); - if (tu.isAssignable(type, eu.getTypeElement(NBT_STORABLE).asType())) { - w.println("if (obj." + name + " != null) nbt.setTag(\"" + name + "\", obj." + name + ".writeToNBT(new NBTTagCompound()));"); - } else { - makeNBTObject(w, type, "obj." + name, newVar("tag")); // TODO: name should depend on field name - w.println("nbt.setTag(\"" + name + "\", " + var("tag") + ");"); - } - w.unindent(); - w.println("}"); - break; - } - break; - default: - makeNBTObject(w, type, "obj." + name, newVar("tag")); // TODO: name should depend on field name - w.println("nbt.setTag(\"" + name + "\", " + var("tag") + ");"); - break; - } - } - - private void makeNBTObject(IndentedPrintWriter w, TypeMirror type, String from, String nbt) { - switch (type.getKind()) { - case BOOLEAN: - w.println("NBTTagByte " + nbt + " = new NBTTagByte((byte) (" + from + " ? 1 : 0));"); - break; - case BYTE: - w.println("NBTTagByte " + nbt + " = new NBTTagByte(" + from + ");"); - break; - case SHORT: - w.println("NBTTagShort " + nbt + " = new NBTTagShort(" + from + ");"); - break; - case INT: - w.println("NBTTagInt " + nbt + " = new NBTTagInt(" + from + ");"); - break; - case LONG: - w.println("NBTTagLong " + nbt + " = new NBTTagLong(" + from + ");"); - break; - case CHAR: - w.println("NBTTagInt " + nbt + " = new NBTTagInt((int) " + from + ");"); - break; - case FLOAT: - w.println("NBTTagFloat " + nbt + " = new NBTTagFloat(" + from + ");"); - break; - case DOUBLE: - w.println("NBTTagDouble " + nbt + " = new NBTTagDouble(" + from + ");"); - break; - case ARRAY: - TypeMirror componentType = ((ArrayType) type).getComponentType(); - if (componentType.getKind() == TypeKind.BYTE) { - w.println("NBTTagByteArray " + nbt + " = new NBTTagByteArray(" + from + ");"); - } else if (componentType.getKind() == TypeKind.INT) { - w.println("NBTTagIntArray " + nbt + " = new NBTTagIntArray(" + from + ");"); - } else { - writeIterable(w, componentType, from, nbt); - } - break; - case DECLARED: - DeclaredType declaredType = (DeclaredType) type; - switch (declaredType.toString()) { - // TODO: less code duplication - case BOOLEAN: - w.println("NBTTagByte " + nbt + " = new NBTTagByte((byte) (" + from + " ? 1 : 0));"); - break; - case BYTE: - w.println("NBTTagByte " + nbt + " = new NBTTagByte(" + from + ");"); - break; - case SHORT: - w.println("NBTTagShort " + nbt + " = new NBTTagShort(" + from + ");"); - break; - case INTEGER: - w.println("NBTTagInt " + nbt + " = new NBTTagInt(" + from + ");"); - break; - case LONG: - w.println("NBTTagLong " + nbt + " = new NBTTagLong(" + from + ");"); - break; - case CHAR: - w.println("NBTTagInt " + nbt + " = new NBTTagInt((int) " + from + ");"); - break; - case FLOAT: - w.println("NBTTagFloat " + nbt + " = new NBTTagFloat(" + from + ");"); - break; - case DOUBLE: - w.println("NBTTagDouble " + nbt + " = new NBTTagDouble(" + from + ");"); - break; - // - case STRING: - w.println("NBTTagString " + nbt + " = new NBTTagString(" + from + ");"); - break; - default: - Types types = processingEnv.getTypeUtils(); - Elements elements = processingEnv.getElementUtils(); - if (types.isAssignable(type, types.erasure(elements.getTypeElement(COLLECTION).asType()))) { - List typeArguments = ((DeclaredType) type).getTypeArguments(); - if (typeArguments.size() != 1) throw new RuntimeException("Missing type arguments for " + type); - TypeMirror elementType = typeArguments.get(0); - writeIterable(w, elementType, from, nbt); - } else if (types.isAssignable(type, types.erasure(elements.getTypeElement(MAP).asType()))) { - List typeArguments = ((DeclaredType) type).getTypeArguments(); - if (typeArguments.size() != 2) throw new RuntimeException("Missing type arguments for " + type); - TypeMirror entryType = types.getDeclaredType(elements.getTypeElement(MAP_ENTRY), - typeArguments.get(0), typeArguments.get(1)); - writeIterable(w, entryType, from + ".entrySet()", nbt); - } else if (types.isAssignable(type, types.erasure(elements.getTypeElement(MAP_ENTRY).asType()))) { - w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); - List typeArguments = ((DeclaredType) type).getTypeArguments(); - if (typeArguments.size() != 2) throw new RuntimeException("Missing type arguments for " + type); - makeNBTObject(w, typeArguments.get(0), from + ".getKey()", newVar("key")); // TODO: configurable key name - w.println(nbt + ".setTag(\"" + var("key") + "\", " + var("key") + ");"); - makeNBTObject(w, typeArguments.get(1), from + ".getValue()", newVar("value")); - w.println(nbt + ".setTag(\"" + var("value") + "\", " + var("value") + ");"); - varGone("key"); - varGone("value"); - } else if (types.isAssignable(type, elements.getTypeElement(NBT_STORABLE).asType())) { - w.println("NBTTagCompound " + nbt + " = " + from + ".writeToNBT(new NBTTagCompound());"); - } else if (types.isAssignable(type, elements.getTypeElement(VEC_3I).asType())) { - w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); - w.println(nbt + ".setInteger(\"x\", " + from + ".getX());"); - w.println(nbt + ".setInteger(\"y\", " + from + ".getY());"); - w.println(nbt + ".setInteger(\"z\", " + from + ".getZ());"); - } else if (types.isAssignable(type, elements.getTypeElement(LOCATION).asType())) { - w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); - w.println(nbt + ".setInteger(\"dim\", " + from + ".getDim());"); - w.println(nbt + ".setInteger(\"x\", " + from + ".getX());"); - w.println(nbt + ".setInteger(\"y\", " + from + ".getY());"); - w.println(nbt + ".setInteger(\"z\", " + from + ".getZ());"); - } else if (types.isAssignable(type, elements.getTypeElement(RGBA).asType())) { - w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); - w.println(nbt + ".setFloat(\"red\", " + from + ".getRed());"); - w.println(nbt + ".setFloat(\"green\", " + from + ".getGreen());"); - w.println(nbt + ".setFloat(\"blue\", " + from + ".getBlue());"); - w.println(nbt + ".setFloat(\"alpha\", " + from + ".getAlpha());"); - } else if (types.isAssignable(type, elements.getTypeElement(VIRTUAL_LOCATION).asType())) { - w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); - w.println(nbt + ".setInteger(\"dim\", " + from + ".getDim());"); - w.println(nbt + ".setInteger(\"x\", " + from + ".getX());"); - w.println(nbt + ".setInteger(\"y\", " + from + ".getY());"); - w.println(nbt + ".setInteger(\"z\", " + from + ".getZ());"); - w.println(nbt + ".setInteger(\"depth\", " + from + ".getDepth());"); - } else if (((DeclaredType) type).asElement().getKind() == ElementKind.ENUM) { - w.println("NBTTagInt " + nbt + " = new NBTTagInt(" + from + ".ordinal());"); - } else { - throw new RuntimeException("Unsupported type " + type + " for variable " + from + "!"); - } - } - break; - default: - throw new RuntimeException("Unsupported type kind " + type + " for variable " + from + "!"); - } - } - - private void writeIterable(IndentedPrintWriter w, TypeMirror componentType, String from, String nbt) { - w.println("NBTTagList " + nbt + " = new NBTTagList();"); - w.println("for (" + componentType + " " + newVar("element") + " : " + from + ") {"); // TODO: no java.lang or java.util - w.indent(); - makeNBTObject(w, componentType, var("element"), newVar("elementNBT")); // TODO: single line if possible - w.println(nbt + ".appendTag(" + var("elementNBT") + ");"); - varGone("element"); - varGone("elementNBT"); - w.unindent(); - w.println("}"); - } - - // Reading - - private void writeFieldReadCode(IndentedPrintWriter w, TypeMirror type, String name) { - w.println("// Read field " + type + " " + name); - switch (type.getKind()) { - case BOOLEAN: - w.println("obj." + name + " = nbt.getBoolean(\"" + name + "\");"); - break; - case BYTE: - w.println("obj." + name + " = nbt.getByte(\"" + name + "\");"); - break; - case SHORT: - w.println("obj." + name + " = nbt.getShort(\"" + name + "\");"); - break; - case INT: - w.println("obj." + name + " = nbt.getInteger(\"" + name + "\");"); - break; - case LONG: - w.println("obj." + name + " = nbt.getLong(\"" + name + "\");"); - break; - case CHAR: - w.println("obj." + name + " = (char) nbt.getInteger(\"" + name + "\");"); - break; - case FLOAT: - w.println("obj." + name + " = nbt.getFloat(\"" + name + "\");"); - break; - case DOUBLE: - w.println("obj." + name + " = nbt.getDouble(\"" + name + "\");"); - break; - case ARRAY: - TypeMirror componentType = ((ArrayType) type).getComponentType(); - if (componentType.getKind() == TypeKind.BYTE) { // TODO: store boolean array as byte array - w.println("obj." + name + " = nbt.getByteArray(\"" + name + "\");"); - } else if (componentType.getKind() == TypeKind.INT) { - w.println("obj." + name + " = nbt.getIntArray(\"" + name + "\");"); - } else { - w.println("NBTBase " + newVar("tag") + " = nbt.getTag(\"" + name + "\");"); - readNBTObject(w, type, newVar("arr"), var("tag")); // TODO: name should depend on field name - w.println("obj." + name + " = " + var("arr") + ";"); - } - break; - case DECLARED: - DeclaredType declaredType = (DeclaredType) type; - Types tu = processingEnv.getTypeUtils(); - Elements eu = processingEnv.getElementUtils(); - switch (declaredType.toString()) { - // TODO: less code duplication - case BOOLEAN: - w.println("obj." + name + " = nbt.getBoolean(\"" + name + "\");"); - break; - case BYTE: - w.println("obj." + name + " = nbt.getByte(\"" + name + "\");"); - break; - case SHORT: - w.println("obj." + name + " = nbt.getShort(\"" + name + "\");"); - break; - case INTEGER: - w.println("obj." + name + " = nbt.getInteger(\"" + name + "\");"); - break; - case LONG: - w.println("obj." + name + " = nbt.getLong(\"" + name + "\");"); - break; - case CHAR: - w.println("obj." + name + " = (char) nbt.getInteger(\"" + name + "\");"); - break; - case FLOAT: - w.println("obj." + name + " = nbt.getFloat(\"" + name + "\");"); - break; - case DOUBLE: - w.println("obj." + name + " = nbt.getDouble(\"" + name + "\");"); - break; - // - case STRING: - w.println("obj." + name + " = nbt.getString(\"" + name + "\");"); - break; - case UUID: // TODO: non top-level UUIDs - w.println("obj." + name + " = nbt.getUUID(\"" + name + "\");"); - break; - default: - if (tu.isAssignable(type, eu.getTypeElement(NBT_STORABLE).asType())) { - w.println("if (nbt.hasKey(\"" + name + "\")) {"); - w.indent(); - w.println("obj." + name + " = new " + type + "();"); - w.println("obj." + name + ".readFromNBT(nbt.getCompoundTag(\"" + name + "\"));"); - w.unindent(); - w.println("}"); - } else { - w.println("if (nbt.hasKey(\"" + name + "\")) {"); - w.indent(); - w.println("NBTBase " + newVar("tag") + " = nbt.getTag(\"" + name + "\");"); - readNBTObject(w, type, newVar("arr"), var("tag")); // TODO: name should depend on field name - w.println("obj." + name + " = " + var("arr") + ";"); - w.unindent(); - w.println("}"); - } - break; - } - break; - default: - w.println("NBTBase " + newVar("tag") + " = nbt.getTag(\"" + name + "\");"); - readNBTObject(w, type, newVar("arr"), var("tag")); // TODO: name should depend on field name - w.println("obj." + name + " = " + var("arr") + ";"); - break; - } - } - - private void readNBTObject(IndentedPrintWriter w, TypeMirror type, String to, String nbt) { - switch (type.getKind()) { - case BOOLEAN: - w.println(type + " " + to + " = ((NBTTagByte) " + nbt + ").getByte() == 1;"); - break; - case BYTE: - w.println(type + " " + to + " = ((NBTTagByte) " + nbt + ").getByte();"); - break; - case SHORT: - w.println(type + " " + to + " = ((NBTTagShort) " + nbt + ").getShort();"); - break; - case INT: - w.println(type + " " + to + " = ((NBTTagInt) " + nbt + ").getInt();"); - break; - case LONG: - w.println(type + " " + to + " = ((NBTTagLong) " + nbt + ").getLong();"); - break; - case CHAR: - w.println(type + " " + to + " = (char) ((NBTTagInt) " + nbt + ").getInt();"); - break; - case FLOAT: - w.println(type + " " + to + " = ((NBTTagFloat) " + nbt + ").getFloat();"); - break; - case DOUBLE: - w.println(type + " " + to + " = ((NBTTagDouble) " + nbt + ").getDouble();"); - break; - case ARRAY: - TypeMirror componentType = ((ArrayType) type).getComponentType(); - if (componentType.getKind() == TypeKind.BYTE) { - w.println(type + " " + to + " = ((NBTTagByteArray) " + nbt + ").getByteArray();"); - } else if (componentType.getKind() == TypeKind.INT) { - w.println(type + " " + to + " = ((NBTTagIntArray) " + nbt + ").getIntArray();"); - } else { - if (componentType.getKind() == TypeKind.ARRAY) { // TODO: better array creation - w.println(type + " " + to + " = (" + type + ") new Object[((NBTTagList) " + nbt + ").tagCount()];"); - } else { - w.println(type + " " + to + " = new " + componentType + "[((NBTTagList) " + nbt + ").tagCount()];"); - } - String i = newVar("i"); // TODO: this is a workaround for not being able to varGone the variable - w.println("int " + i + " = 0;"); - w.println("for (NBTBase " + newVar("elementNBT") + " : (NBTTagList) " + nbt + ") {"); - w.indent(); - readNBTObject(w, componentType, newVar("element"), var("elementNBT")); // TODO: single line if possible - w.println(to + "[" + i + "++] = " + var("element") + ";"); - varGone("element"); - varGone("elementNBT"); - w.unindent(); - w.println("}"); - } - break; - case DECLARED: - DeclaredType declaredType = (DeclaredType) type; - switch (declaredType.toString()) { - // TODO: less code duplication - case BOOLEAN: - w.println(type + " " + to + " = ((NBTTagByte) " + nbt + ").getByte() == 1;"); - break; - case BYTE: - w.println(type + " " + to + " = ((NBTTagByte) " + nbt + ").getByte();"); - break; - case SHORT: - w.println(type + " " + to + " = ((NBTTagShort) " + nbt + ").getShort();"); - break; - case INTEGER: - w.println(type + " " + to + " = ((NBTTagInt) " + nbt + ").getInt();"); - break; - case LONG: - w.println(type + " " + to + " = ((NBTTagLong) " + nbt + ").getLong();"); - break; - case CHAR: - w.println(type + " " + to + " = (char) ((NBTTagInt) " + nbt + ").getInt();"); - break; - case FLOAT: - w.println(type + " " + to + " = ((NBTTagFloat) " + nbt + ").getFloat();"); - break; - case DOUBLE: - w.println(type + " " + to + " = ((NBTTagDouble) " + nbt + ").getDouble();"); - break; - // - case STRING: - w.println(type + " " + to + " = ((NBTTagString) " + nbt + ").getString();"); - break; - default: - Types types = processingEnv.getTypeUtils(); - Elements elements = processingEnv.getElementUtils(); - if (types.isAssignable(type, types.erasure(elements.getTypeElement(COLLECTION).asType()))) { - List typeArguments = ((DeclaredType) type).getTypeArguments(); - if (typeArguments.size() != 1) throw new RuntimeException("Missing type arguments for " + type); - TypeMirror elementType = typeArguments.get(0); - w.println(type + " " + to + " = " + makeContainer(type) + ";"); - w.println("for (NBTBase " + newVar("elementNBT") + " : (NBTTagList) " + nbt + ") {"); - w.indent(); - readNBTObject(w, elementType, newVar("element"), var("elementNBT")); // TODO: single line if possible - w.println(to + ".add(" + var("element") + ");"); - varGone("element"); - varGone("elementNBT"); - w.unindent(); - w.println("}"); - } else if (types.isAssignable(type, types.erasure(elements.getTypeElement(MAP).asType()))) { - List typeArguments = ((DeclaredType) type).getTypeArguments(); - if (typeArguments.size() != 2) throw new RuntimeException("Missing type arguments for " + type); - w.println(type + " " + to + " = " + makeContainer(type) + ";"); - w.println("for (NBTBase " + newVar("elementNBT") + " : (NBTTagList) " + nbt + ") {"); - w.indent(); - readNBTObject(w, typeArguments.get(0), newVar("key"), "((NBTTagCompound) " + var("elementNBT") + ").getTag(\"key\")"); - readNBTObject(w, typeArguments.get(1), newVar("value"), "((NBTTagCompound) " + var("elementNBT") + ").getTag(\"value\")"); - w.println(to + ".put(" + var("key") + ", " + var("value") + ");"); - varGone("key"); - varGone("value"); - varGone("elementNBT"); - w.unindent(); - w.println("}"); - } else if (types.isAssignable(type, elements.getTypeElement(NBT_STORABLE).asType())) { - w.println(type + " " + to + " = new " + type + "();"); - w.println(to + ".readFromNBT((NBTTagCompound) " + nbt + ");"); - } else if (types.isAssignable(type, elements.getTypeElement(VEC_3I).asType())) { - w.println(type + " " + to + " = new " + type + "(" - + "((NBTTagCompound) "+ nbt + ").getInteger(\"x\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"y\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\")" + ");"); - } else if (types.isAssignable(type, elements.getTypeElement(LOCATION).asType())) { - w.println(type + " " + to + " = new " + type + "(" - + "((NBTTagCompound) "+ nbt + ").getInteger(\"dim\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"x\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"y\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\")" + ");"); - } else if (types.isAssignable(type, elements.getTypeElement(RGBA).asType())) { - w.println(type + " " + to + " = new " + type + "(" - + "((NBTTagCompound) "+ nbt + ").getFloat(\"red\"), " - + "((NBTTagCompound) "+ nbt + ").getFloat(\"green\"), " - + "((NBTTagCompound) "+ nbt + ").getFloat(\"blue\"), " - + "((NBTTagCompound) "+ nbt + ").getFloat(\"alpha\")" + ");"); - } else if (types.isAssignable(type, elements.getTypeElement(VIRTUAL_LOCATION).asType())) { - w.println(type + " " + to + " = new " + type + "(" - + "((NBTTagCompound) "+ nbt + ").getInteger(\"dim\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"x\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"y\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"depth\")" + ");"); - } else if (((DeclaredType) type).asElement().getKind() == ElementKind.ENUM) { - w.println(type + " " + to + " = " + type + ".values()[((NBTTagInt) " + nbt + ").getInt()" + "];"); - } else { - throw new RuntimeException("Unsupported type " + type + " for variable " + to + "!"); - } - } - break; - default: - throw new RuntimeException("Unsupported type kind for type " + type + " for variable " + to + "!"); - } - } - - private Object makeContainer(TypeMirror type) { - Types types = processingEnv.getTypeUtils(); - Elements elements = processingEnv.getElementUtils(); - if (types.isAssignable(types.erasure(elements.getTypeElement("java.util.List").asType()), type)) { - return "new java.util.ArrayList<>()"; - } else if (types.isAssignable(types.erasure(elements.getTypeElement("java.util.Set").asType()), type)) { - return "new java.util.HashSet<>()"; - } else if (types.isAssignable(types.erasure(elements.getTypeElement("java.util.Map").asType()), type)) { - return "new java.util.HashMap<>()"; - } else if (types.isAssignable(types.erasure(elements.getTypeElement("com.google.common.collect.BiMap").asType()), type)) { - return "com.google.common.collect.HashBiMap.create()"; - } else if (types.isAssignable(types.erasure(elements.getTypeElement("com.google.common.collect.Multiset").asType()), type)) { - return "com.google.common.collect.HashMultiset.create()"; - } else { // TODO: check that it can be instantiated, don't use generic params - return "new " + type + "()"; - } - } - - private String newVar(String name) { - varCounter.put(name, varCounter.getOrDefault(name, -1) + 1); - return var(name); - } - - private void varGone(String name) { - if (varCounter.get(name) < 0) throw new IllegalStateException("Can't set variable to negative index!"); - varCounter.put(name, varCounter.get(name) - 1); - } - - private String var(String name) { - if (varCounter.get(name) == 0) { - return name; - } else { - return name + varCounter.get(name); - } - } -} diff --git a/AnnotatedNBT/src/main/resources/META-INF/services/javax.annotation.proces‌​sing.Processor b/AnnotatedNBT/src/main/resources/META-INF/services/javax.annotation.proces‌​sing.Processor deleted file mode 100644 index 3693ddc4..00000000 --- a/AnnotatedNBT/src/main/resources/META-INF/services/javax.annotation.proces‌​sing.Processor +++ /dev/null @@ -1 +0,0 @@ -org.dimdev.ddutils.nbt.SavedToNBTProcessor \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5c012c3c..18d0a300 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,10 @@ plugins { apply plugin: 'java' apply plugin: 'net.minecraftforge.gradle.forge' +repositories { + maven { url "https://jitpack.io" } +} + // Version info String baseversion = "3.0.0" // Set beta to 0 after changing this int beta = 4 // Set this to 0 for a non-beta release @@ -42,10 +46,7 @@ jar.archiveName = "dimdoors.jar" // Constant name for travis sourceCompatibility = "1.8" compileJava { - options.compilerArgs += [ - //"-proc:only", // TODO: have generated code available for debugging - "-processor", "org.dimdev.ddutils.nbt.SavedToNBTProcessor,lombok.launch.AnnotationProcessorHider\$AnnotationProcessor" - ] + //options.compilerArgs += "-proc:only" } minecraft { @@ -63,7 +64,7 @@ configurations { dependencies { embed 'com.flowpowered:flow-math:1.0.3' - compile project(':AnnotatedNBT') + compile 'com.github.DimensionalDevelopment:AnnotatedNBT:master-SNAPSHOT' } jar { @@ -79,9 +80,9 @@ processResources { from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version + expand 'version': project.version, 'mcversion': project.minecraft.version } - + // copy everything else, thats not the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' @@ -95,3 +96,7 @@ task generatePocketSchematics(dependsOn: jar, type: JavaExec, group: "dimdoors") //noinspection GroovyAssignabilityCheck (IntelliJ is wrong) args "src/main/resources/assets/dimdoors/pockets/schematic" } + +runClient { + args '--username', 'Runemoro' +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 559c6d56..00000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include 'AnnotatedNBT' diff --git a/src/main/java/org/dimdev/ddutils/RotatedLocation.java b/src/main/java/org/dimdev/ddutils/RotatedLocation.java index ce438957..c2404b63 100644 --- a/src/main/java/org/dimdev/ddutils/RotatedLocation.java +++ b/src/main/java/org/dimdev/ddutils/RotatedLocation.java @@ -4,13 +4,14 @@ import lombok.*; import net.minecraft.nbt.NBTTagCompound; import org.dimdev.ddutils.nbt.INBTStorable; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; @ToString @AllArgsConstructor @NoArgsConstructor -@SavedToNBT public class RotatedLocation implements INBTStorable { - @Getter @SavedToNBT /*private*/ Location location; - @Getter @SavedToNBT /*private*/ float yaw; - @Getter @SavedToNBT /*private*/ float pitch; +@NBTSerializable public class RotatedLocation implements INBTStorable { + @Getter @Saved /*private*/ Location location; + @Getter @Saved /*private*/ float yaw; + @Getter @Saved /*private*/ float pitch; @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); } @Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); } diff --git a/src/main/java/org/dimdev/ddutils/nbt/NBTTest.java b/src/main/java/org/dimdev/ddutils/nbt/NBTTest.java index 3f03e8fd..1f21ac14 100644 --- a/src/main/java/org/dimdev/ddutils/nbt/NBTTest.java +++ b/src/main/java/org/dimdev/ddutils/nbt/NBTTest.java @@ -2,6 +2,8 @@ package org.dimdev.ddutils.nbt; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3i; +import org.dimdev.annotatednbt.NBTSerializable; +import org.dimdev.annotatednbt.Saved; import org.dimdev.ddutils.Location; import org.dimdev.dimdoors.shared.pockets.Pocket; @@ -9,36 +11,35 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -@SavedToNBT -public final class NBTTest { - @SavedToNBT public boolean a; - @SavedToNBT public byte b; - @SavedToNBT public short c; - @SavedToNBT public int d; - @SavedToNBT public long e; - @SavedToNBT public char f; - @SavedToNBT public float g; - @SavedToNBT public double h; - @SavedToNBT public byte[] i; - @SavedToNBT public int[] j; - @SavedToNBT public boolean[] k; - @SavedToNBT public byte[] l; - @SavedToNBT public short[] m; - @SavedToNBT public int[] n; - @SavedToNBT public long[] o; - @SavedToNBT public float[] p; - @SavedToNBT public double[] q; - @SavedToNBT public byte[][] r; - @SavedToNBT public int[][] s; - @SavedToNBT public String str; - @SavedToNBT public Vec3i vec3i; - @SavedToNBT public BlockPos blockPos; - @SavedToNBT public Location location; - @SavedToNBT public String[] strArr; - @SavedToNBT public String[][] strArrArr; - //@SavedToNBT public String[][][][][][][][][][][][][][][] test; - @SavedToNBT public Pocket nbtStorable; - @SavedToNBT public List list = new ArrayList<>(); - @SavedToNBT public Map map; - @SavedToNBT public Map, int[]>, Map>> test2; +@NBTSerializable public final class NBTTest { + @Saved public boolean a; + @Saved public byte b; + @Saved public short c; + @Saved public int d; + @Saved public long e; + @Saved public char f; + @Saved public float g; + @Saved public double h; + @Saved public byte[] i; + @Saved public int[] j; + @Saved public boolean[] k; + @Saved public byte[] l; + @Saved public short[] m; + @Saved public int[] n; + @Saved public long[] o; + @Saved public float[] p; + @Saved public double[] q; + @Saved public byte[][] r; + @Saved public int[][] s; + @Saved public String str; + @Saved public Vec3i vec3i; + @Saved public BlockPos blockPos; + @Saved public Location location; + @Saved public String[] strArr; + @Saved public String[][] strArrArr; + //@Saved public String[][][][][][][][][][][][][][][] test; + @Saved public Pocket nbtStorable; + @Saved public List list = new ArrayList<>(); + @Saved public Map map; + @Saved public Map, int[]>, Map>> test2; } diff --git a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockDimensionalDoor.java b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockDimensionalDoor.java index ee1d492c..cbc77719 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockDimensionalDoor.java +++ b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockDimensionalDoor.java @@ -134,6 +134,7 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro TileEntityFloatingRift newRift = (TileEntityFloatingRift) world.getTileEntity(pos); newRift.copyFrom(rift); newRift.updateAvailableLinks(); + world.notifyBlockUpdate(rift.getPos(), state, world.getBlockState(pos), 0); // TODO: does this work? } else { rift.unregister(); } diff --git a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFabric.java b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFabric.java index 760e6213..a307ab31 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFabric.java +++ b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFabric.java @@ -159,7 +159,7 @@ public class BlockFabric extends Block { if (heldItem.getItem() instanceof ItemBlock && (state.getValue(TYPE).equals(EnumType.REALITY) || state.getValue(TYPE).equals(EnumType.ALTERED))) { Block block = Block.getBlockFromItem(heldItem.getItem()); - if (!state.isNormalCube() || block.hasTileEntity(block.getDefaultState()) + if (!block.getDefaultState().isNormalCube() || block.hasTileEntity(block.getDefaultState()) || block == this // this also keeps it from being replaced by Ancient Fabric || player.isSneaking()) { // TODO: what if the player is holding shift but not sneaking? return false; diff --git a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFloatingRift.java b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFloatingRift.java index 10890234..b7634469 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFloatingRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/blocks/BlockFloatingRift.java @@ -2,6 +2,7 @@ package org.dimdev.dimdoors.shared.blocks; import java.util.*; +import net.minecraft.tileentity.TileEntity; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.client.ParticleRiftEffect; import org.dimdev.dimdoors.shared.items.ModItems; @@ -79,8 +80,10 @@ public class BlockFloatingRift extends BlockSpecialAir implements ITileEntityPro @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { // TODO //ArrayList targets = findReachableBlocks(world, pos, 2, false); - TileEntityFloatingRift rift = (TileEntityFloatingRift) world.getTileEntity(pos); - + TileEntity tileEntity = world.getTileEntity(pos); + // Workaround minecraft/forge bug where this is called even before the TileEntity is created in multiplayer + if (!(tileEntity instanceof TileEntityFloatingRift)) return; + TileEntityFloatingRift rift = (TileEntityFloatingRift) tileEntity; if (0 > 0) { FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.GogglesRiftEffect( world, diff --git a/src/main/java/org/dimdev/dimdoors/shared/pockets/Pocket.java b/src/main/java/org/dimdev/dimdoors/shared/pockets/Pocket.java index e356550d..2a3a7f13 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/pockets/Pocket.java +++ b/src/main/java/org/dimdev/dimdoors/shared/pockets/Pocket.java @@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.pockets; import org.dimdev.ddutils.nbt.INBTStorable; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.shared.VirtualLocation; import org.dimdev.dimdoors.shared.rifts.*; import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift; @@ -17,15 +18,15 @@ import net.minecraft.nbt.*; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; -@SavedToNBT public class Pocket implements INBTStorable { // TODO: better visibilities +@NBTSerializable public class Pocket implements INBTStorable { // TODO: better visibilities - @SavedToNBT @Getter /*package-private*/ int id; - @SavedToNBT @Getter /*package-private*/ int x; // Grid x TODO: rename to gridX and gridY - @SavedToNBT @Getter /*package-private*/ int z; // Grid y - @SavedToNBT @Getter @Setter /*package-private*/ int size; // In chunks TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc. - @SavedToNBT @Getter @Setter /*package-private*/ VirtualLocation virtualLocation; // The non-pocket dimension from which this dungeon was created - @SavedToNBT @Getter @Setter /*package-private*/ Location entrance; - @SavedToNBT @Getter /*package-private*/ List riftLocations; + @Saved @Getter /*package-private*/ int id; + @Saved @Getter /*package-private*/ int x; // Grid x TODO: rename to gridX and gridY + @Saved @Getter /*package-private*/ int z; // Grid y + @Saved @Getter @Setter /*package-private*/ int size; // In chunks TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc. + @Saved @Getter @Setter /*package-private*/ VirtualLocation virtualLocation; // The non-pocket dimension from which this dungeon was created + @Saved @Getter @Setter /*package-private*/ Location entrance; + @Saved @Getter /*package-private*/ List riftLocations; @Getter int dim; // Not saved diff --git a/src/main/java/org/dimdev/dimdoors/shared/pockets/PocketRegistry.java b/src/main/java/org/dimdev/dimdoors/shared/pockets/PocketRegistry.java index adcd7f61..d40de5bd 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/pockets/PocketRegistry.java +++ b/src/main/java/org/dimdev/dimdoors/shared/pockets/PocketRegistry.java @@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.pockets; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.shared.Config; import org.dimdev.ddutils.math.GridUtils; import org.dimdev.dimdoors.DimDoors; @@ -20,18 +21,18 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.storage.MapStorage; import net.minecraft.world.storage.WorldSavedData; -@SavedToNBT public class PocketRegistry extends WorldSavedData { // TODO: unregister pocket entrances, private pocket entrances/exits +@NBTSerializable public class PocketRegistry extends WorldSavedData { // TODO: unregister pocket entrances, private pocket entrances/exits private static final String DATA_NAME = DimDoors.MODID + "_pockets"; @Getter private static final int DATA_VERSION = 0; // IMPORTANT: Update this and upgradeRegistry when making changes. - @SavedToNBT @Getter /*package-private*/ int gridSize; // Determines how much pockets in their dimension are spaced - @SavedToNBT @Getter /*package-private*/ int maxPocketSize; - @SavedToNBT @Getter /*package-private*/ int privatePocketSize; - @SavedToNBT @Getter /*package-private*/ int publicPocketSize; - @SavedToNBT /*package-private*/ BiMap privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only - @SavedToNBT @Getter /*package-private*/ Map pockets; // TODO: remove getter? - @SavedToNBT @Getter /*package-private*/ int nextID; + @Saved @Getter /*package-private*/ int gridSize; // Determines how much pockets in their dimension are spaced + @Saved @Getter /*package-private*/ int maxPocketSize; + @Saved @Getter /*package-private*/ int privatePocketSize; + @Saved @Getter /*package-private*/ int publicPocketSize; + @Saved /*package-private*/ BiMap privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only + @Saved @Getter /*package-private*/ Map pockets; // TODO: remove getter? + @Saved @Getter /*package-private*/ int nextID; @Getter private int dim; diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/AvailableLinkDestination.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/AvailableLinkDestination.java index 48dbf1ee..5c895c86 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/AvailableLinkDestination.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/AvailableLinkDestination.java @@ -1,7 +1,8 @@ package org.dimdev.dimdoors.shared.rifts; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.shared.VirtualLocation; import org.dimdev.ddutils.Location; import org.dimdev.ddutils.math.MathUtils; @@ -19,19 +20,19 @@ import java.util.Map; import java.util.UUID; @Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString -@SavedToNBT public class AvailableLinkDestination extends RiftDestination { // TODO - @SavedToNBT protected float newDungeonRiftProbability; - @SavedToNBT protected float depthPenalization; // TODO: these make the equation assymetric - @SavedToNBT protected float distancePenalization; - @SavedToNBT protected float closenessPenalization; +@NBTSerializable public class AvailableLinkDestination extends RiftDestination { // TODO + @Saved protected float newDungeonRiftProbability; + @Saved protected float depthPenalization; // TODO: these make the equation assymetric + @Saved protected float distancePenalization; + @Saved protected float closenessPenalization; - @SavedToNBT protected boolean dungeonRiftsOnly; - @SavedToNBT protected boolean overworldRifts; - @SavedToNBT protected boolean unstable; - @SavedToNBT protected float nonFloatingRiftWeight; - @SavedToNBT protected float floatingRiftWeight; + @Saved protected boolean dungeonRiftsOnly; + @Saved protected boolean overworldRifts; + @Saved protected boolean unstable; + @Saved protected float nonFloatingRiftWeight; + @Saved protected float floatingRiftWeight; - @SavedToNBT protected boolean noLinkBack; + @Saved protected boolean noLinkBack; // private int maxLinks; @Builder.Default private UUID uuid = UUID.randomUUID(); diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/GlobalDestination.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/GlobalDestination.java index 7cac0981..3f26c30b 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/GlobalDestination.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/GlobalDestination.java @@ -8,11 +8,12 @@ import lombok.ToString; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; @Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString -@SavedToNBT public class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft? - @SavedToNBT @Getter protected Location loc; +@NBTSerializable public class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft? + @Saved @Getter protected Location loc; public GlobalDestination() {} diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/LocalDestination.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/LocalDestination.java index bd2b4946..e53a32e6 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/LocalDestination.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/LocalDestination.java @@ -9,11 +9,12 @@ import lombok.ToString; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; @Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString -@SavedToNBT public class LocalDestination extends RiftDestination { // TODO: use BlockPos - @SavedToNBT protected BlockPos pos; +@NBTSerializable public class LocalDestination extends RiftDestination { // TODO: use BlockPos + @Saved protected BlockPos pos; public LocalDestination() {} diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/PocketEntranceDestination.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/PocketEntranceDestination.java index f22589c4..993aabc2 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/PocketEntranceDestination.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/PocketEntranceDestination.java @@ -1,7 +1,8 @@ package org.dimdev.dimdoors.shared.rifts; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.DimDoors; import lombok.AllArgsConstructor; import lombok.Builder; @@ -15,10 +16,10 @@ import java.util.LinkedList; import java.util.List; @Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString -@SavedToNBT public class PocketEntranceDestination extends RiftDestination { - @SavedToNBT protected float weight; - @SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List ifDestinations = new LinkedList<>(); // TODO addIfDestination method in builder - @SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List otherwiseDestinations = new LinkedList<>(); // TODO addOtherwiseDestination method in builder +@NBTSerializable public class PocketEntranceDestination extends RiftDestination { + @Saved protected float weight; + @Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List ifDestinations = new LinkedList<>(); // TODO addIfDestination method in builder + @Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List otherwiseDestinations = new LinkedList<>(); // TODO addOtherwiseDestination method in builder public PocketEntranceDestination() {} diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/RelativeDestination.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/RelativeDestination.java index 033f4708..bc8938ad 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/RelativeDestination.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/RelativeDestination.java @@ -9,11 +9,12 @@ import lombok.ToString; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.Vec3i; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; @Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString -@SavedToNBT public class RelativeDestination extends RiftDestination { // TODO: use Vec3i - @SavedToNBT protected Vec3i offset; +@NBTSerializable public class RelativeDestination extends RiftDestination { // TODO: use Vec3i + @Saved protected Vec3i offset; public RelativeDestination() {} diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java index 5d637b84..2b8d116b 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java @@ -13,7 +13,8 @@ import org.dimdev.ddutils.Location; import org.dimdev.ddutils.WorldUtils; import org.dimdev.ddutils.nbt.INBTStorable; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.shared.VirtualLocation; import org.dimdev.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo; @@ -21,33 +22,33 @@ import org.dimdev.dimdoors.shared.world.ModDimensions; import java.util.*; -@SavedToNBT public class RiftRegistry extends WorldSavedData { +@NBTSerializable public class RiftRegistry extends WorldSavedData { private static final String DATA_NAME = DimDoors.MODID + "_rifts"; @Getter private static final int DATA_VERSION = 0; // IMPORTANT: Update this and upgradeRegistry when making changes. - @SavedToNBT @Getter protected /*final*/ Map rifts = new HashMap<>(); // TODO: convert to a static directed graph, but store links per-world - @SavedToNBT @Getter protected /*final*/ Map privatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket TODO: split into PrivatePocketRiftRegistry subclass - @SavedToNBT @Getter protected /*final*/ Map> privatePocketEntranceLists = new HashMap<>(); // Player UUID -> private pocket entrances TODO: split into PrivatePocketRiftRegistry subclass - @SavedToNBT @Getter protected /*final*/ Map privatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket - @SavedToNBT @Getter protected /*final*/ Map overworldRifts = new HashMap<>(); + @Saved @Getter protected /*final*/ Map rifts = new HashMap<>(); // TODO: convert to a static directed graph, but store links per-world + @Saved @Getter protected /*final*/ Map privatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket TODO: split into PrivatePocketRiftRegistry subclass + @Saved @Getter protected /*final*/ Map> privatePocketEntranceLists = new HashMap<>(); // Player UUID -> private pocket entrances TODO: split into PrivatePocketRiftRegistry subclass + @Saved @Getter protected /*final*/ Map privatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket + @Saved @Getter protected /*final*/ Map overworldRifts = new HashMap<>(); @Getter private int dim; private World world; @AllArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true) - @SavedToNBT public static class RiftInfo implements INBTStorable { + @NBTSerializable public static class RiftInfo implements INBTStorable { // IntelliJ warnings are wrong, Builder needs these initializers! - @SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Set availableLinks = new HashSet<>(); // TODO: multiset? - @SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset sources = ConcurrentHashMultiset.create(); - @SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset destinations = ConcurrentHashMultiset.create(); + @Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Set availableLinks = new HashSet<>(); // TODO: multiset? + @Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset sources = ConcurrentHashMultiset.create(); + @Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset destinations = ConcurrentHashMultiset.create(); - @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true) + @NBTSerializable @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true) public static class AvailableLinkInfo implements INBTStorable { - @SavedToNBT @Getter @Setter /*package-private*/ float weight; - @SavedToNBT @Getter /*package-private*/ VirtualLocation virtualLocation; - @SavedToNBT @Getter @Wither /*package-private*/ Location location; - @SavedToNBT @Getter /*package-private*/ UUID uuid; + @Saved @Getter @Setter /*package-private*/ float weight; + @Saved @Getter /*package-private*/ VirtualLocation virtualLocation; + @Saved @Getter @Wither /*package-private*/ Location location; + @Saved @Getter /*package-private*/ UUID uuid; @Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); } diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java index ff68f73d..55d66187 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java @@ -1,7 +1,8 @@ package org.dimdev.dimdoors.shared.rifts; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.ddutils.RGBA; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.shared.VirtualLocation; @@ -32,18 +33,18 @@ import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull; import java.util.*; -@SavedToNBT public abstract class TileEntityRift extends TileEntity implements ITickable { // TODO: implement ITeleportSource and ITeleportDestination +@NBTSerializable public abstract class TileEntityRift extends TileEntity implements ITickable { // TODO: implement ITeleportSource and ITeleportDestination - @SavedToNBT@Getter protected VirtualLocation virtualLocation; - @SavedToNBT @Nonnull @Getter protected List destinations; // Not using a set because we can have duplicate destinations. Maybe use Multiset from Guava? - @SavedToNBT @Getter protected boolean makeDestinationPermanent; - @SavedToNBT @Getter protected boolean preserveRotation; - @SavedToNBT @Getter protected float yaw; - @SavedToNBT @Getter protected float pitch; - @SavedToNBT @Getter protected boolean alwaysDelete; // Delete the rift when an entrances rift is broken even if the state was changed or destinations link there. - @SavedToNBT @Getter protected float chaosWeight; - @SavedToNBT @Getter protected boolean forcedColor; - @SavedToNBT @Getter protected RGBA color = null; // TODO: update AnnotatedNBT to be able to save these + @Saved @Getter protected VirtualLocation virtualLocation; + @Saved @Nonnull @Getter protected List destinations; // Not using a set because we can have duplicate destinations. Maybe use Multiset from Guava? + @Saved @Getter protected boolean makeDestinationPermanent; + @Saved @Getter protected boolean preserveRotation; + @Saved @Getter protected float yaw; + @Saved @Getter protected float pitch; + @Saved @Getter protected boolean alwaysDelete; // Delete the rift when an entrances rift is broken even if the state was changed or destinations link there. + @Saved @Getter protected float chaosWeight; + @Saved @Getter protected boolean forcedColor; + @Saved @Getter protected RGBA color = null; // TODO: update AnnotatedNBT to be able to save these // TODO: option to convert to door on teleportTo? protected boolean riftStateChanged; // not saved diff --git a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java index dd98dbee..b046c32a 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java @@ -1,7 +1,8 @@ package org.dimdev.dimdoors.shared.tileentities; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.shared.rifts.TileEntityRift; import org.dimdev.ddutils.Location; import org.dimdev.ddutils.RGBA; @@ -14,20 +15,20 @@ import net.minecraft.util.EnumFacing; import java.util.Random; // TODO: merge horizontal and vertical entrances' render code into one, and support custom sizes -@SavedToNBT public class TileEntityEntranceRift extends TileEntityRift { - @SavedToNBT @Getter /*package-private*/ boolean placeRiftOnBreak = false; - @SavedToNBT @Getter /*package-private*/ boolean closeAfterPassThrough = false; - @SavedToNBT @Getter public boolean shouldRender = true; - @SavedToNBT @Getter public byte lockStatus = 0; +@NBTSerializable public class TileEntityEntranceRift extends TileEntityRift { + @Saved @Getter /*package-private*/ boolean placeRiftOnBreak = false; + @Saved @Getter /*package-private*/ boolean closeAfterPassThrough = false; + @Saved @Getter public boolean shouldRender = true; + @Saved @Getter public byte lockStatus = 0; // Set by the block, not saved and not synced to the client - @SavedToNBT public EnumFacing orientation; - @SavedToNBT public int tpOffset = 1; // TODO: float? - @SavedToNBT public double extendUp = 0.5; // Use += to set these. TODO: @SideOnly client? - @SavedToNBT public double extendDown = 0.5; - @SavedToNBT public double extendLeft = 0.5; - @SavedToNBT public double extendRight = 0.5; - @SavedToNBT public double pushIn = 0.01; // TODO: set to 0, and set on door + @Saved public EnumFacing orientation; + @Saved public int tpOffset = 1; // TODO: float? + @Saved public double extendUp = 0.5; // Use += to set these. TODO: @SideOnly client? + @Saved public double extendDown = 0.5; + @Saved public double extendLeft = 0.5; + @Saved public double extendRight = 0.5; + @Saved public double pushIn = 0.01; // TODO: set to 0, and set on door @Override public void copyFrom(TileEntityRift oldRift) { diff --git a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityFloatingRift.java b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityFloatingRift.java index b9ee6ef1..403008ea 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityFloatingRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityFloatingRift.java @@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.tileentities; import lombok.Setter; import org.dimdev.ddutils.nbt.NBTUtils; -import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.annotatednbt.Saved; +import org.dimdev.annotatednbt.NBTSerializable; import org.dimdev.dimdoors.shared.blocks.ModBlocks; import java.util.List; import java.util.Random; @@ -15,7 +16,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; -@SavedToNBT public class TileEntityFloatingRift extends TileEntityRift implements ITickable { +@NBTSerializable public class TileEntityFloatingRift extends TileEntityRift implements ITickable { private static final int ENDERMAN_SPAWNING_CHANCE = 1; private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32; @@ -26,10 +27,10 @@ import net.minecraft.util.math.AxisAlignedBB; private static final Random random = new Random(); //Need to be saved: - @SavedToNBT /*package-private*/ int updateTimer; - @SavedToNBT public boolean shouldClose = false; // TODO - @SavedToNBT public int spawnedEndermenID = 0; - @SavedToNBT public float growth = 0; + @Saved /*package-private*/ int updateTimer; + @Saved public boolean shouldClose = false; // TODO + @Saved public int spawnedEndermenID = 0; + @Saved public float growth = 0; @Setter private boolean unregisterDisabled = false;