PackSelectionModel.java

net.minecraft.client.gui.screens.packs.PackSelectionModel

信息

  • 全限定名:net.minecraft.client.gui.screens.packs.PackSelectionModel
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.packs
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/packs/PackSelectionModel.java
  • 起始行号:L23
  • 职责:

    TODO

字段/常量

  • repository

    • 类型: PackRepository
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • selected

    • 类型: List<Pack>
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • unselected

    • 类型: List<Pack>
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • iconGetter

    • 类型: Function<Pack,Identifier>
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • onListChanged

    • 类型: Consumer<PackSelectionModel.EntryBase>
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

  • output

    • 类型: Consumer<PackRepository>
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.packs.PackSelectionModel.Entry

    • 类型: interface
    • 修饰符: public
    • 源码定位: L70
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.packs.PackSelectionModel.EntryBase

    • 类型: class
    • 修饰符: public abstract
    • 源码定位: L115
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.packs.PackSelectionModel.SelectedPackEntry

    • 类型: class
    • 修饰符: private
    • 源码定位: L217
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.packs.PackSelectionModel.UnselectedPackEntry

    • 类型: class
    • 修饰符: private
    • 源码定位: L249
    • 说明:

      TODO

构造器

public PackSelectionModel(Consumer<PackSelectionModel.EntryBase> onListChanged, Function<Pack,Identifier> iconGetter, PackRepository repository, Consumer<PackRepository> output) @ L31

  • 构造器名:PackSelectionModel
  • 源码定位:L31
  • 修饰符:public

参数:

  • onListChanged: Consumer<PackSelectionModel.EntryBase>
  • iconGetter: Function<Pack,Identifier>
  • repository: PackRepository
  • output: Consumer

说明:

TODO

方法

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

public Stream<PackSelectionModel.Entry> getUnselected() @ L44

  • 方法名:getUnselected
  • 源码定位:L44
  • 返回类型:Stream<PackSelectionModel.Entry>
  • 修饰符:public

参数:

说明:

TODO

public Stream<PackSelectionModel.Entry> getSelected() @ L48

  • 方法名:getSelected
  • 源码定位:L48
  • 返回类型:Stream<PackSelectionModel.Entry>
  • 修饰符:public

参数:

说明:

TODO

private void updateRepoSelectedList() @ L52

  • 方法名:updateRepoSelectedList
  • 源码定位:L52
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public void commit() @ L56

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

参数:

说明:

TODO

