Git Product home page Git Product logo

mciwb's Introduction

CI Coverage PyPI License

mciwb

Minecraft Interactive World Builder

This project is intended as a fun way to learn the Python Programming Language.

Experienced Python programmers can also use this library to create Minecraft worlds with interactive Python features.

Source https://github.com/gilesknap/mciwb
PyPI pip install mciwb
Documentation https://gilesknap.github.io/mciwb
Releases https://github.com/gilesknap/mciwb/releases

Quick Start

To get started learning Python, see Introduction

For existing Python developers, see API documentation

Example Build

The pagoda and castle with working portcullis were all created programmatically with Python and the current version of MCIWB.

castle-2023-03-15_08.26.24.mp4

Goals

Minecraft Interactive World Builder's goals are:

  • Use Python to create anything inside of Minecraft worlds.
  • Call Python code when events occur inside the world.
  • Use an iPython prompt to interact with the world by typing Python commands
  • Have your player inside the world execute Python code by placing command signs or activating switches/levers with Python actions.

All instructions on how to set up a Minecraft Server and the Python developer environment are included. There are step by step tutorials to introduce Python Programming and the features of Minecraft Interactive World Builder.

.. note::

This is a work in progress. There are now enough tutorials to learn the
fundamentals of Python and enough functionality to have some fun
interacting with Minecraft from Python code.

I will continue to expand the tutorials and add more features to the
library.

Credits

This project would not be possible without mcipc, which provides the client library for Minecraft RCON.

See https://gilesknap.github.io/mciwb for more detailed documentation.

mciwb's People

Contributors

alexanderwells-diamond avatar callumforrester avatar coretl avatar dependabot[bot] avatar evalott100 avatar garryod avatar gdyendell avatar gilesknap avatar misode avatar n6udp avatar qollin avatar tizayi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mciwb's Issues

Document Java ediition

Need to make it clear that you want the java edition now that Minecraft for Windows is in the same launcher.

TODO

  • add a switches modue
    • place a switch/lever/pressure plate etc in the world and hook its activation to a python function
  • Nice profiles functions in mcwb - elipse, rectangle, others?
  • documentation
    • restructure into four quadrant
    • tutorials
      • setup of python/vscode/docker/
      • fundamentals of python (link to beginner course somewhere)
      • basic interaction with the world
      • making .py files
      • functions
        • box
        • pyramid
        • spooky pyramid
        • crazy rollercoaster (to be written)
      • advanced
        • adding sign control to the world
        • switches with functions
        • using monitoring - make spooky pyramid work in background

Would you be interested in a chapter about drawing image?

Hello. We created this to "draw" image from file in Minecraft as a wall:

image

Would you be interested in a chapter to the doc describing that code?

import PIL.Image
im = PIL.Image.open("cat.png")
im = im.resize((20, 20))

def decide_black_or_white(x):
     if x > 50:
         return 255
     else:
         return 0

im = im.convert('L').point(decide_black_or_white, mode='1')
pixel_map = im.load()

pos = world.player.pos

def draw_pixel(position, x):
    world = get_world()
    if x == 255:
        material = Item.BLACK_CONCRETE
    else:
        material = Item.WHITE_CONCRETE
    world.set_block(position, material)

for row in range(20):
    for column in range(20):
        draw_pixel(pos + Direction.UP * (20 - 1) + Direction.DOWN * row + Direction.SOUTH * column, pixel_map[column, row])

That code needs a bit of work, but something like this worked for us. IIRC the screenshot is from different image, it was 100 x 100.

Undo buffer

TODO: implement an undo buffer. This is kind of important as python commands can really trash a world if you get them wrong.

My idea is this. Before any update to the world, clone the effected region into a safe haven at some distant point in the map.

  • support multiple undos
  • Stretch goal: devise a way to save the index into the undo locations in a block somewhere. That way undo will still work after exit and re-entering the world

For Loops Nether Portal

Hello @gilesknap

I'm doing the nether portal build in the loops section. I'm receiving an error that says minecraft:obsidian is not in list. The code works fine when I copy and paste it from the instructions into the terminal, but when I type it in myself, I get the error as shown

In [1]: pos = world.player.pos

In [2]: for x in range(4):
...: # bottom row
...: world.set_block(pos + Direction.EAST * x, Item.OBSIDIAN)
...: # top row
...: world.set_block(pos + Direction.EAST * x, + Direction.UP * 4, Item.OBSIDIAN)
...: for y in range(4):
...: # left side
...: world.set_block(pos + Direction.UP * y, Item.OBSIDIAN)
...: # right side
...: world.set_block(pos + Direction.UP * y + Direction.EAST * 3, Item.OBSIDIAN)
...:
ERROR: ValueError: <Item.OBSIDIAN: 'minecraft:obsidian'> is not in list

Does this all have to be typed into one line in order for it to work?

Older version of rcon package causes `pip install mciwb` to fail

