GithubHelp home page GithubHelp logo

heronerin / mcbotitpython Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 734 KB

A library that allows you to control your minecraft character from python. Allowing you to automate pretty much everything.

License: GNU General Public License v3.0

Python 100.00%
automation botting library minecraft python python-library mcbot minecraft-automation mcbotit

mcbotitpython's Introduction

McBotIt python library


This library allows you to control your minecraft character from python. Allowing you to automate pretty much everything.

I am not responsible if you get banned from your favorite server! Many servers may feel this is cheating!

Although this tool may make use of baritone, using baritone with the mod is optional, it is an optional dependency. Meaning that most functions of the mod will still work, with the exception of several functions which make use of baritone.

Install:

  1. You need to install the minecraft mod in fabric 1.19.4.
  2. It is recommended that you download the baritone api fabric mod in order for some functions to work, but this is optional.
  3. Since this library is not yet in PyPi, you must install it from github with pip install git+https://github.com/HeronErin/McBotItPython.git

Usage:

Now that everything (should) be installed, you need to join a world/server while the mods are installed, if everything is correct you should see a message in chat about what port to use. This is the number that the python library connects to, it changes often, so it is unwise to hardcode it, however this is a trap I often fall into.

Run the following hello world from python to test if everything is correct, if you see a chat message in Minecraft, you are ready to go.

from mcbotit import Player

PORT = int(input("Port: ")) # Gets input from user for the port to connect to
player = Player(PORT) # Creates player instance

player.print("Hello world") # Prints to clients chat

player.kill() # Kills connection thread, otherwise the script would run forever. 

Classes and Methods:

There are a few Classes you need to be aware of:

  1. The Player class.
  2. The Client class.
  3. The InputKeys Enum
  4. And the assorted Inventory classes.

You can view the full documentation here

The Player class

The Player class is the main class you will be dealing with, it is an abstraction over the Client class. This class keeps track of the players position, rotation, velocity, hunger level, and if they are currently falling. It also allows you to register client side commands. And gives you easy access to the inventoryManager.

The following are some fields in the Player class you sould know of:

  • lastX - last known X position
  • lastY - last known Y position
  • lastZ - last known Z position
  • lastPitch - last known pitch rotation value
  • lastYaw - last known yaw rotation value
  • isFalling
  • lastVelocity - A tuple of the players velocity
  • lastHunger
  • lastHealth
  • inventoryManager - used for getting inventory data

You can view the player classes documentation here

The InputKeys Enum

The following are possible values:

  • InputKeys.FORWARD
  • InputKeys.BACKWORD
  • InputKeys.LEFT
  • InputKeys.RIGHT
  • InputKeys.SNEAK
  • InputKeys.LEFT_CLICK
  • InputKeys.RIGHT_CLICK

Docs here

inventoryManager class

All the following return an inventory object:

  • getOpenPlayerInventory()
  • getOpenChest()
  • getOpenShulker()
  • getOpenCraftingTable()
  • getOpenFurnace()
  • getOpenBlastFurnace()
  • getOpenSmoker()
  • getOpen3by3()
  • getOpenEnchantmentTable()
  • getOpenBrewingStand()
  • getOpenAnvil()
  • getOpenVillagerInventory()
  • getOpenBeacon()
  • getOpenHopper()
  • getOpenCartographyTable()
  • getOpenGrindstone()
  • getOpenSmithingTable()

Docs here

Assorted inventory classes

All inventory classes are quite simmular in structor

  • getSlot(row, col)
  • search(itemId) find item in the chest
  • searchPlayerInv(itemId)
  • serialize() return json that can be saved to files

Most of the inventory classes also have fields set to important slots. I'm not going to list all of them here, you can see the documentation here, but here are a few notable ones.

  • PlayerInventory has helmet, chestplace, leggings, boots, offhand, craftingSlot1, craftingSlot2, craftingSlot3, craftingSlot4, and craftingOutput.
  • X3Inventory (getOpen3by3) has self.slot(1-9) for every slot in a dispensor.
  • EnchantmentTable has inputSlot and lapisSlot
  • Anvil has input1, input2, and output.
  • VillagerInventory has input1, input2, and output. Along with a setTradeIndex(i) function for selecting a trade

The Client class

This can be obtained by player.client and use of this should be minimized. This class manages the socket connection itself and has some importent features.

  1. using with player.client: You can take controll of the connection itself, this is used with many of the Player functions. But taking controll can take 0.1 secounds, so you can speed up your code by taking controll of the connection before running a bunch of functions, however this means the the players attributes, like position, will not be updated.

  2. All raw packets can be directly send with this class. Most have functions to call them, but others can be send like this: player.client.send({"cmd": "right click block"})

Docs here

mcbotitpython's People

Contributors

heronerin avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

meshwa428

mcbotitpython's Issues

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.