Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ running the [ELCI](https://github.com/rozukke/ELCI) plugin and using C++. It was
This library is based on [mcpi](https://github.com/martinohanlon/mcpi), which is a Python library with similar functionality.

In addition to C++ support, this library implements several new commands supported by [ELCI](https://github.com/rozukke/ELCI):
- `getBlocks` to get a cuboid of blocks with modifiers in a performant manner,
- `getHeights` to get a 2D area of heights in a performant manner,
- `doCommand` to perform an in-game minecraft command which allows for additional functionality.
- `get_blocks` to get a cuboid of blocks with modifiers in a performant manner,
- `get_heights` to get a 2D area of heights in a performant manner,
- `do_command` to perform an in-game minecraft command which allows for additional functionality.

This C++ version was created for the Royal Melbourne Institute of Technology (RMIT) to supplement the **COSC2084**
(Programming Studio 2) course.
Expand Down
40 changes: 20 additions & 20 deletions example/game-of-life/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
}

Life::Life(int width, int depth) : width(width), depth(depth), isRunning(false), delay(250) {
buildPosition = mc.getPlayerPosition();
buildPosition = mc.get_player_position();
buildPosition.y -= 5;
buildPosition.x -= width / 2;
buildPosition.z -= depth / 2;
Expand All @@ -75,15 +75,15 @@ Life::Life(int width, int depth) : width(width), depth(depth), isRunning(false),
}
}

mc.doCommand("clear @p");
mc.doCommand("give @p minecraft:white_concrete");
mc.doCommand("give @p minecraft:black_concrete");
mc.doCommand("give @p minecraft:green_concrete");
mc.doCommand("give @p minecraft:red_concrete");
mc.doCommand("give @p minecraft:yellow_concrete");
mc.doCommand("give @p minecraft:blue_concrete");
mc.doCommand("give @p minecraft:pink_concrete");
mc.doCommand("give @p minecraft:barrier");
mc.do_command("clear @p");
mc.do_command("give @p minecraft:white_concrete");
mc.do_command("give @p minecraft:black_concrete");
mc.do_command("give @p minecraft:green_concrete");
mc.do_command("give @p minecraft:red_concrete");
mc.do_command("give @p minecraft:yellow_concrete");
mc.do_command("give @p minecraft:blue_concrete");
mc.do_command("give @p minecraft:pink_concrete");
mc.do_command("give @p minecraft:barrier");
}

Life::~Life() {
Expand All @@ -95,47 +95,47 @@ Life::~Life() {

void Life::Update() {
// check for actions
mcpp::Chunk chunk = mc.getBlocks(upperBuildPosition, upperBounds);
mcpp::Chunk chunk = mc.get_blocks(upperBuildPosition, upperBounds);
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
mcpp::BlockType block = chunk.get(x, 0, z);

mcpp::Coordinate position(upperBuildPosition.x + x, upperBuildPosition.y,
upperBuildPosition.z + z);
if (block != mcpp::Blocks::AIR) {
mc.setBlock(position, mcpp::Blocks::AIR);
mc.set_block(position, mcpp::Blocks::AIR);
}

if (block == PLAY_BLOCK) {
Play();
mc.postToChat("Playing");
mc.post_to_chat("Playing");
} else if (block == PAUSE_BLOCK) {
Pause();
mc.postToChat("Pausing");
mc.post_to_chat("Pausing");
} else if (block == ALIVE_BLOCK) {
game[x][z] = 1;
} else if (block == DEAD_BLOCK) {
game[x][z] = 0;
} else if (block == SPEED_BLOCK) {
delay = std::max(delay / 2, 1);
mc.postToChat("Speeding up");
mc.post_to_chat("Speeding up");
} else if (block == SLOW_BLOCK) {
delay *= 2;
mc.postToChat("Slowing down");
mc.post_to_chat("Slowing down");
} else if (block == RANDOM_BLOCK) {
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
game[x][z] = rand() % 2;
}
}
mc.postToChat("Randomizing");
mc.post_to_chat("Randomizing");
} else if (block == CLEAR_BLOCK) {
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
game[x][z] = 0;
}
}
mc.postToChat("Clearing");
mc.post_to_chat("Clearing");
}
}
}
Expand Down Expand Up @@ -172,12 +172,12 @@ void Life::Update() {
}

// draw
mc.setBlocks(buildPosition, bounds, DEAD_BLOCK);
mc.set_blocks(buildPosition, bounds, DEAD_BLOCK);
for (int x = 0; x < width; x++) {
for (int z = 0; z < depth; z++) {
mcpp::Coordinate position(buildPosition.x + x, buildPosition.y, buildPosition.z + z);
if (game[x][z] == 1) {
mc.setBlock(position, ALIVE_BLOCK);
mc.set_block(position, ALIVE_BLOCK);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/hello_minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ int main() {
MinecraftConnection mc;

// Post chat to Minecraft
mc.postToChat("Hello, Minecraft!");
mc.post_to_chat("Hello, Minecraft!");
}
Loading
Loading