Скрипты python для minecraft

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Читайте также:  Kompozer это html редактор

A minecraft bot written in python that can mine, chop wood, farm and build things. Written in python using mineflayer.

License

appenz/minebot

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

pybot — A Minecraft bot written in Python using Mineflayer

pybot is a Minecraft bot written using the Mineflayer framework via the Python to Javascript bridge. It is built for practical utility automating such tasks as mining for resources, mining out rooms or long corridors, building bridges, farming, chopping wood, building structures and moving around resources between chests. It has a partially complete UI written in Tk.

Tested with Java Edition 1.16.5. It will NOT work with 1.18 or 1.19.

Guido Appenzeller, Daniel Appenzeller

To run the bot, your system needs to have:

  • A recent version of Python. On macOS, easiest is to install Python 3 from the www.python.org web site. Homebrew python may require the additional install of tkinter.
  • The python/javascript bridge. ‘pip3 install javascript’ should do the trick.

Copy the account_sample.py to account/account.py and edit the following fields:

  • User Name
  • Password
  • Server IP or name
  • «master» is the in-game name of the player that the bot should take commands from (i.e. your in-game name)
  • version to the server’s minecraft version

You can also specify locations in this file. This is mostly useful to have the bot transfer contents between chests.

Normally the bot will open a Window, but you can also run it without any graphical UX using the «—nowindow» option.

Simple commands are given via chat. The bot has a specific «master» player that it will listen to. Try «come», «inventory» or «status» to get an idea. Other users can also give commands but need to preface it with a callsign.

Many activities can be stopped with the command «stop».

PyBot starts most complex activities around a chest. There are two types:

  • For an activity that dodesn’t need a specifi direction like farming an area, it’s just a chest. Material (e.g. seeds) and resources (e.g. wheat) will be taken from or, after collecting them, placed into that chest.
  • For activities that do have a direction (e.g. dig a tunnel in a specific direction), starting point is a chest and the direction is indicated by placing a torch on the ground directly next to the chest.

For these activities, have the bot come next to the chest and once it is there tell it to «farm» or «mine 3×3».

To start, place a chest in the area you want to farm and start with «farm». The bot will take seeds from the cest, and plant them in any nearby farmland that it can reach. If there are fully grown crops, the pot will harvest them and place them and any extra seeds in the chest. Chat «stop» to stop the bot. Right now, only Wheat is in the code, but other crops are easy to add.

Right now only works with mega spruce trees as they are the most efficient. Plant 2×2 saplings and get a tree with up to 100 blocks of wood. Place a chest within 25 blocks from the tree, put a few stone axes and bread as food in the chest and start with «chop». The bot will do a spiral cut up the trunk and then cut down. It will continue to chop down trees as long as it finds them and deposit the wood into the chest.

Right now, this activity can’t be aborted with stop.

  • Use «mine fast» to start strip mining. By default it will clear a 11 wide and 9 high area of all valuable blocks (it can see through walls to find it)
  • Mine large corridors, try «mine 3×3» or «mine 5×5»
  • The bot will looking for valuable ores off corridors, usually with a default distance of 5
  • The bot will also look in ceilings and the floow up to 2 deep
  • Try «boxmine» to mine out large areas for underground rooms
  • The bot will automatically bridge across chasms/lava
  • It will not defend itself yet, but it will run away when taking damage and ninja-log when below 50%
  • It will light up tunnels
  • If you put a wall sign close to the chest, the bot will record its progress on that sign (e.g. length of tunnel, dangers etc.)

If there is a chest-in-a-minecart next to the starting chest, the bot will deposit into the minecart, and restock from the chest. That makes it easy to keep it supplied with tools while hauling away resources automatically

Try «come» to make the bot come to the player

Still early, but if you add a blueprint to bulueprint_list.py, the bot can build it. Starting point is a chest with a torch. The bot can build a full sorting system with «build sorter».

About

A minecraft bot written in python that can mine, chop wood, farm and build things. Written in python using mineflayer.

Источник

python-minecraft

Introductions and Python Code examples for kids to learn python programming with minecraft. The Python code will run with a modified MCPI (Pi edition API Python Library) call `mcpi-e`, and a mincraft server call spigot with the RaspberryJuice plugin installed.

Python programming with minecraft

Our goal is to learn programming while having fun in Minecraft

alt python-minecraft

0 Pre-Request

0.1 Install Minecraft Java edition

Go to minecraft website download the Java Edition

0.2 Setup mincraft server

0.3 Install Python

Go to Python download page, download and install Python 3.8 and up

0.4 Install mcpi Python module

Window

input below script in the command line. (from start, search “cmd”)

Linux / MacOS