It appears mciwb is not compatible with rcon 2.1.1. But this is the version of rcon that is installed with python 3.9. I am unable to install the latest version of rcon. Which means, I can't install mciwb. Any help would be greatly appreciated.

ERROR: Could not find a version that satisfies the requirement rcon>=2.3.6 (from mcwb>=0.2.1->mciwb) (from versions: 1.0.0, 1.0.1, 1.0.2, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.0.8, 1.0.9, 1.0.12, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7, 1.1.8, 1.1.9, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8, 2.0.0, 2.0.1, 2.0.2, 2.0.8, 2.0.9, 2.1.0, 2.1.1)
ERROR: No matching distribution found for rcon>=2.3.6 (from mcwb>=0.2.1->mciwb)

When I build doors, only half of then is created

Hello. First of all, thank you for this great tool! It is a lot of fun playing with it myself and with my kids :-)

I have a problem building doors. Imagine this code:

pos = world.player.pos
world.set_block(pos, Item.STONE)
world.set_block(pos + Direction.UP, Item.STONE)
world.set_block(pos + Direction.WEST * 2, Item.STONE)
world.set_block(pos + Direction.WEST * 2 + Direction.UP, Item.STONE)
world.set_block(pos + Direction.WEST, Item.ACACIA_DOOR)

But the result looks like this:

image

We have tried multiple ways, but were unsuccessful. Is it possible to build complete doors?

Action signs blank by default?

The action signs don’t have the action written on the sign - so when placing one it pops up a screen where you can then type in “select” for example. The function does work but in the demo video it seems the action command is already written on the sign so placing it is much quicker because it doesn’t require typing each time… Bug 🐞 or feature? 😄

provide save and load

Provide a function to save the current paste selection to file (TODO need a better name for paste selection)

Also provide a load from file to indicated position.

Unhandled exception error in event loop

Hello. I'm trying to learn python with Minecraft using MCIWB.

For context, I'm using Docker, VSCode, Python 3.10.6, and iPython 8.11.0

When I typed in world.player.pos, I get the following error:

Unhandled exception in event loop:
File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/input/vt100.py", line 173, in callback_wrapper
callback()
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 698, in read_from_input
self.key_processor.process_keys()
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 272, in process_keys
self._process_coroutine.send(key_press)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 187, in _process
self._call_handler(matches[-1], key_sequence=buffer[:])
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 322, in _call_handler
handler.call(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 126, in call
result = self.handler(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/IPython/terminal/shortcuts/init.py", line 374, in handle_return_or_newline_or_execute
return newline_or_execute_outer(shell)(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/IPython/terminal/shortcuts/init.py", line 397, in newline_or_execute
status, indent = shell.check_complete(check_text)

Exception 'NoneType' object has no attribute 'check_complete'
Press ENTER to continue...

Unhandled exception in event loop:
File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 698, in read_from_input
self.key_processor.process_keys()
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 272, in process_keys
self._process_coroutine.send(key_press)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 187, in _process
self._call_handler(matches[-1], key_sequence=buffer[:])
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_processor.py", line 322, in _call_handler
handler.call(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 126, in call
result = self.handler(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/IPython/terminal/shortcuts/init.py", line 374, in handle_return_or_newline_or_execute
return newline_or_execute_outer(shell)(event)
File "/home/useradd/my_world/.venv/lib/python3.10/site-packages/IPython/terminal/shortcuts/init.py", line 397, in newline_or_execute
status, indent = shell.check_complete(check_text)

Exception 'NoneType' object has no attribute 'check_complete'
Press ENTER to continue...

I've tried researching the problem, but have had no luck in terms of finding a solution. Is there a way to resolve this?

break up the Iwb class

Maybe keep Iwb as the root class for setting things up and then have properties which are objects for various groups of functions.

e.g. we already have self.copier.

I do want to wrap up the common Client and mcwb commands so that we can provide a simpler interface. Just need to decide on the grouping.

Question about Backup and Restore

Hello @gilesknap

I am following along with the Backup and Restore instructions and I have a question. For the part after (.venv), are we using the username info before the @ sign? I tried a variety of ways, but I keep getting a syntax error.

  1. useradd@DESKTOP-KSM4GML:~/my_world$ (.venv) [useradd@ws1 mciwb]$ ls $HOME/mciwb-backups
    bash: syntax error near unexpected token `[useradd@ws1'

  2. useradd@DESKTOP-KSM4GML:~/my_world$ (.venv) [ahUn1t$@ws1 mciwb]$ mciwb restore my-first-backup
    bash: syntax error near unexpected token `[ahUn1t$@ws1'

  3. useradd@DESKTOP-KSM4GML:~/my_world$ (.venv) [useradd@DESKTOP-KSM4GML mciwb]$ ls $HOME/mciwb-bqckups
    bash: syntax error near unexpected token `[useradd@DESKTOP-KSM4GML'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.