From d71d23194db3b1798bb9f41e4cb7e7de0791cccf Mon Sep 17 00:00:00 2001 From: alemidev Date: Tue, 30 Nov 2021 16:31:42 +0100 Subject: [PATCH] respawn with a delay --- treepuncher/treepuncher.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/treepuncher/treepuncher.py b/treepuncher/treepuncher.py index f30e88c..44b0d0c 100644 --- a/treepuncher/treepuncher.py +++ b/treepuncher/treepuncher.py @@ -1,5 +1,6 @@ import re import logging +import asyncio from typing import List, Dict, Union, Optional, Any, Type from enum import Enum @@ -180,14 +181,16 @@ class Treepuncher(MinecraftClient): @self.on_packet(PacketUpdateHealth) async def player_hp_cb(packet:PacketUpdateHealth): - if packet.health != self.hp and packet.health <= 0: + died = packet.health != self.hp and packet.health <= 0 + self.hp = packet.health + self.food = packet.food + packet.foodSaturation + if died: + self.run_callbacks(TreepuncherEvents.DIED) self._logger.info("Dead, respawning...") + await asyncio.sleep(0.5) await self.dispatcher.write( PacketClientCommand(self.dispatcher.proto, actionId=0) # respawn ) - self.run_callbacks(TreepuncherEvents.DIED) - self.hp = packet.health - self.food = packet.food + packet.foodSaturation @self.on_packet(PacketExperience) async def player_xp_cb(packet:PacketExperience):