0.5 Install a Python Editor

  • Python IDLE
    • IDLD is commine with Python, Open it by in Start->Search, Input “IDLE”
    • For how to use IDLE
    • PyCharm Edu is a python editor help you learn Python
    • Click to download pyCharm Edu
    • VsCode is a editor for many different programming langurage.
    • Click to download VsCode
    • How to install VsCode for python

    1. Get Start Python with Minecraft

    1.1 Connect to the Minecraft server and get your position

    Create a Python project folder, Download and save the sample1.py file to your python project folder

    from mcpi_e.minecraft import Minecraft serverAddress="127.0.0.1" # change to your minecraft server pythonApiPort=4711 #default port for RaspberryJuice plugin is 4711, it could be changed in plugins\RaspberryJuice\config.yml playerName="stoneskin" # change to your username mc = Minecraft.create(serverAddress,pythonApiPort,playerName) pos = mc.player.getPos() print("pos: x:<>,y:<>,z:<>".format(pos.x,pos.y,pos.z)) 

    Use your faverate python editor to open the sample1.py file. When you install python, it come with a python editor call IDLE.j

    1.2. Frequently used mcpi commands

    1.2.1 Find your location

    1.2.2 Teleport

    move player to north 100 block

    x,y,z = pos = mc.player.getTilePos() mc.player.setTilePos(x,y+100,z) 

    1.2.3 Set block

    set the a stone block beside the player

    x,y,z = pos = mc.player.getTilePos() mc.setBlock(x+1, y, z, 1) 

    setblock with constants block.STONE.id

    #setblock with constants block.STONE.id from mcpi_e import block (x,y,z) = pos = mc.player.getTilePos() mc.setBlock(x+1, y, z+1, block.STONE.id) 

    set special block which extra properties

    # set special block which extra properties flower = 38 flowerColor = 3 mc.setBlock(x+1, y, z+1, flower, flowerColor) 

    1.2.4 Get block

    get the block type id of the player stepping on

    # get the block current player step on x, y, z = mc.player.getTilePos() blockId= mc.getBlock(x, y, z) if(blockId == 0): print("current block is Air") 

    2 Learn Python With Minecraft

    To use the code examples in this site, please make sure include the piece of code below before the sample codes

    import mcpi_e.minecraft as minecraft import mcpi_e.block as block from math import * address="127.0.0.1" # change to address of your minecraft server name ="change you your name" mc = minecraft.Minecraft.create(address,4711,name) pos=mc.player.getTilePos() #your other code below . 

    2.1 Understand the coordinates of minecraft

    coordinates of minecraft

    Minecraft coordinates are different than what we learn from geomestry. You need keep the picture below in mind when you do the minecraft coding.

    For basic python syntax, pleas check Python syntax for details.

    The missions/codes below will use print and command from minecraft api mcpi

    clickmeClick to view your Mincraft-Python Missions-1

    2.2 Use for Loop to stack blocks

    for loops are traditionally used when you have a block of code which you wnat to repeat number of times.

    for x in range(0, 3): print("We're on time %d" % (x)) 

    For learnning how to use for loop, please visit Python For Loops

    Below mission only need using for . range loop.

    clickmeClick to view your Coding Missions -2

    2.3 Value Type: String , Number

    In Python any amount of text call a string , you could use string like this

    print("Hello Minecraft") name ="Steve the Miner" print(name) 

    String and Intiger is different DataType, for detail please read Python Data Types. Below is the Data Types we possible will used in our class

    datatypes

    example of get type of a variable:

    The data you got form input is a string, we need convert to number before using as number. int(str) could do this job.

    blockType=input("Enter a block type:") blockTypeId=int(blockType) 

    other way if you want change a int to string, you could use str(number)

    value=103 print("Watermelon block id is "+str(value)) 

    clickmeClick to view your Coding Missions -3

    2.4 Use Condition if . else

    To learn comdition please check Python If…Else

    Booleans represent one of two values: True or False

    For learn more and practic Boolean, please check Python Boolean

    condition

    clickmeClick to view your Coding Missions -4

    3 More Code Samples

    3.1 Dropping the flowers when you move

    Set a random flower on where the play is standing

     flower = 38 while True: x, y, z = mc.playerEn.getPos() blockId= mc.getBlock(x, y, z) print("current block:" + str(mc.getBlock(x, y, z))) if(blockId==0 or blockId ==78): mc.setBlock(x, y, z, flower,randrange(8)) sleep(0.2) 

    alt python-minecraft

    3.2 Build a rainbow in the minecraft

    code example: rainbow.py build a rainbow with colored wool on the player’s location

     import mcpi_e.minecraft as minecraft import mcpi_e.block as block from math import * address="127.0.0.1" # change to your minecraft server name ="change you your name" mc = minecraft.Minecraft.create(address,4711,name) playerPos=mc.player.getTilePos() colors = [14, 1, 4, 5, 3, 11, 10] height=50 for x in range(0, 128): for colourindex in range(0, len(colors)): y = playerPos.y+sin((x / 128.0) * pi) * height + colourindex mc.setBlock(playerPos.x+x - 64, int(y), playerPos.z, block.WOOL.id, colors[len(colors) - 1 - colourindex]) print("rainbow created at x:<> y:<> z:<>".format(playerPos.x,playerPos.y,playerPos.z)) 

    alt python-minecraft

    python-minecraft maintained by stoneskin

    Источник

Оцените статью