-
Notifications
You must be signed in to change notification settings - Fork 0
/
minerbot.py
142 lines (113 loc) · 4.18 KB
/
minerbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import math
from javascript import require, once
import time
mineflayer = require("mineflayer")
class MinerBot:
def __init__(self, username, password) -> None:
try:
self.bot = mineflayer.createBot(
{
"host": "thevoid.pl",
"port": 25565,
"username": username,
"password": password,
"hideErrors": False,
"auth": "microsoft",
}
)
except Exception as e:
print("Z jakiegoś powodu nie udało się połączyć!")
def launchViewer(self):
viewer = require("prismarine-viewer").mineflayer
viewer(self.bot, {"port": 3000, "firstPerson": True})
print("Podgląd włączony.")
def equipPick(self):
tool = self.bot.inventory.findInventoryItem(721)
if tool:
self.bot.equip(tool, "hand")
def makeCobblex(self):
# Send /cx command that creates cobbleX
self.bot.chat("/cx")
def emptyInventory(self, cobblex: bool):
print("Dropping inventory!")
# Ids of items to drop
ids = [684, 585, 692, 696, 687, 686, 792, 235, 734, 234]
# If bot doesn't make cobblex then it should also drop cobblestone
if not cobblex:
ids.append(21)
# Get all items to drop
toDrop = self.bot.inventory.items()
toDrop = list(filter(lambda item: item["type"] in ids, toDrop))
# If there is anython to drop than drop it
if toDrop:
# Get bot yaw
yaw = self.bot.entity.yaw
# Look down
self.bot.look(yaw, -math.pi / 2, True)
time.sleep(1)
# Drop items
for item in toDrop:
if item["type"] == 686:
if item.count >= 5:
self.bot.toss(686, None, item.count - 4)
else:
self.bot.tossStack(item)
time.sleep(0.3)
# Look up (forward)
self.bot.look(yaw, 0, True)
time.sleep(1)
print("Dropped all items!")
def repairPick(self) -> bool:
print("Próbuję naprawić kilof.")
yaw = self.bot.entity.yaw
pitch = self.bot.entity.pitch
diamonds = self.bot.inventory.findInventoryItem(686)
if not diamonds:
return
block = self.bot.findBlock({"matching": [341, 340, 339], "maxDistance": 5})
if block:
anvil = self.bot.openAnvil(block)
try:
anvil.combine(self.bot.heldItem, diamonds)
except Exception as e:
print("Nie udało się naprawić kilofa.")
self.bot.look(yaw, pitch, True)
return False
print("Naprawiono kilof.")
anvil.close()
self.equipPick()
self.bot.look(yaw, pitch, True)
time.sleep(1)
return True
else:
print("Brak kowadła, nie naprawiono kilofa.")
return False
def enchant(self):
print("Próbuję enchantować!")
# Check if there is enought xp
if self.bot.experience.level < 30: return
print("Wystarczająco xp")
# Find encahnting table
block = self.bot.findBlock({"matching": 268, "maxDistance": 5})
# Return if theres no one
if not block: return
print("Jest stół")
# Ids of items to enchant (iron armour)
ids = [746, 747, 748, 749]
# Get all items to enchant
toEnchant = self.bot.inventory.items()
toEnchant = list(filter(lambda item: item["type"] in ids, toEnchant))
# If there is no items to enchant return
if not toEnchant: return
print("Są itemy")
# Open enchanting table
etable = self.bot.openEnchantmentTable(block)
print("Otworzono stół")
# Wait for enchantments to populate
once(etable, "ready")
print("Ready")
# Put first item in etable
etable.putTargetItem(toEnchant[0])
print("Wsadzono itemek")
# Print enchants
print(etable.enchantments)