Pack.java
net.minecraft.server.packs.repository.Pack
信息
- 全限定名:net.minecraft.server.packs.repository.Pack
- 类型:public class
- 包:net.minecraft.server.packs.repository
- 源码路径:src/main/java/net/minecraft/server/packs/repository/Pack.java
- 起始行号:L21
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
location- 类型:
PackLocationInfo - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
resources- 类型:
Pack.ResourcesSupplier - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
metadata- 类型:
Pack.Metadata - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
selectionConfig- 类型:
PackSelectionConfig - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.server.packs.repository.Pack.Metadata- 类型:
record - 修饰符:
public - 源码定位:
L143 - 说明:
TODO
- 类型:
-
net.minecraft.server.packs.repository.Pack.Position- 类型:
enum - 修饰符:
public static - 源码定位:
L146 - 说明:
TODO
- 类型:
-
net.minecraft.server.packs.repository.Pack.ResourcesSupplier- 类型:
interface - 修饰符:
public - 源码定位:
L182 - 说明:
TODO
- 类型:
构造器
public Pack(PackLocationInfo location, Pack.ResourcesSupplier resources, Pack.Metadata metadata, PackSelectionConfig selectionConfig) @ L36
- 构造器名:Pack
- 源码定位:L36
- 修饰符:public
参数:
- location: PackLocationInfo
- resources: Pack.ResourcesSupplier
- metadata: Pack.Metadata
- selectionConfig: PackSelectionConfig
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static Pack readMetaAndCreate(PackLocationInfo location, Pack.ResourcesSupplier resources, PackType packType, PackSelectionConfig selectionConfig) @ L28
- 方法名:readMetaAndCreate
- 源码定位:L28
- 返回类型:Pack
- 修饰符:public static
参数:
- location: PackLocationInfo
- resources: Pack.ResourcesSupplier
- packType: PackType
- selectionConfig: PackSelectionConfig
说明:
TODO
public static Pack.Metadata readPackMetadata(PackLocationInfo location, Pack.ResourcesSupplier resources, PackFormat currentPackVersion, PackType type) @ L43
- 方法名:readPackMetadata
- 源码定位:L43
- 返回类型:Pack.Metadata
- 修饰符:public static
参数:
- location: PackLocationInfo
- resources: Pack.ResourcesSupplier
- currentPackVersion: PackFormat
- type: PackType
说明:
TODO
public PackLocationInfo location() @ L77
- 方法名:location
- 源码定位:L77
- 返回类型:PackLocationInfo
- 修饰符:public
参数:
- 无
说明:
TODO
public Component getTitle() @ L81
- 方法名:getTitle
- 源码定位:L81
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public Component getDescription() @ L85
- 方法名:getDescription
- 源码定位:L85
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public Component getChatLink(boolean enabled) @ L89
- 方法名:getChatLink
- 源码定位:L89
- 返回类型:Component
- 修饰符:public
参数:
- enabled: boolean
说明:
TODO
public PackCompatibility getCompatibility() @ L93
- 方法名:getCompatibility
- 源码定位:L93
- 返回类型:PackCompatibility
- 修饰符:public
参数:
- 无
说明:
TODO
public FeatureFlagSet getRequestedFeatures() @ L97
- 方法名:getRequestedFeatures
- 源码定位:L97
- 返回类型:FeatureFlagSet
- 修饰符:public
参数:
- 无
说明:
TODO
public PackResources open() @ L101
- 方法名:open
- 源码定位:L101
- 返回类型:PackResources
- 修饰符:public
参数:
- 无
说明:
TODO
public String getId() @ L105
- 方法名:getId
- 源码定位:L105
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public PackSelectionConfig selectionConfig() @ L109
- 方法名:selectionConfig
- 源码定位:L109
- 返回类型:PackSelectionConfig
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isRequired() @ L113
- 方法名:isRequired
- 源码定位:L113
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isFixedPosition() @ L117
- 方法名:isFixedPosition
- 源码定位:L117
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public Pack.Position getDefaultPosition() @ L121
- 方法名:getDefaultPosition
- 源码定位:L121
- 返回类型:Pack.Position
- 修饰符:public
参数:
- 无
说明:
TODO
public PackSource getPackSource() @ L125
- 方法名:getPackSource
- 源码定位:L125
- 返回类型:PackSource
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean equals(Object o) @ L129
- 方法名:equals
- 源码定位:L129
- 返回类型:boolean
- 修饰符:public
参数:
- o: Object
说明:
TODO
public int hashCode() @ L138
- 方法名:hashCode
- 源码定位:L138
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class Pack {
private static final Logger LOGGER = LogUtils.getLogger();
private final PackLocationInfo location;
private final Pack.ResourcesSupplier resources;
private final Pack.Metadata metadata;
private final PackSelectionConfig selectionConfig;
public static @Nullable Pack readMetaAndCreate(
PackLocationInfo location, Pack.ResourcesSupplier resources, PackType packType, PackSelectionConfig selectionConfig
) {
PackFormat currentPackVersion = SharedConstants.getCurrentVersion().packVersion(packType);
Pack.Metadata meta = readPackMetadata(location, resources, currentPackVersion, packType);
return meta != null ? new Pack(location, resources, meta, selectionConfig) : null;
}
public Pack(PackLocationInfo location, Pack.ResourcesSupplier resources, Pack.Metadata metadata, PackSelectionConfig selectionConfig) {
this.location = location;
this.resources = resources;
this.metadata = metadata;
this.selectionConfig = selectionConfig;
}
public static Pack.@Nullable Metadata readPackMetadata(
PackLocationInfo location, Pack.ResourcesSupplier resources, PackFormat currentPackVersion, PackType type
) {
try {
Pack.Metadata var11;
try (PackResources pack = resources.openPrimary(location)) {
PackMetadataSection meta;
try {
meta = pack.getMetadataSection(PackMetadataSection.forPackType(type));
} catch (JsonParseException var13) {
LOGGER.warn("Error reading pack metadata, attempting fallback type", (Throwable)var13);
meta = pack.getMetadataSection(PackMetadataSection.FALLBACK_TYPE);
}
if (meta == null) {
LOGGER.warn("Missing metadata in pack {}", location.id());
return null;
}
FeatureFlagsMetadataSection featureFlagMeta = pack.getMetadataSection(FeatureFlagsMetadataSection.TYPE);
FeatureFlagSet requiredFlags = featureFlagMeta != null ? featureFlagMeta.flags() : FeatureFlagSet.of();
PackCompatibility packCompatibility = PackCompatibility.forVersion(meta.supportedFormats(), currentPackVersion);
OverlayMetadataSection overlays = pack.getMetadataSection(OverlayMetadataSection.forPackType(type));
List<String> overlaySet = overlays != null ? overlays.overlaysForVersion(currentPackVersion) : List.of();
var11 = new Pack.Metadata(meta.description(), packCompatibility, requiredFlags, overlaySet);
}
return var11;
} catch (Exception var15) {
LOGGER.warn("Failed to read pack {} metadata", location.id(), var15);
return null;
}
}
public PackLocationInfo location() {
return this.location;
}
public Component getTitle() {
return this.location.title();
}
public Component getDescription() {
return this.metadata.description();
}
public Component getChatLink(boolean enabled) {
return this.location.createChatLink(enabled, this.metadata.description);
}
public PackCompatibility getCompatibility() {
return this.metadata.compatibility();
}
public FeatureFlagSet getRequestedFeatures() {
return this.metadata.requestedFeatures();
}
public PackResources open() {
return this.resources.openFull(this.location, this.metadata);
}
public String getId() {
return this.location.id();
}
public PackSelectionConfig selectionConfig() {
return this.selectionConfig;
}
public boolean isRequired() {
return this.selectionConfig.required();
}
public boolean isFixedPosition() {
return this.selectionConfig.fixedPosition();
}
public Pack.Position getDefaultPosition() {
return this.selectionConfig.defaultPosition();
}
public PackSource getPackSource() {
return this.location.source();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else {
return !(o instanceof Pack that) ? false : this.location.equals(that.location);
}
}
@Override
public int hashCode() {
return this.location.hashCode();
}
public record Metadata(Component description, PackCompatibility compatibility, FeatureFlagSet requestedFeatures, List<String> overlays) {
}
public static enum Position {
TOP,
BOTTOM;
public <T> int insert(List<T> list, T value, Function<T, PackSelectionConfig> converter, boolean reverse) {
Pack.Position self = reverse ? this.opposite() : this;
if (self == BOTTOM) {
int index;
for (index = 0; index < list.size(); index++) {
PackSelectionConfig pack = converter.apply(list.get(index));
if (!pack.fixedPosition() || pack.defaultPosition() != this) {
break;
}
}
list.add(index, value);
return index;
} else {
int index;
for (index = list.size() - 1; index >= 0; index--) {
PackSelectionConfig pack = converter.apply(list.get(index));
if (!pack.fixedPosition() || pack.defaultPosition() != this) {
break;
}
}
list.add(index + 1, value);
return index + 1;
}
}
public Pack.Position opposite() {
return this == TOP ? BOTTOM : TOP;
}
}
public interface ResourcesSupplier {
PackResources openPrimary(PackLocationInfo location);
PackResources openFull(PackLocationInfo location, Pack.Metadata metadata);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
SharedConstants.getCurrentVersion()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
OverlayMetadataSection.forPackType()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
PackMetadataSection.forPackType()
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
PackCompatibility.forVersion()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
FeatureFlagSet.of()
- 引用位置: