--- a/net/minecraft/resources/ResourceKey.java
+++ b/net/minecraft/resources/ResourceKey.java
@@ -51,7 +51,7 @@
     }
 
     public <E> Optional<ResourceKey<E>> cast(ResourceKey<? extends Registry<E>> p_195976_) {
-        return this.isFor(p_195976_) ? Optional.of(this) : Optional.empty();
+        return this.isFor(p_195976_) ? Optional.of((ResourceKey<E>)this) : Optional.empty();
     }
 
     public ResourceLocation location() {
