Implement Tag#equals and Tag#hashCode on forge because forge is nice

This commit is contained in:
shedaniel
2021-02-23 01:03:06 +08:00
parent a7a98aa19f
commit 189f1e211c

View File

@@ -25,6 +25,7 @@ import net.minecraft.tags.TagCollection;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
public class TagHooksImpl {
@@ -37,12 +38,12 @@ public class TagHooksImpl {
public ResourceLocation getName() {
return id;
}
@Override
public boolean contains(T object) {
return getBackend().contains(object);
}
@Override
public List<T> getValues() {
return getBackend().getValues();
@@ -50,7 +51,7 @@ public class TagHooksImpl {
private Tag<T> getBackend() {
TagCollection<T> currentCollection = collection.get();
if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed.
backendCollection = new WeakReference<>(currentCollection);
return backend = currentCollection.getTagOrEmpty(id);
@@ -58,6 +59,21 @@ public class TagHooksImpl {
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();
}
};
}
}