public void addEnderBookRecipe(int recipe) {
   if (!hasEnderBookRecipe(recipe)) {
     enderbookRecipes = Arrays.copyOf(enderbookRecipes, enderbookRecipes.length + 1);
     enderbookRecipes[enderbookRecipes.length - 1] = UnsignedBytes.checkedCast(recipe);
     setDirty();
   }
 }
    private int validateAndClaimId(int id)
    {
        // workaround for broken ML
        int realId = id;
        if (id < Byte.MIN_VALUE)
        {
            FMLLog.warning("Compensating for modloader out of range compensation by mod : entityId %d for mod %s is now %d", id, Loader.instance().activeModContainer().getModId(), realId);
            realId += 3000;
        }

        if (realId < 0)
        {
            realId += Byte.MAX_VALUE;
        }
        try
        {
            UnsignedBytes.checkedCast(realId);
        }
        catch (IllegalArgumentException e)
        {
            FMLLog.log(Level.SEVERE, "The entity ID %d for mod %s is not an unsigned byte and may not work", id, Loader.instance().activeModContainer().getModId());
        }

        if (!availableIndicies.get(realId))
        {
            FMLLog.severe("The mod %s has attempted to register an entity ID %d which is already reserved. This could cause severe problems", Loader.instance().activeModContainer().getModId(), id);
        }
        availableIndicies.clear(realId);
        return realId;
    }
 @Override
 public byte getTag(final Object o) {
   if (o == null) {
     return -1;
   }
   final TFieldIdEnum setField =
       ((TUnion<? extends TUnion<?, ?>, ? extends TFieldIdEnum>) o).getSetField();
   return UnsignedBytes.checkedCast((setField.getThriftFieldId() - 1));
 }
  /**
   * Converts a BufferedImage into a ByteBuffer based on 32-bit values in RGBA byte order
   *
   * @param image any type of BufferedImage
   * @return a ByteBuffer that contains the data in RGBA byte order
   */
  public static ByteBuffer convertToByteBuffer(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    ByteBuffer data = ByteBuffer.allocateDirect(4 * width * height);

    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        int argb = image.getRGB(x, y);
        int r = (argb >> 16) & 0xFF;
        int g = (argb >> 8) & 0xFF;
        int b = argb & 0xFF;
        int a = (argb >> 24) & 0xFF;
        data.put(UnsignedBytes.checkedCast(r));
        data.put(UnsignedBytes.checkedCast(g));
        data.put(UnsignedBytes.checkedCast(b));
        data.put(UnsignedBytes.checkedCast(a));
      }
    }
    data.rewind();
    return data;
  }
Exemple #5
0
 /**
  * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
  * serialization). This has been measured to save at least 400 bytes compared to regular
  * serialization.
  *
  * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
  */
 public void writeTo(OutputStream out) throws IOException {
   // Serial form:
   // 1 signed byte for the strategy
   // 1 unsigned byte for the number of hash functions
   // 1 big endian int, the number of longs in our bitset
   // N big endian longs of our bitset
   DataOutputStream dout = new DataOutputStream(out);
   dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
   dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
   dout.writeInt(bits.data.length);
   for (long value : bits.data) {
     dout.writeLong(value);
   }
 }
 public static void serialiseKey(Key key, ByteBuf w) {
   byte[] id = key.getArray();
   BitBuffer bbuf = BitBuffer.create((key instanceof Key.Inf), (id == null));
   boolean byteFlag = (id != null) && (id.length <= Key.BYTE_KEY_SIZE);
   bbuf.write(byteFlag);
   byte[] flags = bbuf.finalise();
   w.writeBytes(flags);
   if (id != null) {
     if (byteFlag) {
       w.writeByte(UnsignedBytes.checkedCast(id.length));
     } else {
       w.writeInt(id.length);
     }
     w.writeBytes(id);
   }
 }
Exemple #7
0
 @Nonnull
 public static <T extends Enum<T> & Code.Wrapper> T fromInt(
     @Nonnull Class<T> type, @Nonnegative int code) {
   return fromByte(type, UnsignedBytes.checkedCast(code));
 }
 public boolean hasEnderBookRecipe(int recipe) {
   return Bytes.contains(enderbookRecipes, UnsignedBytes.checkedCast(recipe));
 }