Calculate the correct block breaking time
This commit is contained in:
@@ -12,6 +12,8 @@ import utils
|
||||
importlib.reload(utils)
|
||||
import path
|
||||
importlib.reload(path)
|
||||
import blocks
|
||||
importlib.reload(blocks)
|
||||
|
||||
class Game:
|
||||
def __init__(self, global_state):
|
||||
@@ -38,7 +40,7 @@ class Game:
|
||||
def handle_block_change(self, packet):
|
||||
l = self.g.local_state
|
||||
|
||||
if packet.block_state_id == 3887:
|
||||
if packet.block_state_id == blocks.SOUL_TORCH:
|
||||
try:
|
||||
l.goal = LPoint3f(x=packet.location[0], y=packet.location[1], z=packet.location[2])
|
||||
print('new waypoint:', l.goal)
|
||||
@@ -130,22 +132,9 @@ class Game:
|
||||
if packet.window_id == 0:
|
||||
self.g.inv[packet.slot] = packet.slot_data
|
||||
|
||||
def handle_break_animation(self, packet):
|
||||
print(packet)
|
||||
if self.l.breaking and packet.entity_id == self.g.eid:
|
||||
if packet.destroy_stage >= 10:
|
||||
packet = PlayerDiggingPacket()
|
||||
packet.status = 2
|
||||
packet.location = self.l.breaking
|
||||
packet.face = 1
|
||||
self.g.connection.write_packet(packet)
|
||||
self.l.breaking = None
|
||||
|
||||
def handle_break_ack(self, packet):
|
||||
print(packet)
|
||||
|
||||
def break_block(self, location):
|
||||
if self.g.chunks.get_block_at(*location) != 0:
|
||||
bid = self.g.chunks.get_block_at(*location)
|
||||
if bid != 0:
|
||||
packet = PlayerDiggingPacket()
|
||||
packet.status = 0
|
||||
packet.location = location
|
||||
@@ -153,6 +142,22 @@ class Game:
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
self.l.breaking = location
|
||||
self.l.break_time = time.time() + utils.break_time(bid)
|
||||
|
||||
def break_finish(self):
|
||||
packet = PlayerDiggingPacket()
|
||||
packet.status = 2
|
||||
packet.location = self.l.breaking
|
||||
packet.face = 1
|
||||
self.g.connection.write_packet(packet)
|
||||
self.l.breaking = None
|
||||
|
||||
|
||||
def handle_break_animation(self, packet):
|
||||
print(packet)
|
||||
|
||||
def handle_break_ack(self, packet):
|
||||
print(packet)
|
||||
|
||||
def animate(self):
|
||||
packet = serverbound.play.AnimationPacket()
|
||||
@@ -162,3 +167,6 @@ class Game:
|
||||
def tick(self):
|
||||
if self.l.breaking:
|
||||
self.animate()
|
||||
|
||||
if time.time() >= self.l.break_time - 2*utils.TICK:
|
||||
self.break_finish()
|
||||
|
||||
Reference in New Issue
Block a user