Split AnnotatedNBT and bug fixes
This commit is contained in:
parent
7748818ef3
commit
29f9cfc6de
23 changed files with 160 additions and 871 deletions
|
@ -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"
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String, Integer> varCounter = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean process(Set<? extends TypeElement> 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<VariableElement> 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()) {
|
|
||||||
// <editor-fold> 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;
|
|
||||||
// </editor-fold>
|
|
||||||
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()) {
|
|
||||||
// <editor-fold> 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;
|
|
||||||
// </editor-fold>
|
|
||||||
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<? extends TypeMirror> 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<? extends TypeMirror> 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<? extends TypeMirror> 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()) {
|
|
||||||
// <editor-fold> 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;
|
|
||||||
// </editor-fold>
|
|
||||||
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()) {
|
|
||||||
// <editor-fold> 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;
|
|
||||||
// </editor-fold>
|
|
||||||
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<? extends TypeMirror> 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<? extends TypeMirror> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
org.dimdev.ddutils.nbt.SavedToNBTProcessor
|
|
17
build.gradle
17
build.gradle
|
@ -16,6 +16,10 @@ plugins {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://jitpack.io" }
|
||||||
|
}
|
||||||
|
|
||||||
// Version info
|
// Version info
|
||||||
String baseversion = "3.0.0" // Set beta to 0 after changing this
|
String baseversion = "3.0.0" // Set beta to 0 after changing this
|
||||||
int beta = 4 // Set this to 0 for a non-beta release
|
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"
|
sourceCompatibility = "1.8"
|
||||||
compileJava {
|
compileJava {
|
||||||
options.compilerArgs += [
|
//options.compilerArgs += "-proc:only"
|
||||||
//"-proc:only", // TODO: have generated code available for debugging
|
|
||||||
"-processor", "org.dimdev.ddutils.nbt.SavedToNBTProcessor,lombok.launch.AnnotationProcessorHider\$AnnotationProcessor"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
|
@ -63,7 +64,7 @@ configurations {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
embed 'com.flowpowered:flow-math:1.0.3'
|
embed 'com.flowpowered:flow-math:1.0.3'
|
||||||
compile project(':AnnotatedNBT')
|
compile 'com.github.DimensionalDevelopment:AnnotatedNBT:master-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
@ -79,7 +80,7 @@ processResources {
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include 'mcmod.info'
|
include 'mcmod.info'
|
||||||
// replace version and mcversion
|
// 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
|
// copy everything else, thats not the mcmod.info
|
||||||
|
@ -95,3 +96,7 @@ task generatePocketSchematics(dependsOn: jar, type: JavaExec, group: "dimdoors")
|
||||||
//noinspection GroovyAssignabilityCheck (IntelliJ is wrong)
|
//noinspection GroovyAssignabilityCheck (IntelliJ is wrong)
|
||||||
args "src/main/resources/assets/dimdoors/pockets/schematic"
|
args "src/main/resources/assets/dimdoors/pockets/schematic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runClient {
|
||||||
|
args '--username', 'Runemoro'
|
||||||
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
include 'AnnotatedNBT'
|
|
|
@ -4,13 +4,14 @@ import lombok.*;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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
|
@ToString @AllArgsConstructor @NoArgsConstructor
|
||||||
@SavedToNBT public class RotatedLocation implements INBTStorable {
|
@NBTSerializable public class RotatedLocation implements INBTStorable {
|
||||||
@Getter @SavedToNBT /*private*/ Location location;
|
@Getter @Saved /*private*/ Location location;
|
||||||
@Getter @SavedToNBT /*private*/ float yaw;
|
@Getter @Saved /*private*/ float yaw;
|
||||||
@Getter @SavedToNBT /*private*/ float pitch;
|
@Getter @Saved /*private*/ float pitch;
|
||||||
|
|
||||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); }
|
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); }
|
||||||
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.dimdev.ddutils.nbt;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import org.dimdev.annotatednbt.NBTSerializable;
|
||||||
|
import org.dimdev.annotatednbt.Saved;
|
||||||
import org.dimdev.ddutils.Location;
|
import org.dimdev.ddutils.Location;
|
||||||
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||||
|
|
||||||
|
@ -9,36 +11,35 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SavedToNBT
|
@NBTSerializable public final class NBTTest {
|
||||||
public final class NBTTest {
|
@Saved public boolean a;
|
||||||
@SavedToNBT public boolean a;
|
@Saved public byte b;
|
||||||
@SavedToNBT public byte b;
|
@Saved public short c;
|
||||||
@SavedToNBT public short c;
|
@Saved public int d;
|
||||||
@SavedToNBT public int d;
|
@Saved public long e;
|
||||||
@SavedToNBT public long e;
|
@Saved public char f;
|
||||||
@SavedToNBT public char f;
|
@Saved public float g;
|
||||||
@SavedToNBT public float g;
|
@Saved public double h;
|
||||||
@SavedToNBT public double h;
|
@Saved public byte[] i;
|
||||||
@SavedToNBT public byte[] i;
|
@Saved public int[] j;
|
||||||
@SavedToNBT public int[] j;
|
@Saved public boolean[] k;
|
||||||
@SavedToNBT public boolean[] k;
|
@Saved public byte[] l;
|
||||||
@SavedToNBT public byte[] l;
|
@Saved public short[] m;
|
||||||
@SavedToNBT public short[] m;
|
@Saved public int[] n;
|
||||||
@SavedToNBT public int[] n;
|
@Saved public long[] o;
|
||||||
@SavedToNBT public long[] o;
|
@Saved public float[] p;
|
||||||
@SavedToNBT public float[] p;
|
@Saved public double[] q;
|
||||||
@SavedToNBT public double[] q;
|
@Saved public byte[][] r;
|
||||||
@SavedToNBT public byte[][] r;
|
@Saved public int[][] s;
|
||||||
@SavedToNBT public int[][] s;
|
@Saved public String str;
|
||||||
@SavedToNBT public String str;
|
@Saved public Vec3i vec3i;
|
||||||
@SavedToNBT public Vec3i vec3i;
|
@Saved public BlockPos blockPos;
|
||||||
@SavedToNBT public BlockPos blockPos;
|
@Saved public Location location;
|
||||||
@SavedToNBT public Location location;
|
@Saved public String[] strArr;
|
||||||
@SavedToNBT public String[] strArr;
|
@Saved public String[][] strArrArr;
|
||||||
@SavedToNBT public String[][] strArrArr;
|
//@Saved public String[][][][][][][][][][][][][][][] test;
|
||||||
//@SavedToNBT public String[][][][][][][][][][][][][][][] test;
|
@Saved public Pocket nbtStorable;
|
||||||
@SavedToNBT public Pocket nbtStorable;
|
@Saved public List<Integer> list = new ArrayList<>();
|
||||||
@SavedToNBT public List<Integer> list = new ArrayList<>();
|
@Saved public Map<String, Integer> map;
|
||||||
@SavedToNBT public Map<String, Integer> map;
|
@Saved public Map<Map<List<String>, int[]>, Map<Pocket, List<Pocket>>> test2;
|
||||||
@SavedToNBT public Map<Map<List<String>, int[]>, Map<Pocket, List<Pocket>>> test2;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
|
||||||
TileEntityFloatingRift newRift = (TileEntityFloatingRift) world.getTileEntity(pos);
|
TileEntityFloatingRift newRift = (TileEntityFloatingRift) world.getTileEntity(pos);
|
||||||
newRift.copyFrom(rift);
|
newRift.copyFrom(rift);
|
||||||
newRift.updateAvailableLinks();
|
newRift.updateAvailableLinks();
|
||||||
|
world.notifyBlockUpdate(rift.getPos(), state, world.getBlockState(pos), 0); // TODO: does this work?
|
||||||
} else {
|
} else {
|
||||||
rift.unregister();
|
rift.unregister();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))) {
|
if (heldItem.getItem() instanceof ItemBlock && (state.getValue(TYPE).equals(EnumType.REALITY) || state.getValue(TYPE).equals(EnumType.ALTERED))) {
|
||||||
Block block = Block.getBlockFromItem(heldItem.getItem());
|
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
|
|| 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?
|
|| player.isSneaking()) { // TODO: what if the player is holding shift but not sneaking?
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.dimdev.dimdoors.shared.blocks;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import org.dimdev.dimdoors.DimDoors;
|
import org.dimdev.dimdoors.DimDoors;
|
||||||
import org.dimdev.dimdoors.client.ParticleRiftEffect;
|
import org.dimdev.dimdoors.client.ParticleRiftEffect;
|
||||||
import org.dimdev.dimdoors.shared.items.ModItems;
|
import org.dimdev.dimdoors.shared.items.ModItems;
|
||||||
|
@ -79,8 +80,10 @@ public class BlockFloatingRift extends BlockSpecialAir implements ITileEntityPro
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { // TODO
|
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { // TODO
|
||||||
//ArrayList<BlockPos> targets = findReachableBlocks(world, pos, 2, false);
|
//ArrayList<BlockPos> 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) {
|
if (0 > 0) {
|
||||||
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.GogglesRiftEffect(
|
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.GogglesRiftEffect(
|
||||||
world,
|
world,
|
||||||
|
|
|
@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.pockets;
|
||||||
|
|
||||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.VirtualLocation;
|
||||||
import org.dimdev.dimdoors.shared.rifts.*;
|
import org.dimdev.dimdoors.shared.rifts.*;
|
||||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||||
|
@ -17,15 +18,15 @@ import net.minecraft.nbt.*;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
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;
|
@Saved @Getter /*package-private*/ int id;
|
||||||
@SavedToNBT @Getter /*package-private*/ int x; // Grid x TODO: rename to gridX and gridY
|
@Saved @Getter /*package-private*/ int x; // Grid x TODO: rename to gridX and gridY
|
||||||
@SavedToNBT @Getter /*package-private*/ int z; // Grid y
|
@Saved @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.
|
@Saved @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
|
@Saved @Getter @Setter /*package-private*/ VirtualLocation virtualLocation; // The non-pocket dimension from which this dungeon was created
|
||||||
@SavedToNBT @Getter @Setter /*package-private*/ Location entrance;
|
@Saved @Getter @Setter /*package-private*/ Location entrance;
|
||||||
@SavedToNBT @Getter /*package-private*/ List<Location> riftLocations;
|
@Saved @Getter /*package-private*/ List<Location> riftLocations;
|
||||||
|
|
||||||
@Getter int dim; // Not saved
|
@Getter int dim; // Not saved
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.pockets;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
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.dimdoors.shared.Config;
|
||||||
import org.dimdev.ddutils.math.GridUtils;
|
import org.dimdev.ddutils.math.GridUtils;
|
||||||
import org.dimdev.dimdoors.DimDoors;
|
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.MapStorage;
|
||||||
import net.minecraft.world.storage.WorldSavedData;
|
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";
|
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.
|
@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
|
@Saved @Getter /*package-private*/ int gridSize; // Determines how much pockets in their dimension are spaced
|
||||||
@SavedToNBT @Getter /*package-private*/ int maxPocketSize;
|
@Saved @Getter /*package-private*/ int maxPocketSize;
|
||||||
@SavedToNBT @Getter /*package-private*/ int privatePocketSize;
|
@Saved @Getter /*package-private*/ int privatePocketSize;
|
||||||
@SavedToNBT @Getter /*package-private*/ int publicPocketSize;
|
@Saved @Getter /*package-private*/ int publicPocketSize;
|
||||||
@SavedToNBT /*package-private*/ BiMap<String, Integer> privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only
|
@Saved /*package-private*/ BiMap<String, Integer> privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only
|
||||||
@SavedToNBT @Getter /*package-private*/ Map<Integer, Pocket> pockets; // TODO: remove getter?
|
@Saved @Getter /*package-private*/ Map<Integer, Pocket> pockets; // TODO: remove getter?
|
||||||
@SavedToNBT @Getter /*package-private*/ int nextID;
|
@Saved @Getter /*package-private*/ int nextID;
|
||||||
|
|
||||||
@Getter private int dim;
|
@Getter private int dim;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.dimdev.dimdoors.shared.rifts;
|
package org.dimdev.dimdoors.shared.rifts;
|
||||||
|
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.VirtualLocation;
|
||||||
import org.dimdev.ddutils.Location;
|
import org.dimdev.ddutils.Location;
|
||||||
import org.dimdev.ddutils.math.MathUtils;
|
import org.dimdev.ddutils.math.MathUtils;
|
||||||
|
@ -19,19 +20,19 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||||
@SavedToNBT public class AvailableLinkDestination extends RiftDestination { // TODO
|
@NBTSerializable public class AvailableLinkDestination extends RiftDestination { // TODO
|
||||||
@SavedToNBT protected float newDungeonRiftProbability;
|
@Saved protected float newDungeonRiftProbability;
|
||||||
@SavedToNBT protected float depthPenalization; // TODO: these make the equation assymetric
|
@Saved protected float depthPenalization; // TODO: these make the equation assymetric
|
||||||
@SavedToNBT protected float distancePenalization;
|
@Saved protected float distancePenalization;
|
||||||
@SavedToNBT protected float closenessPenalization;
|
@Saved protected float closenessPenalization;
|
||||||
|
|
||||||
@SavedToNBT protected boolean dungeonRiftsOnly;
|
@Saved protected boolean dungeonRiftsOnly;
|
||||||
@SavedToNBT protected boolean overworldRifts;
|
@Saved protected boolean overworldRifts;
|
||||||
@SavedToNBT protected boolean unstable;
|
@Saved protected boolean unstable;
|
||||||
@SavedToNBT protected float nonFloatingRiftWeight;
|
@Saved protected float nonFloatingRiftWeight;
|
||||||
@SavedToNBT protected float floatingRiftWeight;
|
@Saved protected float floatingRiftWeight;
|
||||||
|
|
||||||
@SavedToNBT protected boolean noLinkBack;
|
@Saved protected boolean noLinkBack;
|
||||||
// private int maxLinks;
|
// private int maxLinks;
|
||||||
|
|
||||||
@Builder.Default private UUID uuid = UUID.randomUUID();
|
@Builder.Default private UUID uuid = UUID.randomUUID();
|
||||||
|
|
|
@ -8,11 +8,12 @@ import lombok.ToString;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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
|
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||||
@SavedToNBT public class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft?
|
@NBTSerializable public class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft?
|
||||||
@SavedToNBT @Getter protected Location loc;
|
@Saved @Getter protected Location loc;
|
||||||
|
|
||||||
public GlobalDestination() {}
|
public GlobalDestination() {}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,12 @@ import lombok.ToString;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
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
|
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||||
@SavedToNBT public class LocalDestination extends RiftDestination { // TODO: use BlockPos
|
@NBTSerializable public class LocalDestination extends RiftDestination { // TODO: use BlockPos
|
||||||
@SavedToNBT protected BlockPos pos;
|
@Saved protected BlockPos pos;
|
||||||
|
|
||||||
public LocalDestination() {}
|
public LocalDestination() {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.dimdev.dimdoors.shared.rifts;
|
package org.dimdev.dimdoors.shared.rifts;
|
||||||
|
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.DimDoors;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -15,10 +16,10 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||||
@SavedToNBT public class PocketEntranceDestination extends RiftDestination {
|
@NBTSerializable public class PocketEntranceDestination extends RiftDestination {
|
||||||
@SavedToNBT protected float weight;
|
@Saved protected float weight;
|
||||||
@SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List<WeightedRiftDestination> ifDestinations = new LinkedList<>(); // TODO addIfDestination method in builder
|
@Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List<WeightedRiftDestination> ifDestinations = new LinkedList<>(); // TODO addIfDestination method in builder
|
||||||
@SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List<WeightedRiftDestination> otherwiseDestinations = new LinkedList<>(); // TODO addOtherwiseDestination method in builder
|
@Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default protected List<WeightedRiftDestination> otherwiseDestinations = new LinkedList<>(); // TODO addOtherwiseDestination method in builder
|
||||||
|
|
||||||
public PocketEntranceDestination() {}
|
public PocketEntranceDestination() {}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,12 @@ import lombok.ToString;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.Vec3i;
|
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
|
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||||
@SavedToNBT public class RelativeDestination extends RiftDestination { // TODO: use Vec3i
|
@NBTSerializable public class RelativeDestination extends RiftDestination { // TODO: use Vec3i
|
||||||
@SavedToNBT protected Vec3i offset;
|
@Saved protected Vec3i offset;
|
||||||
|
|
||||||
public RelativeDestination() {}
|
public RelativeDestination() {}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ import org.dimdev.ddutils.Location;
|
||||||
import org.dimdev.ddutils.WorldUtils;
|
import org.dimdev.ddutils.WorldUtils;
|
||||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.DimDoors;
|
||||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||||
import org.dimdev.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
|
import org.dimdev.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
|
||||||
|
@ -21,33 +22,33 @@ import org.dimdev.dimdoors.shared.world.ModDimensions;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@SavedToNBT public class RiftRegistry extends WorldSavedData {
|
@NBTSerializable public class RiftRegistry extends WorldSavedData {
|
||||||
|
|
||||||
private static final String DATA_NAME = DimDoors.MODID + "_rifts";
|
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.
|
@Getter private static final int DATA_VERSION = 0; // IMPORTANT: Update this and upgradeRegistry when making changes.
|
||||||
|
|
||||||
@SavedToNBT @Getter protected /*final*/ Map<Location, RiftInfo> rifts = new HashMap<>(); // TODO: convert to a static directed graph, but store links per-world
|
@Saved @Getter protected /*final*/ Map<Location, RiftInfo> rifts = new HashMap<>(); // TODO: convert to a static directed graph, but store links per-world
|
||||||
@SavedToNBT @Getter protected /*final*/ Map<String, Location> privatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket TODO: split into PrivatePocketRiftRegistry subclass
|
@Saved @Getter protected /*final*/ Map<String, Location> privatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket TODO: split into PrivatePocketRiftRegistry subclass
|
||||||
@SavedToNBT @Getter protected /*final*/ Map<String, List<Location>> privatePocketEntranceLists = new HashMap<>(); // Player UUID -> private pocket entrances TODO: split into PrivatePocketRiftRegistry subclass
|
@Saved @Getter protected /*final*/ Map<String, List<Location>> privatePocketEntranceLists = new HashMap<>(); // Player UUID -> private pocket entrances TODO: split into PrivatePocketRiftRegistry subclass
|
||||||
@SavedToNBT @Getter protected /*final*/ Map<String, Location> privatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
|
@Saved @Getter protected /*final*/ Map<String, Location> privatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
|
||||||
@SavedToNBT @Getter protected /*final*/ Map<String, Location> overworldRifts = new HashMap<>();
|
@Saved @Getter protected /*final*/ Map<String, Location> overworldRifts = new HashMap<>();
|
||||||
|
|
||||||
@Getter private int dim;
|
@Getter private int dim;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
@AllArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true)
|
@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!
|
// IntelliJ warnings are wrong, Builder needs these initializers!
|
||||||
@SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Set<AvailableLinkInfo> availableLinks = new HashSet<>(); // TODO: multiset?
|
@Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Set<AvailableLinkInfo> availableLinks = new HashSet<>(); // TODO: multiset?
|
||||||
@SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset<Location> sources = ConcurrentHashMultiset.create();
|
@Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset<Location> sources = ConcurrentHashMultiset.create();
|
||||||
@SavedToNBT @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset<Location> destinations = ConcurrentHashMultiset.create();
|
@Saved @SuppressWarnings({"UnusedAssignment", "RedundantSuppression"}) @Builder.Default @Getter /*package-private*/ Multiset<Location> destinations = ConcurrentHashMultiset.create();
|
||||||
|
|
||||||
@AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true)
|
@NBTSerializable @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true)
|
||||||
public static class AvailableLinkInfo implements INBTStorable {
|
public static class AvailableLinkInfo implements INBTStorable {
|
||||||
@SavedToNBT @Getter @Setter /*package-private*/ float weight;
|
@Saved @Getter @Setter /*package-private*/ float weight;
|
||||||
@SavedToNBT @Getter /*package-private*/ VirtualLocation virtualLocation;
|
@Saved @Getter /*package-private*/ VirtualLocation virtualLocation;
|
||||||
@SavedToNBT @Getter @Wither /*package-private*/ Location location;
|
@Saved @Getter @Wither /*package-private*/ Location location;
|
||||||
@SavedToNBT @Getter /*package-private*/ UUID uuid;
|
@Saved @Getter /*package-private*/ UUID uuid;
|
||||||
|
|
||||||
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.dimdev.dimdoors.shared.rifts;
|
package org.dimdev.dimdoors.shared.rifts;
|
||||||
|
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.ddutils.RGBA;
|
||||||
import org.dimdev.dimdoors.DimDoors;
|
import org.dimdev.dimdoors.DimDoors;
|
||||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||||
|
@ -32,18 +33,18 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.*;
|
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;
|
@Saved @Getter protected VirtualLocation virtualLocation;
|
||||||
@SavedToNBT @Nonnull @Getter protected List<WeightedRiftDestination> destinations; // Not using a set because we can have duplicate destinations. Maybe use Multiset from Guava?
|
@Saved @Nonnull @Getter protected List<WeightedRiftDestination> destinations; // Not using a set because we can have duplicate destinations. Maybe use Multiset from Guava?
|
||||||
@SavedToNBT @Getter protected boolean makeDestinationPermanent;
|
@Saved @Getter protected boolean makeDestinationPermanent;
|
||||||
@SavedToNBT @Getter protected boolean preserveRotation;
|
@Saved @Getter protected boolean preserveRotation;
|
||||||
@SavedToNBT @Getter protected float yaw;
|
@Saved @Getter protected float yaw;
|
||||||
@SavedToNBT @Getter protected float pitch;
|
@Saved @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.
|
@Saved @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;
|
@Saved @Getter protected float chaosWeight;
|
||||||
@SavedToNBT @Getter protected boolean forcedColor;
|
@Saved @Getter protected boolean forcedColor;
|
||||||
@SavedToNBT @Getter protected RGBA color = null; // TODO: update AnnotatedNBT to be able to save these
|
@Saved @Getter protected RGBA color = null; // TODO: update AnnotatedNBT to be able to save these
|
||||||
// TODO: option to convert to door on teleportTo?
|
// TODO: option to convert to door on teleportTo?
|
||||||
|
|
||||||
protected boolean riftStateChanged; // not saved
|
protected boolean riftStateChanged; // not saved
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.dimdev.dimdoors.shared.tileentities;
|
package org.dimdev.dimdoors.shared.tileentities;
|
||||||
|
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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.dimdoors.shared.rifts.TileEntityRift;
|
||||||
import org.dimdev.ddutils.Location;
|
import org.dimdev.ddutils.Location;
|
||||||
import org.dimdev.ddutils.RGBA;
|
import org.dimdev.ddutils.RGBA;
|
||||||
|
@ -14,20 +15,20 @@ import net.minecraft.util.EnumFacing;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
// TODO: merge horizontal and vertical entrances' render code into one, and support custom sizes
|
// TODO: merge horizontal and vertical entrances' render code into one, and support custom sizes
|
||||||
@SavedToNBT public class TileEntityEntranceRift extends TileEntityRift {
|
@NBTSerializable public class TileEntityEntranceRift extends TileEntityRift {
|
||||||
@SavedToNBT @Getter /*package-private*/ boolean placeRiftOnBreak = false;
|
@Saved @Getter /*package-private*/ boolean placeRiftOnBreak = false;
|
||||||
@SavedToNBT @Getter /*package-private*/ boolean closeAfterPassThrough = false;
|
@Saved @Getter /*package-private*/ boolean closeAfterPassThrough = false;
|
||||||
@SavedToNBT @Getter public boolean shouldRender = true;
|
@Saved @Getter public boolean shouldRender = true;
|
||||||
@SavedToNBT @Getter public byte lockStatus = 0;
|
@Saved @Getter public byte lockStatus = 0;
|
||||||
|
|
||||||
// Set by the block, not saved and not synced to the client
|
// Set by the block, not saved and not synced to the client
|
||||||
@SavedToNBT public EnumFacing orientation;
|
@Saved public EnumFacing orientation;
|
||||||
@SavedToNBT public int tpOffset = 1; // TODO: float?
|
@Saved public int tpOffset = 1; // TODO: float?
|
||||||
@SavedToNBT public double extendUp = 0.5; // Use += to set these. TODO: @SideOnly client?
|
@Saved public double extendUp = 0.5; // Use += to set these. TODO: @SideOnly client?
|
||||||
@SavedToNBT public double extendDown = 0.5;
|
@Saved public double extendDown = 0.5;
|
||||||
@SavedToNBT public double extendLeft = 0.5;
|
@Saved public double extendLeft = 0.5;
|
||||||
@SavedToNBT public double extendRight = 0.5;
|
@Saved public double extendRight = 0.5;
|
||||||
@SavedToNBT public double pushIn = 0.01; // TODO: set to 0, and set on door
|
@Saved public double pushIn = 0.01; // TODO: set to 0, and set on door
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyFrom(TileEntityRift oldRift) {
|
public void copyFrom(TileEntityRift oldRift) {
|
||||||
|
|
|
@ -2,7 +2,8 @@ package org.dimdev.dimdoors.shared.tileentities;
|
||||||
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
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 org.dimdev.dimdoors.shared.blocks.ModBlocks;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -15,7 +16,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
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 ENDERMAN_SPAWNING_CHANCE = 1;
|
||||||
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
|
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();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
//Need to be saved:
|
//Need to be saved:
|
||||||
@SavedToNBT /*package-private*/ int updateTimer;
|
@Saved /*package-private*/ int updateTimer;
|
||||||
@SavedToNBT public boolean shouldClose = false; // TODO
|
@Saved public boolean shouldClose = false; // TODO
|
||||||
@SavedToNBT public int spawnedEndermenID = 0;
|
@Saved public int spawnedEndermenID = 0;
|
||||||
@SavedToNBT public float growth = 0;
|
@Saved public float growth = 0;
|
||||||
|
|
||||||
@Setter private boolean unregisterDisabled = false;
|
@Setter private boolean unregisterDisabled = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue