Open javier-cantu opened 1 month ago
I used a Python script to open the minecraft.jar file and retrieve all the available blocks from the blockstates folder. I extracted the list of blocks and printed them to see what's available. However, even though I have the list, I haven't been able to orient blocks like stairs in any direction other than the default (north), and I'm struggling to change their orientation.
After all that, I found this URL with all the block data values: https://minecraft.wiki/w/Java_Edition_data_values/Blocks, which had everything I was looking for that I somehow missed earlier! Haha.
Hi there :wave:
Regarding the block list:
Great you found the blocks already, I would have also recommended to read them from your version in the client.jar
at assets/minecraft/blockstates
.
For example, on Ubuntu/Linux with the Prism Launcher, the blocks would be at:
~/.local/share/PrismLauncher/libraries/com/mojang/minecraft/[version]/minecraft-[version]-client.jar/assets/minecraft/blockstates
Or on Windows with the Legacy Minecraft Launcher, the blocks would be at:
%appdata%\.minecraft\versions\[version]\[version].jar\assets\minecraft\blockstates
This does potentially not include blocks added with mods, which can be placed with their namespace and block id, e.g., mod_name:block_id
.
I believe this would make a great feature to query all available blocks directly using mcpq, I'll add it to the next protocol version :+1:
Regarding the block orientation: Setting the block states/properties is not natively supported at the moment! This is the next major point in the library that I want to add, as it is so important (in addition to setting nbt/component, which is also missing)!
Block orientation is block states, which I would recommend to set with a command explicitly at the moment:
pos = Vec3(<x>, <y>, <z>).floor()
mc.runCommand(f"setblock {pos.x} {pos.y} {pos.z} minecraft:spruce_stairs[facing=south]")
This is somewhat unfortunate as it is much more complicated than it has to be, but you could put this into a new function like so:
def build(world, block, pos, states: dict[str, str] | None = None):
pos = pos.floor()
if states is None:
world.setBlock(block, pos)
else:
states_list = ",".join(f"{key}={val}" for key,val in states.items())
world.runCommand(f"setblock {pos.x} {pos.y} {pos.z} {block}[{states_list}]")
build(mc, "spruce_stairs", pos)
build(mc, "spruce_stairs", pos, {"facing": "east", "waterlogged": "true"})
This way you could call it with a dict of property values and use it as a replacement for regular setBlock
.
Most things that are currently missing can be simulated using /-commands in this way, until they are natively supported by the protocol. Hope this helps for the moment!
PS: For example, the same method is used to implement the world.setBed
function at the moment.
PPS: You can read the available block states of any given block using the F3 menu in game or at the wiki.
Perfect, I'll be using runCommand() to build for now. Thank you!!
Hello,
I have successfully placed blocks using the following command:
mc.setBlock("obsidian", pos)
I have two questions:
Is there any command or method available to get a list of all the block types that I can use with setBlock()? Because now I can't use numbers to guess.
How can I place blocks that need to face a specific direction, such as stairs? Is there a way to specify the orientation when placing these blocks?
Thank you for your help!