2025-11-24 22:52:51 +03:00

43 lines
1.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.multiplayer;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
public class CacheSlot<C extends Cleaner<C>, D> {
private final Function<C, D> operation;
private @Nullable C context;
private @Nullable D value;
public CacheSlot(Function<C, D> operation) {
this.operation = operation;
}
public D compute(C context) {
if (context == this.context && this.value != null) {
return this.value;
}
D newValue = 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 static interface Cleaner<C extends Cleaner<C>> {
public void registerForCleaning(CacheSlot<C, ?> var1);
}
}