https://pastein.ru/t/k6X
скопируйте уникальную ссылку для отправки
from mcpi.minecraft import Minecraft
import mcpi.block as block
from minecraftstuff import MinecraftDrawing
import math
import time
import collections
import random # Добавляем random
from collections.abc import Iterable
collections.Iterable = Iterable
mc = Minecraft.create()
mcdraw = MinecraftDrawing(mc)
def distanceBetweenPoints(pos1, pos2):
xd = pos2.x - pos1.x
yd = pos2.y - pos1.y
zd = pos2.z - pos1.z
return math.sqrt((xd * xd) + (yd * yd) + (zd * zd))
FAR_AWAY = 15
blockMood = "happy"
friend = mc.player.getTilePos()
friend.x = friend.x + 5
friend.y = mc.getHeight(friend.x, friend.z)
mc.setBlock(friend.x, friend.y, friend.z, block.DIAMOND_BLOCK.id)
while True:
pos = mc.player.getTilePos()
distance = distanceBetweenPoints(pos, friend)
if blockMood == "happy":
if distance < FAR_AWAY:
target = pos.clone()
else:
blockMood = "sad"
mc.postToChat("<Бот> Пожалуйста, вернись. Я скучаю по тебе...")
elif blockMood == "sad":
if distance <= 2:
blockMood = "happy"
mc.postToChat("<Бот> Юхууу!! Ты вернулся, я иду за тобой!")
if random.randint(1, 10) == 10: # Бот обиделся
blockMood = 'hadenough'
mc.postToChat('<Бот> Всё!!! Я обиделся.')
elif blockMood == 'hadenough':
if random.randint(1, 20) == 20:
blockMood = 'happy'
mc.postToChat('<Бот> Ну ладно, я прощаю тебя!')
if friend != target:
line = mcdraw.getLine(friend.x, friend.y, friend.z, target.x, target.y, target.z)
for nextBlock in line[:-1]:
mc.setBlock(friend.x, friend.y, friend.z, block.AIR.id)
friend = nextBlock.clone()
friend.y = mc.getHeight(friend.x, friend.z)
mc.setBlock(friend.x, friend.y, friend.z, block.TNT.id)
time.sleep(0.25)
target = friend.clone()
time.sleep(0.25)