Exemplo n.º 1
0
 @Override
 public void write(org.apache.thrift.protocol.TProtocol prot, BlockInfo struct)
     throws org.apache.thrift.TException {
   TTupleProtocol oprot = (TTupleProtocol) prot;
   BitSet optionals = new BitSet();
   if (struct.isSetBlockId()) {
     optionals.set(0);
   }
   if (struct.isSetLength()) {
     optionals.set(1);
   }
   if (struct.isSetLocations()) {
     optionals.set(2);
   }
   oprot.writeBitSet(optionals, 3);
   if (struct.isSetBlockId()) {
     oprot.writeI64(struct.blockId);
   }
   if (struct.isSetLength()) {
     oprot.writeI64(struct.length);
   }
   if (struct.isSetLocations()) {
     {
       oprot.writeI32(struct.locations.size());
       for (BlockLocation _iter4 : struct.locations) {
         _iter4.write(oprot);
       }
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, BlockInfo struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   BitSet incoming = iprot.readBitSet(3);
   if (incoming.get(0)) {
     struct.blockId = iprot.readI64();
     struct.setBlockIdIsSet(true);
   }
   if (incoming.get(1)) {
     struct.length = iprot.readI64();
     struct.setLengthIsSet(true);
   }
   if (incoming.get(2)) {
     {
       org.apache.thrift.protocol.TList _list5 =
           new org.apache.thrift.protocol.TList(
               org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
       struct.locations = new ArrayList<BlockLocation>(_list5.size);
       BlockLocation _elem6;
       for (int _i7 = 0; _i7 < _list5.size; ++_i7) {
         _elem6 = new BlockLocation();
         _elem6.read(iprot);
         struct.locations.add(_elem6);
       }
     }
     struct.setLocationsIsSet(true);
   }
 }
Exemplo n.º 3
0
    public void write(org.apache.thrift.protocol.TProtocol oprot, BlockInfo struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(BLOCK_ID_FIELD_DESC);
      oprot.writeI64(struct.blockId);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(LENGTH_FIELD_DESC);
      oprot.writeI64(struct.length);
      oprot.writeFieldEnd();
      if (struct.locations != null) {
        oprot.writeFieldBegin(LOCATIONS_FIELD_DESC);
        {
          oprot.writeListBegin(
              new org.apache.thrift.protocol.TList(
                  org.apache.thrift.protocol.TType.STRUCT, struct.locations.size()));
          for (BlockLocation _iter3 : struct.locations) {
            _iter3.write(oprot);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
Exemplo n.º 4
0
 public ProtectionRegenTask GetProtectionRegenTask(BlockLocation blockLocation) {
   for (BlockLocation location : protectionRegenTasks.keySet()) {
     if (location.isLocation(blockLocation)) {
       return protectionRegenTasks.get(location);
     }
   }
   return null;
 }
Exemplo n.º 5
0
 public boolean hasProtectionRegenTask(BlockLocation blockLocation) {
   for (BlockLocation location : protectionRegenTasks.keySet()) {
     if (location.isLocation(blockLocation)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 6
0
    public void read(org.apache.thrift.protocol.TProtocol iprot, BlockInfo struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // BLOCK_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
              struct.blockId = iprot.readI64();
              struct.setBlockIdIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // LENGTH
            if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
              struct.length = iprot.readI64();
              struct.setLengthIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // LOCATIONS
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
                struct.locations = new ArrayList<BlockLocation>(_list0.size);
                BlockLocation _elem1;
                for (int _i2 = 0; _i2 < _list0.size; ++_i2) {
                  _elem1 = new BlockLocation();
                  _elem1.read(iprot);
                  struct.locations.add(_elem1);
                }
                iprot.readListEnd();
              }
              struct.setLocationsIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }
Exemplo n.º 7
0
 public void face(BlockLocation target, int face) {
   BlockLocation offset = getOffsetBlock(target, face);
   if (offset == null) {
     face(target);
     return;
   }
   double x = offset.getX() + ((target.getX() - offset.getX()) / 2.0D) + 0.5;
   double y = offset.getY() + ((target.getY() - offset.getY()) / 2.0D);
   double z = offset.getZ() + ((target.getZ() - offset.getZ()) / 2.0D) + 0.5;
   face(x, y, z);
 }
Exemplo n.º 8
0
 private BlockLocation getOffsetBlock(BlockLocation location, int face) {
   int x = location.getX(), y = location.getY(), z = location.getZ();
   switch (face) {
     case 0:
       return new BlockLocation(x, y + 1, z);
     case 1:
       return new BlockLocation(x, y - 1, z);
     case 2:
       return new BlockLocation(x, y, z + 1);
     case 3:
       return new BlockLocation(x, y, z - 1);
     case 4:
       return new BlockLocation(x + 1, y, z);
     case 5:
       return new BlockLocation(x - 1, y, z);
     default:
       return null;
   }
 }
Exemplo n.º 9
0
 @Override
 public void setBlockMetadataAt(int metadata, BlockLocation blockLocation) {
   ChunkLocation location = new ChunkLocation(blockLocation);
   BlockLocation chunkBlockOffset = new BlockLocation(location);
   Chunk chunk = getChunkAt(location);
   if (chunk == null) return;
   chunk.setBlockMetadataAt(
       metadata,
       blockLocation.getX() - chunkBlockOffset.getX(),
       blockLocation.getY() - chunkBlockOffset.getY(),
       blockLocation.getZ() - chunkBlockOffset.getZ());
 }
Exemplo n.º 10
0
 @Override
 public int getBlockMetadataAt(BlockLocation blockLocation) {
   ChunkLocation location = new ChunkLocation(blockLocation);
   BlockLocation chunkBlockOffset = new BlockLocation(location);
   Chunk chunk = getChunkAt(location);
   if (chunk == null) return 0;
   int metadata =
       chunk.getBlockMetadataAt(
           blockLocation.getX() - chunkBlockOffset.getX(),
           blockLocation.getY() - chunkBlockOffset.getY(),
           blockLocation.getZ() - chunkBlockOffset.getZ());
   return metadata;
 }
Exemplo n.º 11
0
 @Override
 public Block getBlockAt(BlockLocation location) {
   ChunkLocation chunkLocation = new ChunkLocation(location);
   Chunk chunk = getChunkAt(chunkLocation);
   if (chunk == null) return null;
   BlockLocation chunkBlockOffset = new BlockLocation(chunkLocation);
   int chunkOffsetX = location.getX() - chunkBlockOffset.getX();
   int chunkOffsetY = location.getY() - chunkBlockOffset.getY();
   int chunkOffsetZ = location.getZ() - chunkBlockOffset.getZ();
   int id = chunk.getBlockIdAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ);
   int metadata = chunk.getBlockMetadataAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ);
   return new Block(this, chunk, location, id, metadata);
 }
Exemplo n.º 12
0
 public void face(BlockLocation target) {
   face(target.getX() + 0.5, target.getY() + 0.5, target.getZ() + 0.5);
 }