public void findNewPacks() @ L61

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class PackSelectionModel {
    private final PackRepository repository;
    private final List<Pack> selected;
    private final List<Pack> unselected;
    private final Function<Pack, Identifier> iconGetter;
    private final Consumer<PackSelectionModel.EntryBase> onListChanged;
    private final Consumer<PackRepository> output;
 
    public PackSelectionModel(
        Consumer<PackSelectionModel.EntryBase> onListChanged, Function<Pack, Identifier> iconGetter, PackRepository repository, Consumer<PackRepository> output
    ) {
        this.onListChanged = onListChanged;
        this.iconGetter = iconGetter;
        this.repository = repository;
        this.selected = Lists.newArrayList(repository.getSelectedPacks());
        Collections.reverse(this.selected);
        this.unselected = Lists.newArrayList(repository.getAvailablePacks());
        this.unselected.removeAll(this.selected);
        this.output = output;
    }
 
    public Stream<PackSelectionModel.Entry> getUnselected() {
        return this.unselected.stream().map(x$0 -> new PackSelectionModel.UnselectedPackEntry(x$0));
    }
 
    public Stream<PackSelectionModel.Entry> getSelected() {
        return this.selected.stream().map(x$0 -> new PackSelectionModel.SelectedPackEntry(x$0));
    }
 
    private void updateRepoSelectedList() {
        this.repository.setSelected(Lists.reverse(this.selected).stream().map(Pack::getId).collect(ImmutableList.toImmutableList()));
    }
 
    public void commit() {
        this.updateRepoSelectedList();
        this.output.accept(this.repository);
    }
 
    public void findNewPacks() {
        this.repository.reload();
        this.selected.retainAll(this.repository.getAvailablePacks());
        this.unselected.clear();
        this.unselected.addAll(this.repository.getAvailablePacks());
        this.unselected.removeAll(this.selected);
    }
 
    @OnlyIn(Dist.CLIENT)
    public interface Entry {
        Identifier getIconTexture();
 
        PackCompatibility getCompatibility();
 
        String getId();
 
        Component getTitle();
 
        Component getDescription();
 
        PackSource getPackSource();
 
        default Component getExtendedDescription() {
            return this.getPackSource().decorate(this.getDescription());
        }
 
        boolean isFixedPosition();
 
        boolean isRequired();
 
        void select();
 
        void unselect();
 
        void moveUp();
 
        void moveDown();
 
        boolean isSelected();
 
        default boolean canSelect() {
            return !this.isSelected();
        }
 
        default boolean canUnselect() {
            return this.isSelected() && !this.isRequired();
        }
 
        boolean canMoveUp();
 
        boolean canMoveDown();
    }
 
    @OnlyIn(Dist.CLIENT)
    public abstract class EntryBase implements PackSelectionModel.Entry {
        private final Pack pack;
 
        public EntryBase(Pack pack) {
            Objects.requireNonNull(PackSelectionModel.this);
            super();
            this.pack = pack;
        }
 
        protected abstract List<Pack> getSelfList();
 
        protected abstract List<Pack> getOtherList();
 
        @Override
        public Identifier getIconTexture() {
            return PackSelectionModel.this.iconGetter.apply(this.pack);
        }
 
        @Override
        public PackCompatibility getCompatibility() {
            return this.pack.getCompatibility();
        }
 
        @Override
        public String getId() {
            return this.pack.getId();
        }
 
        @Override
        public Component getTitle() {
            return this.pack.getTitle();
        }
 
        @Override
        public Component getDescription() {
            return this.pack.getDescription();
        }
 
        @Override
        public PackSource getPackSource() {
            return this.pack.getPackSource();
        }
 
        @Override
        public boolean isFixedPosition() {
            return this.pack.isFixedPosition();
        }
 
        @Override
        public boolean isRequired() {
            return this.pack.isRequired();
        }
 
        protected void toggleSelection() {
            this.getSelfList().remove(this.pack);
            this.pack.getDefaultPosition().insert(this.getOtherList(), this.pack, Pack::selectionConfig, true);
            PackSelectionModel.this.onListChanged.accept(this);
            PackSelectionModel.this.updateRepoSelectedList();
            this.updateHighContrastOptionInstance();
        }
 
        private void updateHighContrastOptionInstance() {
            if (this.pack.getId().equals("high_contrast")) {
                OptionInstance<Boolean> highContrastMode = Minecraft.getInstance().options.highContrast();
                highContrastMode.set(!highContrastMode.get());
            }
        }
 
        protected void move(int direction) {
            List<Pack> list = this.getSelfList();
            int currentPos = list.indexOf(this.pack);
            list.remove(currentPos);
            list.add(currentPos + direction, this.pack);
            PackSelectionModel.this.onListChanged.accept(this);
        }
 
        @Override
        public boolean canMoveUp() {
            List<Pack> list = this.getSelfList();
            int index = list.indexOf(this.pack);
            return index > 0 && !list.get(index - 1).isFixedPosition();
        }
 
        @Override
        public void moveUp() {
            this.move(-1);
        }
 
        @Override
        public boolean canMoveDown() {
            List<Pack> list = this.getSelfList();
            int index = list.indexOf(this.pack);
            return index >= 0 && index < list.size() - 1 && !list.get(index + 1).isFixedPosition();
        }
 
        @Override
        public void moveDown() {
            this.move(1);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private class SelectedPackEntry extends PackSelectionModel.EntryBase {
        public SelectedPackEntry(Pack pack) {
            Objects.requireNonNull(PackSelectionModel.this);
            super(pack);
        }
 
        @Override
        protected List<Pack> getSelfList() {
            return PackSelectionModel.this.selected;
        }
 
        @Override
        protected List<Pack> getOtherList() {
            return PackSelectionModel.this.unselected;
        }
 
        @Override
        public boolean isSelected() {
            return true;
        }
 
        @Override
        public void select() {
        }
 
        @Override
        public void unselect() {
            this.toggleSelection();
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private class UnselectedPackEntry extends PackSelectionModel.EntryBase {
        public UnselectedPackEntry(Pack pack) {
            Objects.requireNonNull(PackSelectionModel.this);
            super(pack);
        }
 
        @Override
        protected List<Pack> getSelfList() {
            return PackSelectionModel.this.unselected;
        }
 
        @Override
        protected List<Pack> getOtherList() {
            return PackSelectionModel.this.selected;
        }
 
        @Override
        public boolean isSelected() {
            return false;
        }
 
        @Override
        public void select() {
            this.toggleSelection();
        }
 
        @Override
        public void unselect() {
        }
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • Identifier

    • 引用位置: 参数/字段
  • Pack

    • 引用位置: 参数/字段
  • PackRepository

    • 引用位置: 参数/字段