CacheSlot.java

net.minecraft.client.multiplayer.CacheSlot

信息

  • 全限定名:net.minecraft.client.multiplayer.CacheSlot
  • 类型:public class
  • 包:net.minecraft.client.multiplayer
  • 源码路径:src/main/java/net/minecraft/client/multiplayer/CacheSlot.java
  • 起始行号:L9
  • 职责:

    TODO

字段/常量

  • operation

    • 类型: Function<C,D>
    • 修饰符: private final
    • 源码定位: L10
    • 说明:

      TODO

  • context

    • 类型: C
    • 修饰符: private
    • 源码定位: L11
    • 说明:

      TODO

  • value

    • 类型: D
    • 修饰符: private
    • 源码定位: L12
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.multiplayer.CacheSlot.Cleaner
    • 类型: interface
    • 修饰符: public
    • 源码定位: L37
    • 说明:

      TODO

构造器

public CacheSlot(Function<C,D> operation) @ L14

  • 构造器名:CacheSlot
  • 源码定位:L14
  • 修饰符:public

参数:

  • operation: Function<C,D>

说明:

TODO

方法

下面的方法块按源码顺序生成。

public D compute(C context) @ L18

  • 方法名:compute
  • 源码定位:L18
  • 返回类型:D
  • 修饰符:public

参数:

  • context: C

说明:

TODO

public void clear() @ L30

  • 方法名:clear
  • 源码定位:L30
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CacheSlot<C extends CacheSlot.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;
        } else {
            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
    @OnlyIn(Dist.CLIENT)
    public interface Cleaner<C extends CacheSlot.Cleaner<C>> {
        void registerForCleaning(CacheSlot<C, ?> slot);
    }
}

引用的其他类