Package: mcpack
⚠️ THIS PROJECT IS DEPRECATED ⚠️Please migrate tohttps://github.com/vberlier/beetmcpackA python library for programmatically creating and editingMinecraft data packs. Requires python 3.7.frommcpackimportDataPack,Functionpack=DataPack('My cool pack','This is the description of my pack.')pack['my_cool_pack:hello']=Function('say Hello, world!\n''give @s minecraft:dead_bush\n')pack.dump('.minecraft/saves/New World/datapacks')InstallationMake sure that you're using python 3.7 or above. The package can be installed withpip.$pipinstallmcpackUsing mcpackCheck out theexamplesfor a quick overview.Creating a data packTheDataPackclass represents a minecraft data pack.frommcpackimportDataPackpack=DataPack('Test','Test description.')print(pack.name)# 'Test'print(pack.description)# 'Test description.'print(pack.pack_format)# 1print(pack.namespaces)# defaultdict(<class 'mcpack.Namespace'>, {})You can load already existing data packs using theloadclass method.frommcpackimportDataPackpack=DataPack.load('.minecraft/save/New World/datapacks/Test')Thedumpmethod allows you to generate the actual Minecraft data pack. The method will raise aValueErrorif the data pack already exists. You can explicitly overwrite the existing data pack by setting theoverwriteargument toTrue.frommcpackimportDataPackpack=DataPack('Test','Test description.')pack.dump('.minecraft/save/New World/datapacks')pack.dump('.minecraft/save/New World/datapacks',overwrite=True)NamespacesNamespaceobjects hold references to data pack items using a separate dictionary for each type of item.frommcpackimportNamespacenamespace=Namespace()print(namespace.advancements)# {}print(namespace.functions)# {}print(namespace.loot_tables)# {}print(namespace.recipes)# {}print(namespace.structures)# {}print(namespace.block_tags)# {}print(namespace.item_tags)# {}print(namespace.fluid_tags)# {}print(namespace.function_tags)# {}print(namespace.entity_type_tags)# {}You can add namespaces toDataPackobjects using thenamespacesattribute. Note that you won't usually need to create namespaces yourself. If you want to edit a namespace, you just need to retrieve it and thedefaultdictwill create an empty namespace for you if it doesn't already exist.frommcpackimportDataPackpack=DataPack('Test','Test description.')print(pack.namespaces['test'])# Namespace(...)To make things even more convenient, the__getitem__and__setitem__methods ofDataPackobjects are mapped to thenamespacesattribute. It means that you can access namespaces directly from theDataPackobject.print(pack['test'])# Namespace(...)Adding items to namespaces is pretty straight-forward. Simply add them to their respective dictionaries.frommcpackimport(DataPack,Advancement,Function,LootTable,Recipe,Structure,BlockTag,ItemTag,FluidTag,FunctionTag,EntityTypeTag)pack=DataPack('Test','Test description.')pack['test'].advancements['foo']=Advancement(...)pack['test'].functions['foo/spam']=Function(...)pack['test'].loot_tables['foo/egg']=LootTable(...)pack['test'].recipes['bar']=Recipe(...)pack['test'].structures['bar/spam']=Structure(...)pack['test'].block_tags['bar/egg']=BlockTag(...)pack['test'].item_tags['baz']=ItemTag(...)pack['test'].fluid_tags['baz/spam']=FluidTag(...)pack['test'].function_tags['baz/egg']=FunctionTag(...)pack['test'].entity_type_tags['qux']=EntityTypeTag(...)You can also use theDataPackobject directly. The__setitem__method actually checks if the key looks likenamespace:pathand dispatches the item automatically. We can now simplify the previous piece of code quite a bit.frommcpackimport(DataPack,Advancement,Function,LootTable,Recipe,Structure,BlockTag,ItemTag,FluidTag,FunctionTag,EntityTypeTag)pack=DataPack('Test','Test description.')pack['test:foo']=Advancement(...)pack['test:foo/spam']=Function(...)pack['test:foo/egg']=LootTable(...)pack['test:bar']=Recipe(...)pack['test:bar/spam']=Structure(...)pack['test:bar/egg']=BlockTag(...)pack['test:baz']=ItemTag(...)pack['test:baz/spam']=FluidTag(...)pack['test:baz/egg']=FunctionTag(...)pack['test:qux']=EntityTypeTag(...)AdvancementsAdvancementobjects represent Minecraft advancements.frommcpackimportDataPack,Advancementpack=DataPack('Test','Test description.')pack['test:foo']=Advancement()advancement=pack['test'].advancements['foo']print(advancement.display)# Noneprint(advancement.parent)# Noneprint(advancement.criteria)# {}print(advancement.requirements)# Noneprint(advancement.rewards)# NoneAll the attributes can be set in the constructor. They mirror the root properties of the advancement JSON file format.Check out thewikifor further details.FunctionsFunctionobjects represent Minecraft functions.frommcpackimportDataPack,Functionpack=DataPack('Test','Test description.')pack['test:foo']=Function()function=pack['test'].functions['foo']print(function.body)# ''Thebodyattribute can be set in the constructor. The body of the function corresponds to the content of the actual.mcfunctionfile.Check out thewikifor further details.Loot tablesLootTableobjects represent Minecraft loot tables.frommcpackimportDataPack,LootTablepack=DataPack('Test','Test description.')pack['test:foo']=LootTable()loot_table=pack['test'].loot_tables['foo']print(loot_table.pools)# []print(loot_table.type)# 'generic'print(loot_table.functions)# NoneAll the attributes can be set in the constructor. They mirror the root properties of the loot table JSON file format.Check out thewikifor further details.RecipesRecipeobjects represent Minecraft recipes.frommcpackimportDataPack,Recipepack=DataPack('Test','Test description.')pack['test:foo']=Recipe()recipe=pack['test'].recipes['foo']print(recipe.type)# 'crafting_shaped'print(recipe.group)# Noneprint(recipe.pattern)# []print(recipe.key)# {}print(recipe.ingredient)# Noneprint(recipe.ingredients)# Noneprint(recipe.result)# {}print(recipe.experience)# Noneprint(recipe.cookingtime)# Noneprint(recipe.count)# NoneAll the attributes can be set in the constructor. They mirror the root properties of the recipe JSON file format.Check out thewikifor further details.StructuresStructureobjects represent Minecraft structures.frommcpackimportDataPack,Structurepack=DataPack('Test','Test description.')pack['test:foo']=Structure()structure=pack['test'].structures['foo']print(structure.data_version)# Int(1503)print(structure.author)# String('')print(structure.size)# List[Int]([0, 0, 0])print(structure.palette)# List[State]([])print(structure.palettes)# List[List[State]]([])print(structure.blocks)# List[Block]([])print(structure.entities)# List[Entity]([])All the attributes can be set in the constructor. They mirror the root properties of the structure NBT file format.mcpackusesnbtlibto manipulate nbt data. TheStructureclass inherits from annbtlibschema that takes care of wrapping python values with the appropriate nbt tags.Check out thewikifor further details.TagsBlockTag,ItemTag,FluidTag,FunctionTagandEntityTypeTagobjects represent Minecraft block, item, fluid, function and entity type tags respectively. They are all identical in structure, the only difference between them is the namespace directory they get written to.frommcpackimportDataPack,BlockTagpack=DataPack('Test','Test description.')pack['test:foo']=BlockTag()block_tag=pack['test'].block_tags['foo']print(block_tag.values)# []print(block_tag.replace)# FalseThevaluesandreplaceattributes can be set in the constructor. They mirror the root properties of the tag JSON file format.Check out thewikifor further details.ContributingContributions are welcome. This project usespoetryso you'll need to install it first if you want to be able to work with the project locally.$curl-sSLhttps://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py|pythonYou should now be able to install the required dependencies.$poetryinstallYou can run the tests withpoetry run pytest.$poetryrunpytestThe project can also download the latest minecraft releases and run tests against the vanilla data pack. You can enable these tests by using the--vanillaflag.$poetryrunpytest--vanillaLicense -MIT