diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55d3b8a..6045a6a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: with: node-version: 16 - - uses: pnpm/action-setup@v2.2.2 + - uses: pnpm/action-setup@v2 with: run_install: | - recursive: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1a6e37..f8c595b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: with: node-version: 16 - - uses: pnpm/action-setup@v2.2.2 + - uses: pnpm/action-setup@v2 with: run_install: | - recursive: true diff --git a/src/emit/custom.ts b/src/emit/custom.ts new file mode 100644 index 0000000..269c542 --- /dev/null +++ b/src/emit/custom.ts @@ -0,0 +1,68 @@ +import Rule from '../rule' +import { Acceptor } from '@pssbletrngle/pack-resolver' +import { Recipe } from '../parser/recipe' +import { toJson } from '../textHelper' +import { RecipeDefinition } from '../schema/recipe' +import { createId, Id, IdInput } from '../common/id' +import Registry from '../common/registry' +import { LootTable } from '../loader/loot' + +export interface RegistryProvider { + forEach(consumer: (recipe: T, id: Id) => void): void +} + +export default abstract class RuledEmitter> { + + protected constructor(private readonly provider: RegistryProvider) { + } + + + private customEntries = new Registry() + private rulesArray: TRule[] = [] + + protected get rules(): ReadonlyArray { + return this.rulesArray + } + + clear() { + this.rulesArray = [] + } + + protected addRule(rule: TRule) { + this.rulesArray.push(rule) + } + + protected addCustom( + id: IdInput, + value: TEntry + ) { + this.customEntries.set(createId(id), value) + } + + private async modify(acceptor: Acceptor) { + this.provider.forEach((recipe, id) => { + if (this.customRecipe.has(id)) return + + const path = this.recipePath(id) + + const rules = this.rules.filter(it => it.matches(id, recipe, this.logger)) + if (rules.length === 0) return + + const modified = rules.reduce((previous, rule) => previous && rule.modify(previous), recipe) + + acceptor(path, toJson(modified?.toDefinition() ?? RecipeEmitter.EMPTY_RECIPE)) + }) + } + + private async create(acceptor: Acceptor) { + this.customRecipe.forEach((recipe, id) => { + const path = this.recipePath(id) + acceptor(path, toJson(recipe)) + }) + } + + async emit(acceptor: Acceptor) { + await Promise.all([this.modifyRecipes(acceptor), this.createRecipes(acceptor)]) + } + +} diff --git a/src/emit/index.ts b/src/emit/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/emit/loot.ts b/src/emit/loot.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/emit/ruled.ts b/src/emit/ruled.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/loader/loot.ts b/src/loader/loot.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/rule/index.ts b/src/rule/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/rule/lootTable.ts b/src/rule/lootTable.ts new file mode 100644 index 0000000..579ab80 --- /dev/null +++ b/src/rule/lootTable.ts @@ -0,0 +1 @@ +export default class LootRule {} diff --git a/src/rule/recipe/index.ts b/src/rule/recipe.ts similarity index 100% rename from src/rule/recipe/index.ts rename to src/rule/recipe.ts diff --git a/test/__snapshots__/recipeReplacer.test.ts.snap b/test/__snapshots__/recipe.test.ts.snap similarity index 100% rename from test/__snapshots__/recipeReplacer.test.ts.snap rename to test/__snapshots__/recipe.test.ts.snap diff --git a/test/__snapshots__/tagReplacer.test.ts.snap b/test/__snapshots__/tagReplacer.test.ts.snap deleted file mode 100644 index 692f9d0..0000000 --- a/test/__snapshots__/tagReplacer.test.ts.snap +++ /dev/null @@ -1,399 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`adding of tag entries adds tag entries to custom registries: #example:something content 1`] = ` -{ - "replace": false, - "values": [ - "example:entry", - ], -} -`; - -exports[`adding of tag entries adds tag entries: #mineable/axe content 1`] = ` -{ - "replace": false, - "values": [ - { - "required": false, - "value": "create:brass_block", - }, - "minecraft:obsidian", - ], -} -`; - -exports[`removal of tag entries removes tag entries using id: #oak_logs content 1`] = ` -{ - "replace": true, - "values": [ - "minecraft:oak_wood", - "minecraft:stripped_oak_log", - "minecraft:stripped_oak_wood", - ], -} -`; - -exports[`removal of tag entries removes tag entries using predicate: modified #guarded_by_piglins 1`] = ` -{ - "replace": true, - "values": [ - "minecraft:barrel", - "minecraft:black_shulker_box", - "minecraft:blue_shulker_box", - "minecraft:brown_shulker_box", - "minecraft:chest", - "minecraft:cyan_shulker_box", - "minecraft:ender_chest", - "minecraft:gilded_blackstone", - "minecraft:gray_shulker_box", - "minecraft:green_shulker_box", - "minecraft:light_blue_shulker_box", - "minecraft:light_gray_shulker_box", - "minecraft:lime_shulker_box", - "minecraft:magenta_shulker_box", - "minecraft:orange_shulker_box", - "minecraft:pink_shulker_box", - "minecraft:purple_shulker_box", - "minecraft:red_shulker_box", - "minecraft:shulker_box", - "minecraft:trapped_chest", - "minecraft:white_shulker_box", - "minecraft:yellow_shulker_box", - ], -} -`; - -exports[`removal of tag entries removes tag entries using regex: modified #birch_logs 1`] = ` -{ - "replace": true, - "values": [ - "minecraft:birch_log", - "minecraft:birch_wood", - ], -} -`; - -exports[`removal of tag entries removes tag entries using tag: modified #guarded_by_piglins 1`] = ` -{ - "replace": true, - "values": [], -} -`; - -exports[`removal of tag entries removes tag entries using tag: modified #minable/axe 1`] = ` -{ - "replace": true, - "values": [ - "create:adjustable_chain_gearshift", - "create:analog_lever", - "create:andesite_casing", - "create:andesite_door", - "create:andesite_encased_cogwheel", - "create:andesite_encased_large_cogwheel", - "create:andesite_encased_shaft", - "create:belt", - "create:black_sail", - "create:black_seat", - "create:blue_sail", - "create:blue_seat", - "create:brass_casing", - "create:brass_door", - "create:brass_encased_cogwheel", - "create:brass_encased_large_cogwheel", - "create:brass_encased_shaft", - "create:brown_sail", - "create:brown_seat", - "create:cart_assembler", - "create:clipboard", - "create:clockwork_bearing", - "create:clutch", - "create:cogwheel", - "create:content_observer", - "create:contraption_controls", - "create:copper_casing", - "create:copper_door", - "create:copycat_panel", - "create:copycat_step", - "create:creative_crate", - "create:cuckoo_clock", - "create:cyan_sail", - "create:cyan_seat", - "create:deployer", - "create:depot", - "create:display_link", - "create:elevator_contact", - "create:elevator_pulley", - "create:encased_chain_drive", - "create:encased_fan", - "create:encased_fluid_pipe", - "create:flywheel", - "create:framed_glass_door", - "create:gantry_carriage", - "create:gantry_shaft", - "create:gearbox", - "create:gearshift", - "create:gray_sail", - "create:gray_seat", - "create:green_sail", - "create:green_seat", - "create:hand_crank", - "create:large_cogwheel", - "create:large_water_wheel", - "create:lectern_controller", - "create:light_blue_sail", - "create:light_blue_seat", - "create:light_gray_sail", - "create:light_gray_seat", - "create:lime_sail", - "create:lime_seat", - "create:linear_chassis", - "create:magenta_sail", - "create:magenta_seat", - "create:mechanical_arm", - "create:mechanical_bearing", - "create:mechanical_crafter", - "create:mechanical_drill", - "create:mechanical_harvester", - "create:mechanical_mixer", - "create:mechanical_piston", - "create:mechanical_piston_head", - "create:mechanical_plough", - "create:mechanical_press", - "create:mechanical_roller", - "create:mechanical_saw", - "create:mysterious_cuckoo_clock", - "create:nozzle", - "create:orange_sail", - "create:orange_seat", - "create:pink_sail", - "create:pink_seat", - "create:piston_extension_pole", - "create:portable_fluid_interface", - "create:portable_storage_interface", - "create:purple_sail", - "create:purple_seat", - "create:radial_chassis", - "create:railway_casing", - "create:red_sail", - "create:red_seat", - "create:redstone_contact", - "create:redstone_link", - "create:refined_radiance_casing", - "create:rope_pulley", - "create:rotation_speed_controller", - "create:sail_frame", - "create:schematic_table", - "create:secondary_linear_chassis", - "create:sequenced_gearshift", - "create:shadow_steel_casing", - "create:speedometer", - "create:sticky_mechanical_piston", - "create:stockpile_switch", - "create:stressometer", - "create:train_door", - "create:turntable", - "create:water_wheel", - "create:water_wheel_structure", - "create:weighted_ejector", - "create:white_sail", - "create:white_seat", - "create:windmill_bearing", - "create:wooden_bracket", - "create:yellow_sail", - "create:yellow_seat", - "minecraft:acacia_button", - "minecraft:acacia_door", - "minecraft:acacia_fence", - "minecraft:acacia_fence_gate", - "minecraft:acacia_planks", - "minecraft:acacia_pressure_plate", - "minecraft:acacia_sapling", - "minecraft:acacia_sign", - "minecraft:acacia_slab", - "minecraft:acacia_stairs", - "minecraft:acacia_trapdoor", - "minecraft:acacia_wall_sign", - "minecraft:attached_melon_stem", - "minecraft:attached_pumpkin_stem", - "minecraft:azalea", - "minecraft:bamboo", - "minecraft:barrel", - "minecraft:bee_nest", - "minecraft:beehive", - "minecraft:beetroots", - "minecraft:big_dripleaf", - "minecraft:big_dripleaf_stem", - "minecraft:birch_button", - "minecraft:birch_door", - "minecraft:birch_fence", - "minecraft:birch_fence_gate", - "minecraft:birch_planks", - "minecraft:birch_pressure_plate", - "minecraft:birch_sapling", - "minecraft:birch_sign", - "minecraft:birch_slab", - "minecraft:birch_stairs", - "minecraft:birch_trapdoor", - "minecraft:birch_wall_sign", - "minecraft:black_banner", - "minecraft:black_wall_banner", - "minecraft:blue_banner", - "minecraft:blue_wall_banner", - "minecraft:bookshelf", - "minecraft:brown_banner", - "minecraft:brown_mushroom", - "minecraft:brown_mushroom_block", - "minecraft:brown_wall_banner", - "minecraft:campfire", - "minecraft:carrots", - "minecraft:cartography_table", - "minecraft:carved_pumpkin", - "minecraft:cave_vines", - "minecraft:cave_vines_plant", - "minecraft:chest", - "minecraft:chorus_flower", - "minecraft:chorus_plant", - "minecraft:cocoa", - "minecraft:composter", - "minecraft:crafting_table", - "minecraft:crimson_button", - "minecraft:crimson_door", - "minecraft:crimson_fence", - "minecraft:crimson_fence_gate", - "minecraft:crimson_fungus", - "minecraft:crimson_planks", - "minecraft:crimson_pressure_plate", - "minecraft:crimson_sign", - "minecraft:crimson_slab", - "minecraft:crimson_stairs", - "minecraft:crimson_trapdoor", - "minecraft:crimson_wall_sign", - "minecraft:cyan_banner", - "minecraft:cyan_wall_banner", - "minecraft:dark_oak_button", - "minecraft:dark_oak_door", - "minecraft:dark_oak_fence", - "minecraft:dark_oak_fence_gate", - "minecraft:dark_oak_planks", - "minecraft:dark_oak_pressure_plate", - "minecraft:dark_oak_sapling", - "minecraft:dark_oak_sign", - "minecraft:dark_oak_slab", - "minecraft:dark_oak_stairs", - "minecraft:dark_oak_trapdoor", - "minecraft:dark_oak_wall_sign", - "minecraft:daylight_detector", - "minecraft:dead_bush", - "minecraft:fern", - "minecraft:fletching_table", - "minecraft:flowering_azalea", - "minecraft:glow_lichen", - "minecraft:grass", - "minecraft:gray_banner", - "minecraft:gray_wall_banner", - "minecraft:green_banner", - "minecraft:green_wall_banner", - "minecraft:hanging_roots", - "minecraft:jack_o_lantern", - "minecraft:jukebox", - "minecraft:jungle_button", - "minecraft:jungle_door", - "minecraft:jungle_fence", - "minecraft:jungle_fence_gate", - "minecraft:jungle_planks", - "minecraft:jungle_pressure_plate", - "minecraft:jungle_sapling", - "minecraft:jungle_sign", - "minecraft:jungle_slab", - "minecraft:jungle_stairs", - "minecraft:jungle_trapdoor", - "minecraft:jungle_wall_sign", - "minecraft:ladder", - "minecraft:large_fern", - "minecraft:lectern", - "minecraft:light_blue_banner", - "minecraft:light_blue_wall_banner", - "minecraft:light_gray_banner", - "minecraft:light_gray_wall_banner", - "minecraft:lily_pad", - "minecraft:lime_banner", - "minecraft:lime_wall_banner", - "minecraft:loom", - "minecraft:magenta_banner", - "minecraft:magenta_wall_banner", - "minecraft:melon", - "minecraft:melon_stem", - "minecraft:mushroom_stem", - "minecraft:nether_wart", - "minecraft:note_block", - "minecraft:oak_button", - "minecraft:oak_door", - "minecraft:oak_fence", - "minecraft:oak_fence_gate", - "minecraft:oak_planks", - "minecraft:oak_pressure_plate", - "minecraft:oak_sapling", - "minecraft:oak_sign", - "minecraft:oak_slab", - "minecraft:oak_stairs", - "minecraft:oak_trapdoor", - "minecraft:oak_wall_sign", - "minecraft:orange_banner", - "minecraft:orange_wall_banner", - "minecraft:pink_banner", - "minecraft:pink_wall_banner", - "minecraft:potatoes", - "minecraft:pumpkin", - "minecraft:pumpkin_stem", - "minecraft:purple_banner", - "minecraft:purple_wall_banner", - "minecraft:red_banner", - "minecraft:red_mushroom", - "minecraft:red_mushroom_block", - "minecraft:red_wall_banner", - "minecraft:scaffolding", - "minecraft:small_dripleaf", - "minecraft:smithing_table", - "minecraft:soul_campfire", - "minecraft:spore_blossom", - "minecraft:spruce_button", - "minecraft:spruce_door", - "minecraft:spruce_fence", - "minecraft:spruce_fence_gate", - "minecraft:spruce_planks", - "minecraft:spruce_pressure_plate", - "minecraft:spruce_sapling", - "minecraft:spruce_sign", - "minecraft:spruce_slab", - "minecraft:spruce_stairs", - "minecraft:spruce_trapdoor", - "minecraft:spruce_wall_sign", - "minecraft:sugar_cane", - "minecraft:sweet_berry_bush", - "minecraft:tall_grass", - "minecraft:trapped_chest", - "minecraft:twisting_vines", - "minecraft:twisting_vines_plant", - "minecraft:vine", - "minecraft:warped_button", - "minecraft:warped_door", - "minecraft:warped_fence", - "minecraft:warped_fence_gate", - "minecraft:warped_fungus", - "minecraft:warped_planks", - "minecraft:warped_pressure_plate", - "minecraft:warped_sign", - "minecraft:warped_slab", - "minecraft:warped_stairs", - "minecraft:warped_trapdoor", - "minecraft:warped_wall_sign", - "minecraft:weeping_vines", - "minecraft:weeping_vines_plant", - "minecraft:wheat", - "minecraft:white_banner", - "minecraft:white_wall_banner", - "minecraft:yellow_banner", - "minecraft:yellow_wall_banner", - ], -} -`; diff --git a/test/__snapshots__/tagsLoader.test.ts.snap b/test/__snapshots__/tags.test.ts.snap similarity index 76% rename from test/__snapshots__/tagsLoader.test.ts.snap rename to test/__snapshots__/tags.test.ts.snap index 1324cf8..d1cbb07 100644 --- a/test/__snapshots__/tagsLoader.test.ts.snap +++ b/test/__snapshots__/tags.test.ts.snap @@ -1,5 +1,27 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`adding of tag entries adds tag entries to custom registries: #example:something content 1`] = ` +{ + "replace": false, + "values": [ + "example:entry", + ], +} +`; + +exports[`adding of tag entries adds tag entries: #mineable/axe content 1`] = ` +{ + "replace": false, + "values": [ + { + "required": false, + "value": "create:brass_block", + }, + "minecraft:obsidian", + ], +} +`; + exports[`loading of tags loads tags correctly: #logs content 1`] = ` [ "#minecraft:crimson_stems", @@ -1197,3 +1219,379 @@ exports[`loading of tags resolves tags correctly: resolved #trapdoors entries 1` "minecraft:iron_trapdoor", ] `; + +exports[`removal of tag entries removes tag entries using id: #oak_logs content 1`] = ` +{ + "replace": true, + "values": [ + "minecraft:oak_wood", + "minecraft:stripped_oak_log", + "minecraft:stripped_oak_wood", + ], +} +`; + +exports[`removal of tag entries removes tag entries using predicate: modified #guarded_by_piglins 1`] = ` +{ + "replace": true, + "values": [ + "minecraft:barrel", + "minecraft:black_shulker_box", + "minecraft:blue_shulker_box", + "minecraft:brown_shulker_box", + "minecraft:chest", + "minecraft:cyan_shulker_box", + "minecraft:ender_chest", + "minecraft:gilded_blackstone", + "minecraft:gray_shulker_box", + "minecraft:green_shulker_box", + "minecraft:light_blue_shulker_box", + "minecraft:light_gray_shulker_box", + "minecraft:lime_shulker_box", + "minecraft:magenta_shulker_box", + "minecraft:orange_shulker_box", + "minecraft:pink_shulker_box", + "minecraft:purple_shulker_box", + "minecraft:red_shulker_box", + "minecraft:shulker_box", + "minecraft:trapped_chest", + "minecraft:white_shulker_box", + "minecraft:yellow_shulker_box", + ], +} +`; + +exports[`removal of tag entries removes tag entries using regex: modified #birch_logs 1`] = ` +{ + "replace": true, + "values": [ + "minecraft:birch_log", + "minecraft:birch_wood", + ], +} +`; + +exports[`removal of tag entries removes tag entries using tag: modified #guarded_by_piglins 1`] = ` +{ + "replace": true, + "values": [], +} +`; + +exports[`removal of tag entries removes tag entries using tag: modified #minable/axe 1`] = ` +{ + "replace": true, + "values": [ + "create:adjustable_chain_gearshift", + "create:analog_lever", + "create:andesite_casing", + "create:andesite_door", + "create:andesite_encased_cogwheel", + "create:andesite_encased_large_cogwheel", + "create:andesite_encased_shaft", + "create:belt", + "create:black_sail", + "create:black_seat", + "create:blue_sail", + "create:blue_seat", + "create:brass_casing", + "create:brass_door", + "create:brass_encased_cogwheel", + "create:brass_encased_large_cogwheel", + "create:brass_encased_shaft", + "create:brown_sail", + "create:brown_seat", + "create:cart_assembler", + "create:clipboard", + "create:clockwork_bearing", + "create:clutch", + "create:cogwheel", + "create:content_observer", + "create:contraption_controls", + "create:copper_casing", + "create:copper_door", + "create:copycat_panel", + "create:copycat_step", + "create:creative_crate", + "create:cuckoo_clock", + "create:cyan_sail", + "create:cyan_seat", + "create:deployer", + "create:depot", + "create:display_link", + "create:elevator_contact", + "create:elevator_pulley", + "create:encased_chain_drive", + "create:encased_fan", + "create:encased_fluid_pipe", + "create:flywheel", + "create:framed_glass_door", + "create:gantry_carriage", + "create:gantry_shaft", + "create:gearbox", + "create:gearshift", + "create:gray_sail", + "create:gray_seat", + "create:green_sail", + "create:green_seat", + "create:hand_crank", + "create:large_cogwheel", + "create:large_water_wheel", + "create:lectern_controller", + "create:light_blue_sail", + "create:light_blue_seat", + "create:light_gray_sail", + "create:light_gray_seat", + "create:lime_sail", + "create:lime_seat", + "create:linear_chassis", + "create:magenta_sail", + "create:magenta_seat", + "create:mechanical_arm", + "create:mechanical_bearing", + "create:mechanical_crafter", + "create:mechanical_drill", + "create:mechanical_harvester", + "create:mechanical_mixer", + "create:mechanical_piston", + "create:mechanical_piston_head", + "create:mechanical_plough", + "create:mechanical_press", + "create:mechanical_roller", + "create:mechanical_saw", + "create:mysterious_cuckoo_clock", + "create:nozzle", + "create:orange_sail", + "create:orange_seat", + "create:pink_sail", + "create:pink_seat", + "create:piston_extension_pole", + "create:portable_fluid_interface", + "create:portable_storage_interface", + "create:purple_sail", + "create:purple_seat", + "create:radial_chassis", + "create:railway_casing", + "create:red_sail", + "create:red_seat", + "create:redstone_contact", + "create:redstone_link", + "create:refined_radiance_casing", + "create:rope_pulley", + "create:rotation_speed_controller", + "create:sail_frame", + "create:schematic_table", + "create:secondary_linear_chassis", + "create:sequenced_gearshift", + "create:shadow_steel_casing", + "create:speedometer", + "create:sticky_mechanical_piston", + "create:stockpile_switch", + "create:stressometer", + "create:train_door", + "create:turntable", + "create:water_wheel", + "create:water_wheel_structure", + "create:weighted_ejector", + "create:white_sail", + "create:white_seat", + "create:windmill_bearing", + "create:wooden_bracket", + "create:yellow_sail", + "create:yellow_seat", + "minecraft:acacia_button", + "minecraft:acacia_door", + "minecraft:acacia_fence", + "minecraft:acacia_fence_gate", + "minecraft:acacia_planks", + "minecraft:acacia_pressure_plate", + "minecraft:acacia_sapling", + "minecraft:acacia_sign", + "minecraft:acacia_slab", + "minecraft:acacia_stairs", + "minecraft:acacia_trapdoor", + "minecraft:acacia_wall_sign", + "minecraft:attached_melon_stem", + "minecraft:attached_pumpkin_stem", + "minecraft:azalea", + "minecraft:bamboo", + "minecraft:barrel", + "minecraft:bee_nest", + "minecraft:beehive", + "minecraft:beetroots", + "minecraft:big_dripleaf", + "minecraft:big_dripleaf_stem", + "minecraft:birch_button", + "minecraft:birch_door", + "minecraft:birch_fence", + "minecraft:birch_fence_gate", + "minecraft:birch_planks", + "minecraft:birch_pressure_plate", + "minecraft:birch_sapling", + "minecraft:birch_sign", + "minecraft:birch_slab", + "minecraft:birch_stairs", + "minecraft:birch_trapdoor", + "minecraft:birch_wall_sign", + "minecraft:black_banner", + "minecraft:black_wall_banner", + "minecraft:blue_banner", + "minecraft:blue_wall_banner", + "minecraft:bookshelf", + "minecraft:brown_banner", + "minecraft:brown_mushroom", + "minecraft:brown_mushroom_block", + "minecraft:brown_wall_banner", + "minecraft:campfire", + "minecraft:carrots", + "minecraft:cartography_table", + "minecraft:carved_pumpkin", + "minecraft:cave_vines", + "minecraft:cave_vines_plant", + "minecraft:chest", + "minecraft:chorus_flower", + "minecraft:chorus_plant", + "minecraft:cocoa", + "minecraft:composter", + "minecraft:crafting_table", + "minecraft:crimson_button", + "minecraft:crimson_door", + "minecraft:crimson_fence", + "minecraft:crimson_fence_gate", + "minecraft:crimson_fungus", + "minecraft:crimson_planks", + "minecraft:crimson_pressure_plate", + "minecraft:crimson_sign", + "minecraft:crimson_slab", + "minecraft:crimson_stairs", + "minecraft:crimson_trapdoor", + "minecraft:crimson_wall_sign", + "minecraft:cyan_banner", + "minecraft:cyan_wall_banner", + "minecraft:dark_oak_button", + "minecraft:dark_oak_door", + "minecraft:dark_oak_fence", + "minecraft:dark_oak_fence_gate", + "minecraft:dark_oak_planks", + "minecraft:dark_oak_pressure_plate", + "minecraft:dark_oak_sapling", + "minecraft:dark_oak_sign", + "minecraft:dark_oak_slab", + "minecraft:dark_oak_stairs", + "minecraft:dark_oak_trapdoor", + "minecraft:dark_oak_wall_sign", + "minecraft:daylight_detector", + "minecraft:dead_bush", + "minecraft:fern", + "minecraft:fletching_table", + "minecraft:flowering_azalea", + "minecraft:glow_lichen", + "minecraft:grass", + "minecraft:gray_banner", + "minecraft:gray_wall_banner", + "minecraft:green_banner", + "minecraft:green_wall_banner", + "minecraft:hanging_roots", + "minecraft:jack_o_lantern", + "minecraft:jukebox", + "minecraft:jungle_button", + "minecraft:jungle_door", + "minecraft:jungle_fence", + "minecraft:jungle_fence_gate", + "minecraft:jungle_planks", + "minecraft:jungle_pressure_plate", + "minecraft:jungle_sapling", + "minecraft:jungle_sign", + "minecraft:jungle_slab", + "minecraft:jungle_stairs", + "minecraft:jungle_trapdoor", + "minecraft:jungle_wall_sign", + "minecraft:ladder", + "minecraft:large_fern", + "minecraft:lectern", + "minecraft:light_blue_banner", + "minecraft:light_blue_wall_banner", + "minecraft:light_gray_banner", + "minecraft:light_gray_wall_banner", + "minecraft:lily_pad", + "minecraft:lime_banner", + "minecraft:lime_wall_banner", + "minecraft:loom", + "minecraft:magenta_banner", + "minecraft:magenta_wall_banner", + "minecraft:melon", + "minecraft:melon_stem", + "minecraft:mushroom_stem", + "minecraft:nether_wart", + "minecraft:note_block", + "minecraft:oak_button", + "minecraft:oak_door", + "minecraft:oak_fence", + "minecraft:oak_fence_gate", + "minecraft:oak_planks", + "minecraft:oak_pressure_plate", + "minecraft:oak_sapling", + "minecraft:oak_sign", + "minecraft:oak_slab", + "minecraft:oak_stairs", + "minecraft:oak_trapdoor", + "minecraft:oak_wall_sign", + "minecraft:orange_banner", + "minecraft:orange_wall_banner", + "minecraft:pink_banner", + "minecraft:pink_wall_banner", + "minecraft:potatoes", + "minecraft:pumpkin", + "minecraft:pumpkin_stem", + "minecraft:purple_banner", + "minecraft:purple_wall_banner", + "minecraft:red_banner", + "minecraft:red_mushroom", + "minecraft:red_mushroom_block", + "minecraft:red_wall_banner", + "minecraft:scaffolding", + "minecraft:small_dripleaf", + "minecraft:smithing_table", + "minecraft:soul_campfire", + "minecraft:spore_blossom", + "minecraft:spruce_button", + "minecraft:spruce_door", + "minecraft:spruce_fence", + "minecraft:spruce_fence_gate", + "minecraft:spruce_planks", + "minecraft:spruce_pressure_plate", + "minecraft:spruce_sapling", + "minecraft:spruce_sign", + "minecraft:spruce_slab", + "minecraft:spruce_stairs", + "minecraft:spruce_trapdoor", + "minecraft:spruce_wall_sign", + "minecraft:sugar_cane", + "minecraft:sweet_berry_bush", + "minecraft:tall_grass", + "minecraft:trapped_chest", + "minecraft:twisting_vines", + "minecraft:twisting_vines_plant", + "minecraft:vine", + "minecraft:warped_button", + "minecraft:warped_door", + "minecraft:warped_fence", + "minecraft:warped_fence_gate", + "minecraft:warped_fungus", + "minecraft:warped_planks", + "minecraft:warped_pressure_plate", + "minecraft:warped_sign", + "minecraft:warped_slab", + "minecraft:warped_stairs", + "minecraft:warped_trapdoor", + "minecraft:warped_wall_sign", + "minecraft:weeping_vines", + "minecraft:weeping_vines_plant", + "minecraft:wheat", + "minecraft:white_banner", + "minecraft:white_wall_banner", + "minecraft:yellow_banner", + "minecraft:yellow_wall_banner", + ], +} +`; diff --git a/test/recipeReplacer.test.ts b/test/recipe.test.ts similarity index 93% rename from test/recipeReplacer.test.ts rename to test/recipe.test.ts index 6e24f6c..de074e4 100644 --- a/test/recipeReplacer.test.ts +++ b/test/recipe.test.ts @@ -1,4 +1,4 @@ -import RecipeEmitter from '../src/emit/recipe' +import { EMPTY_RECIPE } from '../src/emit/recipe' import PackLoader from '../src/loader/pack' import { ShapedRecipeDefinition } from '../src/parser/recipe/vanilla/shaped' import createTestAcceptor from './mock/TestAcceptor' @@ -98,8 +98,8 @@ describe('recipe removal', () => { expect(acceptor.paths().length).toBe(2) - expect(acceptor.jsonAt('data/minecraft/recipe/piston.json')).toMatchObject(RecipeEmitter.EMPTY_RECIPE) - expect(acceptor.jsonAt('data/minecraft/recipe/sticky_piston.json')).toMatchObject(RecipeEmitter.EMPTY_RECIPE) + expect(acceptor.jsonAt('data/minecraft/recipe/piston.json')).toMatchObject(EMPTY_RECIPE) + expect(acceptor.jsonAt('data/minecraft/recipe/sticky_piston.json')).toMatchObject(EMPTY_RECIPE) }) it('removes recipes with result filter', async () => { @@ -113,12 +113,10 @@ describe('recipe removal', () => { expect(acceptor.paths().length).toBe(3) - expect(acceptor.jsonAt('data/minecraft/recipe/cooked_beef.json')).toMatchObject(RecipeEmitter.EMPTY_RECIPE) - expect(acceptor.jsonAt('data/minecraft/recipe/cooked_beef_from_smoking.json')).toMatchObject( - RecipeEmitter.EMPTY_RECIPE - ) + expect(acceptor.jsonAt('data/minecraft/recipe/cooked_beef.json')).toMatchObject(EMPTY_RECIPE) + expect(acceptor.jsonAt('data/minecraft/recipe/cooked_beef_from_smoking.json')).toMatchObject(EMPTY_RECIPE) expect(acceptor.jsonAt('data/minecraft/recipe/cooked_beef_from_campfire_cooking.json')).toMatchObject( - RecipeEmitter.EMPTY_RECIPE + EMPTY_RECIPE ) }) }) diff --git a/test/tagReplacer.test.ts b/test/tags.test.ts similarity index 63% rename from test/tagReplacer.test.ts rename to test/tags.test.ts index 5b5f64d..69ff661 100644 --- a/test/tagReplacer.test.ts +++ b/test/tags.test.ts @@ -14,6 +14,49 @@ afterEach(() => { loader.clear() }) +describe('loading of tags', () => { + it('loads tags correctly', async () => { + const itemTags = loader.tagRegistry('items') + const blockTags = loader.tagRegistry('blocks') + + expect(blockTags.list().length).toBe(259) + expect(itemTags.list().length).toBe(302) + + expect(blockTags.get('#minecraft:mineable/pickaxe')).toMatchSnapshot('#mineable/pickaxe content') + expect(itemTags.get('#minecraft:logs')).toMatchSnapshot('#logs content') + }) + + it('resolves tags correctly', async () => { + const itemTags = loader.tagRegistry('items') + const blockTags = loader.tagRegistry('blocks') + + expect(blockTags.resolve('#minecraft:mineable/axe')).toMatchSnapshot('resolved #mineable/axe entries') + expect(itemTags.resolve('#minecraft:trapdoors')).toMatchSnapshot('resolved #trapdoors entries') + }) +}) + +describe('tag contain tests', () => { + it('finds item in tag', async () => { + const blockTags = loader.tagRegistry('blocks') + + expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:note_block')).toBeTruthy() + expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:oak_log')).toBeTruthy() + expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:stripped_oak_log')).toBeTruthy() + expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:chest')).toBeTruthy() + + expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:stone')).toBeFalsy() + }) + + it('finds tag in tag', async () => { + const blockTags = loader.tagRegistry('blocks') + + expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:logs')).toBeTruthy() + expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:logs_that_burn')).toBeTruthy() + + expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:trapdoors')).toBeFalsy() + }) +}) + describe('adding of tag entries', () => { it('adds tag entries', async () => { const acceptor = createTestAcceptor() diff --git a/test/tagsLoader.test.ts b/test/tagsLoader.test.ts deleted file mode 100644 index ba659ee..0000000 --- a/test/tagsLoader.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import PackLoader from '../src/loader/pack' -import createTestLogger from './mock/TestLogger' -import createTestResolver from './mock/TestResolver' - -const logger = createTestLogger() -const loader = new PackLoader(logger) - -beforeAll(async () => { - const resolver = createTestResolver({ include: ['data/*/tags/**/*.json'] }) - await loader.loadFrom(resolver) -}, 10_000) - -afterEach(() => { - loader.clear() -}) - -describe('loading of tags', () => { - it('loads tags correctly', async () => { - const itemTags = loader.tagRegistry('items') - const blockTags = loader.tagRegistry('blocks') - - expect(blockTags.list().length).toBe(259) - expect(itemTags.list().length).toBe(302) - - expect(blockTags.get('#minecraft:mineable/pickaxe')).toMatchSnapshot('#mineable/pickaxe content') - expect(itemTags.get('#minecraft:logs')).toMatchSnapshot('#logs content') - }) - - it('resolves tags correctly', async () => { - const itemTags = loader.tagRegistry('items') - const blockTags = loader.tagRegistry('blocks') - - expect(blockTags.resolve('#minecraft:mineable/axe')).toMatchSnapshot('resolved #mineable/axe entries') - expect(itemTags.resolve('#minecraft:trapdoors')).toMatchSnapshot('resolved #trapdoors entries') - }) -}) - -describe('tag contain tests', () => { - it('finds item in tag', async () => { - const blockTags = loader.tagRegistry('blocks') - - expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:note_block')).toBeTruthy() - expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:oak_log')).toBeTruthy() - expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:stripped_oak_log')).toBeTruthy() - expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:chest')).toBeTruthy() - - expect(blockTags.contains('#minecraft:mineable/axe', 'minecraft:stone')).toBeFalsy() - }) - - it('finds tag in tag', async () => { - const blockTags = loader.tagRegistry('blocks') - - expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:logs')).toBeTruthy() - expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:logs_that_burn')).toBeTruthy() - - expect(blockTags.contains('#minecraft:mineable/axe', '#minecraft:trapdoors')).toBeFalsy() - }) -})