package net.minecraft.client.multiplayer; import java.util.function.Function; import org.jspecify.annotations.Nullable; public class CacheSlot, D> { private final Function operation; @Nullable private C context; @Nullable private D value; public CacheSlot(final Function operation) { this.operation = operation; } public D compute(final C context) { if (context == this.context && this.value != null) { return this.value; } else { D newValue = (D)this.operation.apply(context); this.value = newValue; this.context = context; context.registerForCleaning(this); return newValue; } } public void clear() { this.value = null; this.context = null; } @FunctionalInterface public interface Cleaner> { void registerForCleaning(CacheSlot slot); } }