Basic world interaction¶
The Editor and Block classes¶
The most important GDPC objects for world interaction are the Editor
and Block classes.
They are defined in the gdpc.editor and gdpc.block
modules, but they can also be imported directly from the root package:
from gdpc import Editor, Block.
The Editor class is the main point of communication between GDPC and
the GDMC HTTP interface, and thus, the Minecraft world. Almost every form of
world interaction goes through it. It has methods like
placeBlock() and getBlock(),
and it stores various settings, resources, buffers and caches related to world
interaction.
The Block class represents a Minecraft block, which is what you pass
to functions like Editor.placeBlock and what functions like
Editor.getBlock return. Block instances that represent “simple” blocks can
be created by passing the technical ID of the block to the constructor:
block = Block("stone"). For more details and more complex cases, see
Overview - Advanced blocks.
Getting/setting blocks¶
Blocks can be placed with Editor.placeBlock(). It has two required
parameters: the (X,Y,Z)-coordinates to place a block at, and the
block to place (a Block object).
from gdpc import Editor, Block
editor = Editor()
editor.placeBlock((0,128,0), Block("red_concrete"))
Similarly, blocks can be retrieved with Editor.getBlock():
block = editor.getBlock((0,128,0))
print(block) # e.g. "minecraft:red_concrete"
Note
In the snippets above, (0,128,0) is an example of a 3D vector: three numbers
that indicate a position in space. In GDPC, any object that “behaves like a
vector” will work for vector parameters. This includes things like tuples, lists
and numpy arrays.
More info will follow in Overview - Vectors.
More basic interaction¶
To get the biome at a position, use Editor.getBiome(). This will return
the biome’s namespaced ID, such as “minecraft:plains”.
biome = editor.getBiome((0,128,0))
print(biome) # e.g. "minecraft:plains"
To run a Minecraft command in the world,
use Editor.runCommand(). The leading “/” must be omitted.
editor.runCommand("say hello world!")
To get the Minecraft version you’re interacting with, use
Editor.getMinecraftVersion()
version = editor.getMinecraftVersion()
print(version) # e.g. "1.19.2"