Skip to content

Commit

Permalink
Make ResourceKey comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Jan 9, 2025
1 parent 0090005 commit bfe324e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package xyz.bluspring.kilt.forgeinjects.resources;

import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ResourceKey.class)
public abstract class ResourceKeyInject implements Comparable<ResourceKey<?>> {
@Shadow public abstract ResourceLocation location();

@Shadow public abstract ResourceLocation registry();

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;

if (obj == null || this.getClass() != obj.getClass())
return false;

return this.location().equals(((ResourceKey<?>) obj).location()) && this.registry().equals(((ResourceKey<?>) obj).registry());
}

@Override
public int compareTo(@NotNull ResourceKey<?> o) {
int ret = this.registry().compareTo(o.registry());
if (ret == 0)
ret = this.location().compareTo(o.location());

return ret;
}
}
1 change: 1 addition & 0 deletions src/main/resources/kilt_forge_injects.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"network.protocol.status.ServerStatusInject",
"network.syncher.EntityDataSerializersInject",
"resources.HolderSetCodecInject",
"resources.ResourceKeyInject",
"resources.ResourceLocationInject",
"server.BootstrapInject",
"server.MinecraftServerInject",
Expand Down

0 comments on commit bfe324e

Please sign in to comment.