From 04d67ec4eb78d53da09447c1a4726b41dcd8d434 Mon Sep 17 00:00:00 2001
From: SD <harrypotter.starwars.shrish@gmail.com>
Date: Fri, 8 Jan 2021 12:21:53 +0530
Subject: [PATCH] Readd NoneTarget

---
 .../dimdoors/DimensionalDoorsInitializer.java |  2 ++
 .../rift/targets/PocketEntranceMarker.java    |  4 +--
 .../dimdoors/rift/targets/VirtualTarget.java  | 33 ++++++++++++++++++-
 .../java/org/dimdev/dimdoors/util/RGBA.java   |  3 +-
 .../world/pocket/VirtualLocation.java         | 11 +++++++
 5 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java
index 69b08f19..bdd04cce 100644
--- a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java
+++ b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java
@@ -10,6 +10,7 @@ import org.dimdev.dimdoors.item.ModItems;
 import org.dimdev.dimdoors.pockets.SchematicHandler;
 import org.dimdev.dimdoors.pockets.SchematicV2Handler;
 import org.dimdev.dimdoors.rift.targets.Targets;
+import org.dimdev.dimdoors.rift.targets.VirtualTarget;
 import org.dimdev.dimdoors.sound.ModSoundEvents;
 import org.dimdev.dimdoors.util.schematic.v2.SchematicTest;
 import org.dimdev.dimdoors.world.ModBiomes;
@@ -70,6 +71,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
         ModConfig.deserialize();
 
         Targets.registerDefaultTargets();
+		VirtualTarget.VirtualTargetType.register();
 
         SchematicV2Handler.getInstance().load();
         SchematicHandler.INSTANCE.loadSchematics();
diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/PocketEntranceMarker.java b/src/main/java/org/dimdev/dimdoors/rift/targets/PocketEntranceMarker.java
index c2fe9eee..66506568 100644
--- a/src/main/java/org/dimdev/dimdoors/rift/targets/PocketEntranceMarker.java
+++ b/src/main/java/org/dimdev/dimdoors/rift/targets/PocketEntranceMarker.java
@@ -76,8 +76,8 @@ public class PocketEntranceMarker extends VirtualTarget implements EntityTarget
 
 	public static class PocketEntranceMarkerBuilder {
 		private float weight;
-		private VirtualTarget ifDestination;
-		private VirtualTarget otherwiseDestination;
+		private VirtualTarget ifDestination = NoneTarget.INSTANCE;
+		private VirtualTarget otherwiseDestination = NoneTarget.INSTANCE;
 
 		PocketEntranceMarkerBuilder() {
 		}
diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java
index e4473857..3287f7be 100644
--- a/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java
+++ b/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java
@@ -30,7 +30,8 @@ public abstract class VirtualTarget implements Target {
 	}
 
 	public static CompoundTag toTag(VirtualTarget virtualTarget) {
-		String type = REGISTRY.getId(virtualTarget.getType()).toString();
+		Identifier id = REGISTRY.getId(virtualTarget.getType());
+		String type = id.toString();
 
 		CompoundTag tag = virtualTarget.getType().toTag(virtualTarget);
 		tag.putString("type", type);
@@ -87,6 +88,7 @@ public abstract class VirtualTarget implements Target {
 		VirtualTargetType<PrivatePocketTarget> PRIVATE = register("dimdoors:private", a -> new PrivatePocketTarget(), a -> new CompoundTag(), PrivatePocketExitTarget.COLOR);
 		VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("dimdoors:private_pocket_exit", a -> new PrivatePocketExitTarget(), a -> new CompoundTag(), PrivatePocketExitTarget.COLOR);
 		VirtualTargetType<RelativeReference> RELATIVE = register("dimdoors:relative", RelativeReference::fromTag, RelativeReference::toTag, VirtualTarget.COLOR);
+		VirtualTargetType<NoneTarget> NONE = register("dimdoors:none", tag -> NoneTarget.INSTANCE, i -> new CompoundTag(), COLOR);
 
 		T fromTag(CompoundTag tag);
 
@@ -94,6 +96,9 @@ public abstract class VirtualTarget implements Target {
 
 		RGBA getColor();
 
+		static void register() {
+		}
+
 		@SuppressWarnings("unchecked")
 		static <T extends VirtualTarget> VirtualTargetType<T> register(String id, Function<CompoundTag, T> fromTag, Function<T, CompoundTag> toTag, RGBA color) {
 			return Registry.register(REGISTRY, (String) id, new VirtualTargetType<T>() {
@@ -115,4 +120,30 @@ public abstract class VirtualTarget implements Target {
 		}
 	}
 
+	public static class NoneTarget extends VirtualTarget {
+		public static final NoneTarget INSTANCE = new NoneTarget();
+
+		private NoneTarget() {
+		}
+
+		@Override
+		public VirtualTargetType<? extends VirtualTarget> getType() {
+			return VirtualTargetType.NONE;
+		}
+
+		@Override
+		public boolean equals(Object o) {
+			return o == INSTANCE;
+		}
+
+		@Override
+		public int hashCode() {
+			return System.identityHashCode(INSTANCE);
+		}
+
+		@Override
+		public String toString() {
+			return "[none]";
+		}
+	}
 }
diff --git a/src/main/java/org/dimdev/dimdoors/util/RGBA.java b/src/main/java/org/dimdev/dimdoors/util/RGBA.java
index c1c4c54e..ba345e38 100644
--- a/src/main/java/org/dimdev/dimdoors/util/RGBA.java
+++ b/src/main/java/org/dimdev/dimdoors/util/RGBA.java
@@ -11,12 +11,13 @@ import org.jetbrains.annotations.NotNull;
 import net.minecraft.nbt.CompoundTag;
 
 public final class RGBA implements Cloneable, Comparable<RGBA>, Iterable<Float> {
-	public static Codec<RGBA> CODEC = RecordCodecBuilder.create(instance -> instance.group(
+	public static final Codec<RGBA> CODEC = RecordCodecBuilder.create(instance -> instance.group(
 			Codec.FLOAT.fieldOf("red").forGetter(RGBA::getRed),
 			Codec.FLOAT.fieldOf("green").forGetter(RGBA::getGreen),
 			Codec.FLOAT.fieldOf("blue").forGetter(RGBA::getBlue),
 			Codec.FLOAT.fieldOf("alpha").forGetter(RGBA::getAlpha)
 	).apply(instance, RGBA::new));
+	public static final RGBA NONE = new RGBA(0, 0, 0, 0);
 
 	private final float red;
 	private final float green;
diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/VirtualLocation.java b/src/main/java/org/dimdev/dimdoors/world/pocket/VirtualLocation.java
index ae50210b..a5fbaa2f 100644
--- a/src/main/java/org/dimdev/dimdoors/world/pocket/VirtualLocation.java
+++ b/src/main/java/org/dimdev/dimdoors/world/pocket/VirtualLocation.java
@@ -1,5 +1,6 @@
 package org.dimdev.dimdoors.world.pocket;
 
+import com.google.common.base.MoreObjects;
 import com.mojang.serialization.Codec;
 import com.mojang.serialization.codecs.RecordCodecBuilder;
 import org.dimdev.dimdoors.DimensionalDoorsInitializer;
@@ -108,4 +109,14 @@ public class VirtualLocation {
 	public int getDepth() {
 		return this.depth;
 	}
+
+	@Override
+	public String toString() {
+		return MoreObjects.toStringHelper(this)
+				.add("world", this.world)
+				.add("x", this.x)
+				.add("z", this.z)
+				.add("depth", this.depth)
+				.toString();
+	}
 }