--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -197,14 +197,14 @@
         if (optional == null) {
             throw new IllegalStateException("Unregistered memory fetched: " + p_21953_);
         } else {
-            return optional.map(ExpirableValue::getValue);
+            return (Optional<U>)optional.map(ExpirableValue::getValue);
         }
     }
 
     @Nullable
     public <U> Optional<U> getMemoryInternal(MemoryModuleType<U> p_259344_) {
         Optional<? extends ExpirableValue<?>> optional = this.memories.get(p_259344_);
-        return optional == null ? null : optional.map(ExpirableValue::getValue);
+        return optional == null ? null : (Optional<U>)optional.map(ExpirableValue::getValue);
     }
 
     public <U> long getTimeUntilExpiry(MemoryModuleType<U> p_147342_) {
