|
|
|
@ -5,6 +5,7 @@ import random |
|
|
|
|
from math import hypot |
|
|
|
|
from itertools import count |
|
|
|
|
from munch import Munch |
|
|
|
|
from copy import copy |
|
|
|
|
|
|
|
|
|
from panda3d.core import LPoint3f |
|
|
|
|
|
|
|
|
@ -12,13 +13,12 @@ from minecraft.networking.packets import Packet, clientbound, serverbound |
|
|
|
|
from minecraft.networking.types import BlockFace |
|
|
|
|
|
|
|
|
|
from protocol.packets import ( |
|
|
|
|
TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, |
|
|
|
|
SetSlotPacket, PlayerDiggingPacket, |
|
|
|
|
BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, |
|
|
|
|
HeldItemChangePacket, PickItemPacket, OpenWindowPacket, |
|
|
|
|
ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket, |
|
|
|
|
ClientWindowConfirmationPacket, EntityMetadataPacket, |
|
|
|
|
SpawnLivingEntityPacket, EntityPositionPacket, |
|
|
|
|
EntityPositionRotationPacket, DestroyEntitiesPacket, EntityVelocityPacket, |
|
|
|
|
SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
from protocol.types import Slot |
|
|
|
@ -115,20 +115,23 @@ class MCWorld: |
|
|
|
|
air = [] |
|
|
|
|
for i in range(5): |
|
|
|
|
check = utils.padd(center, utils.alternate(i, 1)) |
|
|
|
|
air.extend(self.find_blocks(check, distance, [0], 200)) |
|
|
|
|
air.extend(self.find_blocks(check, distance, [0], 0)) |
|
|
|
|
|
|
|
|
|
bed_clearance = 25 # 5x5 area |
|
|
|
|
clear_distance = 3 |
|
|
|
|
|
|
|
|
|
areas = [] |
|
|
|
|
for a in air: |
|
|
|
|
# check for ground around the area |
|
|
|
|
if len(self.find_blocks(utils.padd(a, path.BLOCK_BELOW), 2, blocks.NON_SOLID_IDS, 9)): |
|
|
|
|
# check for air around the area |
|
|
|
|
if len(self.find_blocks(a, clear_distance, [0], bed_clearance)) < bed_clearance: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# check for air around the area |
|
|
|
|
if len(self.find_blocks(a, 2, [0], 9)) < 9: |
|
|
|
|
# check for ground around the area |
|
|
|
|
if len(self.find_blocks(utils.padd(a, path.BLOCK_BELOW), clear_distance, blocks.NON_SOLID_IDS, bed_clearance)): |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# check for air above the area |
|
|
|
|
if len(self.find_blocks(utils.padd(a, path.BLOCK_ABOVE), 2, [0], 9)) < 9: |
|
|
|
|
if len(self.find_blocks(utils.padd(a, path.BLOCK_ABOVE), clear_distance, [0], bed_clearance)) < bed_clearance: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
areas.append(a) |
|
|
|
@ -183,6 +186,13 @@ class MCWorld: |
|
|
|
|
def find_cache_openings(self, area): |
|
|
|
|
return self.find_bed_openings(area) |
|
|
|
|
|
|
|
|
|
def find_objects(self, object_ids): |
|
|
|
|
result = [] |
|
|
|
|
for eid, obj in copy(self.g.objects).items(): |
|
|
|
|
if obj.get('item_id', None) in object_ids: |
|
|
|
|
result.append(obj) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Game: |
|
|
|
|
def __init__(self, global_state): |
|
|
|
@ -192,7 +202,7 @@ class Game: |
|
|
|
|
register(self.handle_block_change, clientbound.play.BlockChangePacket) |
|
|
|
|
register(self.handle_join_game, clientbound.play.JoinGamePacket) |
|
|
|
|
register(self.handle_position_and_look, clientbound.play.PlayerPositionAndLookPacket) |
|
|
|
|
register(self.handle_time_update, TimeUpdatePacket) |
|
|
|
|
register(self.handle_time_update, clientbound.play.TimeUpdatePacket) |
|
|
|
|
register(self.handle_set_slot, SetSlotPacket) |
|
|
|
|
register(self.handle_break_animation, BlockBreakAnimationPacket) |
|
|
|
|
register(self.handle_break_ack, AcknowledgePlayerDiggingPacket) |
|
|
|
@ -201,10 +211,10 @@ class Game: |
|
|
|
|
register(self.handle_spawn_object, clientbound.play.SpawnObjectPacket) |
|
|
|
|
register(self.handle_entity_metadata, EntityMetadataPacket) |
|
|
|
|
register(self.handle_spawn_living, SpawnLivingEntityPacket) |
|
|
|
|
register(self.handle_entity_position, EntityPositionPacket) |
|
|
|
|
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket) |
|
|
|
|
register(self.handle_entity_position_rotation, EntityPositionRotationPacket) |
|
|
|
|
register(self.handle_destroy_entities, DestroyEntitiesPacket) |
|
|
|
|
register(self.handle_entity_velocity, EntityVelocityPacket) |
|
|
|
|
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket) |
|
|
|
|
|
|
|
|
|
#register(self.handle_packet, Packet, early=True) |
|
|
|
|
|
|
|
|
@ -570,6 +580,7 @@ class Game: |
|
|
|
|
if packet.type_id != 37: return |
|
|
|
|
print(packet) |
|
|
|
|
self.g.objects[packet.entity_id] = Munch( |
|
|
|
|
entity_id=packet.entity_id, |
|
|
|
|
x=packet.x, |
|
|
|
|
y=packet.y, |
|
|
|
|
z=packet.z, |
|
|
|
|