mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Implement Tag#equals and Tag#hashCode on forge because forge is nice
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user