|
@@ -25,6 +25,7 @@ import net.minecraft.tags.TagCollection;
|
|
|
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
public class TagHooksImpl {
|
|
public class TagHooksImpl {
|
|
@@ -37,12 +38,12 @@ public class TagHooksImpl {
|
|
public ResourceLocation getName() {
|
|
public ResourceLocation getName() {
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean contains(T object) {
|
|
public boolean contains(T object) {
|
|
return getBackend().contains(object);
|
|
return getBackend().contains(object);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<T> getValues() {
|
|
public List<T> getValues() {
|
|
return getBackend().getValues();
|
|
return getBackend().getValues();
|
|
@@ -50,7 +51,7 @@ public class TagHooksImpl {
|
|
|
|
|
|
private Tag<T> getBackend() {
|
|
private Tag<T> getBackend() {
|
|
TagCollection<T> currentCollection = collection.get();
|
|
TagCollection<T> currentCollection = collection.get();
|
|
-
|
|
|
|
|
|
+
|
|
if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed.
|
|
if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed.
|
|
backendCollection = new WeakReference<>(currentCollection);
|
|
backendCollection = new WeakReference<>(currentCollection);
|
|
return backend = currentCollection.getTagOrEmpty(id);
|
|
return backend = currentCollection.getTagOrEmpty(id);
|
|
@@ -58,6 +59,21 @@ public class TagHooksImpl {
|
|
return backend;
|
|
return backend;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return "OptionalNamedTag[" + getName().toString() + ']';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean equals(Object o) {
|
|
|
|
+ return o == this || o instanceof Named && Objects.equals(getName(), ((Named) o).getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ return getName().hashCode();
|
|
|
|
+ }
|
|
};
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|