BlockListReport.java
net.minecraft.data.info.BlockListReport
信息
- 全限定名:net.minecraft.data.info.BlockListReport
- 类型:public class
- 包:net.minecraft.data.info
- 源码路径:src/main/java/net/minecraft/data/info/BlockListReport.java
- 起始行号:L22
- 实现:DataProvider
- 职责:
TODO
字段/常量
-
output- 类型:
PackOutput - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
registries- 类型:
CompletableFuture<HolderLookup.Provider> - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public BlockListReport(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) @ L26
- 构造器名:BlockListReport
- 源码定位:L26
- 修饰符:public
参数:
- output: PackOutput
- registries: CompletableFuture<HolderLookup.Provider>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public CompletableFuture<?> run(CachedOutput cache) @ L31
- 方法名:run
- 源码定位:L31
- 返回类型:CompletableFuture<?>
- 修饰符:public
参数:
- cache: CachedOutput
说明:
TODO
public final String getName() @ L98
- 方法名:getName
- 源码定位:L98
- 返回类型:String
- 修饰符:public final
参数:
- 无
说明:
TODO
代码
public class BlockListReport implements DataProvider {
private final PackOutput output;
private final CompletableFuture<HolderLookup.Provider> registries;
public BlockListReport(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
this.output = output;
this.registries = registries;
}
@Override
public CompletableFuture<?> run(CachedOutput cache) {
Path path = this.output.getOutputFolder(PackOutput.Target.REPORTS).resolve("blocks.json");
return this.registries
.thenCompose(
registries -> {
JsonObject root = new JsonObject();
RegistryOps<JsonElement> registryOps = registries.createSerializationContext(JsonOps.INSTANCE);
registries.lookupOrThrow(Registries.BLOCK)
.listElements()
.forEach(
block -> {
JsonObject entry = new JsonObject();
StateDefinition<Block, BlockState> definition = block.value().getStateDefinition();
if (!definition.getProperties().isEmpty()) {
JsonObject properties = new JsonObject();
for (Property<?> property : definition.getProperties()) {
JsonArray values = new JsonArray();
for (Comparable<?> value : property.getPossibleValues()) {
values.add(Util.getPropertyName(property, value));
}
properties.add(property.getName(), values);
}
entry.add("properties", properties);
}
JsonArray protocol = new JsonArray();
for (BlockState state : definition.getPossibleStates()) {
JsonObject stateEntry = new JsonObject();
JsonObject properties = new JsonObject();
for (Property<?> property : definition.getProperties()) {
properties.addProperty(property.getName(), Util.getPropertyName(property, state.getValue(property)));
}
if (!properties.isEmpty()) {
stateEntry.add("properties", properties);
}
stateEntry.addProperty("id", Block.getId(state));
if (state == block.value().defaultBlockState()) {
stateEntry.addProperty("default", true);
}
protocol.add(stateEntry);
}
entry.add("states", protocol);
String id = block.getRegisteredName();
JsonElement data = BlockTypes.CODEC
.codec()
.encodeStart(registryOps, block.value())
.getOrThrow(msg -> new AssertionError("Failed to serialize block " + id + " (is type registered in BlockTypes?): " + msg));
entry.add("definition", data);
root.add(id, entry);
}
);
return DataProvider.saveStable(cache, root, path);
}
);
}
@Override
public final String getName() {
return "Block List";
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
实现/方法调用 - 关联成员:
DataProvider.saveStable()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.getPropertyName()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Block.getId()
- 引用位置: