Ejemplo n.º 1
0
    def parse_play_spawn_mob(self):
        if not self.wrapper.javaserver.entity_control:
            return True
        if self.server.version < PROTOCOL_1_9START:
            dt = self.packet.readpkt(
                [VARINT, NULL, UBYTE, INT, INT, INT, BYTE, BYTE, BYTE, REST])
            dt[3], dt[4], dt[5] = dt[3] / 32, dt[4] / 32, dt[5] / 32
            # "varint:eid|ubyte:type_|int:x|int:y|int:z|byte:pitch|byte:yaw|"
            # "byte:head_pitch|...
            # STOP PARSING HERE: short:velocityX|short:velocityY|
            #     short:velocityZ|rest:metadata")
        else:
            dt = self.packet.readpkt([
                VARINT, UUID, UBYTE, DOUBLE, DOUBLE, DOUBLE, BYTE, BYTE, BYTE,
                REST
            ])

            # ("varint:eid|uuid:entityUUID|ubyte:type_|int:x|int:y|int:z|"
            # "byte:pitch|byte:yaw|byte:head_pitch|
            # STOP PARSING HERE: short:velocityX|short:velocityY|
            #     short:velocityZ|rest:metadata")

        entityuuid = dt[1]

        # if the dt[2] mob type is not in our defined entity types,
        # it won't be tracked.. however, the undefined mob will not
        # cause an exception.
        if dt[2] in self.wrapper.javaserver.entity_control.entitytypes:
            mobname = self.wrapper.javaserver.entity_control.entitytypes[
                dt[2]]["name"]
            newmob = {
                dt[0]:
                Entity(dt[0], entityuuid, dt[2], mobname, (
                    dt[3],
                    dt[4],
                    dt[5],
                ), (dt[6], dt[7], dt[8]), False, self.client.username)
            }

            self.wrapper.javaserver.entity_control.entities.update(newmob)
        return True
Ejemplo n.º 2
0
    def parse_play_spawn_object(self):
        # objects are entities and are GC-ed by detroy entities packet
        if not self.wrapper.javaserver.entity_control:
            return True  # return now if no object tracking
        if self.server.version < PROTOCOL_1_9START:
            dt = self.packet.readpkt(
                [VARINT, NULL, BYTE, INT, INT, INT, BYTE, BYTE])
            dt[3], dt[4], dt[5] = dt[3] / 32, dt[4] / 32, dt[5] / 32
            # "varint:eid|byte:type_|int:x|int:y|int:z|byte:pitch|byte:yaw")
        else:
            dt = self.packet.readpkt(
                [VARINT, UUID, BYTE, DOUBLE, DOUBLE, DOUBLE, BYTE, BYTE])
            # "varint:eid|uuid:objectUUID|byte:type_|int:x|int:y|int:z|
            #     byte:pitch|byte:yaw|int:info|
            # short:velocityX|short:velocityY|short:velocityZ")
        entityuuid = dt[1]

        # we have to check these first, lest the object type be new
        # and cause an exception.
        if dt[2] in self.wrapper.javaserver.entity_control.objecttypes:
            objectname = self.wrapper.javaserver.entity_control.objecttypes[
                dt[2]]
            newobject = {
                dt[0]:
                Entity(dt[0], entityuuid, dt[2], objectname, (
                    dt[3],
                    dt[4],
                    dt[5],
                ), (dt[6], dt[7]), True, self.client.username)
            }

            # in many places here, we could have used another self definition
            # like self.entities = self.wrapper.javaserver..., but we chose
            # not to to make sure (given the lagacy complexity of the code)
            # that we remember where all these classes and methods are
            # in the code and to keep a mental picture of the code layout.
            self.wrapper.javaserver.entity_control.entities.update(newobject)
        return True