Exemple #1
0
  /**
   * Write to the NBT tile entity in the given block.
   *
   * @param target - the target block.
   * @param blockState - the new tile entity.
   * @throws IllegalArgumentException If the block doesn't contain a tile entity.
   */
  public static void writeBlockState(Block target, NbtCompound blockState) {
    BlockState state = target.getState();
    TileEntityAccessor<BlockState> accessor = TileEntityAccessor.getAccessor(state);

    if (accessor != null) {
      accessor.writeBlockState(state, blockState);
    } else {
      throw new IllegalArgumentException("Unable to find tile entity in " + target);
    }
  }
Exemple #2
0
  /**
   * Retrieve the NBT tile entity that represents the given block.
   *
   * @param block - the block.
   * @return The NBT compound, or NULL if the state doesn't have a tile entity.
   */
  public static NbtCompound readBlockState(Block block) {
    BlockState state = block.getState();
    TileEntityAccessor<BlockState> accessor = TileEntityAccessor.getAccessor(state);

    return accessor != null ? accessor.readBlockState(state) : null;
  }