Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class BehaviorPack {
/** 1.21.80 以降、ブロックは geometry と material_instances を両方書く必要がある。 */
static final String FORMAT_VERSION = "1.21.80";
static final String RECIPE_FORMAT_VERSION = "1.20.10";
private static final String MIRRORED_RECIPE_FORMAT_VERSION = "1.20.80";
static final String CODE_PROPERTIES_NOTE = "スタック数・硬さ・道具の条件・ドロップなど、Java のコードで決まる性質は変換していない(Bedrock の既定値になる)";

/** ビヘイビアパックでの定義 1 件の変換結果。{@code status} は GENERATED / PARTIAL / SKIPPED。 */
Expand Down Expand Up @@ -168,6 +169,7 @@ private static Recipe recipe(String bid, JsonObject r, Set<String> available) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("description", Map.of("identifier", bid));
body.put("tags", List.of("crafting_table"));
String formatVersion = RECIPE_FORMAT_VERSION;
String key;
if ("minecraft:crafting_shaped".equals(type)) {
if (!(r.get("pattern") instanceof JsonArray pattern) || pattern.isEmpty() || pattern.size() > 3
Expand Down Expand Up @@ -199,6 +201,11 @@ private static Recipe recipe(String bid, JsonObject r, Set<String> available) {
}
body.put("pattern", rows);
body.put("key", outKeys);
// Java の定形レシピは左右反転も受け付ける。
if (rows.stream().anyMatch(row -> !row.contentEquals(new StringBuilder(row).reverse()))) {
body.put("assume_symmetry", true);
formatVersion = MIRRORED_RECIPE_FORMAT_VERSION;
}
key = "minecraft:recipe_shaped";
} else if ("minecraft:crafting_shapeless".equals(type)) {
if (!(r.get("ingredients") instanceof JsonArray ingredients) || ingredients.isEmpty() || ingredients.size() > 9) {
Expand Down Expand Up @@ -232,7 +239,7 @@ private static Recipe recipe(String bid, JsonObject r, Set<String> available) {
notes.add("バニラのアイテム ID は Java と同じとみなした(Bedrock で名前が違うものがある): " + String.join(", ", vanilla));
}
Map<String, Object> root = new LinkedHashMap<>();
root.put("format_version", RECIPE_FORMAT_VERSION);
root.put("format_version", formatVersion);
root.put(key, body);
return new Recipe(root, notes, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class PackCompiler {
/** 公開する成果物(キャッシュもこの 4 つが揃っているときだけ使う)。 */
public static final List<String> OUTPUT_FILES = List.of(PACK_FILE, BEHAVIOR_PACK_FILE, ADDON_FILE, MAPPING_FILE);
/** 生成器の版。出力の形式を変えたら上げる(キャッシュの鍵に入る)。 */
static final String COMPILER_VERSION = "pack-compiler/9";
static final String COMPILER_VERSION = "pack-compiler/10";
static final long MAX_PACK_BYTES = 256L << 20;
static final int MAX_TEXTURES = 16_384;
/** パックが要求する Bedrock の最低版。1.21.80 以降の書式(ブロックの geometry と material_instances)に合わせる(ADR-0006)。 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,30 @@ private static String unlockedBy(String recipe, String kind) {
r.diagnostics().toString());
}

@Test
void 左右非対称の定形レシピは反転を許可する書式で生成する() throws IOException {
Map<String, byte[]> m = fixture("mirror");
m.put("data/mirror/recipe/asymmetric.json", u("""
{"type":"minecraft:crafting_shaped","pattern":["AB"," A"],
"key":{"A":"mirror:test_ingot","B":"minecraft:redstone"},
"result":{"id":"mirror:test_block"}}
"""));
PackCompiler.Result r = compile(List.of(jar("mirror.jar", m)));
assertTrue(r.ok(), r.diagnostics().toString());
Map<String, byte[]> bp = unzip(r.outputs().get(PackCompiler.BEHAVIOR_PACK_FILE));
var recipe = JsonParser.parseString(text(bp, "recipes/mirror/asymmetric.json")).getAsJsonObject();
assertEquals("1.20.80", recipe.get("format_version").getAsString());
var shaped = recipe.getAsJsonObject("minecraft:recipe_shaped");
assertTrue(shaped.get("assume_symmetry").getAsBoolean());
assertEquals(JsonParser.parseString("[\"AB\",\" A\"]"), shaped.get("pattern"));
assertEquals(JsonParser.parseString("[{\"item\":\"minecraft:redstone\"},{\"item\":\"mirror:test_ingot\"}]"),
shaped.get("unlock"));

var symmetric = JsonParser.parseString(text(bp, "recipes/mirror/test_block.json")).getAsJsonObject();
assertEquals("1.20.10", symmetric.get("format_version").getAsString());
assertFalse(symmetric.getAsJsonObject("minecraft:recipe_shaped").has("assume_symmetry"));
}

@Test
void patternとkeyが対応しない定形レシピは外す() throws IOException {
Map<String, byte[]> m = fixture("pk");
Expand Down
3 changes: 2 additions & 1 deletion docs/adr/0006-mode-b-behavior-pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Mode B では、Java の MOD のコードを BDS で動かさず、宣言デー
| ブロックアイテム | ファイルを作らない(Bedrock がブロックから自動で作る) |
| レシピ | `crafting_shaped` → `minecraft:recipe_shaped`、`crafting_shapeless` → `minecraft:recipe_shapeless`(`tags` は `crafting_table`)。材料と結果は、単一のアイテムのものだけ |

- 左右非対称の定形レシピは書式 `1.20.80` の `assume_symmetry: true` で、Java と同じく左右両方の配置を受け付ける。[Bedrock の定形レシピ](https://learn.microsoft.com/en-us/minecraft/creator/reference/content/recipereference/examples/recipedefinitions/recipe_shaped?view=minecraft-bedrock-stable)

- **変換しないレシピ**(理由付きで SKIPPED、`RECIPE_UNSUPPORTED`):
- 定形レシピで、pattern の文字と key が対応しないもの(未定義の文字、使われないキー)
- タグ(`#c:ingots` など)や、複数候補の材料
Expand Down Expand Up @@ -102,5 +104,4 @@ Mode B では、Java の MOD のコードを BDS で動かさず、宣言デー
- Java のコードで決まる性質は、Mode A で取得した実行時レジストリから補える見込み。実行時レジストリにスタック数・硬さなどを足すのは、将来の課題。
- レシピのバニラのアイテム ID の対応表は無い。
- 立方体以外の形、状態を持つブロック、ブロックのドロップ(ルートテーブル)、道具の条件は変換しない。
- Java の定形レシピは左右反転も受け付けるが、Bedrock 側の反転の指定(`assume_symmetry`)は入れていない。
- `notConverted` には、サーバー側だけの MOD(Geyser など)も並ぶ。Bedrock の成果物に関係しない MOD を区別していない。
Loading