Create python objects that represent Minecraft blocks, items, and entities.
Project description
Minecraft Object Utils
A python library for creating objects that represent blocks, items, and entities from Minecraft Java Edition.
Features
- Support for multiple versions of vanilla Minecraft
- Support for modded Minecraft by importing from custom toml files
- Ensure that block states are valid
Basic Usage
Vanilla Minecraft
The default constructor will reflect objects from the latest version of minecraft. The minecraft namespace is assumed if one is not supplied in the block name.
Basic Example: create a dirt block.
from minecraft_object_utils import MinecraftObjectFactory
mcof = MinecraftObjectFactory()
block1 = mcof.block.create("dirt") # same result as "minecraft:dirt"
item1 = mcof.item.create("minecraft:egg") # same result as "egg"
entity1 = mcof.entity.create("chicken")
Example: create blocks and set some properties.
block2 = mcof.block.create("dispenser")
print(block2.get_state("facing")) # default is "north"
block2.set_state("facing", "east")
print(block2.get_state("facing"))
block2.set_state("triggered", "very") # will error, invalid state
block2.set_state("color", "red") # will error, invalid property
# You can also specify initial block state values with keyword arguments
block3 = mcof.block.create("repeater", facing="south", delay=4)
Modded Minecraft
You can create and import toml files to represent objects from mods.
Example: for Create mod v0.5.0i, make "/your/configs/dir/create-0.5.0i-block.toml" and import:
from minecraft_object_utils import MinecraftObjectFactory, ModInfo
mods = [
ModInfo("minecraft", "1.19"),
ModInfo("create", "0.5.0i", "/your/configs/dir"),
]
mcof_mods = MinecraftObjectFactory(mods)
block3 = mcof_mods.block.create("stone") # assumes "minecraft:stone"
block4 = mcof_mods.block.create("create:chute")
You can also register info to a factory manually. Example:
from minecraft_object_utils import BlockProperty, BlockTraits, MinecraftObjectFactory
cust_f = MinecraftObjectFactory([])
bt1 = BlockTraits("yourmod:yourblock") # block with no state
bt2 = BlockTraits(
"othermod:otherblock",
props=[
BlockProperty("awesome", False, [True, False]),
BlockProperty("fakename", "foo", ["foo", "bar", "baz"]),
],
)
cust_f.block.register(bt1)
cust_f.block.register(bt2)
block5 = cust_f.block.create("yourmod:yourblock")
block6 = cust_f.block.create("othermod:otherblock")
block6.set_state("awesome", True)
Generating toml files
I generated the toml by running Minecraft out of IntelliJ. I'd like to make a fabric/forge mod that can output these files. For now, some rough code is here: minecraft-registry-dumper
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for minecraft_object_utils-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8032fcc52344b1851d35420aa36e9cd1baca03441f22f0dafacdc5ff2f250453 |
|
MD5 | 22db604ea2bfaeeda8aadcb4d8371720 |
|
BLAKE2b-256 | af226e716933f6bf51f2e0c78223a5f385f44d99e82eb6ef133f561e26b70b2e |
Hashes for minecraft_object_utils-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f01fa424dda08e5a0d1ace54acf3cad2c0d74f93a71f35dfeee82a4f18f4c00 |
|
MD5 | 39159a55aca3b1a536ff2a919bee4f8a |
|
BLAKE2b-256 | 0a2b9a85c5516be28361e3ddb76728889a1ec7bc2614e02514092049c516ea06 |